mirror of
https://github.com/PepperDash/PepperDashCore.git
synced 2026-02-16 21:24:43 +00:00
Work in progress. Add EventArgs.cs to root of PepperDash core, exposing the event arg classes to everything in PDC
This commit is contained in:
172
Pepperdash Core/Pepperdash Core/EventArgs.cs
Normal file
172
Pepperdash Core/Pepperdash Core/EventArgs.cs
Normal file
@@ -0,0 +1,172 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using Crestron.SimplSharp;
|
||||||
|
|
||||||
|
namespace PepperDash.Core
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Bool change event args
|
||||||
|
/// </summary>
|
||||||
|
public class BoolChangeEventArgs : EventArgs
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Boolean state property
|
||||||
|
/// </summary>
|
||||||
|
public bool State { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Boolean ushort value property
|
||||||
|
/// </summary>
|
||||||
|
public ushort IntValue { get { return (ushort)(State ? 1 : 0); } }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Boolean change event args type
|
||||||
|
/// </summary>
|
||||||
|
public ushort Type { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Boolean change event args index
|
||||||
|
/// </summary>
|
||||||
|
public ushort Index { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor
|
||||||
|
/// </summary>
|
||||||
|
public BoolChangeEventArgs()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor overload
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="state"></param>
|
||||||
|
/// <param name="type"></param>
|
||||||
|
public BoolChangeEventArgs(bool state, ushort type)
|
||||||
|
{
|
||||||
|
State = state;
|
||||||
|
Type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor overload
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="state"></param>
|
||||||
|
/// <param name="type"></param>
|
||||||
|
/// <param name="index"></param>
|
||||||
|
public BoolChangeEventArgs(bool state, ushort type, ushort index)
|
||||||
|
{
|
||||||
|
State = state;
|
||||||
|
Type = type;
|
||||||
|
Index = index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ushort change event args
|
||||||
|
/// </summary>
|
||||||
|
public class UshrtChangeEventArgs : EventArgs
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Ushort change event args integer value
|
||||||
|
/// </summary>
|
||||||
|
public ushort IntValue { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ushort change event args type
|
||||||
|
/// </summary>
|
||||||
|
public ushort Type { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ushort change event args index
|
||||||
|
/// </summary>
|
||||||
|
public ushort Index { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor
|
||||||
|
/// </summary>
|
||||||
|
public UshrtChangeEventArgs()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor overload
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="intValue"></param>
|
||||||
|
/// <param name="type"></param>
|
||||||
|
public UshrtChangeEventArgs(ushort intValue, ushort type)
|
||||||
|
{
|
||||||
|
IntValue = intValue;
|
||||||
|
Type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor overload
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="intValue"></param>
|
||||||
|
/// <param name="type"></param>
|
||||||
|
/// <param name="index"></param>
|
||||||
|
public UshrtChangeEventArgs(ushort intValue, ushort type, ushort index)
|
||||||
|
{
|
||||||
|
IntValue = intValue;
|
||||||
|
Type = type;
|
||||||
|
Index = index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// String change event args
|
||||||
|
/// </summary>
|
||||||
|
public class StringChangeEventArgs : EventArgs
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// String change event args value
|
||||||
|
/// </summary>
|
||||||
|
public string StringValue { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// String change event args type
|
||||||
|
/// </summary>
|
||||||
|
public ushort Type { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// string change event args index
|
||||||
|
/// </summary>
|
||||||
|
public ushort Index { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor
|
||||||
|
/// </summary>
|
||||||
|
public StringChangeEventArgs()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor overload
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="stringValue"></param>
|
||||||
|
/// <param name="type"></param>
|
||||||
|
public StringChangeEventArgs(string stringValue, ushort type)
|
||||||
|
{
|
||||||
|
StringValue = stringValue;
|
||||||
|
Type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor overload
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="stringValue"></param>
|
||||||
|
/// <param name="type"></param>
|
||||||
|
/// <param name="index"></param>
|
||||||
|
public StringChangeEventArgs(string stringValue, ushort type, ushort index)
|
||||||
|
{
|
||||||
|
StringValue = stringValue;
|
||||||
|
Type = type;
|
||||||
|
Index = index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using Crestron.SimplSharp;
|
||||||
|
|
||||||
|
namespace PepperDash.Core.GenericRESTfulCommunications
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Constants
|
||||||
|
/// </summary>
|
||||||
|
public class GenericRESTfulConstants
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Generic boolean change
|
||||||
|
/// </summary>
|
||||||
|
public const ushort BoolValueChange = 1;
|
||||||
|
/// <summary>
|
||||||
|
/// Generic Ushort change
|
||||||
|
/// </summary>
|
||||||
|
public const ushort UshrtValueChange = 101;
|
||||||
|
/// <summary>
|
||||||
|
/// Response Code Ushort change
|
||||||
|
/// </summary>
|
||||||
|
public const ushort ResponseCodeChange = 102;
|
||||||
|
/// <summary>
|
||||||
|
/// Generic String chagne
|
||||||
|
/// </summary>
|
||||||
|
public const ushort StringValueChange = 201;
|
||||||
|
/// <summary>
|
||||||
|
/// Response string change
|
||||||
|
/// </summary>
|
||||||
|
public const ushort ResponseStringChange = 202;
|
||||||
|
/// <summary>
|
||||||
|
/// Error string change
|
||||||
|
/// </summary>
|
||||||
|
public const ushort ErrorStringChange = 203;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,253 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using Crestron.SimplSharp;
|
||||||
|
using Crestron.SimplSharp.Net.Http;
|
||||||
|
using Crestron.SimplSharp.Net.Https;
|
||||||
|
|
||||||
|
namespace PepperDash.Core.GenericRESTfulCommunications
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Generic RESTful communication class
|
||||||
|
/// </summary>
|
||||||
|
public class GenericRESTfulClient
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Boolean event handler
|
||||||
|
/// </summary>
|
||||||
|
public event EventHandler<BoolChangeEventArgs> BoolChange;
|
||||||
|
/// <summary>
|
||||||
|
/// Ushort event handler
|
||||||
|
/// </summary>
|
||||||
|
public event EventHandler<UshrtChangeEventArgs> UshrtChange;
|
||||||
|
/// <summary>
|
||||||
|
/// String event handler
|
||||||
|
/// </summary>
|
||||||
|
public event EventHandler<StringChangeEventArgs> StringChange;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor
|
||||||
|
/// </summary>
|
||||||
|
public GenericRESTfulClient()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Generic RESTful submit request
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="url"></param>
|
||||||
|
/// <param name="port"></param>
|
||||||
|
/// <param name="requestType"></param>
|
||||||
|
/// <param name="username"></param>
|
||||||
|
/// <param name="password"></param>
|
||||||
|
public void SubmitRequest(string url, ushort port, ushort requestType, string contentType, string username, string password)
|
||||||
|
{
|
||||||
|
if (url.StartsWith("https:", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
SubmitRequestHttps(url, port, requestType, contentType, username, password);
|
||||||
|
}
|
||||||
|
else if (url.StartsWith("http:", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
SubmitRequestHttp(url, port, requestType, contentType, username, password);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
OnStringChange(string.Format("Invalid URL {0}", url), 0, GenericRESTfulConstants.ErrorStringChange);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Private HTTP submit request
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="url"></param>
|
||||||
|
/// <param name="port"></param>
|
||||||
|
/// <param name="requestType"></param>
|
||||||
|
/// <param name="username"></param>
|
||||||
|
/// <param name="password"></param>
|
||||||
|
private void SubmitRequestHttp(string url, ushort port, ushort requestType, string contentType, string username, string password)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
HttpClient client = new HttpClient();
|
||||||
|
HttpClientRequest request = new HttpClientRequest();
|
||||||
|
HttpClientResponse response;
|
||||||
|
|
||||||
|
client.KeepAlive = false;
|
||||||
|
|
||||||
|
if(port >= 1 || port <= 65535)
|
||||||
|
client.Port = port;
|
||||||
|
else
|
||||||
|
client.Port = 80;
|
||||||
|
|
||||||
|
var authorization = "";
|
||||||
|
if (!string.IsNullOrEmpty(username))
|
||||||
|
authorization = EncodeBase64(username, password);
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(authorization))
|
||||||
|
request.Header.SetHeaderValue("Authorization", authorization);
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(contentType))
|
||||||
|
request.Header.ContentType = contentType;
|
||||||
|
|
||||||
|
request.Url.Parse(url);
|
||||||
|
request.RequestType = (Crestron.SimplSharp.Net.Http.RequestType)requestType;
|
||||||
|
|
||||||
|
response = client.Dispatch(request);
|
||||||
|
|
||||||
|
CrestronConsole.PrintLine(string.Format("SubmitRequestHttp Response[{0}]: {1}", response.Code, response.ContentString.ToString()));
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(response.ContentString.ToString()))
|
||||||
|
OnStringChange(response.ContentString.ToString(), 0, GenericRESTfulConstants.ResponseStringChange);
|
||||||
|
|
||||||
|
if (response.Code > 0)
|
||||||
|
OnUshrtChange((ushort)response.Code, 0, GenericRESTfulConstants.ResponseCodeChange);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
//var msg = string.Format("SubmitRequestHttp({0}, {1}, {2}) failed:{3}", url, port, requestType, e.Message);
|
||||||
|
//CrestronConsole.PrintLine(msg);
|
||||||
|
//ErrorLog.Error(msg);
|
||||||
|
|
||||||
|
CrestronConsole.PrintLine(e.Message);
|
||||||
|
OnStringChange(e.Message, 0, GenericRESTfulConstants.ErrorStringChange);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Private HTTPS submit request
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="url"></param>
|
||||||
|
/// <param name="port"></param>
|
||||||
|
/// <param name="requestType"></param>
|
||||||
|
/// <param name="username"></param>
|
||||||
|
/// <param name="password"></param>
|
||||||
|
private void SubmitRequestHttps(string url, ushort port, ushort requestType, string contentType, string username, string password)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
HttpsClient client = new HttpsClient();
|
||||||
|
HttpsClientRequest request = new HttpsClientRequest();
|
||||||
|
HttpsClientResponse response;
|
||||||
|
|
||||||
|
client.KeepAlive = false;
|
||||||
|
client.HostVerification = false;
|
||||||
|
client.PeerVerification = false;
|
||||||
|
|
||||||
|
var authorization = "";
|
||||||
|
if (!string.IsNullOrEmpty(username))
|
||||||
|
authorization = EncodeBase64(username, password);
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(authorization))
|
||||||
|
request.Header.SetHeaderValue("Authorization", authorization);
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(contentType))
|
||||||
|
request.Header.ContentType = contentType;
|
||||||
|
|
||||||
|
request.Url.Parse(url);
|
||||||
|
request.RequestType = (Crestron.SimplSharp.Net.Https.RequestType)requestType;
|
||||||
|
|
||||||
|
response = client.Dispatch(request);
|
||||||
|
|
||||||
|
CrestronConsole.PrintLine(string.Format("SubmitRequestHttp Response[{0}]: {1}", response.Code, response.ContentString.ToString()));
|
||||||
|
|
||||||
|
if(!string.IsNullOrEmpty(response.ContentString.ToString()))
|
||||||
|
OnStringChange(response.ContentString.ToString(), 0, GenericRESTfulConstants.ResponseStringChange);
|
||||||
|
|
||||||
|
if(response.Code > 0)
|
||||||
|
OnUshrtChange((ushort)response.Code, 0, GenericRESTfulConstants.ResponseCodeChange);
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
//var msg = string.Format("SubmitRequestHttps({0}, {1}, {2}, {3}, {4}) failed:{5}", url, port, requestType, username, password, e.Message);
|
||||||
|
//CrestronConsole.PrintLine(msg);
|
||||||
|
//ErrorLog.Error(msg);
|
||||||
|
|
||||||
|
CrestronConsole.PrintLine(e.Message);
|
||||||
|
OnStringChange(e.Message, 0, GenericRESTfulConstants.ErrorStringChange);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Private method to encode username and password to Base64 string
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="username"></param>
|
||||||
|
/// <param name="password"></param>
|
||||||
|
/// <returns>authorization</returns>
|
||||||
|
private string EncodeBase64(string username, string password)
|
||||||
|
{
|
||||||
|
var authorization = "";
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrEmpty(username))
|
||||||
|
{
|
||||||
|
string base64String = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(string.Format("{0}:{1}", username, password)));
|
||||||
|
authorization = string.Format("Basic {0}", base64String);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
var msg = string.Format("EncodeBase64({0}, {1}) failed:\r{2}", username, password, e);
|
||||||
|
CrestronConsole.PrintLine(msg);
|
||||||
|
ErrorLog.Error(msg);
|
||||||
|
return "" ;
|
||||||
|
}
|
||||||
|
|
||||||
|
return authorization;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Protected method to handle boolean change events
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="state"></param>
|
||||||
|
/// <param name="index"></param>
|
||||||
|
/// <param name="type"></param>
|
||||||
|
protected void OnBoolChange(bool state, ushort index, ushort type)
|
||||||
|
{
|
||||||
|
var handler = BoolChange;
|
||||||
|
if (handler != null)
|
||||||
|
{
|
||||||
|
var args = new BoolChangeEventArgs(state, type);
|
||||||
|
args.Index = index;
|
||||||
|
BoolChange(this, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Protected mehtod to handle ushort change events
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
/// <param name="index"></param>
|
||||||
|
/// <param name="type"></param>
|
||||||
|
protected void OnUshrtChange(ushort value, ushort index, ushort type)
|
||||||
|
{
|
||||||
|
var handler = UshrtChange;
|
||||||
|
if (handler != null)
|
||||||
|
{
|
||||||
|
var args = new UshrtChangeEventArgs(value, type);
|
||||||
|
args.Index = index;
|
||||||
|
UshrtChange(this, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Protected method to handle string change events
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
/// <param name="index"></param>
|
||||||
|
/// <param name="type"></param>
|
||||||
|
protected void OnStringChange(string value, ushort index, ushort type)
|
||||||
|
{
|
||||||
|
var handler = StringChange;
|
||||||
|
if (handler != null)
|
||||||
|
{
|
||||||
|
var args = new StringChangeEventArgs(value, type);
|
||||||
|
args.Index = index;
|
||||||
|
StringChange(this, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,36 +6,46 @@ using Crestron.SimplSharp;
|
|||||||
|
|
||||||
namespace PepperDash.Core.JsonStandardObjects
|
namespace PepperDash.Core.JsonStandardObjects
|
||||||
{
|
{
|
||||||
#region Constants
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constants for simpl modules
|
/// Constants for simpl modules
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class JsonStandardDeviceConstants
|
public class JsonStandardDeviceConstants
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Json object evaluated constant
|
||||||
|
/// </summary>
|
||||||
public const ushort JsonObjectEvaluated = 2;
|
public const ushort JsonObjectEvaluated = 2;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Json object changed constant
|
||||||
|
/// </summary>
|
||||||
public const ushort JsonObjectChanged = 104;
|
public const ushort JsonObjectChanged = 104;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion Constants
|
|
||||||
|
|
||||||
|
|
||||||
#region ObjectChangeEventArgs
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class ObjectChangeEventArgs : EventArgs
|
public class DeviceChangeEventArgs : EventArgs
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Device change event args object
|
||||||
|
/// </summary>
|
||||||
public DeviceConfig Device { get; set; }
|
public DeviceConfig Device { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Device change event args type
|
||||||
|
/// </summary>
|
||||||
public ushort Type { get; set; }
|
public ushort Type { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Device change event args index
|
||||||
|
/// </summary>
|
||||||
public ushort Index { get; set; }
|
public ushort Index { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Default constructor
|
/// Default constructor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ObjectChangeEventArgs()
|
public DeviceChangeEventArgs()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -45,7 +55,7 @@ namespace PepperDash.Core.JsonStandardObjects
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="device"></param>
|
/// <param name="device"></param>
|
||||||
/// <param name="type"></param>
|
/// <param name="type"></param>
|
||||||
public ObjectChangeEventArgs(DeviceConfig device, ushort type)
|
public DeviceChangeEventArgs(DeviceConfig device, ushort type)
|
||||||
{
|
{
|
||||||
Device = device;
|
Device = device;
|
||||||
Type = type;
|
Type = type;
|
||||||
@@ -57,13 +67,11 @@ namespace PepperDash.Core.JsonStandardObjects
|
|||||||
/// <param name="device"></param>
|
/// <param name="device"></param>
|
||||||
/// <param name="type"></param>
|
/// <param name="type"></param>
|
||||||
/// <param name="index"></param>
|
/// <param name="index"></param>
|
||||||
public ObjectChangeEventArgs(DeviceConfig device, ushort type, ushort index)
|
public DeviceChangeEventArgs(DeviceConfig device, ushort type, ushort index)
|
||||||
{
|
{
|
||||||
Device = device;
|
Device = device;
|
||||||
Type = type;
|
Type = type;
|
||||||
Index = index;
|
Index = index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion ObjectChangeEventArgs
|
|
||||||
}
|
}
|
||||||
@@ -9,52 +9,10 @@ using PepperDash.Core.JsonToSimpl;
|
|||||||
|
|
||||||
namespace PepperDash.Core.JsonStandardObjects
|
namespace PepperDash.Core.JsonStandardObjects
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
Convert JSON snippt to C#: http://json2csharp.com/#
|
|
||||||
|
|
||||||
JSON Snippet:
|
|
||||||
{
|
|
||||||
"devices": [
|
|
||||||
{
|
|
||||||
"key": "deviceKey",
|
|
||||||
"name": "deviceName",
|
|
||||||
"type": "deviceType",
|
|
||||||
"properties": {
|
|
||||||
"deviceId": 1,
|
|
||||||
"enabled": true,
|
|
||||||
"control": {
|
|
||||||
"method": "methodName",
|
|
||||||
"controlPortDevKey": "deviceControlPortDevKey",
|
|
||||||
"controlPortNumber": 1,
|
|
||||||
"comParams": {
|
|
||||||
"baudRate": 9600,
|
|
||||||
"dataBits": 8,
|
|
||||||
"stopBits": 1,
|
|
||||||
"parity": "None",
|
|
||||||
"protocol": "RS232",
|
|
||||||
"hardwareHandshake": "None",
|
|
||||||
"softwareHandshake": "None",
|
|
||||||
"pacing": 0
|
|
||||||
},
|
|
||||||
"tcpSshProperties": {
|
|
||||||
"address": "172.22.1.101",
|
|
||||||
"port": 23,
|
|
||||||
"username": "user01",
|
|
||||||
"password": "password01",
|
|
||||||
"autoReconnect": false,
|
|
||||||
"autoReconnectIntervalMs": 10000
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Device class
|
/// Device class
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class DeviceConfig : JsonToSimplChildObjectBase
|
public class DeviceConfig
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// JSON config key property
|
/// JSON config key property
|
||||||
@@ -88,7 +46,7 @@ namespace PepperDash.Core.JsonStandardObjects
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Object change event handler
|
/// Object change event handler
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public event EventHandler<ObjectChangeEventArgs> ObjectChange;
|
public event EventHandler<DeviceChangeEventArgs> DeviceChange;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructor
|
/// Constructor
|
||||||
@@ -164,7 +122,8 @@ namespace PepperDash.Core.JsonStandardObjects
|
|||||||
/// <param name="type"></param>
|
/// <param name="type"></param>
|
||||||
protected void OnBoolChange(bool state, ushort index, ushort type)
|
protected void OnBoolChange(bool state, ushort index, ushort type)
|
||||||
{
|
{
|
||||||
if (BoolChange != null)
|
var handler = BoolChange;
|
||||||
|
if (handler != null)
|
||||||
{
|
{
|
||||||
var args = new BoolChangeEventArgs(state, type);
|
var args = new BoolChangeEventArgs(state, type);
|
||||||
args.Index = index;
|
args.Index = index;
|
||||||
@@ -180,7 +139,8 @@ namespace PepperDash.Core.JsonStandardObjects
|
|||||||
/// <param name="type"></param>
|
/// <param name="type"></param>
|
||||||
protected void OnUshrtChange(ushort state, ushort index, ushort type)
|
protected void OnUshrtChange(ushort state, ushort index, ushort type)
|
||||||
{
|
{
|
||||||
if (UshrtChange != null)
|
var handler = UshrtChange;
|
||||||
|
if (handler != null)
|
||||||
{
|
{
|
||||||
var args = new UshrtChangeEventArgs(state, type);
|
var args = new UshrtChangeEventArgs(state, type);
|
||||||
args.Index = index;
|
args.Index = index;
|
||||||
@@ -196,7 +156,8 @@ namespace PepperDash.Core.JsonStandardObjects
|
|||||||
/// <param name="type"></param>
|
/// <param name="type"></param>
|
||||||
protected void OnStringChange(string value, ushort index, ushort type)
|
protected void OnStringChange(string value, ushort index, ushort type)
|
||||||
{
|
{
|
||||||
if (StringChange != null)
|
var handler = StringChange;
|
||||||
|
if (handler != null)
|
||||||
{
|
{
|
||||||
var args = new StringChangeEventArgs(value, type);
|
var args = new StringChangeEventArgs(value, type);
|
||||||
args.Index = index;
|
args.Index = index;
|
||||||
@@ -212,127 +173,14 @@ namespace PepperDash.Core.JsonStandardObjects
|
|||||||
/// <param name="type"></param>
|
/// <param name="type"></param>
|
||||||
protected void OnObjectChange(DeviceConfig device, ushort index, ushort type)
|
protected void OnObjectChange(DeviceConfig device, ushort index, ushort type)
|
||||||
{
|
{
|
||||||
if (ObjectChange != null)
|
if (DeviceChange != null)
|
||||||
{
|
{
|
||||||
var args = new ObjectChangeEventArgs(device, type);
|
var args = new DeviceChangeEventArgs(device, type);
|
||||||
args.Index = index;
|
args.Index = index;
|
||||||
ObjectChange(this, args);
|
DeviceChange(this, args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion EventHandler Helpers
|
#endregion EventHandler Helpers
|
||||||
}
|
}
|
||||||
|
|
||||||
#region JSON Configuration Classes
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Device communication parameter class
|
|
||||||
/// </summary>
|
|
||||||
public class ComParamsConfig
|
|
||||||
{
|
|
||||||
public int baudRate { get; set; }
|
|
||||||
public int dataBits { get; set; }
|
|
||||||
public int stopBits { get; set; }
|
|
||||||
public string parity { get; set; }
|
|
||||||
public string protocol { get; set; }
|
|
||||||
public string hardwareHandshake { get; set; }
|
|
||||||
public string softwareHandshake { get; set; }
|
|
||||||
public int pacing { get; set; }
|
|
||||||
|
|
||||||
// convert properties for simpl
|
|
||||||
public ushort simplBaudRate { get { return Convert.ToUInt16(baudRate); } }
|
|
||||||
public ushort simplDataBits { get { return Convert.ToUInt16(dataBits); } }
|
|
||||||
public ushort simplStopBits { get { return Convert.ToUInt16(stopBits); } }
|
|
||||||
public ushort simplPacing { get { return Convert.ToUInt16(pacing); } }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Constructor
|
|
||||||
/// </summary>
|
|
||||||
public ComParamsConfig()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Device TCP/SSH properties class
|
|
||||||
/// </summary>
|
|
||||||
public class TcpSshPropertiesConfig
|
|
||||||
{
|
|
||||||
public string address { get; set; }
|
|
||||||
public int port { get; set; }
|
|
||||||
public string username { get; set; }
|
|
||||||
public string password { get; set; }
|
|
||||||
public bool autoReconnect { get; set; }
|
|
||||||
public int autoReconnectIntervalMs { get; set; }
|
|
||||||
|
|
||||||
// convert properties for simpl
|
|
||||||
public ushort simplPort { get { return Convert.ToUInt16(port); } }
|
|
||||||
public ushort simplAutoReconnect { get { return (ushort)(autoReconnect ? 1 : 0); } }
|
|
||||||
public ushort simplAutoReconnectIntervalMs { get { return Convert.ToUInt16(autoReconnectIntervalMs); } }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Constructor
|
|
||||||
/// </summary>
|
|
||||||
public TcpSshPropertiesConfig()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Device control class
|
|
||||||
/// </summary>
|
|
||||||
public class ControlConfig
|
|
||||||
{
|
|
||||||
public string method { get; set; }
|
|
||||||
public string controlPortDevKey { get; set; }
|
|
||||||
public int controlPortNumber { get; set; }
|
|
||||||
public ComParamsConfig comParams { get; set; }
|
|
||||||
public TcpSshPropertiesConfig tcpSshProperties { get; set; }
|
|
||||||
|
|
||||||
// convert properties for simpl
|
|
||||||
public ushort simplControlPortNumber { get { return Convert.ToUInt16(controlPortNumber); } }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Constructor
|
|
||||||
/// </summary>
|
|
||||||
public ControlConfig()
|
|
||||||
{
|
|
||||||
comParams = new ComParamsConfig();
|
|
||||||
tcpSshProperties = new TcpSshPropertiesConfig();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Device properties class
|
|
||||||
/// </summary>
|
|
||||||
public class PropertiesConfig
|
|
||||||
{
|
|
||||||
public int deviceId { get; set; }
|
|
||||||
public bool enabled { get; set; }
|
|
||||||
public ControlConfig control { get; set; }
|
|
||||||
|
|
||||||
// convert properties for simpl
|
|
||||||
public ushort simplDeviceId { get { return Convert.ToUInt16(deviceId); } }
|
|
||||||
public ushort simplEnabled { get { return (ushort)(enabled ? 1 : 0); } }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Constructor
|
|
||||||
/// </summary>
|
|
||||||
public PropertiesConfig()
|
|
||||||
{
|
|
||||||
control = new ControlConfig();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Root device class
|
|
||||||
/// </summary>
|
|
||||||
public class RootObject
|
|
||||||
{
|
|
||||||
public List<DeviceConfig> devices { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion JSON Configuration Classes
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,158 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using Crestron.SimplSharp;
|
||||||
|
|
||||||
|
namespace PepperDash.Core.JsonStandardObjects
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
Convert JSON snippt to C#: http://json2csharp.com/#
|
||||||
|
|
||||||
|
JSON Snippet:
|
||||||
|
{
|
||||||
|
"devices": [
|
||||||
|
{
|
||||||
|
"key": "deviceKey",
|
||||||
|
"name": "deviceName",
|
||||||
|
"type": "deviceType",
|
||||||
|
"properties": {
|
||||||
|
"deviceId": 1,
|
||||||
|
"enabled": true,
|
||||||
|
"control": {
|
||||||
|
"method": "methodName",
|
||||||
|
"controlPortDevKey": "deviceControlPortDevKey",
|
||||||
|
"controlPortNumber": 1,
|
||||||
|
"comParams": {
|
||||||
|
"baudRate": 9600,
|
||||||
|
"dataBits": 8,
|
||||||
|
"stopBits": 1,
|
||||||
|
"parity": "None",
|
||||||
|
"protocol": "RS232",
|
||||||
|
"hardwareHandshake": "None",
|
||||||
|
"softwareHandshake": "None",
|
||||||
|
"pacing": 0
|
||||||
|
},
|
||||||
|
"tcpSshProperties": {
|
||||||
|
"address": "172.22.1.101",
|
||||||
|
"port": 23,
|
||||||
|
"username": "user01",
|
||||||
|
"password": "password01",
|
||||||
|
"autoReconnect": false,
|
||||||
|
"autoReconnectIntervalMs": 10000
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
/// <summary>
|
||||||
|
/// Device communication parameter class
|
||||||
|
/// </summary>
|
||||||
|
public class ComParamsConfig
|
||||||
|
{
|
||||||
|
public int baudRate { get; set; }
|
||||||
|
public int dataBits { get; set; }
|
||||||
|
public int stopBits { get; set; }
|
||||||
|
public string parity { get; set; }
|
||||||
|
public string protocol { get; set; }
|
||||||
|
public string hardwareHandshake { get; set; }
|
||||||
|
public string softwareHandshake { get; set; }
|
||||||
|
public int pacing { get; set; }
|
||||||
|
|
||||||
|
// convert properties for simpl
|
||||||
|
public ushort simplBaudRate { get { return Convert.ToUInt16(baudRate); } }
|
||||||
|
public ushort simplDataBits { get { return Convert.ToUInt16(dataBits); } }
|
||||||
|
public ushort simplStopBits { get { return Convert.ToUInt16(stopBits); } }
|
||||||
|
public ushort simplPacing { get { return Convert.ToUInt16(pacing); } }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor
|
||||||
|
/// </summary>
|
||||||
|
public ComParamsConfig()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Device TCP/SSH properties class
|
||||||
|
/// </summary>
|
||||||
|
public class TcpSshPropertiesConfig
|
||||||
|
{
|
||||||
|
public string address { get; set; }
|
||||||
|
public int port { get; set; }
|
||||||
|
public string username { get; set; }
|
||||||
|
public string password { get; set; }
|
||||||
|
public bool autoReconnect { get; set; }
|
||||||
|
public int autoReconnectIntervalMs { get; set; }
|
||||||
|
|
||||||
|
// convert properties for simpl
|
||||||
|
public ushort simplPort { get { return Convert.ToUInt16(port); } }
|
||||||
|
public ushort simplAutoReconnect { get { return (ushort)(autoReconnect ? 1 : 0); } }
|
||||||
|
public ushort simplAutoReconnectIntervalMs { get { return Convert.ToUInt16(autoReconnectIntervalMs); } }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor
|
||||||
|
/// </summary>
|
||||||
|
public TcpSshPropertiesConfig()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Device control class
|
||||||
|
/// </summary>
|
||||||
|
public class ControlConfig
|
||||||
|
{
|
||||||
|
public string method { get; set; }
|
||||||
|
public string controlPortDevKey { get; set; }
|
||||||
|
public int controlPortNumber { get; set; }
|
||||||
|
public ComParamsConfig comParams { get; set; }
|
||||||
|
public TcpSshPropertiesConfig tcpSshProperties { get; set; }
|
||||||
|
|
||||||
|
// convert properties for simpl
|
||||||
|
public ushort simplControlPortNumber { get { return Convert.ToUInt16(controlPortNumber); } }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor
|
||||||
|
/// </summary>
|
||||||
|
public ControlConfig()
|
||||||
|
{
|
||||||
|
comParams = new ComParamsConfig();
|
||||||
|
tcpSshProperties = new TcpSshPropertiesConfig();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Device properties class
|
||||||
|
/// </summary>
|
||||||
|
public class PropertiesConfig
|
||||||
|
{
|
||||||
|
public int deviceId { get; set; }
|
||||||
|
public bool enabled { get; set; }
|
||||||
|
public ControlConfig control { get; set; }
|
||||||
|
|
||||||
|
// convert properties for simpl
|
||||||
|
public ushort simplDeviceId { get { return Convert.ToUInt16(deviceId); } }
|
||||||
|
public ushort simplEnabled { get { return (ushort)(enabled ? 1 : 0); } }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor
|
||||||
|
/// </summary>
|
||||||
|
public PropertiesConfig()
|
||||||
|
{
|
||||||
|
control = new ControlConfig();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Root device class
|
||||||
|
/// </summary>
|
||||||
|
public class RootObject
|
||||||
|
{
|
||||||
|
public List<DeviceConfig> devices { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
59
Pepperdash Core/Pepperdash Core/JsonToSimpl/Constants.cs
Normal file
59
Pepperdash Core/Pepperdash Core/JsonToSimpl/Constants.cs
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using Crestron.SimplSharp;
|
||||||
|
|
||||||
|
namespace PepperDash.Core.JsonToSimpl
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Constants for Simpl modules
|
||||||
|
/// </summary>
|
||||||
|
public class JsonToSimplConstants
|
||||||
|
{
|
||||||
|
public const ushort BoolValueChange = 1;
|
||||||
|
public const ushort JsonIsValidBoolChange = 2;
|
||||||
|
|
||||||
|
public const ushort UshortValueChange = 101;
|
||||||
|
|
||||||
|
public const ushort StringValueChange = 201;
|
||||||
|
public const ushort FullPathToArrayChange = 202;
|
||||||
|
public const ushort ActualFilePathChange = 203;
|
||||||
|
|
||||||
|
// TODO: pdc-20: Added below constants for passing file path and filename back to S+
|
||||||
|
public const ushort FilenameResolvedChange = 204;
|
||||||
|
public const ushort FilePathResolvedChange = 205;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// S+ values delegate
|
||||||
|
/// </summary>
|
||||||
|
public delegate void SPlusValuesDelegate();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// S+ values wrapper
|
||||||
|
/// </summary>
|
||||||
|
public class SPlusValueWrapper
|
||||||
|
{
|
||||||
|
public SPlusType ValueType { get; private set; }
|
||||||
|
public ushort Index { get; private set; }
|
||||||
|
public ushort BoolUShortValue { get; set; }
|
||||||
|
public string StringValue { get; set; }
|
||||||
|
|
||||||
|
public SPlusValueWrapper() { }
|
||||||
|
|
||||||
|
public SPlusValueWrapper(SPlusType type, ushort index)
|
||||||
|
{
|
||||||
|
ValueType = type;
|
||||||
|
Index = index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// S+ types enum
|
||||||
|
/// </summary>
|
||||||
|
public enum SPlusType
|
||||||
|
{
|
||||||
|
Digital, Analog, String
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,129 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using Crestron.SimplSharp;
|
|
||||||
|
|
||||||
namespace PepperDash.Core.JsonToSimpl
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Constants for Simpl modules
|
|
||||||
/// </summary>
|
|
||||||
public class JsonToSimplConstants
|
|
||||||
{
|
|
||||||
public const ushort JsonIsValidBoolChange = 2;
|
|
||||||
|
|
||||||
|
|
||||||
public const ushort BoolValueChange = 1;
|
|
||||||
public const ushort UshortValueChange = 101;
|
|
||||||
public const ushort StringValueChange = 201;
|
|
||||||
public const ushort FullPathToArrayChange = 202;
|
|
||||||
public const ushort ActualFilePathChange = 203;
|
|
||||||
|
|
||||||
// TODO: pdc-20: Added below constants for passing file path and filename back to S+
|
|
||||||
public const ushort FilenameResolvedChange = 204;
|
|
||||||
public const ushort FilePathResolvedChange = 205;
|
|
||||||
}
|
|
||||||
|
|
||||||
//**************************************************************************************************//
|
|
||||||
public delegate void SPlusValuesDelegate();
|
|
||||||
|
|
||||||
public class SPlusValueWrapper
|
|
||||||
{
|
|
||||||
public SPlusType ValueType { get; private set; }
|
|
||||||
public ushort Index { get; private set; }
|
|
||||||
public ushort BoolUShortValue { get; set; }
|
|
||||||
public string StringValue { get; set; }
|
|
||||||
|
|
||||||
public SPlusValueWrapper() { }
|
|
||||||
|
|
||||||
public SPlusValueWrapper(SPlusType type, ushort index)
|
|
||||||
{
|
|
||||||
ValueType = type;
|
|
||||||
Index = index;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum SPlusType
|
|
||||||
{
|
|
||||||
Digital, Analog, String
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//**************************************************************************************************//
|
|
||||||
public class BoolChangeEventArgs : EventArgs
|
|
||||||
{
|
|
||||||
public bool State { get; set; }
|
|
||||||
public ushort IntValue { get { return (ushort)(State ? 1 : 0); } }
|
|
||||||
public ushort Type { get; set; }
|
|
||||||
public ushort Index { get; set; }
|
|
||||||
|
|
||||||
public BoolChangeEventArgs()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public BoolChangeEventArgs(bool state, ushort type)
|
|
||||||
{
|
|
||||||
State = state;
|
|
||||||
Type = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BoolChangeEventArgs(bool state, ushort type, ushort index)
|
|
||||||
{
|
|
||||||
State = state;
|
|
||||||
Type = type;
|
|
||||||
Index = index;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//**************************************************************************************************//
|
|
||||||
public class UshrtChangeEventArgs : EventArgs
|
|
||||||
{
|
|
||||||
public ushort IntValue { get; set; }
|
|
||||||
public ushort Type { get; set; }
|
|
||||||
public ushort Index { get; set; }
|
|
||||||
|
|
||||||
public UshrtChangeEventArgs()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public UshrtChangeEventArgs(ushort intValue, ushort type)
|
|
||||||
{
|
|
||||||
IntValue = intValue;
|
|
||||||
Type = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UshrtChangeEventArgs(ushort intValue, ushort type, ushort index)
|
|
||||||
{
|
|
||||||
IntValue = intValue;
|
|
||||||
Type = type;
|
|
||||||
Index = index;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//**************************************************************************************************//
|
|
||||||
public class StringChangeEventArgs : EventArgs
|
|
||||||
{
|
|
||||||
public string StringValue { get; set; }
|
|
||||||
public ushort Type { get; set; }
|
|
||||||
public ushort Index { get; set; }
|
|
||||||
|
|
||||||
public StringChangeEventArgs()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public StringChangeEventArgs(string stringValue, ushort type)
|
|
||||||
{
|
|
||||||
StringValue = stringValue;
|
|
||||||
Type = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public StringChangeEventArgs(string stringValue, ushort type, ushort index)
|
|
||||||
{
|
|
||||||
StringValue = stringValue;
|
|
||||||
Type = type;
|
|
||||||
Index = index;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -86,7 +86,11 @@
|
|||||||
<Compile Include="Comm\TcpServerConfigObject.cs" />
|
<Compile Include="Comm\TcpServerConfigObject.cs" />
|
||||||
<Compile Include="Config\PortalConfigReader.cs" />
|
<Compile Include="Config\PortalConfigReader.cs" />
|
||||||
<Compile Include="CoreInterfaces.cs" />
|
<Compile Include="CoreInterfaces.cs" />
|
||||||
|
<Compile Include="EventArgs.cs" />
|
||||||
|
<Compile Include="GenericRESTfulCommunications\Constants.cs" />
|
||||||
|
<Compile Include="GenericRESTfulCommunications\GenericRESTful.cs" />
|
||||||
<Compile Include="JsonStandardObjects\EventArgs and Constants.cs" />
|
<Compile Include="JsonStandardObjects\EventArgs and Constants.cs" />
|
||||||
|
<Compile Include="JsonStandardObjects\JsonToSimplDeviceConfig.cs" />
|
||||||
<Compile Include="JsonStandardObjects\JsonToSimplDevice.cs" />
|
<Compile Include="JsonStandardObjects\JsonToSimplDevice.cs" />
|
||||||
<Compile Include="JsonToSimpl\JsonToSimplPortalFileMaster.cs" />
|
<Compile Include="JsonToSimpl\JsonToSimplPortalFileMaster.cs" />
|
||||||
<Compile Include="Logging\Debug.cs" />
|
<Compile Include="Logging\Debug.cs" />
|
||||||
@@ -96,7 +100,7 @@
|
|||||||
<Compile Include="Comm\GenericTcpIpServer.cs" />
|
<Compile Include="Comm\GenericTcpIpServer.cs" />
|
||||||
<Compile Include="EthernetHelper.cs" />
|
<Compile Include="EthernetHelper.cs" />
|
||||||
<Compile Include="Comm\GenericTcpIpClient.cs" />
|
<Compile Include="Comm\GenericTcpIpClient.cs" />
|
||||||
<Compile Include="JsonToSimpl\EventArgs and Constants.cs" />
|
<Compile Include="JsonToSimpl\Constants.cs" />
|
||||||
<Compile Include="JsonToSimpl\Global.cs" />
|
<Compile Include="JsonToSimpl\Global.cs" />
|
||||||
<Compile Include="JsonToSimpl\JsonToSimplArrayLookupChild.cs" />
|
<Compile Include="JsonToSimpl\JsonToSimplArrayLookupChild.cs" />
|
||||||
<Compile Include="JsonToSimpl\JsonToSimplChildObjectBase.cs" />
|
<Compile Include="JsonToSimpl\JsonToSimplChildObjectBase.cs" />
|
||||||
@@ -106,6 +110,13 @@
|
|||||||
<Compile Include="JsonToSimpl\JsonToSimplGenericMaster.cs" />
|
<Compile Include="JsonToSimpl\JsonToSimplGenericMaster.cs" />
|
||||||
<Compile Include="JsonToSimpl\JsonToSimplMaster.cs" />
|
<Compile Include="JsonToSimpl\JsonToSimplMaster.cs" />
|
||||||
<Compile Include="Network\DiscoveryThings.cs" />
|
<Compile Include="Network\DiscoveryThings.cs" />
|
||||||
|
<Compile Include="SystemInfo\ConsoleHelper.cs" />
|
||||||
|
<Compile Include="SystemInfo\ControlSubnetInfo.cs" />
|
||||||
|
<Compile Include="SystemInfo\EthernetInfo.cs" />
|
||||||
|
<Compile Include="SystemInfo\EventArgs and Constants.cs" />
|
||||||
|
<Compile Include="SystemInfo\ProcessorInfo.cs" />
|
||||||
|
<Compile Include="SystemInfo\ProgramInfo.cs" />
|
||||||
|
<Compile Include="SystemInfo\SystemInfoToSimpl.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="WebApi\Presets\Preset.cs" />
|
<Compile Include="WebApi\Presets\Preset.cs" />
|
||||||
<Compile Include="WebApi\Presets\User.cs" />
|
<Compile Include="WebApi\Presets\User.cs" />
|
||||||
|
|||||||
52
Pepperdash Core/Pepperdash Core/SystemInfo/ConsoleHelper.cs
Normal file
52
Pepperdash Core/Pepperdash Core/SystemInfo/ConsoleHelper.cs
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using Crestron.SimplSharp;
|
||||||
|
|
||||||
|
namespace PepperDash.Core.SystemInfo
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Console helper class
|
||||||
|
/// </summary>
|
||||||
|
public class ConsoleHelper
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Cosntructor
|
||||||
|
/// </summary>
|
||||||
|
public ConsoleHelper()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Parse console respopnse method
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cmd"></param>
|
||||||
|
/// <param name="line"></param>
|
||||||
|
/// <param name="startString"></param>
|
||||||
|
/// <param name="endString"></param>
|
||||||
|
/// <returns>console response</returns>
|
||||||
|
public string ParseConsoleResponse(string response, string line, string startString, string endString)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(response) || string.IsNullOrEmpty(line) || string.IsNullOrEmpty(startString) || string.IsNullOrEmpty(endString))
|
||||||
|
return "";
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var linePos = response.IndexOf(line);
|
||||||
|
var startPos = response.IndexOf(startString, linePos) + startString.Length;
|
||||||
|
var endPos = response.IndexOf(endString, startPos);
|
||||||
|
response = response.Substring(startPos, endPos - startPos).Trim();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
var msg = string.Format("ConsoleHelper.ParseConsoleResponse failed:\r{0}", e);
|
||||||
|
CrestronConsole.PrintLine(msg);
|
||||||
|
ErrorLog.Error(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using Crestron.SimplSharp;
|
||||||
|
|
||||||
|
namespace PepperDash.Core.SystemInfo
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Control subnet class
|
||||||
|
/// </summary>
|
||||||
|
public class ControlSubnetConfig
|
||||||
|
{
|
||||||
|
public ushort Enabled { get; set; }
|
||||||
|
public ushort IsInAutomaticMode { get; set; }
|
||||||
|
public string MacAddress { get; set; }
|
||||||
|
public string IpAddress { get; set; }
|
||||||
|
public string Subnet { get; set; }
|
||||||
|
public string RouterPrefix { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor
|
||||||
|
/// </summary>
|
||||||
|
public ControlSubnetConfig()
|
||||||
|
{
|
||||||
|
// add logic here if necessary
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Control subnet info class
|
||||||
|
/// </summary>
|
||||||
|
public class ControlSubnetInfo
|
||||||
|
{
|
||||||
|
public ControlSubnetConfig properties { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor
|
||||||
|
/// </summary>
|
||||||
|
public ControlSubnetInfo()
|
||||||
|
{
|
||||||
|
properties.Enabled = (ushort)0;
|
||||||
|
properties.IsInAutomaticMode = (ushort)0;
|
||||||
|
properties.MacAddress = "NA";
|
||||||
|
properties.IpAddress = "NA";
|
||||||
|
properties.Subnet = "NA";
|
||||||
|
properties.RouterPrefix = "NA";
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get control subnet info
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public bool GetInfo()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// get cs adapter id
|
||||||
|
var adapterId = CrestronEthernetHelper.GetAdapterdIdForSpecifiedAdapterType(EthernetAdapterType.EthernetCSAdapter);
|
||||||
|
if (!adapterId.Equals(EthernetAdapterType.EthernetUnknownAdapter))
|
||||||
|
{
|
||||||
|
properties.Enabled = (ushort)EthernetAdapterType.EthernetCSAdapter;
|
||||||
|
properties.IsInAutomaticMode = (ushort)(CrestronEthernetHelper.IsControlSubnetInAutomaticMode ? 1 : 0);
|
||||||
|
properties.MacAddress = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_MAC_ADDRESS, adapterId);
|
||||||
|
properties.IpAddress = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS, adapterId);
|
||||||
|
properties.Subnet = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_MASK, adapterId);
|
||||||
|
properties.RouterPrefix = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CONTROL_SUBNET_ROUTER_PREFIX, adapterId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
var msg = string.Format("ControlSubnetInfo.GetInfo() failed:\r{0}", e);
|
||||||
|
CrestronConsole.PrintLine(msg);
|
||||||
|
ErrorLog.Error(msg);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
108
Pepperdash Core/Pepperdash Core/SystemInfo/EthernetInfo.cs
Normal file
108
Pepperdash Core/Pepperdash Core/SystemInfo/EthernetInfo.cs
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using Crestron.SimplSharp;
|
||||||
|
|
||||||
|
namespace PepperDash.Core.SystemInfo
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Ethernet class
|
||||||
|
/// </summary>
|
||||||
|
public class EthernetConfig
|
||||||
|
{
|
||||||
|
public ushort DhcpIsOn { get; set; }
|
||||||
|
public string Hostname { get; set; }
|
||||||
|
public string MacAddress { get; set; }
|
||||||
|
public string IpAddress { get; set; }
|
||||||
|
public string Subnet { get; set; }
|
||||||
|
public string Gateway { get; set; }
|
||||||
|
public string Dns1 { get; set; }
|
||||||
|
public string Dns2 { get; set; }
|
||||||
|
public string Dns3 { get; set; }
|
||||||
|
public string Domain { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor
|
||||||
|
/// </summary>
|
||||||
|
public EthernetConfig()
|
||||||
|
{
|
||||||
|
// add logic here if necessary
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public class EthernetInfo
|
||||||
|
{
|
||||||
|
public EthernetConfig properties { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor
|
||||||
|
/// </summary>
|
||||||
|
public EthernetInfo()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public bool GetInfo()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// get lan adapter id
|
||||||
|
var adapterId = CrestronEthernetHelper.GetAdapterdIdForSpecifiedAdapterType(EthernetAdapterType.EthernetLANAdapter);
|
||||||
|
|
||||||
|
// get lan adapter info
|
||||||
|
var dhcpState = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_DHCP_STATE, adapterId);
|
||||||
|
if (!string.IsNullOrEmpty(dhcpState))
|
||||||
|
properties.DhcpIsOn = (ushort)(dhcpState.ToLower().Contains("on") ? 1 : 0);
|
||||||
|
|
||||||
|
properties.Hostname = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_HOSTNAME, adapterId);
|
||||||
|
properties.MacAddress = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_MAC_ADDRESS, adapterId);
|
||||||
|
properties.IpAddress = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS, adapterId);
|
||||||
|
properties.Subnet = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_MASK, adapterId);
|
||||||
|
properties.Gateway = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_ROUTER, adapterId);
|
||||||
|
properties.Domain = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_DOMAIN_NAME, adapterId);
|
||||||
|
|
||||||
|
// returns comma seperate list of dns servers with trailing comma
|
||||||
|
// example return: "8.8.8.8 (DHCP),8.8.4.4 (DHCP),"
|
||||||
|
string dns = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_DNS_SERVER, adapterId);
|
||||||
|
if (string.IsNullOrEmpty(dns))
|
||||||
|
{
|
||||||
|
properties.Dns1 = "0.0.0.0";
|
||||||
|
properties.Dns2 = "0.0.0.0";
|
||||||
|
properties.Dns3 = "0.0.0.0";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dns.Contains(","))
|
||||||
|
{
|
||||||
|
string[] dnsList = dns.Split(',');
|
||||||
|
properties.Dns1 = !string.IsNullOrEmpty(dnsList[0]) ? dnsList[0] : "0.0.0.0";
|
||||||
|
properties.Dns2 = !string.IsNullOrEmpty(dnsList[1]) ? dnsList[1] : "0.0.0.0";
|
||||||
|
properties.Dns3 = !string.IsNullOrEmpty(dnsList[2]) ? dnsList[2] : "0.0.0.0";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
properties.Dns1 = !string.IsNullOrEmpty(dns) ? dns : "0.0.0.0";
|
||||||
|
properties.Dns2 = "0.0.0.0";
|
||||||
|
properties.Dns3 = "0.0.0.0";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
var msg = string.Format("EthernetInfo.GetInfo() failed:\r{0}", e);
|
||||||
|
CrestronConsole.PrintLine(msg);
|
||||||
|
ErrorLog.Error(msg);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,187 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using Crestron.SimplSharp;
|
||||||
|
|
||||||
|
namespace PepperDash.Core.SystemInfo
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Constants
|
||||||
|
/// </summary>
|
||||||
|
public class SystemInfoConstants
|
||||||
|
{
|
||||||
|
public const ushort BoolValueChange = 1;
|
||||||
|
public const ushort CompleteBoolChange = 2;
|
||||||
|
public const ushort BusyBoolChange = 3;
|
||||||
|
|
||||||
|
public const ushort UshortValueChange = 101;
|
||||||
|
|
||||||
|
public const ushort StringValueChange = 201;
|
||||||
|
public const ushort ConsoleResponseChange = 202;
|
||||||
|
public const ushort ProcessorUptimeChange = 203;
|
||||||
|
public const ushort ProgramUptimeChange = 204;
|
||||||
|
|
||||||
|
public const ushort ObjectChange = 301;
|
||||||
|
public const ushort ProcessorObjectChange = 302;
|
||||||
|
public const ushort EthernetObjectChange = 303;
|
||||||
|
public const ushort ControlSubnetObjectChange = 304;
|
||||||
|
public const ushort ProgramObjectChange = 305;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Processor Change Event Args Class
|
||||||
|
/// </summary>
|
||||||
|
public class ProcessorChangeEventArgs : EventArgs
|
||||||
|
{
|
||||||
|
public ProcessorConfig Processor { get; set; }
|
||||||
|
public ushort Type { get; set; }
|
||||||
|
public ushort Index { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor
|
||||||
|
/// </summary>
|
||||||
|
public ProcessorChangeEventArgs()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor overload
|
||||||
|
/// </summary>
|
||||||
|
public ProcessorChangeEventArgs(ProcessorConfig processor, ushort type)
|
||||||
|
{
|
||||||
|
Processor = processor;
|
||||||
|
Type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor
|
||||||
|
/// </summary>
|
||||||
|
public ProcessorChangeEventArgs(ProcessorConfig processor, ushort type, ushort index)
|
||||||
|
{
|
||||||
|
Processor = processor;
|
||||||
|
Type = type;
|
||||||
|
Index = index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ethernet Change Event Args Class
|
||||||
|
/// </summary>
|
||||||
|
public class EthernetChangeEventArgs : EventArgs
|
||||||
|
{
|
||||||
|
public EthernetConfig Adapter { get; set; }
|
||||||
|
public ushort Type { get; set; }
|
||||||
|
public ushort Index { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor
|
||||||
|
/// </summary>
|
||||||
|
public EthernetChangeEventArgs()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor overload
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="Ethernet"></param>
|
||||||
|
/// <param name="type"></param>
|
||||||
|
public EthernetChangeEventArgs(EthernetConfig ethernet, ushort type)
|
||||||
|
{
|
||||||
|
Adapter = ethernet;
|
||||||
|
Type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor overload
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="Ethernet"></param>
|
||||||
|
/// <param name="type"></param>
|
||||||
|
public EthernetChangeEventArgs(EthernetConfig ethernet, ushort type, ushort index)
|
||||||
|
{
|
||||||
|
Adapter = ethernet;
|
||||||
|
Type = type;
|
||||||
|
Index = index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Control Subnet Chage Event Args Class
|
||||||
|
/// </summary>
|
||||||
|
public class ControlSubnetChangeEventArgs : EventArgs
|
||||||
|
{
|
||||||
|
public ControlSubnetConfig Adapter { get; set; }
|
||||||
|
public ushort Type { get; set; }
|
||||||
|
public ushort Index { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor
|
||||||
|
/// </summary>
|
||||||
|
public ControlSubnetChangeEventArgs()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor overload
|
||||||
|
/// </summary>
|
||||||
|
public ControlSubnetChangeEventArgs(ControlSubnetConfig controlSubnet, ushort type)
|
||||||
|
{
|
||||||
|
Adapter = controlSubnet;
|
||||||
|
Type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor overload
|
||||||
|
/// </summary>
|
||||||
|
public ControlSubnetChangeEventArgs(ControlSubnetConfig controlSubnet, ushort type, ushort index)
|
||||||
|
{
|
||||||
|
Adapter = controlSubnet;
|
||||||
|
Type = type;
|
||||||
|
Index = index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Program Change Event Args Class
|
||||||
|
/// </summary>
|
||||||
|
public class ProgramChangeEventArgs : EventArgs
|
||||||
|
{
|
||||||
|
public ProgramConfig Program { get; set; }
|
||||||
|
public ushort Type { get; set; }
|
||||||
|
public ushort Index { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor
|
||||||
|
/// </summary>
|
||||||
|
public ProgramChangeEventArgs()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor overload
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="Program"></param>
|
||||||
|
/// <param name="type"></param>
|
||||||
|
public ProgramChangeEventArgs(ProgramConfig program, ushort type)
|
||||||
|
{
|
||||||
|
Program = program;
|
||||||
|
Type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor overload
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="Program"></param>
|
||||||
|
/// <param name="type"></param>
|
||||||
|
public ProgramChangeEventArgs(ProgramConfig program, ushort type, ushort index)
|
||||||
|
{
|
||||||
|
Program = program;
|
||||||
|
Type = type;
|
||||||
|
Index = index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
121
Pepperdash Core/Pepperdash Core/SystemInfo/ProcessorInfo.cs
Normal file
121
Pepperdash Core/Pepperdash Core/SystemInfo/ProcessorInfo.cs
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using Crestron.SimplSharp;
|
||||||
|
|
||||||
|
namespace PepperDash.Core.SystemInfo
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Processor properties class
|
||||||
|
/// </summary>
|
||||||
|
public class ProcessorConfig
|
||||||
|
{
|
||||||
|
public string Model { get; set; }
|
||||||
|
public string SerialNumber { get; set; }
|
||||||
|
public string Firmware { get; set; }
|
||||||
|
public string FirmwareDate { get; set; }
|
||||||
|
public string OsVersion { get; set; }
|
||||||
|
public string RuntimeEnvironment { get; set; }
|
||||||
|
public string DevicePlatform { get; set; }
|
||||||
|
public string ModuleDirectory { get; set; }
|
||||||
|
public string LocalTimeZone { get; set; }
|
||||||
|
public string ProgramIdTag { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor
|
||||||
|
/// </summary>
|
||||||
|
public ProcessorConfig()
|
||||||
|
{
|
||||||
|
Model = "";
|
||||||
|
SerialNumber = "";
|
||||||
|
Firmware = "";
|
||||||
|
FirmwareDate = "";
|
||||||
|
OsVersion = "";
|
||||||
|
RuntimeEnvironment = "";
|
||||||
|
DevicePlatform = "";
|
||||||
|
ModuleDirectory = "";
|
||||||
|
LocalTimeZone = "";
|
||||||
|
ProgramIdTag = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public class ProcessorInfo
|
||||||
|
{
|
||||||
|
public ProcessorConfig properties { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor
|
||||||
|
/// </summary>
|
||||||
|
public ProcessorInfo()
|
||||||
|
{
|
||||||
|
properties.Model = "";
|
||||||
|
properties.SerialNumber = "";
|
||||||
|
properties.Firmware = "";
|
||||||
|
properties.FirmwareDate = "";
|
||||||
|
properties.OsVersion = "";
|
||||||
|
properties.RuntimeEnvironment = "";
|
||||||
|
properties.DevicePlatform = "";
|
||||||
|
properties.ModuleDirectory = "";
|
||||||
|
properties.LocalTimeZone = "";
|
||||||
|
properties.ProgramIdTag = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get processor info method
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>bool</returns>
|
||||||
|
public bool GetInfo()
|
||||||
|
{
|
||||||
|
var console = new ConsoleHelper();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
properties.Model = InitialParametersClass.ControllerPromptName;
|
||||||
|
properties.SerialNumber = CrestronEnvironment.SystemInfo.SerialNumber;
|
||||||
|
properties.ModuleDirectory = InitialParametersClass.ProgramDirectory.ToString();
|
||||||
|
properties.ProgramIdTag = InitialParametersClass.ProgramIDTag;
|
||||||
|
properties.DevicePlatform = CrestronEnvironment.DevicePlatform.ToString();
|
||||||
|
properties.OsVersion = CrestronEnvironment.OSVersion.Version.ToString();
|
||||||
|
properties.RuntimeEnvironment = CrestronEnvironment.RuntimeEnvironment.ToString();
|
||||||
|
properties.LocalTimeZone = CrestronEnvironment.GetTimeZone().Offset;
|
||||||
|
|
||||||
|
// Does not return firmware version matching a "ver" command
|
||||||
|
// returns the "ver -v" 'CAB' version
|
||||||
|
// example return ver -v:
|
||||||
|
// RMC3 Cntrl Eng [v1.503.3568.25373 (Oct 09 2018), #4001E302] @E-00107f4420f0
|
||||||
|
// Build: 14:05:46 Oct 09 2018 (3568.25373)
|
||||||
|
// Cab: 1.503.0070
|
||||||
|
// Applications: 1.0.6855.21351
|
||||||
|
// Updater: 1.4.24
|
||||||
|
// Bootloader: 1.22.00
|
||||||
|
// RMC3-SetupProgram: 1.003.0011
|
||||||
|
// IOPVersion: FPGA [v09] slot:7
|
||||||
|
// PUF: Unknown
|
||||||
|
//Firmware = CrestronEnvironment.OSVersion.Firmware;
|
||||||
|
//Firmware = InitialParametersClass.FirmwareVersion;
|
||||||
|
|
||||||
|
// Use below logic to get actual firmware ver, not the 'CAB' returned by the above
|
||||||
|
// matches console return of a "ver" and on SystemInfo page
|
||||||
|
// example return ver:
|
||||||
|
// RMC3 Cntrl Eng [v1.503.3568.25373 (Oct 09 2018), #4001E302] @E-00107f4420f0
|
||||||
|
var response = "";
|
||||||
|
CrestronConsole.SendControlSystemCommand("ver", ref response);
|
||||||
|
properties.Firmware = console.ParseConsoleResponse(response, "Cntrl Eng", "[", "(");
|
||||||
|
properties.FirmwareDate = console.ParseConsoleResponse(response, "Cntrl Eng", "(", ")");
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
var msg = string.Format("ProcessorInfo.GetInfo() failed:\r{0}", e);
|
||||||
|
CrestronConsole.PrintLine(msg);
|
||||||
|
ErrorLog.Error(msg);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
88
Pepperdash Core/Pepperdash Core/SystemInfo/ProgramInfo.cs
Normal file
88
Pepperdash Core/Pepperdash Core/SystemInfo/ProgramInfo.cs
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using Crestron.SimplSharp;
|
||||||
|
|
||||||
|
namespace PepperDash.Core.SystemInfo
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Program class
|
||||||
|
/// </summary>
|
||||||
|
public class ProgramConfig
|
||||||
|
{
|
||||||
|
public string Key { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
public string Header { get; set; }
|
||||||
|
public string System { get; set; }
|
||||||
|
public string CompileTime { get; set; }
|
||||||
|
public string Database { get; set; }
|
||||||
|
public string Environment { get; set; }
|
||||||
|
public string Programmer { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor
|
||||||
|
/// </summary>
|
||||||
|
public ProgramConfig()
|
||||||
|
{
|
||||||
|
// add logic here if necessary
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Program info class
|
||||||
|
/// </summary>
|
||||||
|
public class ProgramInfo
|
||||||
|
{
|
||||||
|
public ProgramConfig properties { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor
|
||||||
|
/// </summary>
|
||||||
|
public ProgramInfo()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get program info by index
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="index"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public bool GetInfoByIndex(int index)
|
||||||
|
{
|
||||||
|
var console = new ConsoleHelper();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string response = "";
|
||||||
|
CrestronConsole.SendControlSystemCommand(string.Format("progcomments:{0}", index), ref response);
|
||||||
|
|
||||||
|
// SIMPL returns
|
||||||
|
properties.Name = console.ParseConsoleResponse(response, "Program File", ":", "\x0D");
|
||||||
|
properties.System = console.ParseConsoleResponse(response, "System Name", ":", "\x0D");
|
||||||
|
properties.Programmer = console.ParseConsoleResponse(response, "Programmer", ":", "\x0D");
|
||||||
|
properties.CompileTime = console.ParseConsoleResponse(response, "Compiled On", ":", "\x0D");
|
||||||
|
properties.Database = console.ParseConsoleResponse(response, "CrestronDB", ":", "\x0D");
|
||||||
|
properties.Environment = console.ParseConsoleResponse(response, "Source Env", ":", "\x0D");
|
||||||
|
|
||||||
|
// S# returns
|
||||||
|
if (properties.System.Length == 0)
|
||||||
|
properties.System = console.ParseConsoleResponse(response, "Application Name", ":", "\x0D");
|
||||||
|
if (properties.Database.Length == 0)
|
||||||
|
properties.Database = console.ParseConsoleResponse(response, "PlugInVersion", ":", "\x0D");
|
||||||
|
if (properties.Environment.Length == 0)
|
||||||
|
properties.Environment = console.ParseConsoleResponse(response, "Program Tool", ":", "\x0D");
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
var msg = string.Format("ProgramInfo.GetInfoByIndex({0}) failed:\r{1}", index, e);
|
||||||
|
CrestronConsole.PrintLine(msg);
|
||||||
|
ErrorLog.Error(msg);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
254
Pepperdash Core/Pepperdash Core/SystemInfo/SystemInfoToSimpl.cs
Normal file
254
Pepperdash Core/Pepperdash Core/SystemInfo/SystemInfoToSimpl.cs
Normal file
@@ -0,0 +1,254 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using Crestron.SimplSharp;
|
||||||
|
using Crestron.SimplSharp.CrestronIO;
|
||||||
|
|
||||||
|
namespace PepperDash.Core.SystemInfo
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Processor Info to Simpl Class
|
||||||
|
/// Ported from Technics_Core
|
||||||
|
/// </summary>
|
||||||
|
public class SystemInfoToSimpl
|
||||||
|
{
|
||||||
|
public event EventHandler<BoolChangeEventArgs> BoolChange;
|
||||||
|
public event EventHandler<StringChangeEventArgs> StringChange;
|
||||||
|
public event EventHandler<ProcessorChangeEventArgs> ProcessorChange;
|
||||||
|
public event EventHandler<EthernetChangeEventArgs> EthernetChange;
|
||||||
|
public event EventHandler<ControlSubnetChangeEventArgs> ControlSubnetChange;
|
||||||
|
public event EventHandler<ProgramChangeEventArgs> ProgramChange;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor
|
||||||
|
/// </summary>
|
||||||
|
public SystemInfoToSimpl()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get processor info method
|
||||||
|
/// </summary>
|
||||||
|
public void GetProcessorInfo()
|
||||||
|
{
|
||||||
|
OnBoolChange(true, 0, SystemInfoConstants.BusyBoolChange);
|
||||||
|
|
||||||
|
var processor = new ProcessorInfo();
|
||||||
|
if (processor.GetInfo() == true)
|
||||||
|
OnProcessorChange(processor.properties, 0, SystemInfoConstants.ProcessorObjectChange);
|
||||||
|
|
||||||
|
OnBoolChange(false, 0, SystemInfoConstants.BusyBoolChange);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get processor uptime method
|
||||||
|
/// </summary>
|
||||||
|
public void RefreshProcessorUptime()
|
||||||
|
{
|
||||||
|
var console = new ConsoleHelper();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string response = "";
|
||||||
|
CrestronConsole.SendControlSystemCommand("uptime", ref response);
|
||||||
|
var uptime = console.ParseConsoleResponse(response, "running for", "running for", "\x0D");
|
||||||
|
OnStringChange(uptime, 0, SystemInfoConstants.ProcessorUptimeChange);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
var msg = string.Format("RefreshProcessorUptime failed:\r{0}", e);
|
||||||
|
CrestronConsole.PrintLine(msg);
|
||||||
|
ErrorLog.Error(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// get ethernet info method
|
||||||
|
/// </summary>
|
||||||
|
public void GetEthernetInfo()
|
||||||
|
{
|
||||||
|
OnBoolChange(true, 0, SystemInfoConstants.BusyBoolChange);
|
||||||
|
|
||||||
|
var ethernet = new EthernetInfo();
|
||||||
|
if(ethernet.GetInfo() == true)
|
||||||
|
OnEthernetInfoChange(ethernet.properties, 0, SystemInfoConstants.ObjectChange);
|
||||||
|
|
||||||
|
OnBoolChange(false, 0, SystemInfoConstants.BusyBoolChange);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get control subnet ethernet info method
|
||||||
|
/// </summary>
|
||||||
|
public void GetControlSubnetInfo()
|
||||||
|
{
|
||||||
|
OnBoolChange(true, 0, SystemInfoConstants.BusyBoolChange);
|
||||||
|
|
||||||
|
var ethernet = new ControlSubnetInfo();
|
||||||
|
if(ethernet.GetInfo() == true)
|
||||||
|
OnControlSubnetInfoChange(ethernet.properties, 0, SystemInfoConstants.ObjectChange);
|
||||||
|
|
||||||
|
OnBoolChange(false, 0, SystemInfoConstants.BusyBoolChange);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get program info by index method
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="index"></param>
|
||||||
|
public void GetProgramInfoByIndex(ushort index)
|
||||||
|
{
|
||||||
|
OnBoolChange(true, 0, SystemInfoConstants.BusyBoolChange);
|
||||||
|
|
||||||
|
var program = new ProgramInfo();
|
||||||
|
if (program.GetInfoByIndex(index) == true)
|
||||||
|
OnProgramChange(program.properties, index, SystemInfoConstants.ObjectChange);
|
||||||
|
|
||||||
|
OnBoolChange(false, 0, SystemInfoConstants.BusyBoolChange);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Refresh program uptime by index
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="index"></param>
|
||||||
|
public void RefreshProgramUptimeByIndex(int index)
|
||||||
|
{
|
||||||
|
var console = new ConsoleHelper();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string response = "";
|
||||||
|
CrestronConsole.SendControlSystemCommand(string.Format("proguptime:{0}", index), ref response);
|
||||||
|
string uptime = console.ParseConsoleResponse(response, "running for", "running for", "\x0D");
|
||||||
|
OnStringChange(uptime, (ushort)index, SystemInfoConstants.ProgramUptimeChange);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
var msg = string.Format("RefreshProgramUptimebyIndex({0}) failed:\r{1}", index, e);
|
||||||
|
CrestronConsole.PrintLine(msg);
|
||||||
|
ErrorLog.Error(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Send console command
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cmd"></param>
|
||||||
|
public void SendConsoleCommand(string cmd)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(cmd))
|
||||||
|
return;
|
||||||
|
|
||||||
|
string consoleResponse = "";
|
||||||
|
CrestronConsole.SendControlSystemCommand(cmd, ref consoleResponse);
|
||||||
|
if (!string.IsNullOrEmpty(consoleResponse))
|
||||||
|
{
|
||||||
|
if (consoleResponse.Contains("\x0D\x0A"))
|
||||||
|
consoleResponse.Trim('\n');
|
||||||
|
OnStringChange(consoleResponse, 0, SystemInfoConstants.ConsoleResponseChange);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Boolean change event handler
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="state"></param>
|
||||||
|
/// <param name="index"></param>
|
||||||
|
/// <param name="type"></param>
|
||||||
|
protected void OnBoolChange(bool state, ushort index, ushort type)
|
||||||
|
{
|
||||||
|
var handler = BoolChange;
|
||||||
|
if (handler != null)
|
||||||
|
{
|
||||||
|
var args = new BoolChangeEventArgs(state, type);
|
||||||
|
args.Index = index;
|
||||||
|
BoolChange(this, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// String change event handler
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
/// <param name="index"></param>
|
||||||
|
/// <param name="type"></param>
|
||||||
|
protected void OnStringChange(string value, ushort index, ushort type)
|
||||||
|
{
|
||||||
|
var handler = StringChange;
|
||||||
|
if (handler != null)
|
||||||
|
{
|
||||||
|
var args = new StringChangeEventArgs(value, type);
|
||||||
|
args.Index = index;
|
||||||
|
StringChange(this, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Processor change event handler
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="processor"></param>
|
||||||
|
/// <param name="index"></param>
|
||||||
|
/// <param name="type"></param>
|
||||||
|
protected void OnProcessorChange(ProcessorConfig processor, ushort index, ushort type)
|
||||||
|
{
|
||||||
|
var handler = ProcessorChange;
|
||||||
|
if (handler != null)
|
||||||
|
{
|
||||||
|
var args = new ProcessorChangeEventArgs(processor, type);
|
||||||
|
args.Index = index;
|
||||||
|
ProcessorChange(this, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ethernet change event handler
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ethernet"></param>
|
||||||
|
/// <param name="index"></param>
|
||||||
|
/// <param name="type"></param>
|
||||||
|
protected void OnEthernetInfoChange(EthernetConfig ethernet, ushort index, ushort type)
|
||||||
|
{
|
||||||
|
var handler = EthernetChange;
|
||||||
|
if (handler != null)
|
||||||
|
{
|
||||||
|
var args = new EthernetChangeEventArgs(ethernet, type);
|
||||||
|
args.Index = index;
|
||||||
|
EthernetChange(this, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Control Subnet change event handler
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ethernet"></param>
|
||||||
|
/// <param name="index"></param>
|
||||||
|
/// <param name="type"></param>
|
||||||
|
protected void OnControlSubnetInfoChange(ControlSubnetConfig ethernet, ushort index, ushort type)
|
||||||
|
{
|
||||||
|
var handler = ControlSubnetChange;
|
||||||
|
if (handler != null)
|
||||||
|
{
|
||||||
|
var args = new ControlSubnetChangeEventArgs(ethernet, type);
|
||||||
|
args.Index = index;
|
||||||
|
ControlSubnetChange(this, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Program change event handler
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="program"></param>
|
||||||
|
/// <param name="index"></param>
|
||||||
|
/// <param name="type"></param>
|
||||||
|
protected void OnProgramChange(ProgramConfig program, ushort index, ushort type)
|
||||||
|
{
|
||||||
|
var handler = ProgramChange;
|
||||||
|
if (handler != null)
|
||||||
|
{
|
||||||
|
var args = new ProgramChangeEventArgs(program, type);
|
||||||
|
args.Index = index;
|
||||||
|
ProgramChange(this, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user