diff --git a/packages.config b/packages.config index 242a7b7d..e0ed54c7 100644 --- a/packages.config +++ b/packages.config @@ -1,3 +1,3 @@ - + diff --git a/src/essentials-framework/Essentials Core/PepperDashEssentialsBase/Comm and IR/CommBridge.cs b/src/essentials-framework/Essentials Core/PepperDashEssentialsBase/Comm and IR/CommBridge.cs new file mode 100644 index 00000000..af9fd543 --- /dev/null +++ b/src/essentials-framework/Essentials Core/PepperDashEssentialsBase/Comm and IR/CommBridge.cs @@ -0,0 +1,117 @@ +using System; +using System.Collections.Generic; +using Crestron.SimplSharp.CrestronSockets; +using Crestron.SimplSharpPro.DeviceSupport; +using Newtonsoft.Json; +using System.Text; + +using PepperDash.Core; +using PepperDash.Essentials.Core.Bridges; +using PepperDash.Essentials.Core.Devices; +using PepperDash.Essentials.Core.Config; + + +namespace PepperDash.Essentials.Core +{ + /// + /// Implements IBasicCommunication and sends all communication through an EISC + /// + [Description("Generic communication wrapper class for any IBasicCommunication type")] + public class CommBridge : EssentialsBridgeableDevice, IBasicCommunication + { + private EiscApiAdvanced eisc; + + private IBasicCommunicationJoinMap joinMap; + + public event EventHandler TextReceived; + + public event EventHandler BytesReceived; + + public bool IsConnected { get; private set; } + + public CommBridge(string key, string name) + : base(key, name) + { + + } + + public void SendBytes(byte[] bytes) + { + if (eisc == null) + { + Debug.Console(0, this, "EISC not linked. Call LinkToApi before sending bytes."); + return; + } + eisc.Eisc.SetString(joinMap.SendText.JoinNumber, Encoding.ASCII.GetString(bytes, 0, bytes.Length)); + } + + public void SendText(string text) + { + if (eisc == null) + { + Debug.Console(0, this, "EISC not linked. Call LinkToApi before sending text."); + return; + } + eisc.Eisc.SetString(joinMap.SendText.JoinNumber, text); + } + + public void Connect() { + if (eisc == null) + { + Debug.Console(0, this, "EISC not linked. Call LinkToApi before connecting."); + return; + } + eisc.Eisc.SetBool(joinMap.Connect.JoinNumber, true); + } + + public void Disconnect() { + if (eisc == null) + { + Debug.Console(0, this, "EISC not linked. Call LinkToApi before disconnecting."); + return; + } + eisc.Eisc.SetBool(joinMap.Connect.JoinNumber, false); + } + + public override void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey, EiscApiAdvanced bridge) + { + joinMap = new IBasicCommunicationJoinMap(joinStart); + + var joinMapSerialized = JoinMapHelper.GetSerializedJoinMapForDevice(joinMapKey); + + if (!string.IsNullOrEmpty(joinMapSerialized)) + joinMap = JsonConvert.DeserializeObject(joinMapSerialized); + + if (bridge != null) + { + bridge.AddJoinMap(Key, joinMap); + } + else + { + Debug.Console(0, this, "Please update config to use 'eiscapiadvanced' to get all join map features for this device."); + } + + Debug.Console(1, this, "Linking to Trilist '{0}'", trilist.ID.ToString("X")); + + eisc = bridge; + + trilist.SetBoolSigAction(joinMap.Connected.JoinNumber, (b) => IsConnected = b); + + trilist.SetStringSigAction(joinMap.TextReceived.JoinNumber, (s) => { + var textHandler = TextReceived; + + if (textHandler != null) + { + textHandler(this, new GenericCommMethodReceiveTextArgs(s)); + } + + var bytesHandler = BytesReceived; + + if(bytesHandler != null) + { + bytesHandler(this, new GenericCommMethodReceiveBytesArgs(Encoding.ASCII.GetBytes(s))); + } + }); + } + } +} \ No newline at end of file diff --git a/src/essentials-framework/Essentials Core/PepperDashEssentialsBase/Comm and IR/CommFactory.cs b/src/essentials-framework/Essentials Core/PepperDashEssentialsBase/Comm and IR/CommFactory.cs index 5203d416..d63abd91 100644 --- a/src/essentials-framework/Essentials Core/PepperDashEssentialsBase/Comm and IR/CommFactory.cs +++ b/src/essentials-framework/Essentials Core/PepperDashEssentialsBase/Comm and IR/CommFactory.cs @@ -50,6 +50,9 @@ namespace PepperDash.Essentials.Core case eControlMethod.Com: comm = new ComPortController(deviceConfig.Key + "-com", GetComPort, controlConfig.ComParams, controlConfig); break; + case eControlMethod.ComBridge: + comm = new CommBridge(deviceConfig.Key + "-simpl", deviceConfig.Name + " Simpl"); + break; case eControlMethod.Cec: comm = new CecPortController(deviceConfig.Key + "-cec", GetCecPort, controlConfig); break; diff --git a/src/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj b/src/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj index 0dfd3657..9ae4379d 100644 --- a/src/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj +++ b/src/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj @@ -165,6 +165,7 @@ +