diff --git a/PepperDashEssentials/Bridges/BridgeBase.cs b/PepperDashEssentials/Bridges/BridgeBase.cs index 3fa7a657..cfac69e1 100644 --- a/PepperDashEssentials/Bridges/BridgeBase.cs +++ b/PepperDashEssentials/Bridges/BridgeBase.cs @@ -65,6 +65,8 @@ namespace PepperDash.Essentials.Bridges AddPostActivationAction( () => { + Debug.Console(1, this, "Linking Devices..."); + foreach (var d in PropertiesConfig.Devices) { var device = DeviceManager.GetDeviceForKey(d.DeviceKey); @@ -73,10 +75,13 @@ namespace PepperDash.Essentials.Bridges { if (device is GenericComm) { - (device as GenericComm).LinkToApi(Eisc, d.JoinStart); + + (device as GenericComm).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey); } } } + + Debug.Console(1, this, "Devices Linked."); }); } @@ -88,7 +93,7 @@ namespace PepperDash.Essentials.Bridges void Eisc_SigChange(object currentDevice, Crestron.SimplSharpPro.SigEventArgs args) { if (Debug.Level >= 1) - Debug.Console(1, this, "BridgeApi EISC change: {0} {1}={2}", args.Sig.Type, args.Sig.Number, args.Sig.StringValue); + Debug.Console(1, this, "EiscApi change: {0} {1}={2}", args.Sig.Type, args.Sig.Number, args.Sig.StringValue); var uo = args.Sig.UserObject; if (uo is Action) (uo as Action)(args.Sig.BoolValue); @@ -114,6 +119,9 @@ namespace PepperDash.Essentials.Bridges [JsonProperty("joinStart")] public uint JoinStart { get; set; } + + [JsonProperty("joinMapKey")] + public string JoinMapKey { get; set; } } } diff --git a/PepperDashEssentials/Bridges/IBasicCommunicationBridgeMap.cs b/PepperDashEssentials/Bridges/IBasicCommunicationBridgeMap.cs index ee9ac2f2..29131bd0 100644 --- a/PepperDashEssentials/Bridges/IBasicCommunicationBridgeMap.cs +++ b/PepperDashEssentials/Bridges/IBasicCommunicationBridgeMap.cs @@ -13,12 +13,27 @@ namespace PepperDash.Essentials.Bridges { public static class IBasicCommunicationExtensions { - public static void LinkToApi(this GenericComm comm, BasicTriList trilist, uint joinStart) + public static void LinkToApi(this GenericComm comm, BasicTriList trilist, uint joinStart, string joinMapKey) { + var joinMap = GetJoinMapForDevice(joinMapKey); + + if (joinMap == null) + joinMap = new IBasicCommunicationJoinMap(); + + joinMap.OffsetJoinNumbers(joinStart); + + if (comm.CommPort == null) + { + Debug.Console(1, comm, "Unable to link device '{0}'. CommPort is null", comm.Key); + return; + } + + Debug.Console(1, comm, "Linking device '{0}' to Trilist '{1}'", comm.Key, trilist.ID); + // this is a permanent event handler. This cannot be -= from event - comm.CommPort.TextReceived += (s, a) => trilist.SetString(joinStart, a.Text); - trilist.SetStringSigAction(joinStart, new Action(s => comm.CommPort.SendText(s))); - trilist.SetStringSigAction(joinStart + 1, new Action(s => comm.SetPortConfig(s))); + comm.CommPort.TextReceived += (s, a) => trilist.SetString(joinMap.TextReceived, a.Text); + trilist.SetStringSigAction(joinMap.SendText, new Action(s => comm.CommPort.SendText(s))); + trilist.SetStringSigAction(joinMap.SetPortConfig + 1, new Action(s => comm.SetPortConfig(s))); var sComm = comm.CommPort as ISocketStatus; @@ -26,12 +41,12 @@ namespace PepperDash.Essentials.Bridges { sComm.ConnectionChange += (s, a) => { - trilist.SetUshort(joinStart, (ushort)(a.Client.ClientStatus)); - trilist.SetBool(joinStart, a.Client.ClientStatus == + trilist.SetUshort(joinMap.Status, (ushort)(a.Client.ClientStatus)); + trilist.SetBool(joinMap.Connected, a.Client.ClientStatus == Crestron.SimplSharp.CrestronSockets.SocketStatus.SOCKET_STATUS_CONNECTED); }; - trilist.SetBoolSigAction(joinStart, new Action(b => + trilist.SetBoolSigAction(joinMap.Connect, new Action(b => { if (b) { @@ -44,6 +59,58 @@ namespace PepperDash.Essentials.Bridges })); } } + + /// + /// Attempts to get the join map from config + /// + /// + /// + public static IBasicCommunicationJoinMap GetJoinMapForDevice(string joinMapKey) + { + if(!string.IsNullOrEmpty(joinMapKey)) + return null; + + // TODO: Get the join map from the ConfigReader.ConfigObject + + return null; + } + + public class IBasicCommunicationJoinMap + { + // Default joins + public uint TextReceived { get; set; } + public uint SendText { get; set; } + public uint SetPortConfig { get; set; } + public uint Connect { get; set; } + public uint Connected { get; set; } + public uint Status { get; set; } + + public IBasicCommunicationJoinMap() + { + TextReceived = 1; + SendText = 1; + SetPortConfig = 2; + Connect = 1; + Connected = 1; + Status = 1; + } + + /// + /// Modifies all the join numbers by adding the offset. This should never be called twice + /// + /// + public void OffsetJoinNumbers(uint joinStart) + { + var joinOffset = joinStart - 1; + + TextReceived = TextReceived + joinOffset; + SendText = SendText + joinOffset; + SetPortConfig = SetPortConfig + joinOffset; + Connect = Connect + joinOffset; + Connected = Connected + joinOffset; + Status = Status + joinOffset; + } + } } ///// ///// diff --git a/Release Package/PepperDashEssentials.cpz b/Release Package/PepperDashEssentials.cpz index f3e5a786..730aac16 100644 Binary files a/Release Package/PepperDashEssentials.cpz and b/Release Package/PepperDashEssentials.cpz differ diff --git a/Release Package/PepperDashEssentials.dll b/Release Package/PepperDashEssentials.dll index c01af705..9832c536 100644 Binary files a/Release Package/PepperDashEssentials.dll and b/Release Package/PepperDashEssentials.dll differ diff --git a/essentials-framework b/essentials-framework index 88149415..dbb52a54 160000 --- a/essentials-framework +++ b/essentials-framework @@ -1 +1 @@ -Subproject commit 88149415b77baee1eaa0c87a7f65f0b8425bed3a +Subproject commit dbb52a5428d1cbdd96af7ede9e1d81d3faa52206