Added debug statement if there are more inputs than allowed bu the joinspan.

This commit is contained in:
Trevor Payne
2020-05-05 16:49:50 -05:00
parent 282c8b2cef
commit b3821e90d1
3 changed files with 129 additions and 126 deletions

View File

@@ -1,11 +1,11 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using Crestron.SimplSharp; using Crestron.SimplSharp;
using PepperDash.Essentials.Core; using PepperDash.Essentials.Core;
namespace PepperDash.Essentials.Core.Bridges namespace PepperDash.Essentials.Core.Bridges
{ {
public class IBasicCommunicationJoinMap : JoinMapBaseAdvanced public class IBasicCommunicationJoinMap : JoinMapBaseAdvanced
{ {
@@ -38,5 +38,5 @@ namespace PepperDash.Essentials.Core.Bridges
: base(joinStart, typeof(IBasicCommunicationJoinMap)) : base(joinStart, typeof(IBasicCommunicationJoinMap))
{ {
} }
} }
} }

View File

@@ -1,124 +1,124 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Crestron.SimplSharp.CrestronSockets; using Crestron.SimplSharp.CrestronSockets;
using Crestron.SimplSharpPro.DeviceSupport; using Crestron.SimplSharpPro.DeviceSupport;
using Newtonsoft.Json; using Newtonsoft.Json;
using PepperDash.Core; using PepperDash.Core;
using PepperDash.Essentials.Core.Bridges; using PepperDash.Essentials.Core.Bridges;
using PepperDash.Essentials.Core.Devices; using PepperDash.Essentials.Core.Devices;
using PepperDash.Essentials.Core.Config; using PepperDash.Essentials.Core.Config;
namespace PepperDash.Essentials.Core namespace PepperDash.Essentials.Core
{ {
/// <summary> /// <summary>
/// Serves as a generic wrapper class for all styles of IBasicCommuncation ports /// Serves as a generic wrapper class for all styles of IBasicCommuncation ports
/// </summary> /// </summary>
[Description("Generic communication wrapper class for any IBasicCommunication type")] [Description("Generic communication wrapper class for any IBasicCommunication type")]
public class GenericComm : ReconfigurableBridgableDevice public class GenericComm : ReconfigurableBridgableDevice
{ {
EssentialsControlPropertiesConfig PropertiesConfig; EssentialsControlPropertiesConfig PropertiesConfig;
public IBasicCommunication CommPort { get; private set; } public IBasicCommunication CommPort { get; private set; }
public GenericComm(DeviceConfig config) public GenericComm(DeviceConfig config)
: base(config) : base(config)
{
PropertiesConfig = CommFactory.GetControlPropertiesConfig(config);
CommPort = CommFactory.CreateCommForDevice(config);
}
public static IKeyed BuildDevice(DeviceConfig dc)
{
Debug.Console(1, "Factory Attempting to create new Generic Comm Device");
return new GenericComm(dc);
}
public void SetPortConfig(string portConfig)
{
// TODO: Deserialize new EssentialsControlPropertiesConfig and handle as necessary
try
{
PropertiesConfig = JsonConvert.DeserializeObject<EssentialsControlPropertiesConfig>
(portConfig);
}
catch (Exception e)
{
Debug.Console(2, this, "Error deserializing port config: {0}", e);
}
}
protected override void CustomSetConfig(DeviceConfig config)
{
PropertiesConfig = CommFactory.GetControlPropertiesConfig(config);
ConfigWriter.UpdateDeviceConfig(config);
}
public override void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey, EiscApiAdvanced bridge)
{ {
var joinMap = new IBasicCommunicationJoinMap(joinStart); PropertiesConfig = CommFactory.GetControlPropertiesConfig(config);
var joinMapSerialized = JoinMapHelper.GetSerializedJoinMapForDevice(joinMapKey); CommPort = CommFactory.CreateCommForDevice(config);
if (!string.IsNullOrEmpty(joinMapSerialized)) }
joinMap = JsonConvert.DeserializeObject<IBasicCommunicationJoinMap>(joinMapSerialized);
public static IKeyed BuildDevice(DeviceConfig dc)
if (CommPort == null) {
{ Debug.Console(1, "Factory Attempting to create new Generic Comm Device");
Debug.Console(1, this, "Unable to link device '{0}'. CommPort is null", Key); return new GenericComm(dc);
return; }
}
public void SetPortConfig(string portConfig)
Debug.Console(1, this, "Linking to Trilist '{0}'", trilist.ID.ToString("X")); {
// TODO: Deserialize new EssentialsControlPropertiesConfig and handle as necessary
// this is a permanent event handler. This cannot be -= from event try
CommPort.TextReceived += (s, a) => {
{ PropertiesConfig = JsonConvert.DeserializeObject<EssentialsControlPropertiesConfig>
Debug.Console(2, this, "RX: {0}", a.Text); (portConfig);
trilist.SetString(joinMap.TextReceived.JoinNumber, a.Text); }
catch (Exception e)
{
Debug.Console(2, this, "Error deserializing port config: {0}", e);
}
}
protected override void CustomSetConfig(DeviceConfig config)
{
PropertiesConfig = CommFactory.GetControlPropertiesConfig(config);
ConfigWriter.UpdateDeviceConfig(config);
}
public override void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey, EiscApiAdvanced bridge)
{
var joinMap = new IBasicCommunicationJoinMap(joinStart);
var joinMapSerialized = JoinMapHelper.GetSerializedJoinMapForDevice(joinMapKey);
if (!string.IsNullOrEmpty(joinMapSerialized))
joinMap = JsonConvert.DeserializeObject<IBasicCommunicationJoinMap>(joinMapSerialized);
if (CommPort == null)
{
Debug.Console(1, this, "Unable to link device '{0}'. CommPort is null", Key);
return;
}
Debug.Console(1, this, "Linking to Trilist '{0}'", trilist.ID.ToString("X"));
// this is a permanent event handler. This cannot be -= from event
CommPort.TextReceived += (s, a) =>
{
Debug.Console(2, this, "RX: {0}", a.Text);
trilist.SetString(joinMap.TextReceived.JoinNumber, a.Text);
}; };
trilist.SetStringSigAction(joinMap.SendText.JoinNumber, s => CommPort.SendText(s)); trilist.SetStringSigAction(joinMap.SendText.JoinNumber, s => CommPort.SendText(s));
trilist.SetStringSigAction(joinMap.SetPortConfig.JoinNumber, SetPortConfig); trilist.SetStringSigAction(joinMap.SetPortConfig.JoinNumber, SetPortConfig);
var sComm = this as ISocketStatus; var sComm = this as ISocketStatus;
if (sComm == null) return; if (sComm == null) return;
sComm.ConnectionChange += (s, a) => sComm.ConnectionChange += (s, a) =>
{ {
trilist.SetUshort(joinMap.Status.JoinNumber, (ushort)(a.Client.ClientStatus)); trilist.SetUshort(joinMap.Status.JoinNumber, (ushort)(a.Client.ClientStatus));
trilist.SetBool(joinMap.Connected.JoinNumber, a.Client.ClientStatus == trilist.SetBool(joinMap.Connected.JoinNumber, a.Client.ClientStatus ==
SocketStatus.SOCKET_STATUS_CONNECTED); SocketStatus.SOCKET_STATUS_CONNECTED);
}; };
trilist.SetBoolSigAction(joinMap.Connect.JoinNumber, b => trilist.SetBoolSigAction(joinMap.Connect.JoinNumber, b =>
{ {
if (b) if (b)
{ {
sComm.Connect(); sComm.Connect();
} }
else else
{ {
sComm.Disconnect(); sComm.Disconnect();
} }
}); });
} }
} }
public class GenericCommFactory : EssentialsDeviceFactory<GenericComm> public class GenericCommFactory : EssentialsDeviceFactory<GenericComm>
{ {
public GenericCommFactory() public GenericCommFactory()
{ {
TypeNames = new List<string>() { "genericComm" }; TypeNames = new List<string>() { "genericComm" };
} }
public override EssentialsDevice BuildDevice(DeviceConfig dc) public override EssentialsDevice BuildDevice(DeviceConfig dc)
{ {
Debug.Console(1, "Factory Attempting to create new Generic Comm Device"); Debug.Console(1, "Factory Attempting to create new Generic Comm Device");
return new GenericComm(dc); return new GenericComm(dc);
} }
} }
} }

