diff --git a/PepperDashEssentials/Bridges/BridgeBase.cs b/PepperDashEssentials/Bridges/BridgeBase.cs index b8cf0fc0..3fa7a657 100644 --- a/PepperDashEssentials/Bridges/BridgeBase.cs +++ b/PepperDashEssentials/Bridges/BridgeBase.cs @@ -10,6 +10,7 @@ using Newtonsoft.Json; using PepperDash.Core; using PepperDash.Essentials.Core; using PepperDash.Essentials.Core.Devices; +using PepperDash.Essentials.Core.Config; namespace PepperDash.Essentials.Bridges { @@ -46,17 +47,37 @@ namespace PepperDash.Essentials.Bridges /// public class EiscApi : BridgeApi { + public EiscApiPropertiesConfig PropertiesConfig { get; private set; } + public ThreeSeriesTcpIpEthernetIntersystemCommunications Eisc { get; private set; } - public EiscApi(string key, uint ipid, string hostname) : - base(key) + public EiscApi(DeviceConfig dc) : + base(dc.Key) { - Eisc = new ThreeSeriesTcpIpEthernetIntersystemCommunications(ipid, hostname, Global.ControlSystem); + PropertiesConfig = JsonConvert.DeserializeObject(dc.Properties.ToString()); + + Eisc = new ThreeSeriesTcpIpEthernetIntersystemCommunications(PropertiesConfig.Control.IpIdInt, PropertiesConfig.Control.TcpSshProperties.Address, Global.ControlSystem); Eisc.SigChange += new Crestron.SimplSharpPro.DeviceSupport.SigEventHandler(Eisc_SigChange); Eisc.Register(); + + AddPostActivationAction( () => + { + foreach (var d in PropertiesConfig.Devices) + { + var device = DeviceManager.GetDeviceForKey(d.DeviceKey); + + if (device != null) + { + if (device is GenericComm) + { + (device as GenericComm).LinkToApi(Eisc, d.JoinStart); + } + } + } + }); } /// @@ -83,7 +104,6 @@ namespace PepperDash.Essentials.Bridges [JsonProperty("control")] public EssentialsControlPropertiesConfig Control { get; set; } - [JsonProperty("devices")] public List Devices { get; set; } @@ -93,7 +113,7 @@ namespace PepperDash.Essentials.Bridges public string DeviceKey { get; set; } [JsonProperty("joinStart")] - public int JoinStart { get; set; } + public uint JoinStart { get; set; } } } @@ -165,42 +185,42 @@ namespace PepperDash.Essentials.Bridges - /// - /// Each flavor of API is a static class with static properties and a static constructor that - /// links up the things to do. - /// - public class DmChassisControllerApi : DeviceApiBase - { - IntFeedback Output1Feedback; - IntFeedback Output2Feedback; + ///// + ///// Each flavor of API is a static class with static properties and a static constructor that + ///// links up the things to do. + ///// + //public class DmChassisControllerApi : DeviceApiBase + //{ + // IntFeedback Output1Feedback; + // IntFeedback Output2Feedback; - public DmChassisControllerApi(DmChassisController dev) - { - Output1Feedback = new IntFeedback( new Func(() => 1)); - Output2Feedback = new IntFeedback( new Func(() => 2)); + // public DmChassisControllerApi(DmChassisController dev) + // { + // Output1Feedback = new IntFeedback( new Func(() => 1)); + // Output2Feedback = new IntFeedback( new Func(() => 2)); - ActionApi = new Dictionary - { + // ActionApi = new Dictionary + // { - }; + // }; - FeedbackApi = new Dictionary - { - { "Output-1/fb", Output1Feedback }, - { "Output-2/fb", Output2Feedback } - }; - } + // FeedbackApi = new Dictionary + // { + // { "Output-1/fb", Output1Feedback }, + // { "Output-2/fb", Output2Feedback } + // }; + // } - /// - /// Factory method - /// - /// - /// - public static DmChassisControllerApi GetActionApiForDevice(DmChassisController dev) - { - return new DmChassisControllerApi(dev); - } - } + // /// + // /// Factory method + // /// + // /// + // /// + // public static DmChassisControllerApi GetActionApiForDevice(DmChassisController dev) + // { + // return new DmChassisControllerApi(dev); + // } + //} } \ No newline at end of file diff --git a/PepperDashEssentials/Bridges/BridgeFactory.cs b/PepperDashEssentials/Bridges/BridgeFactory.cs index 97cc6fce..90adc115 100644 --- a/PepperDashEssentials/Bridges/BridgeFactory.cs +++ b/PepperDashEssentials/Bridges/BridgeFactory.cs @@ -9,6 +9,7 @@ using PepperDash.Essentials.Core; using PepperDash.Essentials.Core.Config; using PepperDash.Core; using PepperDash.Essentials.Core.Routing; +using PepperDash.Essentials.Bridges; using Crestron.SimplSharpPro; using Crestron.SimplSharpPro.EthernetCommunication; @@ -16,7 +17,7 @@ namespace PepperDash.Essentials { public class BridgeFactory { - public static IKeyed GetDevice(PepperDash.Essentials.Core.Config.DeviceConfig dc) + public static IKeyed GetDevice(DeviceConfig dc) { // ? why is this static JTA 2018-06-13? @@ -25,22 +26,18 @@ namespace PepperDash.Essentials var type = dc.Type; var properties = dc.Properties; var propAnon = new { }; - JsonConvert.DeserializeAnonymousType(dc.Properties.ToString(), propAnon); var typeName = dc.Type.ToLower(); var groupName = dc.Group.ToLower(); Debug.Console(0, "Name {0}, Key {1}, Type {2}, Properties {3}", name, key, type, properties.ToString()); - if (typeName == "dm") + + if (typeName == "eiscapi") { - return new DmBridge(key, name, properties); + return new EiscApi(dc); } - else if (typeName == "comm") - { - return new CommBridge(key, name, properties); - } - else - return null; + + return null; } } diff --git a/PepperDashEssentials/Bridges/IBasicCommunicationBridgeMap.cs b/PepperDashEssentials/Bridges/IBasicCommunicationBridgeMap.cs index 69806109..ee9ac2f2 100644 --- a/PepperDashEssentials/Bridges/IBasicCommunicationBridgeMap.cs +++ b/PepperDashEssentials/Bridges/IBasicCommunicationBridgeMap.cs @@ -9,81 +9,74 @@ using PepperDash.Core; using PepperDash.Essentials.Core; using PepperDash.Essentials.DM; -namespace PepperDash.Essentials.Bridges.TEST +namespace PepperDash.Essentials.Bridges { + public static class IBasicCommunicationExtensions + { + public static void LinkToApi(this GenericComm comm, BasicTriList trilist, uint joinStart) + { + // 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))); + - /// - /// - /// - public static class DmChassisControllerApiExtensions - { - public static void LinkToApi(this PepperDash.Essentials.DM.DmChassisController chassis, - BasicTriList trilist, Dictionary map, uint joinstart) - { - uint joinOffset = joinstart - 1; + var sComm = comm.CommPort as ISocketStatus; + if (sComm != null) + { + sComm.ConnectionChange += (s, a) => + { + trilist.SetUshort(joinStart, (ushort)(a.Client.ClientStatus)); + trilist.SetBool(joinStart, a.Client.ClientStatus == + Crestron.SimplSharp.CrestronSockets.SocketStatus.SOCKET_STATUS_CONNECTED); + }; - uint videoSelectOffset = 0 + joinOffset; - uint audioSelectOffset = 40 + joinOffset; + trilist.SetBoolSigAction(joinStart, new Action(b => + { + if (b) + { + sComm.Connect(); + } + else + { + sComm.Disconnect(); + } + })); + } + } + } + ///// + ///// + ///// + //public static class DmChassisControllerApiExtensions + //{ + // public static void LinkToApi(this PepperDash.Essentials.DM.DmChassisController chassis, + // BasicTriList trilist, Dictionary map, uint joinstart) + // { + // uint joinOffset = joinstart - 1; + + // uint videoSelectOffset = 0 + joinOffset; + // uint audioSelectOffset = 40 + joinOffset; - // loop chassis number of inupts - for (uint i = 1; i <= chassis.Chassis.NumberOfOutputs; i++) - { - trilist.SetUShortSigAction(videoSelectOffset + i, new Action(u => chassis.ExecuteSwitch(u, i, eRoutingSignalType.Video))); - trilist.SetUShortSigAction(audioSelectOffset + i, new Action(u => chassis.ExecuteSwitch(u, i, eRoutingSignalType.Audio))); - } + // // loop chassis number of inupts + // for (uint i = 1; i <= chassis.Chassis.NumberOfOutputs; i++) + // { + // trilist.SetUShortSigAction(videoSelectOffset + i, new Action(u => chassis.ExecuteSwitch(u, i, eRoutingSignalType.Video))); + // trilist.SetUShortSigAction(audioSelectOffset + i, new Action(u => chassis.ExecuteSwitch(u, i, eRoutingSignalType.Audio))); + // } - // wire up output change detection (try to add feedbacks or something to DMChassisController?? + // // wire up output change detection (try to add feedbacks or something to DMChassisController?? - // names? + // // names? - // HDCP? + // // HDCP? - } - } + // } + //} - /// - /// For trilists to com sockets only - /// - public static class IBasicCommunicationApiExtensions - { - /// - /// - /// - /// - /// - /// - public static void LinkToApi(this IBasicCommunication comm, BasicTriList trilist, uint joinStart) - { - // this is a permanent event handler. This cannot be -= from event - comm.TextReceived += (s, a) => trilist.SetString(joinStart, a.Text); - trilist.SetStringSigAction(joinStart, new Action(s => comm.SendText(s))); - var sComm = comm as ISocketStatus; - if (sComm != null) - { - sComm.ConnectionChange += (s, a) => - { - trilist.SetUshort(joinStart, (ushort)(a.Client.ClientStatus)); - trilist.SetBool(joinStart, a.Client.ClientStatus == - Crestron.SimplSharp.CrestronSockets.SocketStatus.SOCKET_STATUS_CONNECTED); - }; - - trilist.SetBoolSigAction(joinStart, new Action(b => - { - if (b) - { - sComm.Connect(); - } - else - { - sComm.Disconnect(); - } - })); - } - } - } } \ No newline at end of file diff --git a/PepperDashEssentials/ControlSystem.cs b/PepperDashEssentials/ControlSystem.cs index 02a95d85..a5558cf3 100644 --- a/PepperDashEssentials/ControlSystem.cs +++ b/PepperDashEssentials/ControlSystem.cs @@ -231,9 +231,12 @@ namespace PepperDash.Essentials continue; } - // Try local factory first + // Try local factories first var newDev = DeviceFactory.GetDevice(devConf); + if (newDev == null) + newDev = BridgeFactory.GetDevice(devConf); + // Then associated library factories if (newDev == null) newDev = PepperDash.Essentials.Core.DeviceFactory.GetDevice(devConf); diff --git a/PepperDashEssentials/PepperDashEssentials.csproj b/PepperDashEssentials/PepperDashEssentials.csproj index 59c180ee..46da4be2 100644 --- a/PepperDashEssentials/PepperDashEssentials.csproj +++ b/PepperDashEssentials/PepperDashEssentials.csproj @@ -112,6 +112,7 @@ + diff --git a/Release Package/PepperDashEssentials.cpz b/Release Package/PepperDashEssentials.cpz index 7da84300..f3e5a786 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 40f3f54b..c01af705 100644 Binary files a/Release Package/PepperDashEssentials.dll and b/Release Package/PepperDashEssentials.dll differ diff --git a/essentials-framework b/essentials-framework index ae1719ee..88149415 160000 --- a/essentials-framework +++ b/essentials-framework @@ -1 +1 @@ -Subproject commit ae1719ee9b2864c91b42be05874d0d5b13e27ed5 +Subproject commit 88149415b77baee1eaa0c87a7f65f0b8425bed3a