Continued working on XML comments

This commit is contained in:
Jason DeVito
2020-10-16 12:03:30 -05:00
parent 9ea7be39e8
commit 3acb9bc22b
12 changed files with 561 additions and 265 deletions

View File

@@ -13,7 +13,7 @@ namespace PepperDash.Core
/// <summary> /// <summary>
/// Defines the string event handler for line events on the gather /// Defines the string event handler for line events on the gather
/// </summary> /// </summary>
/// <param name="text"></param> /// <param name="text">A string</param>
public delegate void LineReceivedHandler(string text); public delegate void LineReceivedHandler(string text);
/// <summary> /// <summary>
@@ -44,17 +44,20 @@ namespace PepperDash.Core
StringBuilder ReceiveBuffer = new StringBuilder(); StringBuilder ReceiveBuffer = new StringBuilder();
/// <summary> /// <summary>
/// Delimiter, like it says! /// Delimiter character
/// </summary> /// </summary>
char Delimiter; char Delimiter;
/// <summary>
/// Delimiter string
/// </summary>
string StringDelimiter; string StringDelimiter;
/// <summary> /// <summary>
/// Fires up a gather, given a IBasicCommunicaion port and char for de /// Fires up a gather, given a IBasicCommunicaion port and char for delimiter
/// </summary> /// </summary>
/// <param name="port"></param> /// <param name="port"><seealso cref="PepperDash.Core.ICommunicationReceiver"/>ICommunicationReceiver port</param>
/// <param name="delimiter"></param> /// <param name="delimiter">Delimiter character</param>
public CommunicationGather(ICommunicationReceiver port, char delimiter) public CommunicationGather(ICommunicationReceiver port, char delimiter)
{ {
Port = port; Port = port;
@@ -63,10 +66,10 @@ namespace PepperDash.Core
} }
/// <summary> /// <summary>
/// /// Fires up a gather, given a IBasicCommunicaion port and string for delimiter
/// </summary> /// </summary>
/// <param name="port"></param> /// <param name="port"><seealso cref="PepperDash.Core.ICommunicationReceiver"/>ICommunicationReceiver port</param>
/// <param name="delimiter"></param> /// <param name="delimiter">Delimiter string</param>
public CommunicationGather(ICommunicationReceiver port, string delimiter) public CommunicationGather(ICommunicationReceiver port, string delimiter)
{ {
Port = port; Port = port;
@@ -119,10 +122,10 @@ namespace PepperDash.Core
} }
/// <summary> /// <summary>
/// /// Handler for delimited data coming from port
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender">An object</param>
/// <param name="args"></param> /// <param name="args">A GenericCommMethodReceiveTextArgs</param>
void Port_TextReceivedStringDelimiter(object sender, GenericCommMethodReceiveTextArgs args) void Port_TextReceivedStringDelimiter(object sender, GenericCommMethodReceiveTextArgs args)
{ {
var handler = LineReceived; var handler = LineReceived;

View File

@@ -18,33 +18,80 @@ using Crestron.SimplSharp.CrestronSockets;
namespace PepperDash.Core namespace PepperDash.Core
{ {
/// <summary>
/// Socket Status Delegate
/// </summary>
/// <param name="client"><seealso cref="PepperDash.Core.ISocketStatus"/>A ISocketStatus client</param>
public delegate void GenericSocketStatusChangeEventDelegate(ISocketStatus client); public delegate void GenericSocketStatusChangeEventDelegate(ISocketStatus client);
/// <summary>
/// Generic socket status change event args class
/// </summary>
public class GenericSocketStatusChageEventArgs : EventArgs public class GenericSocketStatusChageEventArgs : EventArgs
{ {
/// <summary>
/// Client property implementing ISocketStatus
/// </summary>
/// <seealso cref="PepperDash.Core.ISocketStatus"/>
/// <inheritdoc/>
public ISocketStatus Client { get; private set; } public ISocketStatus Client { get; private set; }
/// <summary>
/// Constructor
/// </summary>
/// <remarks>
/// Initializes a new instance of the GenericSocketStatusChangeEventArgs class
/// </remarks>
/// <param name="client">A client implementing ISocketStatus</param>
public GenericSocketStatusChageEventArgs(ISocketStatus client) public GenericSocketStatusChageEventArgs(ISocketStatus client)
{ {
Client = client; Client = client;
} }
/// <summary> /// <summary>
/// Stupid S+ Constructor /// Constructor
/// </summary> /// </summary>
/// <remarks>
/// S+ requires an empty constructor, if not implemented the class will not be avialble in S+
/// </remarks>
public GenericSocketStatusChageEventArgs() { } public GenericSocketStatusChageEventArgs() { }
} }
/// <summary>
/// Generic TCP Server state change event delegate
/// </summary>
/// <param name="state"><seealso cref="Crestron.SimplSharp.CrestronSockets.ServerState"/>Server state enum</param>
public delegate void GenericTcpServerStateChangedEventDelegate(ServerState state); public delegate void GenericTcpServerStateChangedEventDelegate(ServerState state);
/// <summary>
/// Generic TCP Server statte change event args class
/// </summary>
public class GenericTcpServerStateChangedEventArgs : EventArgs public class GenericTcpServerStateChangedEventArgs : EventArgs
{ {
/// <summary>
/// State property
/// </summary>
/// <remarks>
/// Implements Crestron sockets server state
/// </remarks>
/// <seealso cref="Crestron.SimplSharp.CrestronSockets.ServerState"/>
public ServerState State { get; private set; } public ServerState State { get; private set; }
/// <summary>
/// Constructor
/// </summary>
/// <param name="state">A server implementing ServerState</param>
public GenericTcpServerStateChangedEventArgs(ServerState state) public GenericTcpServerStateChangedEventArgs(ServerState state)
{ {
State = state; State = state;
} }
/// <summary> /// <summary>
/// Stupid S+ Constructor /// Constructor
/// </summary> /// </summary>
/// <remarks>
/// S+ requires an empty constructor, if not implemented the class will not be avialble in S+
/// </remarks>
public GenericTcpServerStateChangedEventArgs() { } public GenericTcpServerStateChangedEventArgs() { }
} }

View File

@@ -8,7 +8,50 @@ namespace PepperDash.Core
{ {
/// <summary> /// <summary>
/// Crestron Control Methods for a comm object /// Crestron Control Methods for a comm object
/// </summary> /// </summary>
/// <remarks>
/// Currently Http, Https, Ws, and Wss will not create comm objects, however having them defined in the
/// enum resolves the issue where they would cause an exception if passed into the comm factory.
///
/// When using the eControlMethods in a JSON configuration file use the following example:
/// <code>
/// "method": "[eControlMethod Enum]"
/// </code>
///
/// Below is a full example of the device JSON configuration
/// <code>
/// {
/// "key": "device-key",
/// "name": "Device Name",
/// "group": "comm",
/// "type": "genericComm",
/// "properties": {
/// "control": {
/// "method": "Com",
/// "controlPortDevKey": "processor",
/// "controlPortNumber": 1,
/// "comParams": {
/// "hardwareHandshake": "None",
/// "parity": "None",
/// "protocol": "RS232",
/// "baudRate": 9600,
/// "dataBits": 8,
/// "softwareHandshake": "None",
/// "stopBits": 1
/// },
/// "tcpSshProperties": {
/// "address": "",
/// "port": 1515,
/// "username": "",
/// "password": "",
/// "autoReconnect": false,
/// "autoReconnectIntervalMs": 30000
/// }
/// }
/// }
/// }
/// </code>
/// </remarks>
public enum eControlMethod public enum eControlMethod
{ {
None = 0, Com, IpId, IpidTcp, IR, Ssh, Tcpip, Telnet, Cresnet, Cec, Udp, Http, Https, Ws, Wss None = 0, Com, IpId, IpidTcp, IR, Ssh, Tcpip, Telnet, Cresnet, Cec, Udp, Http, Https, Ws, Wss

View File

@@ -15,11 +15,25 @@ namespace PepperDash.Core
/// </summary> /// </summary>
public interface ICommunicationReceiver : IKeyed public interface ICommunicationReceiver : IKeyed
{ {
/// <summary>
/// Event handler for bytes received
/// </summary>
event EventHandler<GenericCommMethodReceiveBytesArgs> BytesReceived; event EventHandler<GenericCommMethodReceiveBytesArgs> BytesReceived;
/// <summary>
/// Event hanlder for text recieved
/// </summary>
event EventHandler<GenericCommMethodReceiveTextArgs> TextReceived; event EventHandler<GenericCommMethodReceiveTextArgs> TextReceived;
/// <summary>
/// Is connected property.
/// </summary>
bool IsConnected { get; } bool IsConnected { get; }
/// <summary>
/// Connect method
/// </summary>
void Connect(); void Connect();
/// <summary>
/// Disconnect method
/// </summary>
void Disconnect(); void Disconnect();
} }
@@ -66,6 +80,10 @@ namespace PepperDash.Core
} }
/// <summary>
/// Represents a device that can automatically reconnect when a connection drops. Typically
/// used with IP based communications.
/// </summary>
public interface IAutoReconnect public interface IAutoReconnect
{ {
bool AutoReconnect { get; set; } bool AutoReconnect { get; set; }
@@ -73,7 +91,7 @@ namespace PepperDash.Core
} }
/// <summary> /// <summary>
/// /// Generic communication method status change type Enum
/// </summary> /// </summary>
public enum eGenericCommMethodStatusChangeType public enum eGenericCommMethodStatusChangeType
{ {
@@ -84,15 +102,23 @@ namespace PepperDash.Core
/// This delegate defines handler for IBasicCommunication status changes /// This delegate defines handler for IBasicCommunication status changes
/// </summary> /// </summary>
/// <param name="comm">Device firing the status change</param> /// <param name="comm">Device firing the status change</param>
/// <param name="status"></param> /// <param name="status">A eGenericCommMethodStatusChangeType enum</param>
public delegate void GenericCommMethodStatusHandler(IBasicCommunication comm, eGenericCommMethodStatusChangeType status); public delegate void GenericCommMethodStatusHandler(IBasicCommunication comm, eGenericCommMethodStatusChangeType status);
/// <summary> /// <summary>
/// /// Generic communication method receive bytes args class
/// </summary> /// </summary>
public class GenericCommMethodReceiveBytesArgs : EventArgs public class GenericCommMethodReceiveBytesArgs : EventArgs
{ {
/// <summary>
/// Bytes array property
/// </summary>
public byte[] Bytes { get; private set; } public byte[] Bytes { get; private set; }
/// <summary>
/// Constructor
/// </summary>
/// <param name="bytes">An array of bytes</param>
public GenericCommMethodReceiveBytesArgs(byte[] bytes) public GenericCommMethodReceiveBytesArgs(byte[] bytes)
{ {
Bytes = bytes; Bytes = bytes;
@@ -105,11 +131,22 @@ namespace PepperDash.Core
} }
/// <summary> /// <summary>
/// /// Generic communication method receive text args class
/// </summary> /// </summary>
/// <remarks>
/// Inherits from <seealso cref="System.EventArgs"/>
/// </remarks>
public class GenericCommMethodReceiveTextArgs : EventArgs public class GenericCommMethodReceiveTextArgs : EventArgs
{ {
/// <summary>
/// Text string property
/// </summary>
public string Text { get; private set; } public string Text { get; private set; }
/// <summary>
/// Constructor
/// </summary>
/// <param name="text">A string</param>
public GenericCommMethodReceiveTextArgs(string text) public GenericCommMethodReceiveTextArgs(string text)
{ {
Text = text; Text = text;
@@ -124,15 +161,24 @@ namespace PepperDash.Core
/// <summary> /// <summary>
/// /// Communication text helper class
/// </summary> /// </summary>
public class ComTextHelper public class ComTextHelper
{ {
/// <summary>
/// Method to convert escaped bytes to an array of escaped bytes
/// </summary>
/// <param name="bytes">An array of bytes</param>
/// <returns>Array of escaped characters</returns>
public static string GetEscapedText(byte[] bytes) public static string GetEscapedText(byte[] bytes)
{ {
return String.Concat(bytes.Select(b => string.Format(@"[{0:X2}]", (int)b)).ToArray()); return String.Concat(bytes.Select(b => string.Format(@"[{0:X2}]", (int)b)).ToArray());
} }
/// <summary>
/// Method to coonvert a string to an array of escaped bytes
/// </summary>
/// <param name="text">A string</param>
/// <returns>Array of escaped characters</returns>
public static string GetEscapedText(string text) public static string GetEscapedText(string text)
{ {
var bytes = Encoding.GetEncoding(28591).GetBytes(text); var bytes = Encoding.GetEncoding(28591).GetBytes(text);

View File

@@ -1,30 +1,33 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using Crestron.SimplSharp; using Crestron.SimplSharp;
namespace PepperDash.Core namespace PepperDash.Core
{ {
/// <summary> /// <summary>
/// Unique key interface to require a unique key for the class /// Unique key interface to require a unique key for the class
/// </summary> /// </summary>
public interface IKeyed public interface IKeyed
{ {
/// <summary> /// <summary>
/// Unique Key /// Unique Key
/// </summary> /// </summary>
string Key { get; } string Key { get; }
} }
/// <summary> /// <summary>
/// Named Keyed device interface. Forces the devie to have a Unique Key and a name. /// Named Keyed device interface
/// </summary> /// </summary>
public interface IKeyName : IKeyed /// <remarks>
{ /// Forces the device to have a Unique Key and a name.
/// <summary> /// </remarks>
/// Isn't it obvious :) public interface IKeyName : IKeyed
/// </summary> {
string Name { get; } /// <summary>
} /// Isn't it obvious :)
/// </summary>
string Name { get; }
}
} }

View File

@@ -33,7 +33,14 @@ namespace PepperDash.Core
///// </summary> ///// </summary>
//public bool HasConfig { get { return Config != null; } } //public bool HasConfig { get { return Config != null; } }
/// <summary>
///
/// </summary>
List<Action> _PreActivationActions; List<Action> _PreActivationActions;
/// <summary>
///
/// </summary>
List<Action> _PostActivationActions; List<Action> _PostActivationActions;
public static Device DefaultDevice { get { return _DefaultDevice; } } public static Device DefaultDevice { get { return _DefaultDevice; } }
@@ -51,6 +58,11 @@ namespace PepperDash.Core
} }
/// <summary>
/// Constructor overload
/// </summary>
/// <param name="key"></param>
/// <param name="name"></param>
public Device(string key, string name) : this(key) public Device(string key, string name) : this(key)
{ {
Name = name; Name = name;

View File

@@ -1,118 +1,136 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using Crestron.SimplSharp; using Crestron.SimplSharp;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace PepperDash.Core namespace PepperDash.Core
{ {
public class EthernetHelper public class EthernetHelper
{ {
/// <summary> /// <summary>
/// /// Lan Helper property
/// </summary> /// </summary>
public static EthernetHelper LanHelper public static EthernetHelper LanHelper
{ {
get get
{ {
if (_LanHelper == null) _LanHelper = new EthernetHelper(0); if (_LanHelper == null) _LanHelper = new EthernetHelper(0);
return _LanHelper; return _LanHelper;
} }
} }
static EthernetHelper _LanHelper; static EthernetHelper _LanHelper;
// ADD OTHER HELPERS HERE // ADD OTHER HELPERS HERE
/// <summary> /// <summary>
/// /// Port Number property
/// </summary> /// </summary>
public int PortNumber { get; private set; } public int PortNumber { get; private set; }
private EthernetHelper(int portNumber) private EthernetHelper(int portNumber)
{ {
PortNumber = portNumber; PortNumber = portNumber;
} }
/// <summary> /// <summary>
/// /// Link Active property
/// </summary> /// </summary>
[JsonProperty("linkActive")] /// <returns>
public bool LinkActive /// Current link status
{ /// </returns>
get [JsonProperty("linkActive")]
{ public bool LinkActive
var status = CrestronEthernetHelper.GetEthernetParameter( {
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_LINK_STATUS, 0); get
Debug.Console(0, "LinkActive = {0}", status); {
return status == ""; var status = CrestronEthernetHelper.GetEthernetParameter(
} CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_LINK_STATUS, 0);
} Debug.Console(0, "LinkActive = {0}", status);
return status == "";
/// <summary> }
/// }
/// </summary>
[JsonProperty("dchpActive")] /// <summary>
public bool DhcpActive /// DHCP Active property
{ /// </summary>
get /// <returns>
{ /// Current DHCP state
return CrestronEthernetHelper.GetEthernetParameter( /// </returns>
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_DHCP_STATE, 0) == "ON"; [JsonProperty("dchpActive")]
} public bool DhcpActive
} {
get
/// <summary> {
/// return CrestronEthernetHelper.GetEthernetParameter(
/// </summary> CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_DHCP_STATE, 0) == "ON";
[JsonProperty("hostname")] }
public string Hostname }
{
get /// <summary>
{ /// Hostname property
return CrestronEthernetHelper.GetEthernetParameter( /// </summary>
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_HOSTNAME, 0); /// <returns>
} /// Current hostname
} /// </returns>
[JsonProperty("hostname")]
/// <summary> public string Hostname
/// {
/// </summary> get
[JsonProperty("ipAddress")] {
public string IPAddress return CrestronEthernetHelper.GetEthernetParameter(
{ CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_HOSTNAME, 0);
get }
{ }
return CrestronEthernetHelper.GetEthernetParameter(
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS, 0); /// <summary>
} /// IP Address property
} /// </summary>
/// <returns>
/// <summary> /// Current IP address
/// /// </returns>
/// </summary> [JsonProperty("ipAddress")]
[JsonProperty("subnetMask")] public string IPAddress
public string SubnetMask {
{ get
get {
{ return CrestronEthernetHelper.GetEthernetParameter(
return CrestronEthernetHelper.GetEthernetParameter( CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS, 0);
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_MASK, 0); }
} }
}
/// <summary>
/// <summary> /// Subnet Mask property
/// /// </summary>
/// </summary> /// <returns>
[JsonProperty("defaultGateway")] /// Current subnet mask
public string DefaultGateway /// </returns>
{ [JsonProperty("subnetMask")]
get public string SubnetMask
{ {
return CrestronEthernetHelper.GetEthernetParameter( get
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_ROUTER, 0); {
} return CrestronEthernetHelper.GetEthernetParameter(
} CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_MASK, 0);
} }
}
/// <summary>
/// Default Gateway property
/// </summary>
/// <returns>
/// Current router
/// </returns>
[JsonProperty("defaultGateway")]
public string DefaultGateway
{
get
{
return CrestronEthernetHelper.GetEthernetParameter(
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_ROUTER, 0);
}
}
}
} }

View File

@@ -7,23 +7,72 @@ using Crestron.SimplSharp;
namespace PepperDash.Core namespace PepperDash.Core
{ {
/// <summary> /// <summary>
/// Bool change event args /// Main <c>BoolChangeEventArgs</c> class
/// </summary> /// </summary>
/// <remarks>
/// Bool change event args are accessible by all classes and are used to pass boolean values from S# to S+. Constants can be created
/// in the classes using the event args. Constants, when used, associate returned values with specific S+ properties.
/// <example>
/// Implement the following when
/// <code>
/// public event EventHandler<BoolChangeEventArgs> BoolChange;
/// </code>
/// <code>
/// protected void OnBoolChange(bool state, ushort index, ushort type)
/// {
/// var handler = BoolChange;
/// if (handler == null) return;
/// var args = new BoolChangeEventArgs(state, type) {Index = index};
/// BoolChange(this, args);
/// }
/// </code>
/// When referencing events in S+ you must create a event handler callback method and register the event.
/// <code>
/// EventHandler BoolChanged(SampleSimplSharpClass sender, BoolChangeEventArgs args)
/// {
/// If(DebugEnable) Trace("BoolChanged: args[%u].Type[%u] = %u\r", args.Index, args.Type, args.IntValue);
///
/// Switch(args.Type)
/// {
/// Case(SampleSimplSharpClass.BoolValueChange):
/// {
/// // specific bool value changed
/// }
/// Default:
/// {
/// // generic bool value changed
/// }
/// }
/// }
/// </code>
/// Register the event
/// <code>
/// Function Main()
/// {
/// //RegisterEveent([S+ class name], [S# event], [S+ event handler]);
/// RegisterEveent(mySplusClass, BoolChange, BoolChanged);
/// }
/// </code>
/// </example>
/// </remarks>
public class BoolChangeEventArgs : EventArgs public class BoolChangeEventArgs : EventArgs
{ {
/// <summary> /// <summary>
/// Boolean state property /// State property
/// </summary> /// </summary>
/// <value>Boolean</value>
public bool State { get; set; } public bool State { get; set; }
/// <summary> /// <summary>
/// Boolean ushort value property /// Integer value property
/// </summary> /// </summary>
/// <value>Ushort</value>
public ushort IntValue { get { return (ushort)(State ? 1 : 0); } } public ushort IntValue { get { return (ushort)(State ? 1 : 0); } }
/// <summary> /// <summary>
/// Boolean change event args type /// Type property
/// </summary> /// </summary>
/// <value>Ushort</value>
public ushort Type { get; set; } public ushort Type { get; set; }
/// <summary> /// <summary>
@@ -34,16 +83,22 @@ namespace PepperDash.Core
/// <summary> /// <summary>
/// Constructor /// Constructor
/// </summary> /// </summary>
/// <remarks>
/// S+ requires an empty contructor, otherwise the class will not be avialable in S+.
/// </remarks>
public BoolChangeEventArgs() public BoolChangeEventArgs()
{ {
} }
/// <summary> /// <summary>
/// Constructor overload /// Constructor
/// </summary> /// </summary>
/// <param name="state"></param> /// <remarks>
/// <param name="type"></param> /// Accepts State as a boolean and Type as a ushort.
/// </remarks>
/// <param name="state">a boolean value</param>
/// <param name="type">a ushort number</param>
public BoolChangeEventArgs(bool state, ushort type) public BoolChangeEventArgs(bool state, ushort type)
{ {
State = state; State = state;
@@ -51,11 +106,14 @@ namespace PepperDash.Core
} }
/// <summary> /// <summary>
/// Constructor overload /// Constructor
/// </summary> /// </summary>
/// <param name="state"></param> /// <remarks>
/// <param name="type"></param> /// Accepts State as a boolean, type as a ushort and index as ushort.
/// <param name="index"></param> /// </remarks>
/// <param name="state">a boolean value</param>
/// <param name="type">a ushort number</param>
/// <param name="index">a ushort number</param>
public BoolChangeEventArgs(bool state, ushort type, ushort index) public BoolChangeEventArgs(bool state, ushort type, ushort index)
{ {
State = state; State = state;
@@ -65,8 +123,54 @@ namespace PepperDash.Core
} }
/// <summary> /// <summary>
/// Ushort change event args /// Main <c>UshrtChangeEventArgs</c> class
/// </summary> /// </summary>
/// <remarks>
/// Ushort change event args are accessible by all classes and are used to pass ushort values from S# to S+. Constants can be created
/// in the classes using the event args. Constants, when used, associate returned values with specific S+ properties.
/// <example>
/// When using UshrtChangeEventArgs in a class you will need to include a change handler method.
/// <code>
/// public event EventHandler<UshrtChangeEventArgs> UshortChange;
/// </code>
/// <code>
/// protected void OnUshortChange(ushort value, ushort index, ushort type)
/// {
/// var handler = UshortChange;
/// if (handler == null) return;
/// var args = new UshrtChangeEventArgs(value, type) {Index = index};
/// UshortChange(this, args);
/// }
/// </code>
/// When referencing events in S+ you must create a event handler callback method and register the event.
/// <code>
/// EventHandler UshortChanged(SampleSimplSharpClass sender, UshrtChangeEventArgs args)
/// {
/// If(DebugEnable) Trace("UshortChanged: args[%u].Type[%u] = %u\r", args.Index, args.Type, args.IntValue);
///
/// Switch(args.Type)
/// {
/// Case(SampleSimplSharpClass.UshortValueChange):
/// {
/// // specific ushort value changed
/// }
/// Default:
/// {
/// // generic ushort value changed
/// }
/// }
/// }
/// </code>
/// Register the event
/// <code>
/// Function Main()
/// {
/// //RegisterEveent([S+ class name], [S# event], [S+ event handler]);
/// RegisterEveent(mySplusClass, UshortChange, UshortChanged);
/// }
/// </code>
/// </example>
/// </remarks>
public class UshrtChangeEventArgs : EventArgs public class UshrtChangeEventArgs : EventArgs
{ {
/// <summary> /// <summary>
@@ -95,8 +199,8 @@ namespace PepperDash.Core
/// <summary> /// <summary>
/// Constructor overload /// Constructor overload
/// </summary> /// </summary>
/// <param name="intValue"></param> /// <param name="intValue">a ushort number</param>
/// <param name="type"></param> /// <param name="type">a ushort number</param>
public UshrtChangeEventArgs(ushort intValue, ushort type) public UshrtChangeEventArgs(ushort intValue, ushort type)
{ {
IntValue = intValue; IntValue = intValue;
@@ -106,9 +210,9 @@ namespace PepperDash.Core
/// <summary> /// <summary>
/// Constructor overload /// Constructor overload
/// </summary> /// </summary>
/// <param name="intValue"></param> /// <param name="intValue">a ushort number</param>
/// <param name="type"></param> /// <param name="type">a ushort number</param>
/// <param name="index"></param> /// <param name="index">a ushort number</param>
public UshrtChangeEventArgs(ushort intValue, ushort type, ushort index) public UshrtChangeEventArgs(ushort intValue, ushort type, ushort index)
{ {
IntValue = intValue; IntValue = intValue;
@@ -118,8 +222,54 @@ namespace PepperDash.Core
} }
/// <summary> /// <summary>
/// String change event args /// Main <c>StringChangeEventArgs</c> class
/// </summary> /// </summary>
/// <remarks>
/// String change event args are accessible by all classes and are used to pass ushort values from S# to S+. Constants can be created
/// in the classes using the event args. Constants, when used, associate returned values with specific S+ properties.
/// <example>
/// When using StringChangeEventArgs in a class you will need to include a change handler method.
/// <code>
/// public event EventHandler<StringChangeEventArgs> StringChange;
/// </code>
/// <code>
/// protected void OnStringChange(string stringValue, ushort index, ushort type)
/// {
/// var handler = StringChange;
/// if (handler == null) return;
/// var args = new StringChangeEventArgs(stringValue, type) {Index = index};
/// StringChange(this, args);
/// }
/// </code>
/// When referencing events in S+ you must create a event handler callback method and register the event.
/// <code>
/// EventHandler StringChanged(SampleSimplSharpClass sender, StringChangeEventArgs args)
/// {
/// If(DebugEnable) Trace("StringChanged: args[%u].Type[%u] = %u\r", args.Index, args.Type, args.StringValue);
///
/// Switch(args.Type)
/// {
/// Case(SampleSimplSharpClass.StringValueChange):
/// {
/// // specific ushort value changed
/// }
/// Default:
/// {
/// // generic ushort value changed
/// }
/// }
/// }
/// </code>
/// Register the event
/// <code>
/// Function Main()
/// {
/// //RegisterEveent([S+ class name], [S# event], [S+ event handler]);
/// RegisterEveent(mySplusClass, StringChange, StringChanged);
/// }
/// </code>
/// </example>
/// </remarks>
public class StringChangeEventArgs : EventArgs public class StringChangeEventArgs : EventArgs
{ {
/// <summary> /// <summary>
@@ -148,8 +298,8 @@ namespace PepperDash.Core
/// <summary> /// <summary>
/// Constructor overload /// Constructor overload
/// </summary> /// </summary>
/// <param name="stringValue"></param> /// <param name="stringValue">a string</param>
/// <param name="type"></param> /// <param name="type">a ushort number</param>
public StringChangeEventArgs(string stringValue, ushort type) public StringChangeEventArgs(string stringValue, ushort type)
{ {
StringValue = stringValue; StringValue = stringValue;
@@ -159,9 +309,9 @@ namespace PepperDash.Core
/// <summary> /// <summary>
/// Constructor overload /// Constructor overload
/// </summary> /// </summary>
/// <param name="stringValue"></param> /// <param name="stringValue">a string</param>
/// <param name="type"></param> /// <param name="type">a ushort number</param>
/// <param name="index"></param> /// <param name="index">a ushort number</param>
public StringChangeEventArgs(string stringValue, ushort type, ushort index) public StringChangeEventArgs(string stringValue, ushort type, ushort index)
{ {
StringValue = stringValue; StringValue = stringValue;

View File

@@ -208,12 +208,9 @@ namespace PepperDash.Core.GenericRESTfulCommunications
protected void OnBoolChange(bool state, ushort index, ushort type) protected void OnBoolChange(bool state, ushort index, ushort type)
{ {
var handler = BoolChange; var handler = BoolChange;
if (handler != null) if (handler == null) return;
{ var args = new BoolChangeEventArgs(state, type) {Index = index};
var args = new BoolChangeEventArgs(state, type); BoolChange(this, args);
args.Index = index;
BoolChange(this, args);
}
} }
/// <summary> /// <summary>
@@ -225,12 +222,9 @@ namespace PepperDash.Core.GenericRESTfulCommunications
protected void OnUshrtChange(ushort value, ushort index, ushort type) protected void OnUshrtChange(ushort value, ushort index, ushort type)
{ {
var handler = UshrtChange; var handler = UshrtChange;
if (handler != null) if (handler == null) return;
{ var args = new UshrtChangeEventArgs(value, type) {Index = index};
var args = new UshrtChangeEventArgs(value, type); UshrtChange(this, args);
args.Index = index;
UshrtChange(this, args);
}
} }
/// <summary> /// <summary>

View File

@@ -7,8 +7,11 @@ using Crestron.SimplSharp;
namespace PepperDash.Core.SystemInfo namespace PepperDash.Core.SystemInfo
{ {
/// <summary> /// <summary>
/// Processor info class /// Processor Info
/// </summary> /// </summary>
/// <remarks>
/// Stores processor information
/// </remarks>
public class ProcessorInfo public class ProcessorInfo
{ {
public string Model { get; set; } public string Model { get; set; }

View File

@@ -1,14 +1,19 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using Crestron.SimplSharp; using Crestron.SimplSharp;
using PepperDash.Core.DebugThings;
namespace PepperDash.Core.SystemInfo namespace PepperDash.Core.SystemInfo
{ {
/// <summary> /// <summary>
/// System Info class /// System Info to Simpl
/// </summary> /// </summary>
/// <remarks>
/// Contains methods that can be called from S+ to get information about the system.
/// </remarks>
public class SystemInfoToSimpl public class SystemInfoToSimpl
{ {
public event EventHandler<BoolChangeEventArgs> BoolChange; public event EventHandler<BoolChangeEventArgs> BoolChange;
@@ -36,7 +41,7 @@ namespace PepperDash.Core.SystemInfo
try try
{ {
var processor = new ProcessorInfo(); var processor = new ProcessorInfo();
processor.Model = InitialParametersClass.ControllerPromptName; processor.Model = InitialParametersClass.ControllerPromptName;
processor.SerialNumber = CrestronEnvironment.SystemInfo.SerialNumber; processor.SerialNumber = CrestronEnvironment.SystemInfo.SerialNumber;
processor.ModuleDirectory = InitialParametersClass.ProgramDirectory.ToString(); processor.ModuleDirectory = InitialParametersClass.ProgramDirectory.ToString();
@@ -281,6 +286,7 @@ namespace PepperDash.Core.SystemInfo
catch (Exception e) catch (Exception e)
{ {
var msg = string.Format("RefreshProgramUptimebyIndex({0}) failed:\r{1}", index, e.Message); var msg = string.Format("RefreshProgramUptimebyIndex({0}) failed:\r{1}", index, e.Message);
Debug.Console(0,"");
CrestronConsole.PrintLine(msg); CrestronConsole.PrintLine(msg);
//ErrorLog.Error(msg); //ErrorLog.Error(msg);
} }
@@ -295,25 +301,31 @@ namespace PepperDash.Core.SystemInfo
if (string.IsNullOrEmpty(cmd)) if (string.IsNullOrEmpty(cmd))
return; return;
string response = ""; try
CrestronConsole.SendControlSystemCommand(cmd, ref response);
if (!string.IsNullOrEmpty(response))
{ {
if (response.EndsWith("\x0D\\x0A")) string response = "";
response.Trim('\n'); CrestronConsole.SendControlSystemCommand(cmd, ref response);
if (string.IsNullOrEmpty(response)) return;
OnStringChange(response, 0, SystemInfoConstants.ConsoleResponseChange); if (response.Contains('\n'))
{
var lines = response.Split('\n');
if (lines == null) return;
foreach (var line in lines.Where(line => !string.IsNullOrEmpty(line)))
{
OnStringChange(line, 0, SystemInfoConstants.ConsoleResponseChange);
}
}
else
{
OnStringChange(response, 0, SystemInfoConstants.ConsoleResponseChange);
}
} }
catch (Exception ex)
{
Debug.Console(0,"Console Command Exception: {0}", ex);
}
} }
/// <summary>
/// private method to parse console messages
/// </summary>
/// <param name="response"></param>
/// <param name="line"></param>
/// <param name="start"></param>
/// <param name="end"></param>
/// <returns></returns>
private string ParseConsoleResponse(string data, string line, string dataStart, string dataEnd) private string ParseConsoleResponse(string data, string line, string dataStart, string dataEnd)
{ {
var response = ""; var response = "";
@@ -337,13 +349,7 @@ namespace PepperDash.Core.SystemInfo
return response; return response;
} }
/// <summary>
/// Protected 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) protected void OnBoolChange(bool state, ushort index, ushort type)
{ {
var handler = BoolChange; var handler = BoolChange;
@@ -354,13 +360,7 @@ namespace PepperDash.Core.SystemInfo
BoolChange(this, args); BoolChange(this, args);
} }
} }
/// <summary>
/// Protected 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) protected void OnStringChange(string value, ushort index, ushort type)
{ {
var handler = StringChange; var handler = StringChange;
@@ -371,13 +371,7 @@ namespace PepperDash.Core.SystemInfo
StringChange(this, args); StringChange(this, args);
} }
} }
/// <summary>
/// Protected processor config change event handler
/// </summary>
/// <param name="processor"></param>
/// <param name="index"></param>
/// <param name="type"></param>
protected void OnProcessorChange(ProcessorInfo processor, ushort index, ushort type) protected void OnProcessorChange(ProcessorInfo processor, ushort index, ushort type)
{ {
var handler = ProcessorChange; var handler = ProcessorChange;
@@ -388,13 +382,7 @@ namespace PepperDash.Core.SystemInfo
ProcessorChange(this, args); ProcessorChange(this, args);
} }
} }
/// <summary>
/// Ethernet change event handler
/// </summary>
/// <param name="ethernet"></param>
/// <param name="index"></param>
/// <param name="type"></param>
protected void OnEthernetInfoChange(EthernetInfo ethernet, ushort index, ushort type) protected void OnEthernetInfoChange(EthernetInfo ethernet, ushort index, ushort type)
{ {
var handler = EthernetChange; var handler = EthernetChange;
@@ -405,13 +393,7 @@ namespace PepperDash.Core.SystemInfo
EthernetChange(this, args); 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(ControlSubnetInfo ethernet, ushort index, ushort type) protected void OnControlSubnetInfoChange(ControlSubnetInfo ethernet, ushort index, ushort type)
{ {
var handler = ControlSubnetChange; var handler = ControlSubnetChange;
@@ -422,13 +404,7 @@ namespace PepperDash.Core.SystemInfo
ControlSubnetChange(this, args); ControlSubnetChange(this, args);
} }
} }
/// <summary>
/// Program change event handler
/// </summary>
/// <param name="program"></param>
/// <param name="index"></param>
/// <param name="type"></param>
protected void OnProgramChange(ProgramInfo program, ushort index, ushort type) protected void OnProgramChange(ProgramInfo program, ushort index, ushort type)
{ {
var handler = ProgramChange; var handler = ProgramChange;

View File

@@ -29,7 +29,8 @@ namespace PepperDash.Core.Intersystem.Tokens
public override byte[] GetBytes() public override byte[] GetBytes()
{ {
var serialBytes = Encoding.GetEncoding(28591).GetBytes(Value); var serialBytes = String.IsNullOrEmpty(Value) ? new byte[0] : Encoding.GetEncoding(28591).GetBytes(Value);
var xsig = new byte[serialBytes.Length + 3]; var xsig = new byte[serialBytes.Length + 3];
xsig[0] = (byte)(0xC8 | (Index >> 7)); xsig[0] = (byte)(0xC8 | (Index >> 7));
xsig[1] = (byte)((Index - 1) & 0x7F); xsig[1] = (byte)((Index - 1) & 0x7F);