mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-14 04:04:58 +00:00
Changes base class and implements LinkToApi method
This commit is contained in:
@@ -2,11 +2,12 @@
|
|||||||
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.CrestronSockets;
|
||||||
|
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.Devices;
|
using PepperDash.Essentials.Core.Devices;
|
||||||
using PepperDash.Essentials.Core.Config;
|
using PepperDash.Essentials.Core.Config;
|
||||||
|
|
||||||
@@ -16,7 +17,7 @@ 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>
|
||||||
public class GenericComm : ReconfigurableDevice
|
public class GenericComm : ReconfigurableBridgableDevice
|
||||||
{
|
{
|
||||||
EssentialsControlPropertiesConfig PropertiesConfig;
|
EssentialsControlPropertiesConfig PropertiesConfig;
|
||||||
|
|
||||||
@@ -43,7 +44,7 @@ namespace PepperDash.Essentials.Core
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
PropertiesConfig = JsonConvert.DeserializeObject<EssentialsControlPropertiesConfig>
|
PropertiesConfig = JsonConvert.DeserializeObject<EssentialsControlPropertiesConfig>
|
||||||
(portConfig.ToString());
|
(portConfig);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@@ -57,9 +58,59 @@ namespace PepperDash.Essentials.Core
|
|||||||
|
|
||||||
ConfigWriter.UpdateDeviceConfig(config);
|
ConfigWriter.UpdateDeviceConfig(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey, EiscApi bridge)
|
||||||
|
{
|
||||||
|
var joinMap = new IBasicCommunicationJoinMap();
|
||||||
|
|
||||||
|
var joinMapSerialized = JoinMapHelper.GetSerializedJoinMapForDevice(joinMapKey);
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(joinMapSerialized))
|
||||||
|
joinMap = JsonConvert.DeserializeObject<IBasicCommunicationJoinMap>(joinMapSerialized);
|
||||||
|
joinMap.OffsetJoinNumbers(joinStart);
|
||||||
|
|
||||||
|
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, a.Text);
|
||||||
|
};
|
||||||
|
trilist.SetStringSigAction(joinMap.SendText, s => CommPort.SendText(s));
|
||||||
|
trilist.SetStringSigAction(joinMap.SetPortConfig, SetPortConfig);
|
||||||
|
|
||||||
|
|
||||||
|
var sComm = this as ISocketStatus;
|
||||||
|
if (sComm == null) return;
|
||||||
|
sComm.ConnectionChange += (s, a) =>
|
||||||
|
{
|
||||||
|
trilist.SetUshort(joinMap.Status, (ushort)(a.Client.ClientStatus));
|
||||||
|
trilist.SetBool(joinMap.Connected, a.Client.ClientStatus ==
|
||||||
|
SocketStatus.SOCKET_STATUS_CONNECTED);
|
||||||
|
};
|
||||||
|
|
||||||
|
trilist.SetBoolSigAction(joinMap.Connect, b =>
|
||||||
|
{
|
||||||
|
if (b)
|
||||||
|
{
|
||||||
|
sComm.Connect();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sComm.Disconnect();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class GenericCommFactory : Essentials.Core.EssentialsDeviceFactory<GenericComm>
|
public class GenericCommFactory : EssentialsDeviceFactory<GenericComm>
|
||||||
{
|
{
|
||||||
public GenericCommFactory()
|
public GenericCommFactory()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user