View File

@@ -198,10 +198,13 @@ namespace PepperDash.Essentials.Core
var tempKey = inputKeys.ElementAt(i); var tempKey = inputKeys.ElementAt(i);
trilist.SetSigTrueAction((ushort)(joinMap.InputSelectOffset.JoinNumber + i), trilist.SetSigTrueAction((ushort)(joinMap.InputSelectOffset.JoinNumber + i),
() => displayDevice.ExecuteSwitch(displayDevice.InputPorts[tempKey].Selector)); () => displayDevice.ExecuteSwitch(displayDevice.InputPorts[tempKey].Selector));
Debug.Console(2, displayDevice, "Setting Input Select Action on Digital Join {0} to Input: {1}", Debug.Console(2, displayDevice, "Setting Input Select Action on Digital Join {0} to Input: {1}",
joinMap.InputSelectOffset.JoinNumber + i, displayDevice.InputPorts[tempKey].Key.ToString()); joinMap.InputSelectOffset.JoinNumber + i, displayDevice.InputPorts[tempKey].Key.ToString());
trilist.StringInput[(ushort)(joinMap.InputNamesOffset.JoinNumber + i)].StringValue = displayDevice.InputPorts[i].Key.ToString(); trilist.StringInput[(ushort)(joinMap.InputNamesOffset.JoinNumber + i)].StringValue = displayDevice.InputPorts[i].Key.ToString();
} }
else
Debug.Console(2, displayDevice, "Device has {0} inputs. The Join Map allows up to {1} inputs. Discarding inputs {2} - {3} from bridge.",
displayDevice.InputPorts.Count, joinMap.InputNamesOffset.JoinSpan, i + 1, displayDevice.InputPorts.Count);
} }
Debug.Console(2, displayDevice, "Setting Input Select Action on Analog Join {0}", joinMap.InputSelect); Debug.Console(2, displayDevice, "Setting Input Select Action on Analog Join {0}", joinMap.InputSelect);