Completed development and testing of PDC-25. Reviewed with Heath, tweaked a few things for better efficency, I have a sample program available for review

This commit is contained in:
Jason DeVito
2019-10-02 18:38:35 -05:00
parent c9b06ec3ca
commit 9ba46eb3d5
4 changed files with 513 additions and 466 deletions

View File

@@ -3,6 +3,8 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using Crestron.SimplSharp; using Crestron.SimplSharp;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using PepperDash.Core.JsonToSimpl; using PepperDash.Core.JsonToSimpl;
namespace PepperDash.Core.JsonStandardObjects namespace PepperDash.Core.JsonStandardObjects
@@ -52,7 +54,7 @@ namespace PepperDash.Core.JsonStandardObjects
/// <summary> /// <summary>
/// Device class /// Device class
/// </summary> /// </summary>
public class DeviceConfig public class DeviceConfig : JsonToSimplChildObjectBase
{ {
/// <summary> /// <summary>
/// JSON config key property /// JSON config key property
@@ -93,54 +95,64 @@ namespace PepperDash.Core.JsonStandardObjects
/// </summary> /// </summary>
public DeviceConfig() public DeviceConfig()
{ {
// add logic here if necessary properties = new PropertiesConfig();
} }
/// <summary> /// <summary>
/// Initialize Device Module /// Initialize method
/// </summary> /// </summary>
/// <param name="uniqueID">JSON master unique ID</param> /// <param name="uniqueID"></param>
/// <param name="key">Device key to search for</param> /// <param name="deviceKey"></param>
public void Initialize(string uniqueID, string key) public void Initialize(string uniqueID, string deviceKey)
{ {
// S+ set EvaluateFb low // S+ set EvaluateFb low
OnBoolChange(false, 0, JsonStandardDeviceConstants.JsonObjectEvaluated); OnBoolChange(false, 0, JsonStandardDeviceConstants.JsonObjectEvaluated);
// validate parameters // validate parameters
if (string.IsNullOrEmpty(uniqueID)) if (string.IsNullOrEmpty(uniqueID) || string.IsNullOrEmpty(deviceKey))
{ {
Debug.Console(1, "UniqueID is null or empty"); Debug.Console(1, "UniqueID ({0} or key ({1} is null or empty", uniqueID, deviceKey);
return; // S+ set EvaluteFb high
} OnBoolChange(true, 0, JsonStandardDeviceConstants.JsonObjectEvaluated);
if (string.IsNullOrEmpty(key))
{
Debug.Console(1, "Device key is null or empty");
return; return;
} }
key = deviceKey;
try try
{ {
// get the file using the unique ID // get the file using the unique ID
JsonToSimplMaster jsonMaster = J2SGlobal.GetMasterByFile(uniqueID); JsonToSimplMaster jsonMaster = J2SGlobal.GetMasterByFile(uniqueID);
var device = jsonMaster.JsonObject.ToObject<RootObject>().devices.FirstOrDefault(d => d.key.Equals(key)); if (jsonMaster == null)
name = device.name;
type = device.type;
properties = device.properties;
// Pass object to S+
OnObjectChange(this, 0, JsonStandardDeviceConstants.JsonObjectChanged);
}
catch (Exception e)
{ {
var msg = string.Format("Device lookup failed:\r{0}", e); Debug.Console(1, "Could not find JSON file with uniqueID {0}", uniqueID);
CrestronConsole.PrintLine(msg);
ErrorLog.Error(msg);
return; return;
} }
// get the device configuration using the key
var devices = jsonMaster.JsonObject.ToObject<RootObject>().devices;
var device = devices.FirstOrDefault(d => d.key.Equals(key));
if (device == null)
{
Debug.Console(1, "Could not find device with key {0}", key);
return;
}
OnObjectChange(device, 0, JsonStandardDeviceConstants.JsonObjectChanged);
var index = devices.IndexOf(device);
OnStringChange(string.Format("devices[{0}]", index), 0, JsonToSimplConstants.FullPathToArrayChange);
}
catch (Exception e)
{
var msg = string.Format("Device {0} lookup failed:\r{1}", key, e);
CrestronConsole.PrintLine(msg);
ErrorLog.Error(msg);
}
finally
{
// S+ set EvaluteFb high // S+ set EvaluteFb high
OnBoolChange(true, 0, JsonStandardDeviceConstants.JsonObjectEvaluated); OnBoolChange(true, 0, JsonStandardDeviceConstants.JsonObjectEvaluated);
} }
}
#region EventHandler Helpers #region EventHandler Helpers
@@ -228,10 +240,18 @@ namespace PepperDash.Core.JsonStandardObjects
public int pacing { get; set; } public int pacing { get; set; }
// convert properties for simpl // convert properties for simpl
public ushort simplBaudRate { get { return (ushort)Convert.ToUInt16(baudRate); } } public ushort simplBaudRate { get { return Convert.ToUInt16(baudRate); } }
public ushort simplDataBits { get { return Convert.ToUInt16(dataBits); } } public ushort simplDataBits { get { return Convert.ToUInt16(dataBits); } }
public ushort simplStopBits { get { return Convert.ToUInt16(stopBits); } } public ushort simplStopBits { get { return Convert.ToUInt16(stopBits); } }
public ushort simplPacing { get { return Convert.ToUInt16(pacing); } } public ushort simplPacing { get { return Convert.ToUInt16(pacing); } }
/// <summary>
/// Constructor
/// </summary>
public ComParamsConfig()
{
}
} }
/// <summary> /// <summary>
@@ -247,9 +267,17 @@ namespace PepperDash.Core.JsonStandardObjects
public int autoReconnectIntervalMs { get; set; } public int autoReconnectIntervalMs { get; set; }
// convert properties for simpl // convert properties for simpl
public ushort simplPort { get { return (ushort)Convert.ToUInt16(port); } } public ushort simplPort { get { return Convert.ToUInt16(port); } }
public ushort simplAutoReconnect { get { return (ushort)(autoReconnect ? 1 : 0); } } public ushort simplAutoReconnect { get { return (ushort)(autoReconnect ? 1 : 0); } }
public ushort simplAutoReconnectIntervalMs { get { return Convert.ToUInt16(autoReconnectIntervalMs); } } public ushort simplAutoReconnectIntervalMs { get { return Convert.ToUInt16(autoReconnectIntervalMs); } }
/// <summary>
/// Constructor
/// </summary>
public TcpSshPropertiesConfig()
{
}
} }
/// <summary> /// <summary>
@@ -265,6 +293,15 @@ namespace PepperDash.Core.JsonStandardObjects
// convert properties for simpl // convert properties for simpl
public ushort simplControlPortNumber { get { return Convert.ToUInt16(controlPortNumber); } } public ushort simplControlPortNumber { get { return Convert.ToUInt16(controlPortNumber); } }
/// <summary>
/// Constructor
/// </summary>
public ControlConfig()
{
comParams = new ComParamsConfig();
tcpSshProperties = new TcpSshPropertiesConfig();
}
} }
/// <summary> /// <summary>
@@ -279,6 +316,14 @@ namespace PepperDash.Core.JsonStandardObjects
// convert properties for simpl // convert properties for simpl
public ushort simplDeviceId { get { return Convert.ToUInt16(deviceId); } } public ushort simplDeviceId { get { return Convert.ToUInt16(deviceId); } }
public ushort simplEnabled { get { return (ushort)(enabled ? 1 : 0); } } public ushort simplEnabled { get { return (ushort)(enabled ? 1 : 0); } }
/// <summary>
/// Constructor
/// </summary>
public PropertiesConfig()
{
control = new ControlConfig();
}
} }
/// <summary> /// <summary>

View File

@@ -72,7 +72,7 @@ namespace PepperDash.Core.JsonToSimpl
public override void ProcessAll() public override void ProcessAll()
{ {
if(FindInArray()) if (FindInArray())
base.ProcessAll(); base.ProcessAll();
} }

View File

@@ -119,5 +119,7 @@
</ProjectExtensions> </ProjectExtensions>
<PropertyGroup> <PropertyGroup>
<PostBuildEvent>rem S# preparation will execute after these operations</PostBuildEvent> <PostBuildEvent>rem S# preparation will execute after these operations</PostBuildEvent>
<PreBuildEvent>del "$(TargetDir)PepperDash_Core.*" /q
</PreBuildEvent>
</PropertyGroup> </PropertyGroup>
</Project> </Project>