From 0a3f2bb524d75b1800141ad02291a8f9f96cc930 Mon Sep 17 00:00:00 2001 From: Trevor Payne Date: Wed, 1 Jul 2020 10:35:57 -0500 Subject: [PATCH] WIP Cresnet Gateway SUpport --- .../Factory/ReadyEventArgs.cs | 30 ++ .../Gateways/CenRfgwController.cs | 272 ++++++++++-------- .../PepperDash_Essentials_Core.csproj | 1 + .../Remotes/Hrxx0WirelessRemoteController.cs | 45 ++- .../Chassis/DmChassisController.cs | 1 + 5 files changed, 232 insertions(+), 117 deletions(-) create mode 100644 essentials-framework/Essentials Core/PepperDashEssentialsBase/Factory/ReadyEventArgs.cs diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Factory/ReadyEventArgs.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Factory/ReadyEventArgs.cs new file mode 100644 index 00000000..6999bd74 --- /dev/null +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Factory/ReadyEventArgs.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Crestron.SimplSharp; + +namespace PepperDash_Essentials_Core +{ + public delegate void IsReadyEventHandler(object source, IsReadyEventArgs e); + + public class IsReadyEventArgs : EventArgs + { + private readonly bool _EventData; + + public IsReadyEventArgs(bool data) + { + _EventData = data; + } + + public bool GetData() + { + return _EventData; + } + } + + public interface IHasReady + { + event IsReadyEventHandler IsReady; + } +} \ No newline at end of file diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Gateways/CenRfgwController.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Gateways/CenRfgwController.cs index 1fd7da6d..767714d1 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Gateways/CenRfgwController.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Gateways/CenRfgwController.cs @@ -6,134 +6,182 @@ using Crestron.SimplSharp; using Crestron.SimplSharpPro; using Crestron.SimplSharpPro.Gateways; using Newtonsoft.Json; +using Crestron.SimplSharpPro.DeviceSupport; using PepperDash.Core; using PepperDash.Essentials.Core; using PepperDash.Essentials.Core.Config; +using PepperDash_Essentials_Core; -namespace PepperDash.Essentials.Core +namespace PepperDash.Essentials.Core { - [Description("Wrapper class for Crestron Infinet-EX Gateways")] - public class CenRfgwController : CrestronGenericBaseDevice - { - private GatewayBase _Gateway; - public GatewayBase GateWay { get { return _Gateway; } } - - /// - /// Constructor for the on-board gateway - /// - /// - /// - public CenRfgwController(string key, string name, GatewayBase gateway) : - base(key, name, gateway) - { - _Gateway = gateway; - } - - public static CenRfgwController GetNewExGatewayController(string key, string name, ushort ipId, ushort cresnetId, string gatewayType) - { - eExGatewayType type = (eExGatewayType)Enum.Parse(typeof(eExGatewayType), gatewayType, true); - try - { - var cs = Global.ControlSystem; - - GatewayBase gw = null; - switch (type) - { - case eExGatewayType.Ethernet: - gw = new CenRfgwEx(ipId, cs); - break; - case eExGatewayType.EthernetShared: - gw = new CenRfgwExEthernetSharable(ipId, cs); - break; - case eExGatewayType.Cresnet: - gw = new CenRfgwExCresnet(cresnetId, cs); - break; - } - return new CenRfgwController(key, name, gw); - } - catch (Exception) - { - Debug.Console(0, "ERROR: Cannot create EX Gateway, id {0}, type {1}", type == eExGatewayType.Cresnet ? cresnetId : ipId, gatewayType); - return null; - } - } - public static CenRfgwController GetNewErGatewayController(string key, string name, ushort ipId, ushort cresnetId, string gatewayType) - { - eExGatewayType type = (eExGatewayType)Enum.Parse(typeof(eExGatewayType), gatewayType, true); - try - { - var cs = Global.ControlSystem; - - GatewayBase gw = null; - switch (type) - { - case eExGatewayType.Ethernet: - gw = new CenErfgwPoe(ipId, cs); - break; - case eExGatewayType.EthernetShared: - gw = new CenErfgwPoeEthernetSharable(ipId, cs); - break; - case eExGatewayType.Cresnet: - gw = new CenErfgwPoeCresnet(cresnetId, cs); - break; - } - return new CenRfgwController(key, name, gw); - } - catch (Exception) - { - Debug.Console(0, "ERROR: Cannot create ER Gateway, id {0}, type {1}", type== eExGatewayType.Cresnet ? cresnetId : ipId, gatewayType); - return null; - } - } - - } - - - - public enum eExGatewayType - { - Ethernet, EthernetShared, Cresnet - } + [Description("Wrapper class for Crestron Infinet-EX Gateways")] + public class CenRfgwController : CrestronGenericBaseDevice, IHasReady + { + public event IsReadyEventHandler IsReady; + private GatewayBase _gateway; - #region Factory - public class CenRfgwControllerFactory : EssentialsDeviceFactory - { - public CenRfgwControllerFactory() - { - TypeNames = new List() { "cenrfgwex", "cenerfgwpoe" }; - } - - public override EssentialsDevice BuildDevice(DeviceConfig dc) + public GatewayBase GateWay { + get { return _gateway; } + } - Debug.Console(1, "Factory Attempting to create new CEN-GWEXER Device"); - - var props = JsonConvert.DeserializeObject(dc.Properties.ToString()); + /// + /// Constructor for the on-board gateway + /// + /// + /// + public CenRfgwController(string key, string name, GatewayBase gateway) : + base(key, name, gateway) + { + _gateway = gateway; + IsReady(this, new IsReadyEventArgs(true)); + } - var type = dc.Type.ToLower(); - var control = props.Control; - var ipid = control.IpIdInt; - var cresnetId = control.CresnetIdInt; - var gatewayType = props.GatewayType; - - switch (type) + public CenRfgwController(string key, Func preActivationFunc, DeviceConfig config) : + base(key, config.Name) + { + IsReady(this, new IsReadyEventArgs(false)); + AddPreActivationAction(() => { - case ("cenrfgwex"): - return CenRfgwController.GetNewExGatewayController(dc.Key, dc.Name, - (ushort)ipid, (ushort)cresnetId, gatewayType); - case ("cenerfgwpoe"): - return CenRfgwController.GetNewErGatewayController(dc.Key, dc.Name, - (ushort)ipid, (ushort)cresnetId, gatewayType); - default: - return null; - } + _gateway = preActivationFunc(config); + + RegisterCrestronGenericBase(_gateway); + IsReady(this, new IsReadyEventArgs(true)); + + }); + } + + public static GatewayBase GetNewIpRfGateway(DeviceConfig dc) + { + var control = CommFactory.GetControlPropertiesConfig(dc); + var name = dc.Name; + var type = dc.Type; + var key = dc.Key; + var ipId = control.IpIdInt; + + if (type.Equals("cenrfgwex", StringComparison.InvariantCultureIgnoreCase)) + { + return new CenRfgwEx(ipId, Global.ControlSystem); + } + if (type.Equals("cenerfgwpoe", StringComparison.InvariantCultureIgnoreCase)) + { + return new CenErfgwPoe(ipId, Global.ControlSystem); + } + return null; + } + + public static GatewayBase GetNewSharedIpRfGateway(DeviceConfig dc) + { + var control = CommFactory.GetControlPropertiesConfig(dc); + var ipId = control.IpIdInt; + + if (dc.Type.Equals("cenrfgwex", StringComparison.InvariantCultureIgnoreCase)) + { + return new CenRfgwExEthernetSharable(ipId, Global.ControlSystem); + } + if (dc.Type.Equals("cenerfgwpoe", StringComparison.InvariantCultureIgnoreCase)) + { + return new CenErfgwPoeEthernetSharable(ipId, Global.ControlSystem); + } + return null; + } + + public static GatewayBase GetCenRfgwCresnetController(DeviceConfig dc) + { + var control = CommFactory.GetControlPropertiesConfig(dc); + var type = dc.Type; + var cresnetId = control.CresnetIdInt; + var branchId = control.ControlPortNumber; + var parentKey = string.IsNullOrEmpty(control.ControlPortDevKey) ? "processor" : control.ControlPortDevKey; + + if (parentKey.Equals("processor", StringComparison.CurrentCultureIgnoreCase)) + { + Debug.Console(0, "Device {0} is a valid cresnet master - creating new GlsOdtCCn"); + if (type.Equals("cenerfgwpoe", StringComparison.InvariantCultureIgnoreCase)) + { + return new CenErfgwPoeCresnet(cresnetId, Global.ControlSystem); + } + if (type.Equals("cenrfgwex", StringComparison.InvariantCultureIgnoreCase)) + { + return new CenRfgwExCresnet(cresnetId, Global.ControlSystem); + } + } + var cresnetBridge = DeviceManager.GetDeviceForKey(parentKey) as ICresnetBridge; + + if (cresnetBridge != null) + { + Debug.Console(0, "Device {0} is a valid cresnet master - creating new GlsOdtCCn"); + + if (type.Equals("cenerfgwpoe", StringComparison.InvariantCultureIgnoreCase)) + { + return new CenErfgwPoeCresnet(cresnetId, cresnetBridge.Branches[branchId]); + } + if (type.Equals("cenrfgwex", StringComparison.InvariantCultureIgnoreCase)) + { + return new CenRfgwExCresnet(cresnetId, cresnetBridge.Branches[branchId]); + } + } + Debug.Console(0, "Device {0} is not a valid cresnet master", branchId); + return null; + } + + + + + + + + public enum eExGatewayType + { + Ethernet, + EthernetShared, + Cresnet + } + + + #region Factory + + public class CenRfgwControllerFactory : EssentialsDeviceFactory + { + public CenRfgwControllerFactory() + { + TypeNames = new List() {"cenrfgwex", "cenerfgwpoe"}; + } + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + + Debug.Console(1, "Factory Attempting to create new CEN-GWEXER Device"); + + var props = JsonConvert.DeserializeObject(dc.Properties.ToString()); + + var type = dc.Type.ToLower(); + var control = props.Control; + var ipid = control.IpIdInt; + var cresnetId = control.CresnetIdInt; + + eExGatewayType gatewayType = + (eExGatewayType) Enum.Parse(typeof (eExGatewayType), props.GatewayType, true); + + switch (gatewayType) + { + case (eExGatewayType.Ethernet): + return new CenRfgwController(dc.Key, dc.Name, CenRfgwController.GetNewIpRfGateway(dc)); + case (eExGatewayType.EthernetShared): + return new CenRfgwController(dc.Key, dc.Name, CenRfgwController.GetNewSharedIpRfGateway(dc)); + case (eExGatewayType.Cresnet): + return new CenRfgwController(dc.Key, CenRfgwController.GetCenRfgwCresnetController, dc); + } + return null; + } } } + #endregion +} -} \ No newline at end of file diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj b/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj index 55a157b4..4e1676fb 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj @@ -192,6 +192,7 @@ + diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Remotes/Hrxx0WirelessRemoteController.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Remotes/Hrxx0WirelessRemoteController.cs index 746f449f..dd52257e 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Remotes/Hrxx0WirelessRemoteController.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Remotes/Hrxx0WirelessRemoteController.cs @@ -21,6 +21,8 @@ namespace PepperDash.Essentials.Core [Description("Wrapper class for all HR-Series remotes")] public class Hrxx0WirelessRemoteController : EssentialsBridgeableDevice, IHasFeedback { + private CenRfgwController _gateway; + private Hr1x0WirelessRemoteBase _remote; public FeedbackCollection Feedbacks { get; set; } @@ -33,6 +35,39 @@ namespace PepperDash.Essentials.Core { Feedbacks = new FeedbackCollection(); + var props = JsonConvert.DeserializeObject(config.Properties.ToString()); + + var type = config.Type; + var rfId = (uint)props.Control.InfinetIdInt; + + GatewayBase gateway; + + if (props.GatewayDeviceKey == "processor") + { + gateway = Global.ControlSystem.ControllerRFGatewayDevice; + } + + else + { + var gatewayDev = DeviceManager.GetDeviceForKey(props.GatewayDeviceKey) as CenRfgwController; + if (gatewayDev == null) + { + Debug.Console(0, "GetHr1x0WirelessRemote: Device '{0}' is not a valid device", props.GatewayDeviceKey); + } + if (gatewayDev != null) + { + Debug.Console(0, "GetHr1x0WirelessRemote: Device '{0}' is a valid device", props.GatewayDeviceKey); + gateway = gatewayDev.GateWay; + _gateway = gatewayDev; + } + } + + if (_gateway != null) + { + _gateway.IsReady += new PepperDash_Essentials_Core.IsReadyEventHandler(_gateway_IsReady); + } + + AddPreActivationAction(() => { _remote = preActivationFunc(config); @@ -47,6 +82,11 @@ namespace PepperDash.Essentials.Core }); } + void _gateway_IsReady(object source, PepperDash_Essentials_Core.IsReadyEventArgs e) + { + throw new NotImplementedException(); + } + void _remote_BaseEvent(GenericBase device, BaseEventArgs args) { if(args.EventId == Hr1x0EventIds.BatteryCriticalFeedbackEventId) @@ -137,11 +177,6 @@ namespace PepperDash.Essentials.Core return remoteBase; } - static void gateway_BaseEvent(GenericBase device, BaseEventArgs args) - { - throw new NotImplementedException(); - } - #endregion #region Factory diff --git a/essentials-framework/Essentials DM/Essentials_DM/Chassis/DmChassisController.cs b/essentials-framework/Essentials DM/Essentials_DM/Chassis/DmChassisController.cs index 9a28f75f..9cd0c655 100644 --- a/essentials-framework/Essentials DM/Essentials_DM/Chassis/DmChassisController.cs +++ b/essentials-framework/Essentials DM/Essentials_DM/Chassis/DmChassisController.cs @@ -614,6 +614,7 @@ namespace PepperDash.Essentials.DM var cecPort2 = outputCard.Card2.HdmiOutput; AddDmcHdoPorts(number, cecPort1, cecPort2); } + else if (type == "dmchdo") { var outputCard = new DmcHdoSingle(number, Chassis);