Merge pull request #74 from PepperDash/feature/update-systemmonitorcontroller

Feature/update systemmonitorcontroller
This commit is contained in:
Neil Dorin
2020-03-25 17:26:06 -06:00
committed by GitHub
9 changed files with 611 additions and 204 deletions

View File

@@ -144,6 +144,12 @@ jobs:
Remove-Item -Path .\*.zip Remove-Item -Path .\*.zip
- name: Check directory again - name: Check directory again
run: Get-ChildItem ./ run: Get-ChildItem ./
# Copy Contents of output folder to root directory
- name: Copy Files to root & delete output directory
run: |
Remove-Item -Path .\* -Include @("*.cpz","*.md","*.cplz","*.json","*.dll","*.clz")
Get-ChildItem -Path .\output\* | Copy-Item -Destination .\
Remove-Item -Path .\output -Recurse
# Commits the build output to the branch and tags it with the version # Commits the build output to the branch and tags it with the version
- name: Commit build output and tag the commit - name: Commit build output and tag the commit
shell: powershell shell: powershell

View File

@@ -1,11 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp; using Crestron.SimplSharp;
using Newtonsoft.Json;
using PepperDash.Core; using PepperDash.Core;
using PepperDash.Essentials.Core.Monitoring; using PepperDash.Essentials.Core.Monitoring;
@@ -23,11 +17,11 @@ namespace PepperDash.Essentials.AppServer.Messengers
SysMon = sysMon; SysMon = sysMon;
SysMon.SystemMonitorPropertiesChanged += new EventHandler<EventArgs>(SysMon_SystemMonitorPropertiesChanged); SysMon.SystemMonitorPropertiesChanged += SysMon_SystemMonitorPropertiesChanged;
foreach (var p in SysMon.ProgramStatusFeedbackCollection) foreach (var p in SysMon.ProgramStatusFeedbackCollection)
{ {
p.Value.ProgramInfoChanged += new EventHandler<ProgramInfoEventArgs>(ProgramInfoChanged); p.Value.ProgramInfoChanged += ProgramInfoChanged;
} }
CrestronConsole.AddNewConsoleCommand(s => SendFullStatusMessage(), "SendFullSysMonStatus", "Sends the full System Monitor Status", ConsoleAccessLevelEnum.AccessOperator); CrestronConsole.AddNewConsoleCommand(s => SendFullStatusMessage(), "SendFullSysMonStatus", "Sends the full System Monitor Status", ConsoleAccessLevelEnum.AccessOperator);
@@ -72,18 +66,15 @@ namespace PepperDash.Essentials.AppServer.Messengers
Debug.Console(1, "Posting System Monitor Status Message."); Debug.Console(1, "Posting System Monitor Status Message.");
// This takes a while, launch a new thread // This takes a while, launch a new thread
CrestronInvoke.BeginInvoke((o) => CrestronInvoke.BeginInvoke(o => PostStatusMessage(new
{ {
PostStatusMessage(new timeZone = SysMon.TimeZoneFeedback.IntValue,
{ timeZoneName = SysMon.TimeZoneTextFeedback.StringValue,
timeZone = SysMon.TimeZoneFeedback.IntValue, ioControllerVersion = SysMon.IoControllerVersionFeedback.StringValue,
timeZoneName = SysMon.TimeZoneTextFeedback.StringValue, snmpVersion = SysMon.SnmpVersionFeedback.StringValue,
ioControllerVersion = SysMon.IOControllerVersionFeedback.StringValue, bacnetVersion = SysMon.BaCnetAppVersionFeedback.StringValue,
snmpVersion = SysMon.SnmpVersionFeedback.StringValue, controllerVersion = SysMon.ControllerVersionFeedback.StringValue
bacnetVersion = SysMon.BACnetAppVersionFeedback.StringValue, }));
controllerVersion = SysMon.ControllerVersionFeedback.StringValue
});
});
} }
protected override void CustomRegisterWithAppServer(MobileControlSystemController appServerController) protected override void CustomRegisterWithAppServer(MobileControlSystemController appServerController)

View File

@@ -1,9 +1,4 @@
using System; using PepperDash.Essentials.Core;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using PepperDash.Essentials.Core;
namespace PepperDash.Essentials.Bridges namespace PepperDash.Essentials.Bridges
{ {
@@ -14,11 +9,21 @@ namespace PepperDash.Essentials.Bridges
/// </summary> /// </summary>
public uint ProgramStartJoin { get; set; } public uint ProgramStartJoin { get; set; }
/// <summary>
/// Offset to indicate where the range of iterated Ethernet joins will start
/// </summary>
public uint EthernetStartJoin { get; set; }
/// <summary> /// <summary>
/// Offset between each program join set /// Offset between each program join set
/// </summary> /// </summary>
public uint ProgramOffsetJoin { get; set; } public uint ProgramOffsetJoin { get; set; }
/// <summary>
/// Offset between each Ethernet Interface join set
/// </summary>
public uint EthernetOffsetJoin { get; set; }
#region Digitals #region Digitals
/// <summary> /// <summary>
/// Range Sets and reports whether the corresponding program slot is started /// Range Sets and reports whether the corresponding program slot is started
@@ -87,6 +92,68 @@ namespace PepperDash.Essentials.Bridges
/// Serialized JSON output that aggregates the program info of the corresponding program /// Serialized JSON output that aggregates the program info of the corresponding program
/// </summary> /// </summary>
public uint AggregatedProgramInfo { get; set; } public uint AggregatedProgramInfo { get; set; }
/// <summary>
/// Reports the controller serial number
/// </summary>
public uint SerialNumber { get; set; }
/// <summary>
/// Reports the controller model
/// </summary>
public uint Model { get; set; }
/// <summary>
/// Reports the Host name set on the corresponding interface
/// </summary>
public uint HostName { get; set; }
/// <summary>
/// Reports the Current IP address set on the corresponding interface. If DHCP is enabled, this will be the DHCP assigned address.
/// </summary>
public uint CurrentIpAddress { get; set; }
/// <summary>
/// Reporst the Current Default Gateway set on the corresponding interface. If DHCP is enabled, this will be the DHCP assigned gateway
/// </summary>
public uint CurrentDefaultGateway { get; set; }
/// <summary>
/// Reports the Current Subnet Mask set on the corresponding interface. If DHCP is enabled, this will be the DHCP assigned subnet mask
/// </summary>
public uint CurrentSubnetMask { get; set; }
/// <summary>
/// Reports the Static IP address set on the corresponding interface. If DHCP is disabled, this will match the Current IP address
/// </summary>
public uint StaticIpAddress { get; set; }
/// <summary>
/// Reporst the Static Default Gateway set on the corresponding interface. If DHCP is disabled, this will match the Current gateway
/// </summary>
public uint StaticDefaultGateway { get; set; }
/// <summary>
/// Reports the Current Subnet Mask set on the corresponding interface. If DHCP is enabled, this will be the DHCP assigned subnet mask
/// </summary>
public uint StaticSubnetMask { get; set; }
/// <summary>
/// Reports the current DomainFeedback on the corresponding interface
/// </summary>
public uint Domain { get; set; }
/// <summary>
/// Reports the current DNS Servers on the corresponding interface
/// </summary>
public uint DnsServer { get; set; }
/// <summary>
/// Reports the MAC Address of the corresponding interface
/// </summary>
public uint MacAddress { get; set; }
/// <summary>
/// Reports the DHCP Status of the corresponding interface
/// </summary>
public uint DhcpStatus { get; set; }
/// <summary>
/// Reports the current uptime. Updated in 5 minute intervals.
/// </summary>
public uint Uptime { get; set; }
/// <summary>
/// Reports the date of the last boot
/// </summary>
public uint LastBoot { get; set; }
#endregion #endregion
public SystemMonitorJoinMap() public SystemMonitorJoinMap()
@@ -98,6 +165,10 @@ namespace PepperDash.Essentials.Bridges
SnmpAppVersion = 3; SnmpAppVersion = 3;
BACnetAppVersion = 4; BACnetAppVersion = 4;
ControllerVersion = 5; ControllerVersion = 5;
SerialNumber = 6;
Model = 7;
Uptime = 8;
LastBoot = 9;
ProgramStartJoin = 10; ProgramStartJoin = 10;
@@ -115,6 +186,23 @@ namespace PepperDash.Essentials.Bridges
ProgramCrestronDatabaseVersion = 3; ProgramCrestronDatabaseVersion = 3;
ProgramEnvironmentVersion = 4; ProgramEnvironmentVersion = 4;
AggregatedProgramInfo = 5; AggregatedProgramInfo = 5;
EthernetStartJoin = 75;
EthernetOffsetJoin = 15;
// Offset in groups of 15
HostName = 1;
CurrentIpAddress = 2;
CurrentSubnetMask = 3;
CurrentDefaultGateway = 4;
StaticIpAddress = 5;
StaticSubnetMask = 6;
StaticDefaultGateway = 7;
Domain = 8;
DnsServer = 9;
MacAddress = 10;
DhcpStatus = 11;
} }
public override void OffsetJoinNumbers(uint joinStart) public override void OffsetJoinNumbers(uint joinStart)
@@ -131,6 +219,7 @@ namespace PepperDash.Essentials.Bridges
// Sets the initial join value where the iterated program joins will begin // Sets the initial join value where the iterated program joins will begin
ProgramStartJoin = ProgramStartJoin + joinOffset; ProgramStartJoin = ProgramStartJoin + joinOffset;
EthernetStartJoin = EthernetStartJoin + joinOffset;
} }
} }
} }

