fix: devcommstatus response now prints correctly

This commit is contained in:
Andrew Welker
2024-07-26 06:47:48 -05:00
parent 97bd30e9c9
commit 7a263a644a

View File

@@ -1,13 +1,11 @@
using System; using Crestron.SimplSharp;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using Crestron.SimplSharp;
using Crestron.SimplSharpPro; using Crestron.SimplSharpPro;
using PepperDash.Core; using PepperDash.Core;
using Serilog.Events; using Serilog.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
namespace PepperDash.Essentials.Core namespace PepperDash.Essentials.Core
@@ -19,10 +17,11 @@ namespace PepperDash.Essentials.Core
private static readonly CCriticalSection DeviceCriticalSection = new CCriticalSection(); private static readonly CCriticalSection DeviceCriticalSection = new CCriticalSection();
private static readonly CEvent AllowAddDevicesCEvent = new CEvent(false, true); private static readonly CEvent AllowAddDevicesCEvent = new CEvent(false, true);
//public static List<Device> Devices { get { return _Devices; } } //public static List<Device> Devices { get { return _Devices; } }
//static List<Device> _Devices = new List<Device>(); //static List<Device> _Devices = new List<Device>();
static readonly Dictionary<string, IKeyed> Devices = new Dictionary<string, IKeyed>(StringComparer.OrdinalIgnoreCase); private static readonly Dictionary<string, IKeyed> Devices = new Dictionary<string, IKeyed>(StringComparer.OrdinalIgnoreCase);
/// <summary> /// <summary>
/// Returns a copy of all the devices in a list /// Returns a copy of all the devices in a list
@@ -64,7 +63,7 @@ namespace PepperDash.Essentials.Core
DeviceCriticalSection.Enter(); DeviceCriticalSection.Enter();
AddDeviceEnabled = false; AddDeviceEnabled = false;
// PreActivate all devices // PreActivate all devices
Debug.LogMessage(LogEventLevel.Information,"****PreActivation starting...****"); Debug.LogMessage(LogEventLevel.Information, "****PreActivation starting...****");
foreach (var d in Devices.Values) foreach (var d in Devices.Values)
{ {
try try
@@ -203,8 +202,7 @@ namespace PepperDash.Essentials.Core
Debug.LogMessage(LogEventLevel.Information, "Device '{0}' not found", devKey); Debug.LogMessage(LogEventLevel.Information, "Device '{0}' not found", devKey);
return; return;
} }
var statusDev = dev as IHasFeedback; if (!(dev is IHasFeedback statusDev))
if (statusDev == null)
{ {
Debug.LogMessage(LogEventLevel.Information, "Device '{0}' does not have visible feedbacks", devKey); Debug.LogMessage(LogEventLevel.Information, "Device '{0}' does not have visible feedbacks", devKey);
return; return;
@@ -225,13 +223,11 @@ namespace PepperDash.Essentials.Core
private static void ListDeviceCommStatuses(string input) private static void ListDeviceCommStatuses(string input)
{ {
var sb = new StringBuilder();
foreach (var dev in Devices.Values.OfType<ICommunicationMonitor>()) foreach (var dev in Devices.Values.OfType<ICommunicationMonitor>())
{ {
sb.Append(string.Format("{0}: {1}\r", dev, CrestronConsole.ConsoleCommandResponse($"{dev}: {dev.CommunicationMonitor.Status}{Environment.NewLine}");
dev.CommunicationMonitor.Status));
} }
CrestronConsole.ConsoleCommandResponse(sb.ToString());
} }
@@ -367,8 +363,7 @@ namespace PepperDash.Essentials.Core
} }
//Debug.LogMessage(LogEventLevel.Verbose, "**** {0} - {1} ****", match.Groups[1].Value, match.Groups[2].Value); //Debug.LogMessage(LogEventLevel.Verbose, "**** {0} - {1} ****", match.Groups[1].Value, match.Groups[2].Value);
var com = GetDeviceForKey(match.Groups[1].Value) as ComPortController; if (!(GetDeviceForKey(match.Groups[1].Value) is ComPortController com))
if (com == null)
{ {
CrestronConsole.ConsoleCommandResponse("'{0}' is not a comm port device", match.Groups[1].Value); CrestronConsole.ConsoleCommandResponse("'{0}' is not a comm port device", match.Groups[1].Value);
return; return;
@@ -423,16 +418,15 @@ namespace PepperDash.Essentials.Core
var deviceKey = args[0]; var deviceKey = args[0];
var setting = args[1]; var setting = args[1];
var timeout= String.Empty; var timeout = String.Empty;
if (args.Length >= 3) if (args.Length >= 3)
{ {
timeout = args[2]; timeout = args[2];
} }
var device = GetDeviceForKey(deviceKey) as IStreamDebugging;
if (device == null) if (!(GetDeviceForKey(deviceKey) is IStreamDebugging device))
{ {
CrestronConsole.ConsoleCommandResponse("Unable to get device with key: {0}", deviceKey); CrestronConsole.ConsoleCommandResponse("Unable to get device with key: {0}", deviceKey);
return; return;
@@ -479,9 +473,7 @@ namespace PepperDash.Essentials.Core
{ {
foreach (var device in AllDevices) foreach (var device in AllDevices)
{ {
var streamDevice = device as IStreamDebugging; if (device is IStreamDebugging streamDevice)
if (streamDevice != null)
{ {
streamDevice.StreamDebugging.SetDebuggingWithDefaultTimeout(eStreamDebuggingSetting.Off); streamDevice.StreamDebugging.SetDebuggingWithDefaultTimeout(eStreamDebuggingSetting.Off);
} }