mirror of
https://github.com/PepperDash/EssentialsPluginTemplate.git
synced 2026-01-11 19:44:38 +00:00
Merge pull request #10 from PepperDash/feature/add-inline-documentation-and-todos
Feature/add inline documentation and todos
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
using PepperDash.Essentials.Core;
|
||||
|
||||
namespace EssentialsPluginTemplate
|
||||
{
|
||||
/// <summary>
|
||||
/// Plugin device Bridge Join Map
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Rename the class to match the device plugin being developed. Reference Essentials JoinMaps, if one exists for the device plugin being developed
|
||||
/// </remarks>
|
||||
/// <see cref="PepperDash.Essentials.Core.Bridges"/>
|
||||
/// <example>
|
||||
/// "EssentialsPluginBridgeJoinMapTemplate" renamed to "SamsungMdcBridgeJoinMap"
|
||||
/// </example>
|
||||
public class EssentialsPluginBridgeJoinMapTemplate : JoinMapBaseAdvanced
|
||||
{
|
||||
#region Digital
|
||||
|
||||
// TODO [ ] Add digital joins below plugin being developed
|
||||
|
||||
[JoinName("IsOnline")]
|
||||
public JoinDataComplete IsOnline = new JoinDataComplete(
|
||||
new JoinData
|
||||
{
|
||||
JoinNumber = 1,
|
||||
JoinSpan = 1
|
||||
},
|
||||
new JoinMetadata
|
||||
{
|
||||
Description = "Is Online",
|
||||
JoinCapabilities = eJoinCapabilities.ToSIMPL,
|
||||
JoinType = eJoinType.Digital
|
||||
});
|
||||
|
||||
[JoinName("Connect")]
|
||||
public JoinDataComplete Connect = new JoinDataComplete(
|
||||
new JoinData
|
||||
{
|
||||
JoinNumber = 2,
|
||||
JoinSpan = 1
|
||||
},
|
||||
new JoinMetadata
|
||||
{
|
||||
Description = "Connect (Held)/Disconnect (Release) & corresponding feedback",
|
||||
JoinCapabilities = eJoinCapabilities.ToFromSIMPL,
|
||||
JoinType = eJoinType.Digital
|
||||
});
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Analog
|
||||
|
||||
// TODO [ ] Add analog joins below plugin being developed
|
||||
|
||||
[JoinName("Status")]
|
||||
public JoinDataComplete Status = new JoinDataComplete(
|
||||
new JoinData
|
||||
{
|
||||
JoinNumber = 1,
|
||||
JoinSpan = 1
|
||||
},
|
||||
new JoinMetadata
|
||||
{
|
||||
Description = "Socket Status",
|
||||
JoinCapabilities = eJoinCapabilities.ToSIMPL,
|
||||
JoinType = eJoinType.Analog
|
||||
});
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Serial
|
||||
|
||||
// TODO [ ] Add serial joins below plugin being developed
|
||||
|
||||
public JoinDataComplete DeviceName = new JoinDataComplete(
|
||||
new JoinData
|
||||
{
|
||||
JoinNumber = 1,
|
||||
JoinSpan = 1
|
||||
},
|
||||
new JoinMetadata
|
||||
{
|
||||
Description = "Device Name",
|
||||
JoinCapabilities = eJoinCapabilities.ToSIMPL,
|
||||
JoinType = eJoinType.Serial
|
||||
});
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Plugin device BridgeJoinMap constructor
|
||||
/// </summary>
|
||||
/// <param name="joinStart">This will be the join it starts on the EISC bridge</param>
|
||||
public EssentialsPluginBridgeJoinMapTemplate(uint joinStart)
|
||||
: base(joinStart, typeof(EssentialsPluginBridgeJoinMapTemplate))
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,37 +1,195 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
|
||||
using PepperDash.Core;
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
using PepperDash.Essentials.Core;
|
||||
|
||||
namespace EssentialsPluginTemplateEPI
|
||||
namespace EssentialsPluginTemplate
|
||||
{
|
||||
/// <summary>
|
||||
/// Example of a config class that represents the structure of the Properties object of a DeviceConfig.
|
||||
/// The BuildDevice method will attempt to deserialize the Properties object into this class.
|
||||
/// Populate with any necssary properties for your device
|
||||
/// </summary>
|
||||
public class EssentialsPluginTemplatePropertiesConfig
|
||||
/// <summary>
|
||||
/// Plugin device configuration object
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Rename the class to match the device plugin being created
|
||||
/// </remarks>
|
||||
/// <example>
|
||||
/// "EssentialsPluginConfigObjectTemplate" renamed to "SamsungMdcConfig"
|
||||
/// </example>
|
||||
[ConfigSnippet("\"properties\":{\"control\":{}")]
|
||||
public class EssentialsPluginConfigObjectTemplate
|
||||
{
|
||||
// Below are some example properties
|
||||
/// <summary>
|
||||
/// JSON control object
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Typically this object is not required, but in some instances it may be needed. For example, when building a
|
||||
/// plugin that is using Telnet (TCP/IP) communications and requires login, the device will need to handle the login.
|
||||
/// In order to do so, you will need the username and password in the "tcpSshProperties" object.
|
||||
/// </remarks>
|
||||
/// <example>
|
||||
/// <code>
|
||||
/// "control": {
|
||||
/// "method": "tcpIp",
|
||||
/// "controlPortDevKey": "processor",
|
||||
/// "controlPortNumber": 1,
|
||||
/// "comParams": {
|
||||
/// "baudRate": 9600,
|
||||
/// "dataBits": 8,
|
||||
/// "stopBits": 1,
|
||||
/// "parity": "None",
|
||||
/// "protocol": "RS232",
|
||||
/// "hardwareHandshake": "None",
|
||||
/// "softwareHandshake": "None"
|
||||
/// },
|
||||
/// "tcpSshProperties": {
|
||||
/// "address": "172.22.0.101",
|
||||
/// "port": 23,
|
||||
/// "username": "admin",
|
||||
/// "password": "password",
|
||||
/// "autoReconnect": true,
|
||||
/// "autoReconnectIntervalMs": 10000
|
||||
/// }
|
||||
/// }
|
||||
/// </code>
|
||||
/// </example>
|
||||
[JsonProperty("control")]
|
||||
public EssentialsControlPropertiesConfig Control { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Serializes the poll time value
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This is an exmaple device plugin property. This should be modified or deleted as needed for the plugin being built.
|
||||
/// </remarks>
|
||||
/// <value>
|
||||
/// PollTimeMs property gets/sets the value as a long
|
||||
/// </value>
|
||||
/// <example>
|
||||
/// <code>
|
||||
/// "properties": {
|
||||
/// "polltimeMs": 30000
|
||||
/// }
|
||||
/// </code>
|
||||
/// </example>
|
||||
[JsonProperty("pollTimeMs")]
|
||||
public long PollTimeMs { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Control properties if needed to communicate with device.
|
||||
/// The JsonProperty attribute has been added to specify the name
|
||||
/// of the object and that it is required
|
||||
/// </summary>
|
||||
[JsonProperty("control", Required = Required.Always)]
|
||||
ControlPropertiesConfig Control { get; set; }
|
||||
/// <summary>
|
||||
/// Serializes the warning timeout value
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This is an exmaple device plugin property. This should be modified or deleted as needed for the plugin being built.
|
||||
/// </remarks>
|
||||
/// <value>
|
||||
/// WarningTimeoutMs property gets/sets the value as a long
|
||||
/// </value>
|
||||
/// <example>
|
||||
/// <code>
|
||||
/// "properties": {
|
||||
/// "warningTimeoutMs": 180000
|
||||
/// }
|
||||
/// </code>
|
||||
/// </example>
|
||||
[JsonProperty("warningTimeoutMs")]
|
||||
public long WarningTimeoutMs { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Add custom properties here
|
||||
/// </summary>
|
||||
[JsonProperty("myDeviceProperty")]
|
||||
string MyDeviceProperty { get; set; }
|
||||
/// <summary>
|
||||
/// Serializes the error timeout value
|
||||
/// </summary>
|
||||
/// /// <remarks>
|
||||
/// This is an exmaple device plugin property. This should be modified or deleted as needed for the plugin being built.
|
||||
/// </remarks>
|
||||
/// <value>
|
||||
/// ErrorTimeoutMs property gets/sets the value as a long
|
||||
/// </value>
|
||||
/// <example>
|
||||
/// <code>
|
||||
/// "properties": {
|
||||
/// "errorTimeoutMs": 300000
|
||||
/// }
|
||||
/// </code>
|
||||
/// </example>
|
||||
[JsonProperty("errorTimeoutMs")]
|
||||
public long ErrorTimeoutMs { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Example dictionary of objects
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This is an example collection configuration object. This should be modified or deleted as needed for the plugin being built.
|
||||
/// </remarks>
|
||||
/// <example>
|
||||
/// <code>
|
||||
/// "properties": {
|
||||
/// "presets": {
|
||||
/// "preset1": {
|
||||
/// "enabled": true,
|
||||
/// "name": "Preset 1"
|
||||
/// }
|
||||
/// }
|
||||
/// }
|
||||
/// </code>
|
||||
/// </example>
|
||||
/// <example>
|
||||
/// <code>
|
||||
/// "properties": {
|
||||
/// "inputNames": {
|
||||
/// "input1": "Input 1",
|
||||
/// "input2": "Input 2"
|
||||
/// }
|
||||
/// }
|
||||
/// </code>
|
||||
/// </example>
|
||||
[JsonProperty("DeviceDictionary")]
|
||||
public Dictionary<string, EssentialsPluginConfigObjectDictionaryTemplate> DeviceDictionary { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Constuctor
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// If using a collection you must instantiate the collection in the constructor
|
||||
/// to avoid exceptions when reading the configuration file
|
||||
/// </remarks>
|
||||
public EssentialsPluginConfigObjectTemplate()
|
||||
{
|
||||
DeviceDictionary = new Dictionary<string, EssentialsPluginConfigObjectDictionaryTemplate>();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Example plugin configuration dictionary object
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This is an example collection of configuration objects. This can be modified or deleted as needed for the plugin being built.
|
||||
/// </remarks>
|
||||
/// <example>
|
||||
/// <code>
|
||||
/// "properties": {
|
||||
/// "dictionary": {
|
||||
/// "item1": {
|
||||
/// "name": "Item 1 Name",
|
||||
/// "value": "Item 1 Value"
|
||||
/// }
|
||||
/// }
|
||||
/// }
|
||||
/// </code>
|
||||
/// </example>
|
||||
public class EssentialsPluginConfigObjectDictionaryTemplate
|
||||
{
|
||||
/// <summary>
|
||||
/// Serializes collection name property
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This is an example collection of configuration objects. This can be modified or deleted as needed for the plugin being built.
|
||||
/// </remarks>
|
||||
[JsonProperty("name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Serializes collection value property
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This is an example collection of configuration objects. This can be modified or deleted as needed for the plugin being built.
|
||||
/// </remarks>
|
||||
[JsonProperty("value")]
|
||||
public uint Value { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,67 +1,246 @@
|
||||
using Crestron.SimplSharpPro.DeviceSupport;
|
||||
using Newtonsoft.Json;
|
||||
using PDT.EssentialsPluginTemplate.EPI;
|
||||
// For Basic SIMPL# Classes
|
||||
// For Basic SIMPL#Pro classes
|
||||
|
||||
using Crestron.SimplSharpPro.DeviceSupport;
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Essentials.Core;
|
||||
using PepperDash.Essentials.Core.Bridges;
|
||||
using PepperDash.Core;
|
||||
|
||||
namespace EssentialsPluginTemplateEPI
|
||||
namespace EssentialsPluginTemplate
|
||||
{
|
||||
/// <summary>
|
||||
/// Example of a plugin device
|
||||
/// </summary>
|
||||
public class EssentialsPluginTemplateDevice : EssentialsDevice, IBridgeAdvanced
|
||||
{
|
||||
/// <summary>
|
||||
/// Device Constructor. Called by BuildDevice
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="config"></param>
|
||||
public EssentialsPluginTemplateDevice(string key, string name, EssentialsPluginTemplatePropertiesConfig config)
|
||||
: base(key, name)
|
||||
{
|
||||
/// <summary>
|
||||
/// Plugin device
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Rename the class to match the device plugin being developed.
|
||||
/// </remarks>
|
||||
/// <example>
|
||||
/// "EssentialsPluginDeviceTemplate" renamed to "SamsungMdcDevice"
|
||||
/// </example>
|
||||
public class EssentialsPluginDeviceTemplate : EssentialsBridgeableDevice
|
||||
{
|
||||
// TODO [ ] Add, modify, remove properties and fields as needed for the plugin being developed
|
||||
private readonly IBasicCommunication _comms;
|
||||
private readonly GenericCommunicationMonitor _commsMonitor;
|
||||
|
||||
}
|
||||
// _comms gather for ASCII based API's
|
||||
// TODO [ ] If not using an ASCII based API, delete the properties below
|
||||
private readonly CommunicationGather _commsGather;
|
||||
private const string CommsDelimiter = "\r";
|
||||
|
||||
/// <summary>
|
||||
/// Add items to be executed during the Activaction phase
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override bool CustomActivate()
|
||||
{
|
||||
|
||||
return base.CustomActivate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method gets called by the EiscApi bridge and calls your bridge extension method
|
||||
/// </summary>
|
||||
/// <param name="trilist"></param>
|
||||
/// <param name="joinStart"></param>
|
||||
/// <param name="joinMapKey"></param>
|
||||
public void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey, EiscApiAdvanced bridge)
|
||||
{
|
||||
// Construct the default join map
|
||||
var joinMap = new EssentialsPluginTemplateBridgeJoinMap(joinStart);
|
||||
|
||||
// Attempt to get a custom join map if specified in config
|
||||
var joinMapSerialized = JoinMapHelper.GetJoinMapForDevice(joinMapKey);
|
||||
|
||||
// If we find a custom join map, deserialize it
|
||||
if (!string.IsNullOrEmpty(joinMapSerialized))
|
||||
joinMap = JsonConvert.DeserializeObject<EssentialsPluginTemplateBridgeJoinMap>(joinMapSerialized);
|
||||
|
||||
//Checking if the bridge is null allows for backwards compatability with configurations that use EiscApi instead of EiscApiAdvanced
|
||||
if (bridge != null)
|
||||
{
|
||||
bridge.AddJoinMap(Key, joinMap);
|
||||
}
|
||||
|
||||
// Set all your join actions here
|
||||
// _comms byte buffer for HEX/byte based API's
|
||||
// TODO [ ] If not using an HEX/byte based API, delete the properties below
|
||||
private byte[] _commsByteBuffer = { };
|
||||
|
||||
|
||||
// Link all your feedbacks to joins here
|
||||
}
|
||||
}
|
||||
}
|
||||
private EssentialsPluginConfigObjectTemplate _config;
|
||||
|
||||
/// <summary>
|
||||
/// Connects/disconnects the comms of the plugin device
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// triggers the _comms.Connect/Disconnect as well as thee comms monitor start/stop
|
||||
/// </remarks>
|
||||
public bool Connect
|
||||
{
|
||||
get { return _comms.IsConnected; }
|
||||
set
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
_comms.Connect();
|
||||
_commsMonitor.Start();
|
||||
}
|
||||
else
|
||||
{
|
||||
_comms.Disconnect();
|
||||
_commsMonitor.Stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reports connect feedback through the bridge
|
||||
/// </summary>
|
||||
public BoolFeedback ConnectFeedback { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Reports online feedback through the bridge
|
||||
/// </summary>
|
||||
public BoolFeedback OnlineFeedback { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Reports socket status feedback through the bridge
|
||||
/// </summary>
|
||||
public IntFeedback StatusFeedback { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Plugin device constructor
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="config"></param>
|
||||
/// <param name="comms"></param>
|
||||
public EssentialsPluginDeviceTemplate(string key, string name, EssentialsPluginConfigObjectTemplate config, IBasicCommunication comms)
|
||||
: base(key, name)
|
||||
{
|
||||
Debug.Console(0, this, "Constructing new {0} instance", name);
|
||||
|
||||
// TODO [ ] Update the constructor as needed for the plugin device being developed
|
||||
|
||||
_config = config;
|
||||
|
||||
ConnectFeedback = new BoolFeedback(() => Connect);
|
||||
OnlineFeedback = new BoolFeedback(() => _commsMonitor.IsOnline);
|
||||
StatusFeedback = new IntFeedback(() => (int)_commsMonitor.Status);
|
||||
|
||||
_comms = comms;
|
||||
_commsMonitor = new GenericCommunicationMonitor(this, _comms, _config.PollTimeMs, _config.WarningTimeoutMs, _config.ErrorTimeoutMs, Poll);
|
||||
|
||||
var socket = _comms as ISocketStatus;
|
||||
if (socket != null)
|
||||
{
|
||||
// device comms is IP **ELSE** device comms is RS232
|
||||
socket.ConnectionChange += socket_ConnectionChange;
|
||||
Connect = true;
|
||||
}
|
||||
|
||||
// _comms gather for ASCII based API's
|
||||
// TODO [ ] If not using an ASCII based API, delete the properties below
|
||||
_commsGather = new CommunicationGather(_comms, CommsDelimiter);
|
||||
AddPostActivationAction(() => _commsGather.LineReceived += Handle_LineRecieved);
|
||||
|
||||
// _comms byte buffer for HEX/byte based API's
|
||||
// TODO [ ] If not using an HEX/byte based API, delete the properties below
|
||||
_comms.BytesReceived += Handle_BytesReceived;
|
||||
AddPostActivationAction(() => _comms.BytesReceived += Handle_BytesReceived);
|
||||
}
|
||||
|
||||
#region Overrides of EssentialsBridgeableDevice
|
||||
|
||||
/// <summary>
|
||||
/// Links the plugin device to the EISC bridge
|
||||
/// </summary>
|
||||
/// <param name="trilist"></param>
|
||||
/// <param name="joinStart"></param>
|
||||
/// <param name="joinMapKey"></param>
|
||||
/// <param name="bridge"></param>
|
||||
public override void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey, EiscApiAdvanced bridge)
|
||||
{
|
||||
var joinMap = new EssentialsPluginBridgeJoinMapTemplate(joinStart);
|
||||
|
||||
// This adds the join map to the collection on the bridge
|
||||
if (bridge != null)
|
||||
{
|
||||
bridge.AddJoinMap(Key, joinMap);
|
||||
}
|
||||
|
||||
var customJoins = JoinMapHelper.TryGetJoinMapAdvancedForDevice(joinMapKey);
|
||||
|
||||
if (customJoins != null)
|
||||
{
|
||||
joinMap.SetCustomJoinData(customJoins);
|
||||
}
|
||||
|
||||
Debug.Console(1, "Linking to Trilist '{0}'", trilist.ID.ToString("X"));
|
||||
Debug.Console(0, "Linking to Bridge Type {0}", GetType().Name);
|
||||
|
||||
// TODO [ ] Implement bridge links as needed
|
||||
|
||||
// links to bridge
|
||||
trilist.SetString(joinMap.DeviceName.JoinNumber, Name);
|
||||
|
||||
trilist.SetBoolSigAction(joinMap.Connect.JoinNumber, sig => Connect = sig);
|
||||
ConnectFeedback.LinkInputSig(trilist.BooleanInput[joinMap.Connect.JoinNumber]);
|
||||
|
||||
StatusFeedback.LinkInputSig(trilist.UShortInput[joinMap.Status.JoinNumber]);
|
||||
OnlineFeedback.LinkInputSig(trilist.BooleanInput[joinMap.IsOnline.JoinNumber]);
|
||||
|
||||
UpdateFeedbacks();
|
||||
|
||||
trilist.OnlineStatusChange += (o, a) =>
|
||||
{
|
||||
if (!a.DeviceOnLine) return;
|
||||
|
||||
trilist.SetString(joinMap.DeviceName.JoinNumber, Name);
|
||||
UpdateFeedbacks();
|
||||
};
|
||||
}
|
||||
|
||||
private void UpdateFeedbacks()
|
||||
{
|
||||
// TODO [ ] Update as needed for the plugin being developed
|
||||
ConnectFeedback.FireUpdate();
|
||||
OnlineFeedback.FireUpdate();
|
||||
StatusFeedback.FireUpdate();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private void socket_ConnectionChange(object sender, GenericSocketStatusChageEventArgs args)
|
||||
{
|
||||
if (ConnectFeedback != null)
|
||||
ConnectFeedback.FireUpdate();
|
||||
|
||||
if (StatusFeedback != null)
|
||||
StatusFeedback.FireUpdate();
|
||||
}
|
||||
|
||||
// TODO [ ] If not using an ASCII based API, delete the properties below
|
||||
private void Handle_LineRecieved(object sender, GenericCommMethodReceiveTextArgs args)
|
||||
{
|
||||
// TODO [ ] Implement method
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
// TODO [ ] If not using an HEX/byte based API, delete the properties below
|
||||
private void Handle_BytesReceived(object sender, GenericCommMethodReceiveBytesArgs args)
|
||||
{
|
||||
// TODO [ ] Implement method
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
// TODO [ ] If not using an ACII based API, delete the properties below
|
||||
/// <summary>
|
||||
/// Sends text to the device plugin comms
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Can be used to test commands with the device plugin using the DEVPROPS and DEVJSON console commands
|
||||
/// </remarks>
|
||||
/// <param name="text">Command to be sent</param>
|
||||
public void SendText(string text)
|
||||
{
|
||||
if (string.IsNullOrEmpty(text)) return;
|
||||
|
||||
_comms.SendText(string.Format("{0}{1}", text, CommsDelimiter));
|
||||
}
|
||||
|
||||
// TODO [ ] If not using an HEX/byte based API, delete the properties below
|
||||
/// <summary>
|
||||
/// Sends bytes to the device plugin comms
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Can be used to test commands with the device plugin using the DEVPROPS and DEVJSON console commands
|
||||
/// </remarks>
|
||||
/// <param name="bytes">Bytes to be sent</param>
|
||||
public void SendBytes(byte[] bytes)
|
||||
{
|
||||
if (bytes == null) return;
|
||||
|
||||
_comms.SendBytes(bytes);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Polls the device
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Poll method is used by the communication monitor. Update the poll method as needed for the plugin being developed
|
||||
/// </remarks>
|
||||
public void Poll()
|
||||
{
|
||||
// TODO [ ] Update Poll method as needed for the plugin being developed
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,43 +1,92 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Crestron.SimplSharp; // For Basic SIMPL# Classes
|
||||
using Crestron.SimplSharpPro; // For Basic SIMPL#Pro classes
|
||||
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
using PepperDash.Essentials;
|
||||
using PepperDash.Essentials.Core;
|
||||
using PepperDash.Essentials.Core.Config;
|
||||
using System.Collections.Generic;
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Essentials.Core;
|
||||
|
||||
namespace EssentialsPluginTemplateEPI
|
||||
namespace EssentialsPluginTemplate
|
||||
{
|
||||
/// <summary>
|
||||
/// This class contains the necessary properties and methods required to function as an Essentials Plugin
|
||||
/// </summary>
|
||||
public class EssentialsPluginFactory:EssentialsPluginDeviceFactory<EssentialsPluginTemplateDevice>
|
||||
/// <summary>
|
||||
/// Plugin device factory
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Rename the class to match the device plugin being developed
|
||||
/// </remarks>
|
||||
/// <example>
|
||||
/// "EssentialsPluginFactoryTemplate" renamed to "SamsungMdcFactory"
|
||||
/// </example>
|
||||
public class EssentialsPluginFactoryTemplate : EssentialsPluginDeviceFactory<EssentialsPluginDeviceTemplate>
|
||||
{
|
||||
public EssentialsPluginFactory()
|
||||
/// <summary>
|
||||
/// Plugin device factory constructor
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Update the MinimumEssentialsFrameworkVersion & TypeNames as needed when creating a plugin
|
||||
/// </remarks>
|
||||
/// <example>
|
||||
/// <code>
|
||||
/// // Set the minimum Essentials Framework Version
|
||||
/// MinimumEssentialsFrameworkVersion = "1.5.5";
|
||||
/// // In the constructor we initialize the list with the typenames that will build an instance of this device
|
||||
#pragma warning disable 1570
|
||||
/// TypeNames = new List<string>() { "SamsungMdc", "SamsungMdcDisplay" };
|
||||
#pragma warning restore 1570
|
||||
/// </code>
|
||||
/// </example>
|
||||
public EssentialsPluginFactoryTemplate()
|
||||
{
|
||||
// This string is used to define the minimum version of the
|
||||
// Essentials Framework required for this plugin
|
||||
MinimumEssentialsFrameworkVersion = "1.6.1";
|
||||
// Set the minimum Essentials Framework Version
|
||||
// TODO [ ] Update the Essentials minimum framework version which this plugin has been tested against
|
||||
MinimumEssentialsFrameworkVersion = "1.6.4";
|
||||
|
||||
//The strings defined in this list will be used in the configuration file to build the device in this plugin.
|
||||
TypeNames = new List<string> {"essentialsPluginTemplateDevice"};
|
||||
// In the constructor we initialize the list with the typenames that will build an instance of this device
|
||||
// TODO [ ] Update the TypeNames for the plugin being developed
|
||||
TypeNames = new List<string>() { "examplePluginDevice" };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds and returns an instance of EssentialsPluginDeviceTemplate
|
||||
/// </summary>
|
||||
/// <param name="dc">device configuration</param>
|
||||
/// <returns>plugin device or null</returns>
|
||||
/// <remarks>
|
||||
/// The example provided below takes the device key, name, properties config and the comms device created.
|
||||
/// Modify the EssetnialsPlugingDeviceTemplate constructor as needed to meet the requirements of the plugin device.
|
||||
/// </remarks>
|
||||
/// <seealso cref="PepperDash.Core.eControlMethod"/>
|
||||
public override EssentialsDevice BuildDevice(PepperDash.Essentials.Core.Config.DeviceConfig dc)
|
||||
{
|
||||
Debug.Console(1, "[{0}] Factory Attempting to create new device from type: {1}", dc.Key, dc.Type);
|
||||
|
||||
// get the plugin device properties configuration object & check for null
|
||||
var propertiesConfig = dc.Properties.ToObject<EssentialsPluginConfigObjectTemplate>();
|
||||
if (propertiesConfig == null)
|
||||
{
|
||||
Debug.Console(0, "[{0}] Factory: failed to read properties config for {1}", dc.Key, dc.Name);
|
||||
return null;
|
||||
}
|
||||
|
||||
// TODO [ ] Discuss with Andrew/Neil on recommended best practice
|
||||
|
||||
// Method 1
|
||||
//var username = dc.Properties["control"].Value<TcpSshPropertiesConfig>("tcpSshProperties").Username;
|
||||
//var password = dc.Properties["control"].Value<TcpSshPropertiesConfig>("tcpSshProperties").Password;
|
||||
//var method = dc.Properties["control"].Value<string>("method");
|
||||
|
||||
// Method 2 - Returns a JValue, has to be casted to string
|
||||
var username = (string)dc.Properties["control"]["tcpSshProperties"]["username"];
|
||||
var password = (string)dc.Properties["control"]["tcpSshProperties"]["password"];
|
||||
var method = (string)dc.Properties["control"]["method"];
|
||||
|
||||
// build the plugin device comms & check for null
|
||||
// TODO { ] As of PepperDash Core 1.0.41, HTTP and HTTPS are not valid eControlMethods and will throw an exception.
|
||||
var comms = CommFactory.CreateCommForDevice(dc);
|
||||
if (comms == null)
|
||||
{
|
||||
Debug.Console(0, "[{0}] Factory: failed to create comm for {1}", dc.Key, dc.Name);
|
||||
return null;
|
||||
}
|
||||
|
||||
return new EssentialsPluginDeviceTemplate(dc.Key, dc.Name, propertiesConfig, comms);
|
||||
}
|
||||
|
||||
#region Overrides of EssentialsDeviceFactory<EssentialsPluginTemplateDevice>
|
||||
|
||||
public override EssentialsDevice BuildDevice(DeviceConfig dc)
|
||||
{
|
||||
var config = dc.Properties.ToObject<EssentialsPluginTemplatePropertiesConfig>();
|
||||
var newDevice = new EssentialsPluginTemplateDevice(dc.Key, dc.Name, config);
|
||||
return newDevice;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
using PepperDash.Essentials.Core;
|
||||
|
||||
namespace PDT.EssentialsPluginTemplate.EPI
|
||||
{
|
||||
public class EssentialsPluginTemplateBridgeJoinMap : JoinMapBaseAdvanced
|
||||
{
|
||||
[JoinName("IsOnline")]
|
||||
public JoinDataComplete IsOnline = new JoinDataComplete(new JoinData {JoinNumber = 1, JoinSpan = 1},
|
||||
new JoinMetadata
|
||||
{
|
||||
Description = "Device is Online",
|
||||
JoinType = eJoinType.Digital,
|
||||
JoinCapabilities = eJoinCapabilities.ToSIMPL
|
||||
});
|
||||
|
||||
|
||||
public EssentialsPluginTemplateBridgeJoinMap(uint joinStart):base(joinStart, typeof(EssentialsPluginTemplateBridgeJoinMap))
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -95,9 +95,9 @@
|
||||
<Reference Include="System.Data" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="EssentialsPluginTemplateBridgeJoinMap.cs" />
|
||||
<Compile Include="EssentialsPluginTemplateConfigObject.cs" />
|
||||
<Compile Include="EssentialsPluginTemplateFactory.cs" />
|
||||
<Compile Include="EssentialsPluginTemplateJoinMap.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="EssentialsPluginTemplateDevice.cs" />
|
||||
<None Include="Properties\ControlSystem.cfg" />
|
||||
|
||||
@@ -25,3 +25,9 @@ To verify that the packages installed correctly, open the plugin solution in you
|
||||
### Installing Different versions of PepperDash Core
|
||||
|
||||
If you need a different version of PepperDash Core, use the command `nuget install .\packages.config -OutputDirectory .\packages -excludeVersion -Version {versionToGet}`. Omitting the `-Version` option will pull the version indicated in the packages.config file.
|
||||
|
||||
### Instructions for Renaming Solution and Files
|
||||
|
||||
See the Task List in Visual Studio for a guide on how to start using the templage. There is extensive inline documentation and examples as well.
|
||||
|
||||
For renaming instructions in particular, see the XML `remarks` tags on class definitions
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
<packages>
|
||||
<package id="PepperDashEssentials" version="1.6.2" targetFramework="net35" allowedVersions="[1.0,2.0)"/>
|
||||
<package id="PepperDashEssentials" version="1.6.4" targetFramework="net35" allowedVersions="[1.0,2.0)"/>
|
||||
</packages>
|
||||
Reference in New Issue
Block a user