WIP Cresnet Gateway SUpport

This commit is contained in:
Trevor Payne
2020-07-01 10:35:57 -05:00
parent ac379763ce
commit 0a3f2bb524
5 changed files with 232 additions and 117 deletions

View File

@@ -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;
}
}

View File

@@ -6,20 +6,28 @@ using Crestron.SimplSharp;
using Crestron.SimplSharpPro; using Crestron.SimplSharpPro;
using Crestron.SimplSharpPro.Gateways; using Crestron.SimplSharpPro.Gateways;
using Newtonsoft.Json; using Newtonsoft.Json;
using Crestron.SimplSharpPro.DeviceSupport;
using PepperDash.Core; using PepperDash.Core;
using PepperDash.Essentials.Core; using PepperDash.Essentials.Core;
using PepperDash.Essentials.Core.Config; 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")] [Description("Wrapper class for Crestron Infinet-EX Gateways")]
public class CenRfgwController : CrestronGenericBaseDevice public class CenRfgwController : CrestronGenericBaseDevice, IHasReady
{ {
private GatewayBase _Gateway; public event IsReadyEventHandler IsReady;
public GatewayBase GateWay { get { return _Gateway; } }
private GatewayBase _gateway;
public GatewayBase GateWay
{
get { return _gateway; }
}
/// <summary> /// <summary>
/// Constructor for the on-board gateway /// Constructor for the on-board gateway
@@ -29,77 +37,114 @@ namespace PepperDash.Essentials.Core
public CenRfgwController(string key, string name, GatewayBase gateway) : public CenRfgwController(string key, string name, GatewayBase gateway) :
base(key, name, gateway) base(key, name, gateway)
{ {
_Gateway = gateway; _gateway = gateway;
IsReady(this, new IsReadyEventArgs(true));
} }
public static CenRfgwController GetNewExGatewayController(string key, string name, ushort ipId, ushort cresnetId, string gatewayType) public CenRfgwController(string key, Func<DeviceConfig, GatewayBase> preActivationFunc, DeviceConfig config) :
base(key, config.Name)
{ {
eExGatewayType type = (eExGatewayType)Enum.Parse(typeof(eExGatewayType), gatewayType, true); IsReady(this, new IsReadyEventArgs(false));
try AddPreActivationAction(() =>
{ {
var cs = Global.ControlSystem; _gateway = preActivationFunc(config);
GatewayBase gw = null; RegisterCrestronGenericBase(_gateway);
switch (type) IsReady(this, new IsReadyEventArgs(true));
{
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);
} public static GatewayBase GetNewIpRfGateway(DeviceConfig dc)
catch (Exception)
{ {
Debug.Console(0, "ERROR: Cannot create EX Gateway, id {0}, type {1}", type == eExGatewayType.Cresnet ? cresnetId : ipId, gatewayType); 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; 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; public static GatewayBase GetNewSharedIpRfGateway(DeviceConfig dc)
switch (type)
{ {
case eExGatewayType.Ethernet: var control = CommFactory.GetControlPropertiesConfig(dc);
gw = new CenErfgwPoe(ipId, cs); var ipId = control.IpIdInt;
break;
case eExGatewayType.EthernetShared: if (dc.Type.Equals("cenrfgwex", StringComparison.InvariantCultureIgnoreCase))
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 new CenRfgwExEthernetSharable(ipId, Global.ControlSystem);
}
if (dc.Type.Equals("cenerfgwpoe", StringComparison.InvariantCultureIgnoreCase))
{
return new CenErfgwPoeEthernetSharable(ipId, Global.ControlSystem);
}
return null; 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 public enum eExGatewayType
{ {
Ethernet, EthernetShared, Cresnet Ethernet,
EthernetShared,
Cresnet
} }
#region Factory #region Factory
public class CenRfgwControllerFactory : EssentialsDeviceFactory<CenRfgwController> public class CenRfgwControllerFactory : EssentialsDeviceFactory<CenRfgwController>
{ {
public CenRfgwControllerFactory() public CenRfgwControllerFactory()
@@ -118,22 +163,25 @@ namespace PepperDash.Essentials.Core
var control = props.Control; var control = props.Control;
var ipid = control.IpIdInt; var ipid = control.IpIdInt;
var cresnetId = control.CresnetIdInt; var cresnetId = control.CresnetIdInt;
var gatewayType = props.GatewayType;
switch (type) eExGatewayType gatewayType =
(eExGatewayType) Enum.Parse(typeof (eExGatewayType), props.GatewayType, true);
switch (gatewayType)
{ {
case ("cenrfgwex"): case (eExGatewayType.Ethernet):
return CenRfgwController.GetNewExGatewayController(dc.Key, dc.Name, return new CenRfgwController(dc.Key, dc.Name, CenRfgwController.GetNewIpRfGateway(dc));
(ushort)ipid, (ushort)cresnetId, gatewayType); case (eExGatewayType.EthernetShared):
case ("cenerfgwpoe"): return new CenRfgwController(dc.Key, dc.Name, CenRfgwController.GetNewSharedIpRfGateway(dc));
return CenRfgwController.GetNewErGatewayController(dc.Key, dc.Name, case (eExGatewayType.Cresnet):
(ushort)ipid, (ushort)cresnetId, gatewayType); return new CenRfgwController(dc.Key, CenRfgwController.GetCenRfgwCresnetController, dc);
default: }
return null; return null;
} }
} }
} }
#endregion #endregion
} }

View File

@@ -192,6 +192,7 @@
<Compile Include="Devices\VolumeDeviceChangeEventArgs.cs" /> <Compile Include="Devices\VolumeDeviceChangeEventArgs.cs" />
<Compile Include="Factory\DeviceFactory.cs" /> <Compile Include="Factory\DeviceFactory.cs" />
<Compile Include="Factory\IDeviceFactory.cs" /> <Compile Include="Factory\IDeviceFactory.cs" />
<Compile Include="Factory\ReadyEventArgs.cs" />
<Compile Include="Feedbacks\BoolFeedback.cs" /> <Compile Include="Feedbacks\BoolFeedback.cs" />
<Compile Include="Feedbacks\FeedbackCollection.cs" /> <Compile Include="Feedbacks\FeedbackCollection.cs" />
<Compile Include="Feedbacks\FeedbackEventArgs.cs" /> <Compile Include="Feedbacks\FeedbackEventArgs.cs" />

View File

@@ -21,6 +21,8 @@ namespace PepperDash.Essentials.Core
[Description("Wrapper class for all HR-Series remotes")] [Description("Wrapper class for all HR-Series remotes")]
public class Hrxx0WirelessRemoteController : EssentialsBridgeableDevice, IHasFeedback public class Hrxx0WirelessRemoteController : EssentialsBridgeableDevice, IHasFeedback
{ {
private CenRfgwController _gateway;
private Hr1x0WirelessRemoteBase _remote; private Hr1x0WirelessRemoteBase _remote;
public FeedbackCollection<Feedback> Feedbacks { get; set; } public FeedbackCollection<Feedback> Feedbacks { get; set; }
@@ -33,6 +35,39 @@ namespace PepperDash.Essentials.Core
{ {
Feedbacks = new FeedbackCollection<Feedback>(); Feedbacks = new FeedbackCollection<Feedback>();
var props = JsonConvert.DeserializeObject<CrestronRemotePropertiesConfig>(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(() => AddPreActivationAction(() =>
{ {
_remote = preActivationFunc(config); _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) void _remote_BaseEvent(GenericBase device, BaseEventArgs args)
{ {
if(args.EventId == Hr1x0EventIds.BatteryCriticalFeedbackEventId) if(args.EventId == Hr1x0EventIds.BatteryCriticalFeedbackEventId)
@@ -137,11 +177,6 @@ namespace PepperDash.Essentials.Core
return remoteBase; return remoteBase;
} }
static void gateway_BaseEvent(GenericBase device, BaseEventArgs args)
{
throw new NotImplementedException();
}
#endregion #endregion
#region Factory #region Factory

View File

@@ -614,6 +614,7 @@ namespace PepperDash.Essentials.DM
var cecPort2 = outputCard.Card2.HdmiOutput; var cecPort2 = outputCard.Card2.HdmiOutput;
AddDmcHdoPorts(number, cecPort1, cecPort2); AddDmcHdoPorts(number, cecPort1, cecPort2);
} }
else if (type == "dmchdo") else if (type == "dmchdo")
{ {
var outputCard = new DmcHdoSingle(number, Chassis); var outputCard = new DmcHdoSingle(number, Chassis);