Adds debug statement to Hardware_OnlineStatusChange callback to help figure out issues with devices not reporting online status correctly. Removes IsRegistered from Feedbacks and fires update manually.

This commit is contained in:
Neil Dorin
2020-02-12 16:07:43 -07:00
parent 56fae89ae2
commit f1278d0ee4

View File

@@ -1,35 +1,35 @@
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 Crestron.SimplSharpPro; using Crestron.SimplSharpPro;
using Crestron.SimplSharpPro.DeviceSupport; using Crestron.SimplSharpPro.DeviceSupport;
using PepperDash.Core; using PepperDash.Core;
namespace PepperDash.Essentials.Core namespace PepperDash.Essentials.Core
{ {
/// <summary> /// <summary>
/// A bridge class to cover the basic features of GenericBase hardware /// A bridge class to cover the basic features of GenericBase hardware
/// </summary> /// </summary>
public class CrestronGenericBaseDevice : Device, IOnline, IHasFeedback, ICommunicationMonitor, IUsageTracking public class CrestronGenericBaseDevice : Device, IOnline, IHasFeedback, ICommunicationMonitor, IUsageTracking
{ {
public virtual GenericBase Hardware { get; protected set; } public virtual GenericBase Hardware { get; protected set; }
/// <summary> /// <summary>
/// Returns a list containing the Outputs that we want to expose. /// Returns a list containing the Outputs that we want to expose.
/// </summary> /// </summary>
public FeedbackCollection<Feedback> Feedbacks { get; private set; } public FeedbackCollection<Feedback> Feedbacks { get; private set; }
public BoolFeedback IsOnline { get; private set; } public BoolFeedback IsOnline { get; private set; }
public BoolFeedback IsRegistered { get; private set; } public BoolFeedback IsRegistered { get; private set; }
public StringFeedback IpConnectionsText { get; private set; } public StringFeedback IpConnectionsText { get; private set; }
/// <summary> /// <summary>
/// Used by implementing classes to prevent registration with Crestron TLDM. For /// Used by implementing classes to prevent registration with Crestron TLDM. For
/// devices like RMCs and TXs attached to a chassis. /// devices like RMCs and TXs attached to a chassis.
/// </summary> /// </summary>
public bool PreventRegistration { get; protected set; } public bool PreventRegistration { get; protected set; }
public CrestronGenericBaseDevice(string key, string name, GenericBase hardware) public CrestronGenericBaseDevice(string key, string name, GenericBase hardware)
@@ -47,118 +47,123 @@ namespace PepperDash.Essentials.Core
else else
return string.Empty; return string.Empty;
}); });
AddToFeedbackList(IsOnline, IsRegistered, IpConnectionsText); AddToFeedbackList(IsOnline, IpConnectionsText);
CommunicationMonitor = new CrestronGenericBaseCommunicationMonitor(this, hardware, 120000, 300000); CommunicationMonitor = new CrestronGenericBaseCommunicationMonitor(this, hardware, 120000, 300000);
} }
/// <summary> /// <summary>
/// Make sure that overriding classes call this! /// Make sure that overriding classes call this!
/// Registers the Crestron device, connects up to the base events, starts communication monitor /// Registers the Crestron device, connects up to the base events, starts communication monitor
/// </summary> /// </summary>
public override bool CustomActivate() public override bool CustomActivate()
{ {
Debug.Console(0, this, "Activating"); Debug.Console(0, this, "Activating");
if (!PreventRegistration) if (!PreventRegistration)
{ {
//Debug.Console(1, this, " Does not require registration. Skipping"); //Debug.Console(1, this, " Does not require registration. Skipping");
var response = Hardware.RegisterWithLogging(Key); var response = Hardware.RegisterWithLogging(Key);
if (response != eDeviceRegistrationUnRegistrationResponse.Success) if (response != eDeviceRegistrationUnRegistrationResponse.Success)
{ {
//Debug.Console(0, this, "ERROR: Cannot register Crestron device: {0}", response); //Debug.Console(0, this, "ERROR: Cannot register Crestron device: {0}", response);
return false; return false;
} }
IsRegistered.FireUpdate();
} }
foreach (var f in Feedbacks) foreach (var f in Feedbacks)
{ {
f.FireUpdate(); f.FireUpdate();
} }
Hardware.OnlineStatusChange += new OnlineStatusChangeEventHandler(Hardware_OnlineStatusChange); Hardware.OnlineStatusChange += new OnlineStatusChangeEventHandler(Hardware_OnlineStatusChange);
CommunicationMonitor.Start(); CommunicationMonitor.Start();
return true; return true;
} }
/// <summary> /// <summary>
/// This disconnects events and unregisters the base hardware device. /// This disconnects events and unregisters the base hardware device.
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public override bool Deactivate() public override bool Deactivate()
{ {
CommunicationMonitor.Stop(); CommunicationMonitor.Stop();
Hardware.OnlineStatusChange -= Hardware_OnlineStatusChange; Hardware.OnlineStatusChange -= Hardware_OnlineStatusChange;
return Hardware.UnRegister() == eDeviceRegistrationUnRegistrationResponse.Success; var success = Hardware.UnRegister() == eDeviceRegistrationUnRegistrationResponse.Success;
}
IsRegistered.FireUpdate();
/// <summary>
/// Adds feedback(s) to the list return success;
/// </summary> }
/// <param name="newFbs"></param>
public void AddToFeedbackList(params Feedback[] newFbs) /// <summary>
{ /// Adds feedback(s) to the list
foreach (var f in newFbs) /// </summary>
{ /// <param name="newFbs"></param>
if (f != null) public void AddToFeedbackList(params Feedback[] newFbs)
{ {
if (!Feedbacks.Contains(f)) foreach (var f in newFbs)
{ {
if (f != null)
{
if (!Feedbacks.Contains(f))
{
Feedbacks.Add(f); Feedbacks.Add(f);
} }
} }
} }
} }
void Hardware_OnlineStatusChange(GenericBase currentDevice, OnlineOfflineEventArgs args) void Hardware_OnlineStatusChange(GenericBase currentDevice, OnlineOfflineEventArgs args)
{ {
//if (args.DeviceOnLine) Debug.Console(2, this, "OnlineStatusChange Event. Online = {0}", args.DeviceOnLine);
//{ foreach (var feedback in Feedbacks)
foreach (var feedback in Feedbacks) {
{ if (feedback != null)
if (feedback != null) feedback.FireUpdate();
feedback.FireUpdate(); }
} }
//}
} #region IStatusMonitor Members
#region IStatusMonitor Members public StatusMonitorBase CommunicationMonitor { get; private set; }
#endregion
public StatusMonitorBase CommunicationMonitor { get; private set; }
#endregion #region IUsageTracking Members
#region IUsageTracking Members public UsageTracking UsageTracker { get; set; }
public UsageTracking UsageTracker { get; set; } #endregion
}
#endregion
} //***********************************************************************************
public class CrestronGenericBaseDeviceEventIds
//*********************************************************************************** {
public class CrestronGenericBaseDeviceEventIds public const uint IsOnline = 1;
{ public const uint IpConnectionsText =2;
public const uint IsOnline = 1; }
public const uint IpConnectionsText =2;
} /// <summary>
/// Adds logging to Register() failure
/// <summary> /// </summary>
/// Adds logging to Register() failure public static class GenericBaseExtensions
/// </summary> {
public static class GenericBaseExtensions public static eDeviceRegistrationUnRegistrationResponse RegisterWithLogging(this GenericBase device, string key)
{ {
public static eDeviceRegistrationUnRegistrationResponse RegisterWithLogging(this GenericBase device, string key) var result = device.Register();
{ var level = result == eDeviceRegistrationUnRegistrationResponse.Success ?
var result = device.Register(); Debug.ErrorLogLevel.Notice : Debug.ErrorLogLevel.Error;
var level = result == eDeviceRegistrationUnRegistrationResponse.Success ? Debug.Console(0, level, "Register device result: '{0}', type '{1}', result {2}", key, device, result);
Debug.ErrorLogLevel.Notice : Debug.ErrorLogLevel.Error; //if (result != eDeviceRegistrationUnRegistrationResponse.Success)
Debug.Console(0, level, "Register device result: '{0}', type '{1}', result {2}", key, device, result); //{
//if (result != eDeviceRegistrationUnRegistrationResponse.Success) // Debug.Console(0, Debug.ErrorLogLevel.Error, "Cannot register device '{0}': {1}", key, result);
//{ //}
// Debug.Console(0, Debug.ErrorLogLevel.Error, "Cannot register device '{0}': {1}", key, result); return result;
//} }
return result;
} }
}
} }