View File

@@ -1,9 +1,4 @@
using System; using Crestron.SimplSharpPro.DeviceSupport;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using Crestron.SimplSharpPro.DeviceSupport;
using Crestron.SimplSharpPro.Diagnostics; using Crestron.SimplSharpPro.Diagnostics;
using PepperDash.Core; using PepperDash.Core;
using PepperDash.Essentials.Core; using PepperDash.Essentials.Core;
@@ -17,7 +12,7 @@ namespace PepperDash.Essentials.Bridges
{ {
public static void LinkToApi(this SystemMonitorController systemMonitorController, BasicTriList trilist, uint joinStart, string joinMapKey) public static void LinkToApi(this SystemMonitorController systemMonitorController, BasicTriList trilist, uint joinStart, string joinMapKey)
{ {
SystemMonitorJoinMap joinMap = new SystemMonitorJoinMap(); var joinMap = new SystemMonitorJoinMap();
var joinMapSerialized = JoinMapHelper.GetJoinMapForDevice(joinMapKey); var joinMapSerialized = JoinMapHelper.GetJoinMapForDevice(joinMapKey);
@@ -30,36 +25,71 @@ namespace PepperDash.Essentials.Bridges
Debug.Console(2, systemMonitorController, "Linking API starting at join: {0}", joinStart); Debug.Console(2, systemMonitorController, "Linking API starting at join: {0}", joinStart);
systemMonitorController.TimeZoneFeedback.LinkInputSig(trilist.UShortInput[joinMap.TimeZone]); systemMonitorController.TimeZoneFeedback.LinkInputSig(trilist.UShortInput[joinMap.TimeZone]);
//trilist.SetUShortSigAction(joinMap.TimeZone, new Action<ushort>(u => systemMonitorController.SetTimeZone(u)));
systemMonitorController.TimeZoneTextFeedback.LinkInputSig(trilist.StringInput[joinMap.TimeZoneName]); systemMonitorController.TimeZoneTextFeedback.LinkInputSig(trilist.StringInput[joinMap.TimeZoneName]);
systemMonitorController.IOControllerVersionFeedback.LinkInputSig(trilist.StringInput[joinMap.IOControllerVersion]); systemMonitorController.IoControllerVersionFeedback.LinkInputSig(trilist.StringInput[joinMap.IOControllerVersion]);
systemMonitorController.SnmpVersionFeedback.LinkInputSig(trilist.StringInput[joinMap.SnmpAppVersion]); systemMonitorController.SnmpVersionFeedback.LinkInputSig(trilist.StringInput[joinMap.SnmpAppVersion]);
systemMonitorController.BACnetAppVersionFeedback.LinkInputSig(trilist.StringInput[joinMap.BACnetAppVersion]); systemMonitorController.BaCnetAppVersionFeedback.LinkInputSig(trilist.StringInput[joinMap.BACnetAppVersion]);
systemMonitorController.ControllerVersionFeedback.LinkInputSig(trilist.StringInput[joinMap.ControllerVersion]); systemMonitorController.ControllerVersionFeedback.LinkInputSig(trilist.StringInput[joinMap.ControllerVersion]);
systemMonitorController.SerialNumberFeedback.LinkInputSig(trilist.StringInput[joinMap.SerialNumber]);
systemMonitorController.ModelFeedback.LinkInputSig(trilist.StringInput[joinMap.Model]);
systemMonitorController.UptimeFeedback.LinkInputSig(trilist.StringInput[joinMap.Uptime]);
systemMonitorController.LastStartFeedback.LinkInputSig(trilist.StringInput[joinMap.LastBoot]);
// iterate the program status feedback collection and map all the joins // iterate the program status feedback collection and map all the joins
LinkProgramInfoJoins(systemMonitorController, trilist, joinMap);
LinkEthernetInfoJoins(systemMonitorController, trilist, joinMap);
}
private static void LinkEthernetInfoJoins(SystemMonitorController systemMonitorController, BasicTriList trilist, SystemMonitorJoinMap joinMap)
{
var ethernetSlotJoinStart = joinMap.EthernetStartJoin;
foreach (var fb in systemMonitorController.EthernetStatusFeedbackCollection)
{
fb.Value.CurrentIpAddressFeedback.LinkInputSig(trilist.StringInput[ethernetSlotJoinStart + joinMap.CurrentIpAddress]);
fb.Value.CurrentSubnetMaskFeedback.LinkInputSig(trilist.StringInput[ethernetSlotJoinStart + joinMap.CurrentSubnetMask]);
fb.Value.CurrentDefaultGatewayFeedback.LinkInputSig(trilist.StringInput[ethernetSlotJoinStart + joinMap.CurrentDefaultGateway]);
fb.Value.StaticIpAddressFeedback.LinkInputSig(trilist.StringInput[ethernetSlotJoinStart + joinMap.StaticIpAddress]);
fb.Value.StaticSubnetMaskFeedback.LinkInputSig(trilist.StringInput[ethernetSlotJoinStart + joinMap.StaticSubnetMask]);
fb.Value.StaticDefaultGatewayFeedback.LinkInputSig(trilist.StringInput[ethernetSlotJoinStart + joinMap.StaticDefaultGateway]);
fb.Value.HostNameFeedback.LinkInputSig(trilist.StringInput[ethernetSlotJoinStart + joinMap.HostName]);
fb.Value.MacAddressFeedback.LinkInputSig(trilist.StringInput[ethernetSlotJoinStart + joinMap.MacAddress]);
fb.Value.DomainFeedback.LinkInputSig(trilist.StringInput[ethernetSlotJoinStart + joinMap.Domain]);
fb.Value.DnsServerFeedback.LinkInputSig(trilist.StringInput[ethernetSlotJoinStart + joinMap.DnsServer]);
fb.Value.DhcpStatusFeedback.LinkInputSig(trilist.StringInput[ethernetSlotJoinStart + joinMap.DhcpStatus]);
ethernetSlotJoinStart += joinMap.EthernetOffsetJoin;
}
}
private static void LinkProgramInfoJoins(SystemMonitorController systemMonitorController, BasicTriList trilist,
SystemMonitorJoinMap joinMap)
{
var programSlotJoinStart = joinMap.ProgramStartJoin; var programSlotJoinStart = joinMap.ProgramStartJoin;
foreach (var p in systemMonitorController.ProgramStatusFeedbackCollection) foreach (var p in systemMonitorController.ProgramStatusFeedbackCollection)
{ {
var programNumber = p.Value.Program.Number; var programNumber = p.Value.Program.Number;
trilist.SetBoolSigAction(programSlotJoinStart + joinMap.ProgramStart, new Action<bool> trilist.SetBoolSigAction(programSlotJoinStart + joinMap.ProgramStart,
(b => SystemMonitor.ProgramCollection[programNumber].OperatingState = eProgramOperatingState.Start)); b => SystemMonitor.ProgramCollection[programNumber].OperatingState = eProgramOperatingState.Start);
p.Value.ProgramStartedFeedback.LinkInputSig(trilist.BooleanInput[programSlotJoinStart + joinMap.ProgramStart]); p.Value.ProgramStartedFeedback.LinkInputSig(trilist.BooleanInput[programSlotJoinStart + joinMap.ProgramStart]);
trilist.SetBoolSigAction(programSlotJoinStart + joinMap.ProgramStop, new Action<bool> trilist.SetBoolSigAction(programSlotJoinStart + joinMap.ProgramStop,
(b => SystemMonitor.ProgramCollection[programNumber].OperatingState = eProgramOperatingState.Stop)); b => SystemMonitor.ProgramCollection[programNumber].OperatingState = eProgramOperatingState.Stop);
p.Value.ProgramStoppedFeedback.LinkInputSig(trilist.BooleanInput[programSlotJoinStart + joinMap.ProgramStop]); p.Value.ProgramStoppedFeedback.LinkInputSig(trilist.BooleanInput[programSlotJoinStart + joinMap.ProgramStop]);
trilist.SetBoolSigAction(programSlotJoinStart + joinMap.ProgramRegister, new Action<bool> trilist.SetBoolSigAction(programSlotJoinStart + joinMap.ProgramRegister,
(b => SystemMonitor.ProgramCollection[programNumber].RegistrationState = eProgramRegistrationState.Register)); b => SystemMonitor.ProgramCollection[programNumber].RegistrationState = eProgramRegistrationState.Register);
p.Value.ProgramRegisteredFeedback.LinkInputSig(trilist.BooleanInput[programSlotJoinStart + joinMap.ProgramRegister]); p.Value.ProgramRegisteredFeedback.LinkInputSig(
trilist.BooleanInput[programSlotJoinStart + joinMap.ProgramRegister]);
trilist.SetBoolSigAction(programSlotJoinStart + joinMap.ProgramUnregister, new Action<bool> trilist.SetBoolSigAction(programSlotJoinStart + joinMap.ProgramUnregister,
(b => SystemMonitor.ProgramCollection[programNumber].RegistrationState = eProgramRegistrationState.Unregister)); b => SystemMonitor.ProgramCollection[programNumber].RegistrationState = eProgramRegistrationState.Unregister);
p.Value.ProgramUnregisteredFeedback.LinkInputSig(trilist.BooleanInput[programSlotJoinStart + joinMap.ProgramUnregister]); p.Value.ProgramUnregisteredFeedback.LinkInputSig(
trilist.BooleanInput[programSlotJoinStart + joinMap.ProgramUnregister]);
p.Value.ProgramNameFeedback.LinkInputSig(trilist.StringInput[programSlotJoinStart + joinMap.ProgramName]); p.Value.ProgramNameFeedback.LinkInputSig(trilist.StringInput[programSlotJoinStart + joinMap.ProgramName]);
p.Value.ProgramCompileTimeFeedback.LinkInputSig( p.Value.ProgramCompileTimeFeedback.LinkInputSig(

View File

@@ -34,18 +34,34 @@ namespace PepperDash.Essentials.Core
List<Crestron.SimplSharpPro.DeviceSupport.Feedback> LinkedCrestronFeedbacks = new List<Crestron.SimplSharpPro.DeviceSupport.Feedback>(); List<Crestron.SimplSharpPro.DeviceSupport.Feedback> LinkedCrestronFeedbacks = new List<Crestron.SimplSharpPro.DeviceSupport.Feedback>();
/// <summary>
/// Creates the feedback with the Func as described.
/// </summary>
/// <remarks>
/// While the linked sig value will be updated with the current value stored when it is linked to a EISC Bridge,
/// it will NOT reflect an actual value from a device until <seealso cref="FireUpdate"/> has been called
/// </remarks>
/// <param name="valueFunc">Delegate to invoke when this feedback needs to be updated</param>
public BoolFeedback(Func<bool> valueFunc) public BoolFeedback(Func<bool> valueFunc)
: this(null, valueFunc) : this(null, valueFunc)
{ {
} }
/// <summary>
/// Creates the feedback with the Func as described.
/// </summary>
/// <remarks>
/// While the linked sig value will be updated with the current value stored when it is linked to a EISC Bridge,
/// it will NOT reflect an actual value from a device until <seealso cref="FireUpdate"/> has been called
/// </remarks>
/// <param name="key">Key to find this Feedback</param>
/// <param name="valueFunc">Delegate to invoke when this feedback needs to be updated</param>
public BoolFeedback(string key, Func<bool> valueFunc) public BoolFeedback(string key, Func<bool> valueFunc)
: base(key) : base(key)
{ {
ValueFunc = valueFunc; ValueFunc = valueFunc;
} }
public override void FireUpdate() public override void FireUpdate()
{ {
bool newValue = InTestMode ? TestValue : ValueFunc.Invoke(); bool newValue = InTestMode ? TestValue : ValueFunc.Invoke();

View File

@@ -23,11 +23,28 @@ namespace PepperDash.Essentials.Core
Func<int> ValueFunc; Func<int> ValueFunc;
List<UShortInputSig> LinkedInputSigs = new List<UShortInputSig>(); List<UShortInputSig> LinkedInputSigs = new List<UShortInputSig>();
/// <summary>
/// Creates the feedback with the Func as described.
/// </summary>
/// <remarks>
/// While the linked sig value will be updated with the current value stored when it is linked to a EISC Bridge,
/// it will NOT reflect an actual value from a device until <seealso cref="FireUpdate"/> has been called
/// </remarks>
/// <param name="valueFunc">Delegate to invoke when this feedback needs to be updated</param>
public IntFeedback(Func<int> valueFunc) public IntFeedback(Func<int> valueFunc)
: this(null, valueFunc) : this(null, valueFunc)
{ {
} }
/// <summary>
/// Creates the feedback with the Func as described.
/// </summary>
/// <remarks>
/// While the linked sig value will be updated with the current value stored when it is linked to a EISC Bridge,
/// it will NOT reflect an actual value from a device until <seealso cref="FireUpdate"/> has been called
/// </remarks>
/// <param name="key">Key to find this Feedback</param>
/// <param name="valueFunc">Delegate to invoke when this feedback needs to be updated</param>
public IntFeedback(string key, Func<int> valueFunc) public IntFeedback(string key, Func<int> valueFunc)
: base(key) : base(key)
{ {

View File

@@ -7,6 +7,7 @@ using Crestron.SimplSharpPro;
namespace PepperDash.Essentials.Core namespace PepperDash.Essentials.Core
{ {
public class StringFeedback : Feedback public class StringFeedback : Feedback
{ {
public override string StringValue { get { return _StringValue; } } // ValueFunc.Invoke(); } } public override string StringValue { get { return _StringValue; } } // ValueFunc.Invoke(); } }
@@ -18,16 +19,33 @@ namespace PepperDash.Essentials.Core
public string TestValue { get; private set; } public string TestValue { get; private set; }
/// <summary> /// <summary>
/// Evalutated on FireUpdate /// Evaluated on FireUpdate
/// </summary> /// </summary>
public Func<string> ValueFunc { get; private set; } public Func<string> ValueFunc { get; private set; }
List<StringInputSig> LinkedInputSigs = new List<StringInputSig>(); List<StringInputSig> LinkedInputSigs = new List<StringInputSig>();
/// <summary>
/// Creates the feedback with the Func as described.
/// </summary>
/// <remarks>
/// While the linked sig value will be updated with the current value stored when it is linked to a EISC Bridge,
/// it will NOT reflect an actual value from a device until <seealso cref="FireUpdate"/> has been called
/// </remarks>
/// <param name="valueFunc">Delegate to invoke when this feedback needs to be updated</param>
public StringFeedback(Func<string> valueFunc) public StringFeedback(Func<string> valueFunc)
: this(null, valueFunc) : this(null, valueFunc)
{ {
} }
/// <summary>
/// Creates the feedback with the Func as described.
/// </summary>
/// <remarks>
/// While the linked sig value will be updated with the current value stored when it is linked to a EISC Bridge,
/// it will NOT reflect an actual value from a device until <seealso cref="FireUpdate"/> has been called
/// </remarks>
/// <param name="key">Key to find this Feedback</param>
/// <param name="valueFunc">Delegate to invoke when this feedback needs to be updated</param>
public StringFeedback(string key, Func<string> valueFunc) public StringFeedback(string key, Func<string> valueFunc)
: base(key) : base(key)
{ {

View File

@@ -1,13 +1,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp; using Crestron.SimplSharp;
using Crestron.SimplSharpPro.Diagnostics; using Crestron.SimplSharpPro.Diagnostics;
using PepperDash.Core; using PepperDash.Core;
using PepperDash.Essentials.Core;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Converters; using Newtonsoft.Json.Converters;
@@ -19,18 +14,32 @@ namespace PepperDash.Essentials.Core.Monitoring
/// </summary> /// </summary>
public class SystemMonitorController : Device public class SystemMonitorController : Device
{ {
private const long UptimePollTime = 300000;
private CTimer _uptimePollTimer;
private string _uptime;
private string _lastStart;
public event EventHandler<EventArgs> SystemMonitorPropertiesChanged; public event EventHandler<EventArgs> SystemMonitorPropertiesChanged;
public Dictionary<uint, ProgramStatusFeedbacks> ProgramStatusFeedbackCollection; public Dictionary<uint, ProgramStatusFeedbacks> ProgramStatusFeedbackCollection;
public Dictionary<short, EthernetStatusFeedbacks> EthernetStatusFeedbackCollection;
public IntFeedback TimeZoneFeedback { get; set; } public IntFeedback TimeZoneFeedback { get; protected set; }
public StringFeedback TimeZoneTextFeedback { get; set; } public StringFeedback TimeZoneTextFeedback { get; protected set; }
public StringFeedback IoControllerVersionFeedback { get; protected set; }
public StringFeedback SnmpVersionFeedback { get; protected set; }
public StringFeedback BaCnetAppVersionFeedback { get; protected set; }
public StringFeedback ControllerVersionFeedback { get; protected set; }
//new feedbacks. Issue #50
public StringFeedback SerialNumberFeedback { get; protected set; }
public StringFeedback ModelFeedback { get; set; }
public StringFeedback UptimeFeedback { get; set; }
public StringFeedback LastStartFeedback { get; set; }
public StringFeedback IOControllerVersionFeedback { get; set; }
public StringFeedback SnmpVersionFeedback { get; set; }
public StringFeedback BACnetAppVersionFeedback { get; set; }
public StringFeedback ControllerVersionFeedback { get; set; }
public SystemMonitorController(string key) public SystemMonitorController(string key)
: base(key) : base(key)
{ {
@@ -38,21 +47,18 @@ namespace PepperDash.Essentials.Core.Monitoring
SystemMonitor.ProgramInitialization.ProgramInitializationUnderUserControl = true; SystemMonitor.ProgramInitialization.ProgramInitializationUnderUserControl = true;
//CrestronConsole.AddNewConsoleCommand(RefreshSystemMonitorData, "RefreshSystemMonitor", "Refreshes System Monitor Feedbacks", ConsoleAccessLevelEnum.AccessOperator); TimeZoneFeedback = new IntFeedback(() => SystemMonitor.TimeZoneInformation.TimeZoneNumber);
TimeZoneTextFeedback = new StringFeedback(() => SystemMonitor.TimeZoneInformation.TimeZoneName);
TimeZoneFeedback = new IntFeedback(new Func<int>( () => SystemMonitor.TimeZoneInformation.TimeZoneNumber)); IoControllerVersionFeedback = new StringFeedback(() => SystemMonitor.VersionInformation.IOPVersion);
TimeZoneTextFeedback = new StringFeedback(new Func<string>( () => SystemMonitor.TimeZoneInformation.TimeZoneName)); SnmpVersionFeedback = new StringFeedback(() => SystemMonitor.VersionInformation.SNMPVersion);
BaCnetAppVersionFeedback = new StringFeedback(() => SystemMonitor.VersionInformation.BACNetVersion);
ControllerVersionFeedback = new StringFeedback(() => SystemMonitor.VersionInformation.ControlSystemVersion);
IOControllerVersionFeedback = new StringFeedback(new Func<string>( () => SystemMonitor.VersionInformation.IOPVersion)); SerialNumberFeedback = new StringFeedback(() => CrestronEnvironment.SystemInfo.SerialNumber);
SnmpVersionFeedback = new StringFeedback(new Func<string>( () => SystemMonitor.VersionInformation.SNMPVersion)); ModelFeedback = new StringFeedback(() => InitialParametersClass.ControllerPromptName);
BACnetAppVersionFeedback = new StringFeedback(new Func<string>( () => SystemMonitor.VersionInformation.BACNetVersion)); UptimeFeedback = new StringFeedback(() => _uptime);
ControllerVersionFeedback = new StringFeedback(new Func<string>( () => SystemMonitor.VersionInformation.ControlSystemVersion)); LastStartFeedback = new StringFeedback(()=> _lastStart);
//var status = string.Format("System Monitor Status: \r TimeZone: {0}\rTimeZoneText: {1}\rIOControllerVersion: {2}\rSnmpAppVersionFeedback: {3}\rBACnetAppVersionFeedback: {4}\rControllerVersionFeedback: {5}",
// SystemMonitor.TimeZoneInformation.TimeZoneNumber, SystemMonitor.TimeZoneInformation.TimeZoneName, SystemMonitor.VersionInformation.IOPVersion, SystemMonitor.VersionInformation.SNMPVersion,
// SystemMonitor.VersionInformation.BACNetVersion, SystemMonitor.VersionInformation.ControlSystemVersion);
//Debug.Console(1, this, status);
ProgramStatusFeedbackCollection = new Dictionary<uint, ProgramStatusFeedbacks>(); ProgramStatusFeedbackCollection = new Dictionary<uint, ProgramStatusFeedbacks>();
@@ -62,43 +68,132 @@ namespace PepperDash.Essentials.Core.Monitoring
ProgramStatusFeedbackCollection.Add(prog.Number, program); ProgramStatusFeedbackCollection.Add(prog.Number, program);
} }
SystemMonitor.ProgramChange += new ProgramStateChangeEventHandler(SystemMonitor_ProgramChange); CreateEthernetStatusFeedbacks();
SystemMonitor.TimeZoneInformation.TimeZoneChange += new TimeZoneChangeEventHandler(TimeZoneInformation_TimeZoneChange); UpdateEthernetStatusFeeedbacks();
_uptimePollTimer = new CTimer(PollUptime,null,0, UptimePollTime);
SystemMonitor.ProgramChange += SystemMonitor_ProgramChange;
SystemMonitor.TimeZoneInformation.TimeZoneChange += TimeZoneInformation_TimeZoneChange;
CrestronEnvironment.EthernetEventHandler += CrestronEnvironmentOnEthernetEventHandler;
CrestronEnvironment.ProgramStatusEventHandler += CrestronEnvironmentOnProgramStatusEventHandler;
}
private void CrestronEnvironmentOnProgramStatusEventHandler(eProgramStatusEventType programEventType)
{
if (programEventType != eProgramStatusEventType.Stopping) return;
_uptimePollTimer.Stop();
_uptimePollTimer.Dispose();
_uptimePollTimer = null;
}
private void PollUptime(object obj)
{
var consoleResponse = string.Empty;
CrestronConsole.SendControlSystemCommand("uptime", ref consoleResponse);
ParseUptime(consoleResponse);
UptimeFeedback.FireUpdate();
LastStartFeedback.FireUpdate();
}
private void ParseUptime(string response)
{
var splitString = response.Trim().Split('\r', '\n');
var lastStartRaw = splitString[2];
var lastStartIndex = lastStartRaw.IndexOf(':');
_lastStart = lastStartRaw.Substring(lastStartIndex + 1).Trim();
var uptimeRaw = splitString[0];
var forIndex = uptimeRaw.IndexOf("for", StringComparison.Ordinal);
//4 => "for " to get what's on the right
_uptime = uptimeRaw.Substring(forIndex + 4);
}
private void CrestronEnvironmentOnEthernetEventHandler(EthernetEventArgs ethernetEventArgs)
{
if (ethernetEventArgs.EthernetEventType != eEthernetEventType.LinkUp) return;
foreach (var fb in EthernetStatusFeedbackCollection)
{
fb.Value.UpdateEthernetStatus();
}
}
private void CreateEthernetStatusFeedbacks()
{
EthernetStatusFeedbackCollection = new Dictionary<short, EthernetStatusFeedbacks>();
Debug.Console(2, "Creating {0} EthernetStatusFeedbacks", InitialParametersClass.NumberOfEthernetInterfaces);
for (short i = 0; i < InitialParametersClass.NumberOfEthernetInterfaces; i++)
{
Debug.Console(2, "Creating EthernetStatusFeedback for Interface {0}", i);
var ethernetInterface = new EthernetStatusFeedbacks(i);
EthernetStatusFeedbackCollection.Add(i, ethernetInterface);
}
}
private void UpdateEthernetStatusFeeedbacks()
{
foreach (var iface in EthernetStatusFeedbackCollection)
{
iface.Value.CurrentIpAddressFeedback.FireUpdate();
iface.Value.CurrentSubnetMaskFeedback.FireUpdate();
iface.Value.CurrentDefaultGatewayFeedback.FireUpdate();
iface.Value.StaticIpAddressFeedback.FireUpdate();
iface.Value.StaticSubnetMaskFeedback.FireUpdate();
iface.Value.StaticDefaultGatewayFeedback.FireUpdate();
iface.Value.HostNameFeedback.FireUpdate();
iface.Value.DnsServerFeedback.FireUpdate();
iface.Value.DomainFeedback.FireUpdate();
iface.Value.DhcpStatusFeedback.FireUpdate();
iface.Value.MacAddressFeedback.FireUpdate();
}
} }
/// <summary> /// <summary>
/// Gets data in separate thread /// Gets data in separate thread
/// </summary> /// </summary>
/// <param name="command"></param> private void RefreshSystemMonitorData()
void RefreshSystemMonitorData(string command)
{ {
// this takes a while, launch a new thread // this takes a while, launch a new thread
CrestronInvoke.BeginInvoke((o) => CrestronInvoke.BeginInvoke(UpdateFeedback);
{
TimeZoneFeedback.FireUpdate();
TimeZoneTextFeedback.FireUpdate();
IOControllerVersionFeedback.FireUpdate();
SnmpVersionFeedback.FireUpdate();
BACnetAppVersionFeedback.FireUpdate();
ControllerVersionFeedback.FireUpdate();
OnSystemMonitorPropertiesChanged();
}
);
} }
void OnSystemMonitorPropertiesChanged() private void UpdateFeedback(object o)
{
TimeZoneFeedback.FireUpdate();
TimeZoneTextFeedback.FireUpdate();
IoControllerVersionFeedback.FireUpdate();
SnmpVersionFeedback.FireUpdate();
BaCnetAppVersionFeedback.FireUpdate();
ControllerVersionFeedback.FireUpdate();
SerialNumberFeedback.FireUpdate();
ModelFeedback.FireUpdate();
OnSystemMonitorPropertiesChanged();
}
private void OnSystemMonitorPropertiesChanged()
{ {
var handler = SystemMonitorPropertiesChanged; var handler = SystemMonitorPropertiesChanged;
if (handler != null) if (handler != null)
{ {
handler(this, new EventArgs()); handler(this, new EventArgs());
} }
} }
public override bool CustomActivate() public override bool CustomActivate()
{ {
RefreshSystemMonitorData(null); RefreshSystemMonitorData();
return base.CustomActivate(); return base.CustomActivate();
} }
@@ -114,46 +209,41 @@ namespace PepperDash.Essentials.Core.Monitoring
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="args"></param> /// <param name="args"></param>
void SystemMonitor_ProgramChange(Program sender, ProgramEventArgs args) private void SystemMonitor_ProgramChange(Program sender, ProgramEventArgs args)
{ {
Debug.Console(2, this, "Program Change Detected for slot: {0}", sender.Number); Debug.Console(2, this, "Program Change Detected for slot: {0}", sender.Number);
Debug.Console(2, this, "Event Type: {0}", args.EventType); Debug.Console(2, this, "Event Type: {0}", args.EventType);
var program = ProgramStatusFeedbackCollection[sender.Number]; var program = ProgramStatusFeedbackCollection[sender.Number];
if (args.EventType == eProgramChangeEventType.OperatingState) switch (args.EventType)
{ {
program.ProgramStartedFeedback.FireUpdate(); case eProgramChangeEventType.OperatingState:
program.ProgramStoppedFeedback.FireUpdate(); program.ProgramStartedFeedback.FireUpdate();
program.ProgramStoppedFeedback.FireUpdate();
program.ProgramInfo.OperatingState = args.OperatingState; program.ProgramInfo.OperatingState = args.OperatingState;
if (args.OperatingState == eProgramOperatingState.Start)
//program.GetProgramInfo(); program.GetProgramInfo();
else
if (args.OperatingState == eProgramOperatingState.Start) {
program.GetProgramInfo(); program.AggregatedProgramInfoFeedback.FireUpdate();
else program.OnProgramInfoChanged();
{ }
program.AggregatedProgramInfoFeedback.FireUpdate(); break;
program.OnProgramInfoChanged(); case eProgramChangeEventType.RegistrationState:
} program.ProgramRegisteredFeedback.FireUpdate();
program.ProgramUnregisteredFeedback.FireUpdate();
program.ProgramInfo.RegistrationState = args.RegistrationState;
program.GetProgramInfo();
break;
} }
else if (args.EventType == eProgramChangeEventType.RegistrationState)
{
program.ProgramRegisteredFeedback.FireUpdate();
program.ProgramUnregisteredFeedback.FireUpdate();
program.ProgramInfo.RegistrationState = args.RegistrationState;
program.GetProgramInfo();
}
} }
/// <summary> /// <summary>
/// Responds to time zone changes and updates the appropriate feedbacks /// Responds to time zone changes and updates the appropriate feedbacks
/// </summary> /// </summary>
/// <param name="args"></param> /// <param name="args"></param>
void TimeZoneInformation_TimeZoneChange(TimeZoneEventArgs args) private void TimeZoneInformation_TimeZoneChange(TimeZoneEventArgs args)
{ {
Debug.Console(2, this, "Time Zone Change Detected."); Debug.Console(2, this, "Time Zone Change Detected.");
TimeZoneFeedback.FireUpdate(); TimeZoneFeedback.FireUpdate();
@@ -162,6 +252,121 @@ namespace PepperDash.Essentials.Core.Monitoring
OnSystemMonitorPropertiesChanged(); OnSystemMonitorPropertiesChanged();
} }
public class EthernetStatusFeedbacks
{
public StringFeedback HostNameFeedback { get; protected set; }
public StringFeedback DnsServerFeedback { get; protected set; }
public StringFeedback DomainFeedback { get; protected set; }
public StringFeedback MacAddressFeedback { get; protected set; }
public StringFeedback DhcpStatusFeedback { get; protected set; }
public StringFeedback CurrentIpAddressFeedback { get; protected set; }
public StringFeedback CurrentSubnetMaskFeedback { get; protected set; }
public StringFeedback CurrentDefaultGatewayFeedback { get; protected set; }
public StringFeedback StaticIpAddressFeedback { get; protected set; }
public StringFeedback StaticSubnetMaskFeedback { get; protected set; }
public StringFeedback StaticDefaultGatewayFeedback { get; protected set; }
public EthernetStatusFeedbacks(short adapterIndex)
{
Debug.Console(2, "Ethernet Information for interface {0}", adapterIndex);
Debug.Console(2, "Adapter Index: {1} Hostname: {0}", CrestronEthernetHelper.GetEthernetParameter(
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_HOSTNAME, adapterIndex), adapterIndex);
Debug.Console(2, "Adapter Index: {1} Current IP Address: {0}", CrestronEthernetHelper.GetEthernetParameter(
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS, adapterIndex), adapterIndex);
Debug.Console(2, "Adapter Index: {1} Current Subnet Mask: {0}", CrestronEthernetHelper.GetEthernetParameter(
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_MASK, adapterIndex), adapterIndex);
Debug.Console(2, "Adapter Index: {1} Current Router: {0}", CrestronEthernetHelper.GetEthernetParameter(
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_ROUTER, adapterIndex), adapterIndex);
Debug.Console(2, "Adapter Index: {1} Static IP Address: {0}", CrestronEthernetHelper.GetEthernetParameter(
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_STATIC_IPADDRESS, adapterIndex), adapterIndex);
Debug.Console(2, "Adapter Index: {1} Static Subnet Mask: {0}", CrestronEthernetHelper.GetEthernetParameter(
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_STATIC_IPMASK, adapterIndex), adapterIndex);
Debug.Console(2, "Adapter Index: {1} Static Router: {0}", CrestronEthernetHelper.GetEthernetParameter(
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_STATIC_ROUTER, adapterIndex), adapterIndex);
Debug.Console(2, "Adapter Index: {1} DNS Servers: {0}", CrestronEthernetHelper.GetEthernetParameter(
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_DNS_SERVER, adapterIndex), adapterIndex);
Debug.Console(2, "Adapter Index: {1} DHCP State: {0}", CrestronEthernetHelper.GetEthernetParameter(
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_DHCP_STATE, adapterIndex), adapterIndex);
Debug.Console(2, "Adapter Index: {1} Domain Name: {0}", CrestronEthernetHelper.GetEthernetParameter(
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_DOMAIN_NAME, adapterIndex), adapterIndex);
Debug.Console(2, "Adapter Index: {1} MAC Address: {0}", CrestronEthernetHelper.GetEthernetParameter(
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_MAC_ADDRESS, adapterIndex), adapterIndex);
HostNameFeedback =
new StringFeedback(
() =>
CrestronEthernetHelper.GetEthernetParameter(
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_HOSTNAME, adapterIndex));
CurrentIpAddressFeedback =
new StringFeedback(
() =>
CrestronEthernetHelper.GetEthernetParameter(
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS, adapterIndex));
CurrentDefaultGatewayFeedback =
new StringFeedback(
() =>
CrestronEthernetHelper.GetEthernetParameter(
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_ROUTER, adapterIndex));
CurrentSubnetMaskFeedback =
new StringFeedback(
() =>
CrestronEthernetHelper.GetEthernetParameter(
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_MASK, adapterIndex));
StaticIpAddressFeedback =
new StringFeedback(
() =>
CrestronEthernetHelper.GetEthernetParameter(
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS, adapterIndex));
StaticDefaultGatewayFeedback =
new StringFeedback(
() =>
CrestronEthernetHelper.GetEthernetParameter(
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_ROUTER, adapterIndex));
StaticSubnetMaskFeedback =
new StringFeedback(
() =>
CrestronEthernetHelper.GetEthernetParameter(
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_MASK, adapterIndex));
DomainFeedback =
new StringFeedback(
() =>
CrestronEthernetHelper.GetEthernetParameter(
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_DOMAIN_NAME, adapterIndex));
DnsServerFeedback =
new StringFeedback(
() =>
CrestronEthernetHelper.GetEthernetParameter(
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_DNS_SERVER, adapterIndex));
MacAddressFeedback =
new StringFeedback(
() =>
CrestronEthernetHelper.GetEthernetParameter(
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_MAC_ADDRESS, adapterIndex));
DhcpStatusFeedback = new StringFeedback(
() =>
CrestronEthernetHelper.GetEthernetParameter(
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_DHCP_STATE, adapterIndex));
}
public void UpdateEthernetStatus()
{
HostNameFeedback.FireUpdate();
CurrentIpAddressFeedback.FireUpdate();
CurrentSubnetMaskFeedback.FireUpdate();
CurrentDefaultGatewayFeedback.FireUpdate();
StaticIpAddressFeedback.FireUpdate();
StaticSubnetMaskFeedback.FireUpdate();
StaticDefaultGatewayFeedback.FireUpdate();
DomainFeedback.FireUpdate();
DnsServerFeedback.FireUpdate();
MacAddressFeedback.FireUpdate();
DhcpStatusFeedback.FireUpdate();
}
}
public class ProgramStatusFeedbacks public class ProgramStatusFeedbacks
{ {
@@ -192,17 +397,19 @@ namespace PepperDash.Essentials.Core.Monitoring
ProgramInfo.OperatingState = Program.OperatingState; ProgramInfo.OperatingState = Program.OperatingState;
ProgramInfo.RegistrationState = Program.RegistrationState; ProgramInfo.RegistrationState = Program.RegistrationState;
ProgramStartedFeedback = new BoolFeedback(new Func<bool>( () => Program.OperatingState == eProgramOperatingState.Start)); ProgramStartedFeedback = new BoolFeedback(() => Program.OperatingState == eProgramOperatingState.Start);
ProgramStoppedFeedback = new BoolFeedback(new Func<bool>( () => Program.OperatingState == eProgramOperatingState.Stop)); ProgramStoppedFeedback = new BoolFeedback(() => Program.OperatingState == eProgramOperatingState.Stop);
ProgramRegisteredFeedback = new BoolFeedback(new Func<bool>( () => Program.RegistrationState == eProgramRegistrationState.Register)); ProgramRegisteredFeedback =
ProgramUnregisteredFeedback = new BoolFeedback(new Func<bool>( () => Program.RegistrationState == eProgramRegistrationState.Unregister)); new BoolFeedback(() => Program.RegistrationState == eProgramRegistrationState.Register);
ProgramUnregisteredFeedback =
new BoolFeedback(() => Program.RegistrationState == eProgramRegistrationState.Unregister);
ProgramNameFeedback = new StringFeedback(new Func<string>(() => ProgramInfo.ProgramFile)); ProgramNameFeedback = new StringFeedback(() => ProgramInfo.ProgramFile);
ProgramCompileTimeFeedback = new StringFeedback(new Func<string>(() => ProgramInfo.CompileTime)); ProgramCompileTimeFeedback = new StringFeedback(() => ProgramInfo.CompileTime);
CrestronDataBaseVersionFeedback = new StringFeedback(new Func<string>(() => ProgramInfo.CrestronDB)); CrestronDataBaseVersionFeedback = new StringFeedback(() => ProgramInfo.CrestronDb);
EnvironmentVersionFeedback = new StringFeedback(new Func<string>(() => ProgramInfo.Environment)); EnvironmentVersionFeedback = new StringFeedback(() => ProgramInfo.Environment);
AggregatedProgramInfoFeedback = new StringFeedback(new Func<string>(() => JsonConvert.SerializeObject(ProgramInfo))); AggregatedProgramInfoFeedback = new StringFeedback(() => JsonConvert.SerializeObject(ProgramInfo));
GetProgramInfo(); GetProgramInfo();
} }
@@ -212,74 +419,99 @@ namespace PepperDash.Essentials.Core.Monitoring
/// </summary> /// </summary>
public void GetProgramInfo() public void GetProgramInfo()
{ {
CrestronInvoke.BeginInvoke((o) => CrestronInvoke.BeginInvoke(GetProgramInfo);
}
private void GetProgramInfo(object o)
{
Debug.Console(2, "Attempting to get program info for slot: {0}", Program.Number);
string response = null;
if (Program.RegistrationState == eProgramRegistrationState.Unregister || Program.OperatingState == eProgramOperatingState.Stop)
{ {
Debug.Console(2, "Attempting to get program info for slot: {0}", Program.Number); Debug.Console(2, "Program {0} not registered. Setting default values for program information.",
Program.Number);
string response = null; ProgramInfo = new ProgramInfo(Program.Number)
var success = CrestronConsole.SendControlSystemCommand(string.Format("progcomments:{0}", Program.Number), ref response);
if (success)
{ {
//Debug.Console(2, "Progcomments Response: \r{0}", response); OperatingState = Program.OperatingState,
RegistrationState = Program.RegistrationState
};
if (!response.ToLower().Contains("bad or incomplete")) return;
{ }
// Shared properteis
ProgramInfo.ProgramFile = ParseConsoleData(response, "Program File", ": ", "\n");
ProgramInfo.CompilerRevision = ParseConsoleData(response, "Compiler Rev", ": ", "\n");
ProgramInfo.CompileTime = ParseConsoleData(response, "Compiled On", ": ", "\n");
ProgramInfo.Include4Dat = ParseConsoleData(response, "Include4.dat", ": ", "\n");
var success = CrestronConsole.SendControlSystemCommand(
string.Format("progcomments:{0}", Program.Number), ref response);
if (!success)
{
Debug.Console(2, "Progcomments Attempt Unsuccessful for slot: {0}", Program.Number);
UpdateFeedbacks();
return;
}
if (ProgramInfo.ProgramFile.Contains(".dll")) if (response.ToLower().Contains("bad or incomplete"))
{ {
// SSP Program Debug.Console(2,
ProgramInfo.FriendlyName = ParseConsoleData(response, "Friendly Name", ": ", "\n"); "Program in slot {0} not running. Setting default ProgramInfo for slot: {0}",
ProgramInfo.ApplicationName = ParseConsoleData(response, "Application Name", ": ", "\n"); Program.Number);
ProgramInfo.ProgramTool = ParseConsoleData(response, "Program Tool", ": ", "\n");
ProgramInfo.MinFirmwareVersion = ParseConsoleData(response, "Min Firmware Version", ": ", "\n");
ProgramInfo.PlugInVersion = ParseConsoleData(response, "PlugInVersion", ": ", "\n");
}
else if (ProgramInfo.ProgramFile.Contains(".smw"))
{
// SIMPL Windows Program
ProgramInfo.FriendlyName = ParseConsoleData(response, "Friendly Name", ":", "\n");
ProgramInfo.SystemName = ParseConsoleData(response, "System Name", ": ", "\n");
ProgramInfo.CrestronDB = ParseConsoleData(response, "CrestronDB", ": ", "\n");
ProgramInfo.Environment = ParseConsoleData(response, "Source Env", ": ", "\n");
ProgramInfo.Programmer = ParseConsoleData(response, "Programmer", ": ", "\n");
} // Assume no valid program info. Constructing a new object will wipe all properties
//Debug.Console(2, "ProgramInfo: \r{0}", JsonConvert.SerializeObject(ProgramInfo)); ProgramInfo = new ProgramInfo(Program.Number)
}
else
{
Debug.Console(2, "Bad or incomplete console command response. Initializing ProgramInfo for slot: {0}", Program.Number);
// Assume no valid program info. Constructing a new object will wipe all properties
ProgramInfo = new ProgramInfo(Program.Number);
ProgramInfo.OperatingState = Program.OperatingState;
ProgramInfo.RegistrationState = Program.RegistrationState;
}
}
else
{ {
Debug.Console(2, "Progcomments Attempt Unsuccessful for slot: {0}", Program.Number); OperatingState = Program.OperatingState,
} RegistrationState = Program.RegistrationState
};
ProgramNameFeedback.FireUpdate(); UpdateFeedbacks();
ProgramCompileTimeFeedback.FireUpdate();
CrestronDataBaseVersionFeedback.FireUpdate();
EnvironmentVersionFeedback.FireUpdate();
AggregatedProgramInfoFeedback.FireUpdate(); return;
}
OnProgramInfoChanged();
}); // Shared properteis
ProgramInfo.ProgramFile = ParseConsoleData(response, "Program File", ": ", "\n");
ProgramInfo.CompilerRevision = ParseConsoleData(response, "Compiler Rev", ": ", "\n");
ProgramInfo.CompileTime = ParseConsoleData(response, "Compiled On", ": ", "\n");
ProgramInfo.Include4Dat = ParseConsoleData(response, "Include4.dat", ": ", "\n");
if (ProgramInfo.ProgramFile.Contains(".dll"))
{
// SSP Program
ProgramInfo.FriendlyName = ParseConsoleData(response, "Friendly Name", ": ", "\n");
ProgramInfo.ApplicationName = ParseConsoleData(response, "Application Name", ": ", "\n");
ProgramInfo.ProgramTool = ParseConsoleData(response, "Program Tool", ": ", "\n");
ProgramInfo.MinFirmwareVersion = ParseConsoleData(response, "Min Firmware Version", ": ",
"\n");
ProgramInfo.PlugInVersion = ParseConsoleData(response, "PlugInVersion", ": ", "\n");
}
else if (ProgramInfo.ProgramFile.Contains(".smw"))
{
// SIMPL Windows Program
ProgramInfo.FriendlyName = ParseConsoleData(response, "Friendly Name", ":", "\n");
ProgramInfo.SystemName = ParseConsoleData(response, "System Name", ": ", "\n");
ProgramInfo.CrestronDb = ParseConsoleData(response, "CrestronDB", ": ", "\n");
ProgramInfo.Environment = ParseConsoleData(response, "Source Env", ": ", "\n");
ProgramInfo.Programmer = ParseConsoleData(response, "Programmer", ": ", "\n");
}
Debug.Console(2, "Program info for slot {0} successfully updated", Program.Number);
UpdateFeedbacks();
}
private void UpdateFeedbacks()
{
ProgramNameFeedback.FireUpdate();
ProgramCompileTimeFeedback.FireUpdate();
CrestronDataBaseVersionFeedback.FireUpdate();
EnvironmentVersionFeedback.FireUpdate();
AggregatedProgramInfoFeedback.FireUpdate();
OnProgramInfoChanged();
} }
public void OnProgramInfoChanged() public void OnProgramInfoChanged()
@@ -294,30 +526,28 @@ namespace PepperDash.Essentials.Core.Monitoring
private string ParseConsoleData(string data, string line, string startString, string endString) private string ParseConsoleData(string data, string line, string startString, string endString)
{ {
string outputData = ""; var outputData = "";
if (data.Length > 0) if (data.Length <= 0) return outputData;
try
{ {
try //Debug.Console(2, "ParseConsoleData Data: {0}, Line {1}, startStirng {2}, endString {3}", data, line, startString, endString);
{ var linePosition = data.IndexOf(line, StringComparison.Ordinal);
var startPosition = data.IndexOf(startString, linePosition, StringComparison.Ordinal) +
//Debug.Console(2, "ParseConsoleData Data: {0}, Line {1}, startStirng {2}, endString {3}", data, line, startString, endString); startString.Length;
var linePosition = data.IndexOf(line); var endPosition = data.IndexOf(endString, startPosition, StringComparison.Ordinal);
var startPosition = data.IndexOf(startString, linePosition) + startString.Length; outputData = data.Substring(startPosition, endPosition - startPosition).Trim();
var endPosition = data.IndexOf(endString, startPosition); //Debug.Console(2, "ParseConsoleData Return: {0}", outputData);
outputData = data.Substring(startPosition, endPosition - startPosition).Trim(); }
//Debug.Console(2, "ParseConsoleData Return: {0}", outputData); catch (Exception e)
} {
catch (Exception e) Debug.Console(1, "Error Parsing Console Data:\r{0}", e);
{
Debug.Console(1, "Error Parsing Console Data:\r{0}", e);
}
} }
return outputData; return outputData;
} }
} }
} }
/// <summary> /// <summary>
@@ -330,32 +560,39 @@ namespace PepperDash.Essentials.Core.Monitoring
[JsonProperty("programNumber")] [JsonProperty("programNumber")]
public uint ProgramNumber { get; private set; } public uint ProgramNumber { get; private set; }
[JsonConverter(typeof(StringEnumConverter))] [JsonConverter(typeof (StringEnumConverter))]
[JsonProperty("operatingState")] [JsonProperty("operatingState")]
public eProgramOperatingState OperatingState { get; set; } public eProgramOperatingState OperatingState { get; set; }
[JsonConverter(typeof(StringEnumConverter))] [JsonConverter(typeof (StringEnumConverter))]
[JsonProperty("registrationState")] [JsonProperty("registrationState")]
public eProgramRegistrationState RegistrationState { get; set; } public eProgramRegistrationState RegistrationState { get; set; }
[JsonProperty("programFile")] [JsonProperty("programFile")]
public string ProgramFile { get; set; } public string ProgramFile { get; set; }
[JsonProperty("friendlyName")] [JsonProperty("friendlyName")]
public string FriendlyName { get; set; } public string FriendlyName { get; set; }
[JsonProperty("compilerRevision")] [JsonProperty("compilerRevision")]
public string CompilerRevision { get; set; } public string CompilerRevision { get; set; }
[JsonProperty("compileTime")] [JsonProperty("compileTime")]
public string CompileTime { get; set; } public string CompileTime { get; set; }
[JsonProperty("include4Dat")] [JsonProperty("include4Dat")]
public string Include4Dat { get; set; } public string Include4Dat { get; set; }
// SIMPL Windows properties // SIMPL Windows properties
[JsonProperty("systemName")] [JsonProperty("systemName")]
public string SystemName { get; set; } public string SystemName { get; set; }
[JsonProperty("crestronDb")] [JsonProperty("crestronDb")]
public string CrestronDB { get; set; } public string CrestronDb { get; set; }
[JsonProperty("environment")] [JsonProperty("environment")]
public string Environment { get; set; } public string Environment { get; set; }
[JsonProperty("programmer")] [JsonProperty("programmer")]
public string Programmer { get; set; } public string Programmer { get; set; }
@@ -363,10 +600,13 @@ namespace PepperDash.Essentials.Core.Monitoring
// SSP Properties // SSP Properties
[JsonProperty("applicationName")] [JsonProperty("applicationName")]
public string ApplicationName { get; set; } public string ApplicationName { get; set; }
[JsonProperty("programTool")] [JsonProperty("programTool")]
public string ProgramTool { get; set; } public string ProgramTool { get; set; }
[JsonProperty("minFirmwareVersion")] [JsonProperty("minFirmwareVersion")]
public string MinFirmwareVersion { get; set; } public string MinFirmwareVersion { get; set; }
[JsonProperty("plugInVersion")] [JsonProperty("plugInVersion")]
public string PlugInVersion { get; set; } public string PlugInVersion { get; set; }
@@ -381,7 +621,7 @@ namespace PepperDash.Essentials.Core.Monitoring
Include4Dat = ""; Include4Dat = "";
SystemName = ""; SystemName = "";
CrestronDB = ""; CrestronDb = "";
Environment = ""; Environment = "";
Programmer = ""; Programmer = "";

View File

@@ -84,7 +84,7 @@
</Reference> </Reference>
<Reference Include="SimplSharpReflectionInterface, Version=1.0.5583.25238, Culture=neutral, PublicKeyToken=1099c178b3b54c3b, processorArchitecture=MSIL"> <Reference Include="SimplSharpReflectionInterface, Version=1.0.5583.25238, Culture=neutral, PublicKeyToken=1099c178b3b54c3b, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\..\ProgramData\Crestron\SDK\SimplSharpReflectionInterface.dll</HintPath> <HintPath>..\..\..\..\..\..\..\..\ProgramData\Crestron\SDK\SimplSharpReflectionInterface.dll</HintPath>
</Reference> </Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />