Merge pull request #1371 from PepperDash/temp-to-dev

This commit is contained in:
Neil Dorin
2025-12-23 12:14:03 -05:00
committed by GitHub
5 changed files with 215 additions and 128 deletions

View File

@@ -2,25 +2,29 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Reflection;
using Crestron.SimplSharp; using Crestron.SimplSharp;
using Crestron.SimplSharpPro; using Crestron.SimplSharpPro;
using Crestron.SimplSharpPro.DeviceSupport; using Crestron.SimplSharpPro.DeviceSupport;
using Crestron.SimplSharpPro.EthernetCommunication; using Crestron.SimplSharpPro.EthernetCommunication;
using Newtonsoft.Json; using Newtonsoft.Json;
using PepperDash.Core; using PepperDash.Core;
using PepperDash.Core.Logging;
using PepperDash.Essentials.Core.Config; using PepperDash.Essentials.Core.Config;
using Serilog.Events; using Serilog.Events;
//using PepperDash.Essentials.Devices.Common.Cameras;
namespace PepperDash.Essentials.Core.Bridges namespace PepperDash.Essentials.Core.Bridges
{ {
/// <summary> /// <summary>
/// Base class for bridge API variants /// Base class for bridge API variants
/// </summary> /// </summary>
[Obsolete("Will be removed in v3.0.0")]
public abstract class BridgeApi : EssentialsDevice public abstract class BridgeApi : EssentialsDevice
{ {
/// <summary>
/// Constructor
/// </summary>
/// <param name="key">Device key</param>
protected BridgeApi(string key) : protected BridgeApi(string key) :
base(key) base(key)
{ {
@@ -29,23 +33,36 @@ namespace PepperDash.Essentials.Core.Bridges
} }
/// <summary> /// <summary>
/// Represents a EiscApiAdvanced /// Class to link devices and rooms to an EISC Instance
/// </summary> /// </summary>
public class EiscApiAdvanced : BridgeApi, ICommunicationMonitor public class EiscApiAdvanced : BridgeApi, ICommunicationMonitor
{ {
/// <summary>
/// Gets the PropertiesConfig
/// </summary>
public EiscApiPropertiesConfig PropertiesConfig { get; private set; } public EiscApiPropertiesConfig PropertiesConfig { get; private set; }
/// <summary>
/// Gets the JoinMaps dictionary
/// </summary>
public Dictionary<string, JoinMapBaseAdvanced> JoinMaps { get; private set; } public Dictionary<string, JoinMapBaseAdvanced> JoinMaps { get; private set; }
/// <summary>
/// Gets the EISC instance
/// </summary>
public BasicTriList Eisc { get; private set; } public BasicTriList Eisc { get; private set; }
/// <summary>
/// Constructor
/// </summary>
/// <param name="dc">Device configuration</param>
/// <param name="eisc">EISC instance</param>
public EiscApiAdvanced(DeviceConfig dc, BasicTriList eisc) : public EiscApiAdvanced(DeviceConfig dc, BasicTriList eisc) :
base(dc.Key) base(dc.Key)
{ {
JoinMaps = new Dictionary<string, JoinMapBaseAdvanced>(); JoinMaps = new Dictionary<string, JoinMapBaseAdvanced>();
PropertiesConfig = dc.Properties.ToObject<EiscApiPropertiesConfig>(); PropertiesConfig = dc.Properties.ToObject<EiscApiPropertiesConfig>();
//PropertiesConfig = JsonConvert.DeserializeObject<EiscApiPropertiesConfig>(dc.Properties.ToString());
Eisc = eisc; Eisc = eisc;
@@ -60,8 +77,7 @@ namespace PepperDash.Essentials.Core.Bridges
/// <summary> /// <summary>
/// CustomActivate method /// CustomActivate method
/// </summary> /// </summary>
/// <inheritdoc />
public override bool CustomActivate() public override bool CustomActivate()
{ {
CommunicationMonitor.Start(); CommunicationMonitor.Start();
@@ -83,7 +99,7 @@ namespace PepperDash.Essentials.Core.Bridges
if (PropertiesConfig.Devices == null) if (PropertiesConfig.Devices == null)
{ {
Debug.LogMessage(LogEventLevel.Debug, this, "No devices linked to this bridge"); this.LogDebug("No devices linked to this bridge");
return; return;
} }
@@ -104,9 +120,7 @@ namespace PepperDash.Essentials.Core.Bridges
continue; continue;
} }
Debug.LogMessage(LogEventLevel.Information, this, this.LogWarning("{deviceKey} is not compatible with this bridge type. Please update the device.", device.Key);
"{0} is not compatible with this bridge type. Please use 'eiscapi' instead, or updae the device.",
device.Key);
} }
} }
@@ -121,34 +135,31 @@ namespace PepperDash.Essentials.Core.Bridges
if (registerResult != eDeviceRegistrationUnRegistrationResponse.Success) if (registerResult != eDeviceRegistrationUnRegistrationResponse.Success)
{ {
Debug.LogMessage(LogEventLevel.Verbose, this, "Registration result: {0}", registerResult); this.LogVerbose("Registration result: {registerResult}", registerResult);
return; return;
} }
Debug.LogMessage(LogEventLevel.Debug, this, "EISC registration successful"); this.LogDebug("EISC registration successful");
} }
/// <summary> /// <summary>
/// LinkRooms method /// Link rooms to this EISC. Rooms MUST implement IBridgeAdvanced
/// </summary> /// </summary>
public void LinkRooms() public void LinkRooms()
{ {
Debug.LogMessage(LogEventLevel.Debug, this, "Linking Rooms..."); this.LogDebug("Linking Rooms...");
if (PropertiesConfig.Rooms == null) if (PropertiesConfig.Rooms == null)
{ {
Debug.LogMessage(LogEventLevel.Debug, this, "No rooms linked to this bridge."); this.LogDebug("No rooms linked to this bridge.");
return; return;
} }
foreach (var room in PropertiesConfig.Rooms) foreach (var room in PropertiesConfig.Rooms)
{ {
var rm = DeviceManager.GetDeviceForKey(room.RoomKey) as IBridgeAdvanced; if (!(DeviceManager.GetDeviceForKey(room.RoomKey) is IBridgeAdvanced rm))
if (rm == null)
{ {
Debug.LogMessage(LogEventLevel.Debug, this, this.LogDebug("Room {roomKey} does not implement IBridgeAdvanced. Skipping...", room.RoomKey);
"Room {0} does not implement IBridgeAdvanced. Skipping...", room.RoomKey);
continue; continue;
} }
@@ -159,11 +170,8 @@ namespace PepperDash.Essentials.Core.Bridges
/// <summary> /// <summary>
/// Adds a join map /// Adds a join map
/// </summary> /// </summary>
/// <param name="deviceKey"></param> /// <param name="deviceKey">The key of the device to add the join map for</param>
/// <param name="joinMap"></param> /// <param name="joinMap">The join map to add</param>
/// <summary>
/// AddJoinMap method
/// </summary>
public void AddJoinMap(string deviceKey, JoinMapBaseAdvanced joinMap) public void AddJoinMap(string deviceKey, JoinMapBaseAdvanced joinMap)
{ {
if (!JoinMaps.ContainsKey(deviceKey)) if (!JoinMaps.ContainsKey(deviceKey))
@@ -172,14 +180,13 @@ namespace PepperDash.Essentials.Core.Bridges
} }
else else
{ {
Debug.LogMessage(LogEventLevel.Verbose, this, "Unable to add join map with key '{0}'. Key already exists in JoinMaps dictionary", deviceKey); this.LogWarning("Unable to add join map with key '{deviceKey}'. Key already exists in JoinMaps dictionary", deviceKey);
} }
} }
/// <summary> /// <summary>
/// PrintJoinMaps method /// PrintJoinMaps method
/// </summary> /// </summary>
/// <inheritdoc />
public virtual void PrintJoinMaps() public virtual void PrintJoinMaps()
{ {
CrestronConsole.ConsoleCommandResponse("Join Maps for EISC IPID: {0}\r\n", Eisc.ID.ToString("X")); CrestronConsole.ConsoleCommandResponse("Join Maps for EISC IPID: {0}\r\n", Eisc.ID.ToString("X"));
@@ -190,17 +197,17 @@ namespace PepperDash.Essentials.Core.Bridges
joinMap.Value.PrintJoinMapInfo(); joinMap.Value.PrintJoinMapInfo();
} }
} }
/// <summary> /// <summary>
/// MarkdownForBridge method /// MarkdownForBridge method
/// </summary> /// </summary>
/// <inheritdoc />
public virtual void MarkdownForBridge(string bridgeKey) public virtual void MarkdownForBridge(string bridgeKey)
{ {
Debug.LogMessage(LogEventLevel.Information, this, "Writing Joinmaps to files for EISC IPID: {0}", Eisc.ID.ToString("X")); this.LogInformation("Writing Joinmaps to files for EISC IPID: {eiscId}", Eisc.ID.ToString("X"));
foreach (var joinMap in JoinMaps) foreach (var joinMap in JoinMaps)
{ {
Debug.LogMessage(LogEventLevel.Information, "Generating markdown for device '{0}':", joinMap.Key); this.LogInformation("Generating markdown for device '{deviceKey}':", joinMap.Key);
joinMap.Value.MarkdownJoinMapInfo(joinMap.Key, bridgeKey); joinMap.Value.MarkdownJoinMapInfo(joinMap.Key, bridgeKey);
} }
} }
@@ -208,53 +215,45 @@ namespace PepperDash.Essentials.Core.Bridges
/// <summary> /// <summary>
/// Prints the join map for a device by key /// Prints the join map for a device by key
/// </summary> /// </summary>
/// <param name="deviceKey"></param> /// <param name="deviceKey">The key of the device to print the join map for</param>
/// <summary>
/// PrintJoinMapForDevice method
/// </summary>
public void PrintJoinMapForDevice(string deviceKey) public void PrintJoinMapForDevice(string deviceKey)
{ {
var joinMap = JoinMaps[deviceKey]; var joinMap = JoinMaps[deviceKey];
if (joinMap == null) if (joinMap == null)
{ {
Debug.LogMessage(LogEventLevel.Information, this, "Unable to find joinMap for device with key: '{0}'", deviceKey); this.LogInformation("Unable to find joinMap for device with key: '{deviceKey}'", deviceKey);
return; return;
} }
Debug.LogMessage(LogEventLevel.Information, "Join map for device '{0}' on EISC '{1}':", deviceKey, Key); this.LogInformation("Join map for device '{deviceKey}' on EISC '{eiscKey}':", deviceKey, Key);
joinMap.PrintJoinMapInfo(); joinMap.PrintJoinMapInfo();
} }
/// <summary> /// <summary>
/// Prints the join map for a device by key /// Prints the join map for a device by key in Markdown format
/// </summary>
/// <param name="deviceKey"></param>
/// <summary>
/// MarkdownJoinMapForDevice method
/// </summary> /// </summary>
/// <param name="deviceKey">The key of the device to print the join map for</param>
/// <param name="bridgeKey">The key of the bridge to use for the Markdown output</param>
public void MarkdownJoinMapForDevice(string deviceKey, string bridgeKey) public void MarkdownJoinMapForDevice(string deviceKey, string bridgeKey)
{ {
var joinMap = JoinMaps[deviceKey]; var joinMap = JoinMaps[deviceKey];
if (joinMap == null) if (joinMap == null)
{ {
Debug.LogMessage(LogEventLevel.Information, this, "Unable to find joinMap for device with key: '{0}'", deviceKey); this.LogInformation("Unable to find joinMap for device with key: '{deviceKey}'", deviceKey);
return; return;
} }
Debug.LogMessage(LogEventLevel.Information, "Join map for device '{0}' on EISC '{1}':", deviceKey, Key); this.LogInformation("Join map for device '{deviceKey}' on EISC '{eiscKey}':", deviceKey, Key);
joinMap.MarkdownJoinMapInfo(deviceKey, bridgeKey); joinMap.MarkdownJoinMapInfo(deviceKey, bridgeKey);
} }
/// <summary> /// <summary>
/// Used for debugging to trigger an action based on a join number and type /// Used for debugging to trigger an action based on a join number and type
/// </summary> /// </summary>
/// <param name="join"></param> /// <param name="join">The join number to execute the action for</param>
/// <param name="type"></param> /// <param name="type">The type of join (digital, analog, serial)</param>
/// <param name="state"></param> /// <param name="state">The state to pass to the action</param>
/// <summary>
/// ExecuteJoinAction method
/// </summary>
public void ExecuteJoinAction(uint join, string type, object state) public void ExecuteJoinAction(uint join, string type, object state)
{ {
try try
@@ -263,78 +262,87 @@ namespace PepperDash.Essentials.Core.Bridges
{ {
case "digital": case "digital":
{ {
var uo = Eisc.BooleanOutput[join].UserObject as Action<bool>; if (Eisc.BooleanOutput[join].UserObject is Action<bool> userObject)
if (uo != null)
{ {
Debug.LogMessage(LogEventLevel.Verbose, this, "Executing Action: {0}", uo.ToString()); this.LogVerbose("Executing Boolean Action");
uo(Convert.ToBoolean(state)); userObject(Convert.ToBoolean(state));
} }
else else
Debug.LogMessage(LogEventLevel.Verbose, this, "User Action is null. Nothing to Execute"); this.LogVerbose("User Object is null. Nothing to Execute");
break; break;
} }
case "analog": case "analog":
{ {
var uo = Eisc.BooleanOutput[join].UserObject as Action<ushort>; if (Eisc.UShortOutput[join].UserObject is Action<ushort> userObject)
if (uo != null)
{ {
Debug.LogMessage(LogEventLevel.Verbose, this, "Executing Action: {0}", uo.ToString()); this.LogVerbose("Executing Analog Action");
uo(Convert.ToUInt16(state)); userObject(Convert.ToUInt16(state));
} }
else else
Debug.LogMessage(LogEventLevel.Verbose, this, "User Action is null. Nothing to Execute"); break; this.LogVerbose("User Object is null. Nothing to Execute");
break;
} }
case "serial": case "serial":
{ {
var uo = Eisc.BooleanOutput[join].UserObject as Action<string>; if (Eisc.StringOutput[join].UserObject is Action<string> userObject)
if (uo != null)
{ {
Debug.LogMessage(LogEventLevel.Verbose, this, "Executing Action: {0}", uo.ToString()); this.LogVerbose("Executing Serial Action");
uo(Convert.ToString(state)); userObject(Convert.ToString(state));
} }
else else
Debug.LogMessage(LogEventLevel.Verbose, this, "User Action is null. Nothing to Execute"); this.LogVerbose("User Object is null. Nothing to Execute");
break; break;
} }
default: default:
{ {
Debug.LogMessage(LogEventLevel.Verbose, "Unknown join type. Use digital/serial/analog"); this.LogVerbose("Unknown join type. Use digital/serial/analog");
break; break;
} }
} }
} }
catch (Exception e) catch (Exception e)
{ {
Debug.LogMessage(LogEventLevel.Debug, this, "Error: {0}", e); this.LogError("ExecuteJoinAction error: {message}", e.Message);
this.LogDebug(e, "Stack Trace: ");
} }
} }
/// <summary> /// <summary>
/// Handles incoming sig changes /// Handle incoming sig changes
/// </summary> /// </summary>
/// <param name="currentDevice"></param> /// <param name="currentDevice">BasicTriList device that triggered the event</param>
/// <param name="args"></param> /// <param name="args">Event arguments containing the signal information</param>
protected void Eisc_SigChange(object currentDevice, SigEventArgs args) protected void Eisc_SigChange(object currentDevice, SigEventArgs args)
{ {
try try
{ {
Debug.LogMessage(LogEventLevel.Verbose, this, "EiscApiAdvanced change: {0} {1}={2}", args.Sig.Type, args.Sig.Number, args.Sig.StringValue); this.LogVerbose("EiscApiAdvanced change: {type} {number}={value}", args.Sig.Type, args.Sig.Number, args.Sig.StringValue);
var uo = args.Sig.UserObject; var userObject = args.Sig.UserObject;
if (uo == null) return; if (userObject == null) return;
Debug.LogMessage(LogEventLevel.Debug, this, "Executing Action: {0}", uo.ToString());
if (uo is Action<bool>) if (userObject is Action<bool>)
(uo as Action<bool>)(args.Sig.BoolValue); {
else if (uo is Action<ushort>) this.LogDebug("Executing Boolean Action");
(uo as Action<ushort>)(args.Sig.UShortValue); (userObject as Action<bool>)(args.Sig.BoolValue);
else if (uo is Action<string>) }
(uo as Action<string>)(args.Sig.StringValue); else if (userObject is Action<ushort>)
{
this.LogDebug("Executing Analog Action");
(userObject as Action<ushort>)(args.Sig.UShortValue);
}
else if (userObject is Action<string>)
{
this.LogDebug("Executing Serial Action");
(userObject as Action<string>)(args.Sig.StringValue);
}
} }
catch (Exception e) catch (Exception e)
{ {
Debug.LogMessage(LogEventLevel.Verbose, this, "Error in Eisc_SigChange handler: {0}", e); this.LogError("Eisc_SigChange handler error: {message}", e.Message);
this.LogDebug(e, "Stack Trace: ");
} }
} }
@@ -423,22 +431,33 @@ namespace PepperDash.Essentials.Core.Bridges
} }
/// <summary> /// <summary>
/// Represents a EiscApiAdvancedFactory /// Factory class for EiscApiAdvanced devices
/// </summary> /// </summary>
/// <remarks>
/// Supported types:
/// eiscapiadv - Create a standard EISC client over TCP/IP
/// eiscapiadvanced - Create a standard EISC client over TCP/IP
/// eiscapiadvancedserver - Create an EISC server
/// eiscapiadvancedclient - Create an EISC client
/// vceiscapiadv - Create a VC-4 EISC client
/// vceiscapiadvanced - Create a VC-4 EISC client
/// eiscapiadvudp - Create a standard EISC client over UDP
/// eiscapiadvancedudp - Create a standard EISC client over UDP
/// </remarks>
public class EiscApiAdvancedFactory : EssentialsDeviceFactory<EiscApiAdvanced> public class EiscApiAdvancedFactory : EssentialsDeviceFactory<EiscApiAdvanced>
{ {
/// <summary>
/// Constructor
/// </summary>
public EiscApiAdvancedFactory() public EiscApiAdvancedFactory()
{ {
TypeNames = new List<string> { "eiscapiadv", "eiscapiadvanced", "eiscapiadvancedserver", "eiscapiadvancedclient", "vceiscapiadv", "vceiscapiadvanced" }; TypeNames = new List<string> { "eiscapiadv", "eiscapiadvanced", "eiscapiadvancedserver", "eiscapiadvancedclient", "vceiscapiadv", "vceiscapiadvanced", "eiscapiadvudp", "eiscapiadvancedudp" };
} }
/// <summary>
/// BuildDevice method
/// </summary>
/// <inheritdoc /> /// <inheritdoc />
public override EssentialsDevice BuildDevice(DeviceConfig dc) public override EssentialsDevice BuildDevice(DeviceConfig dc)
{ {
Debug.LogMessage(LogEventLevel.Debug, "Factory Attempting to create new EiscApiAdvanced Device"); Debug.LogDebug("Attempting to create new EiscApiAdvanced Device");
var controlProperties = CommFactory.GetControlPropertiesConfig(dc); var controlProperties = CommFactory.GetControlPropertiesConfig(dc);
@@ -446,6 +465,13 @@ namespace PepperDash.Essentials.Core.Bridges
switch (dc.Type.ToLower()) switch (dc.Type.ToLower())
{ {
case "eiscapiadvudp":
case "eiscapiadvancedudp":
{
eisc = new EthernetIntersystemCommunications(controlProperties.IpIdInt,
controlProperties.TcpSshProperties.Address, Global.ControlSystem);
break;
}
case "eiscapiadv": case "eiscapiadv":
case "eiscapiadvanced": case "eiscapiadvanced":
{ {
@@ -468,7 +494,7 @@ namespace PepperDash.Essentials.Core.Bridges
{ {
if (string.IsNullOrEmpty(controlProperties.RoomId)) if (string.IsNullOrEmpty(controlProperties.RoomId))
{ {
Debug.LogMessage(LogEventLevel.Information, "Unable to build VC-4 EISC Client for device {0}. Room ID is missing or empty", dc.Key); Debug.LogInformation("Unable to build VC-4 EISC Client for device {deviceKey}. Room ID is missing or empty", dc.Key);
eisc = null; eisc = null;
break; break;
} }

View File

@@ -1,11 +1,11 @@
using Crestron.SimplSharpPro.Keypads; using System;
using PepperDash.Essentials.Core.Queues;
using PepperDash.Essentials.Core.Routing;
using Serilog.Events;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using Crestron.SimplSharpPro.Keypads;
using PepperDash.Essentials.Core.Queues;
using PepperDash.Essentials.Core.Routing;
using Serilog.Events;
using Debug = PepperDash.Core.Debug; using Debug = PepperDash.Core.Debug;
@@ -115,7 +115,7 @@ namespace PepperDash.Essentials.Core
public static (RouteDescriptor, RouteDescriptor) GetRouteToSource(this IRoutingInputs destination, IRoutingOutputs source, eRoutingSignalType signalType, RoutingInputPort destinationPort, RoutingOutputPort sourcePort) public static (RouteDescriptor, RouteDescriptor) GetRouteToSource(this IRoutingInputs destination, IRoutingOutputs source, eRoutingSignalType signalType, RoutingInputPort destinationPort, RoutingOutputPort sourcePort)
{ {
// if it's a single signal type, find the route // if it's a single signal type, find the route
if (!signalType.HasFlag(eRoutingSignalType.AudioVideo) && if (!signalType.HasFlag(eRoutingSignalType.AudioVideo) &&
!(signalType.HasFlag(eRoutingSignalType.Video) && signalType.HasFlag(eRoutingSignalType.SecondaryAudio))) !(signalType.HasFlag(eRoutingSignalType.Video) && signalType.HasFlag(eRoutingSignalType.SecondaryAudio)))
{ {
var singleTypeRouteDescriptor = new RouteDescriptor(source, destination, destinationPort, signalType); var singleTypeRouteDescriptor = new RouteDescriptor(source, destination, destinationPort, signalType);
@@ -134,14 +134,15 @@ namespace PepperDash.Essentials.Core
} }
// otherwise, audioVideo needs to be handled as two steps. // otherwise, audioVideo needs to be handled as two steps.
Debug.LogMessage(LogEventLevel.Debug, "Attempting to build source route from {sourceKey} of type {type}", destination, source.Key); Debug.LogMessage(LogEventLevel.Debug, "Attempting to build source route from {destinationKey} to {sourceKey} of type {type}", destination, source.Key, signalType);
RouteDescriptor audioRouteDescriptor; RouteDescriptor audioRouteDescriptor;
if (signalType.HasFlag(eRoutingSignalType.SecondaryAudio)) if (signalType.HasFlag(eRoutingSignalType.SecondaryAudio))
{ {
audioRouteDescriptor = new RouteDescriptor(source, destination, destinationPort, eRoutingSignalType.SecondaryAudio); audioRouteDescriptor = new RouteDescriptor(source, destination, destinationPort, eRoutingSignalType.SecondaryAudio);
} else }
else
{ {
audioRouteDescriptor = new RouteDescriptor(source, destination, destinationPort, eRoutingSignalType.Audio); audioRouteDescriptor = new RouteDescriptor(source, destination, destinationPort, eRoutingSignalType.Audio);
} }
@@ -199,13 +200,13 @@ namespace PepperDash.Essentials.Core
Source = source, Source = source,
SourcePort = sourcePort, SourcePort = sourcePort,
SignalType = signalType SignalType = signalType
}; };
var coolingDevice = destination as IWarmingCooling; var coolingDevice = destination as IWarmingCooling;
//We already have a route request for this device, and it's a cooling device and is cooling //We already have a route request for this device, and it's a cooling device and is cooling
if (RouteRequests.TryGetValue(destination.Key, out RouteRequest existingRouteRequest) && coolingDevice != null && coolingDevice.IsCoolingDownFeedback.BoolValue == true) if (RouteRequests.TryGetValue(destination.Key, out RouteRequest existingRouteRequest) && coolingDevice != null && coolingDevice.IsCoolingDownFeedback.BoolValue == true)
{ {
coolingDevice.IsCoolingDownFeedback.OutputChange -= existingRouteRequest.HandleCooldown; coolingDevice.IsCoolingDownFeedback.OutputChange -= existingRouteRequest.HandleCooldown;
coolingDevice.IsCoolingDownFeedback.OutputChange += routeRequest.HandleCooldown; coolingDevice.IsCoolingDownFeedback.OutputChange += routeRequest.HandleCooldown;
@@ -219,7 +220,7 @@ namespace PepperDash.Essentials.Core
//New Request //New Request
if (coolingDevice != null && coolingDevice.IsCoolingDownFeedback.BoolValue == true) if (coolingDevice != null && coolingDevice.IsCoolingDownFeedback.BoolValue == true)
{ {
coolingDevice.IsCoolingDownFeedback.OutputChange += routeRequest.HandleCooldown; coolingDevice.IsCoolingDownFeedback.OutputChange += routeRequest.HandleCooldown;
RouteRequests.Add(destination.Key, routeRequest); RouteRequests.Add(destination.Key, routeRequest);
@@ -239,9 +240,9 @@ namespace PepperDash.Essentials.Core
Debug.LogMessage(LogEventLevel.Information, "Device: {destination} is NOT cooling down. Removing stored route request and routing to source key: {sourceKey}", null, destination.Key, routeRequest.Source.Key); Debug.LogMessage(LogEventLevel.Information, "Device: {destination} is NOT cooling down. Removing stored route request and routing to source key: {sourceKey}", null, destination.Key, routeRequest.Source.Key);
} }
routeRequestQueue.Enqueue(new ReleaseRouteQueueItem(ReleaseRouteInternal, destination,destinationPort?.Key ?? string.Empty, false)); routeRequestQueue.Enqueue(new ReleaseRouteQueueItem(ReleaseRouteInternal, destination, destinationPort?.Key ?? string.Empty, false));
routeRequestQueue.Enqueue(new RouteRequestQueueItem(RunRouteRequest, routeRequest)); routeRequestQueue.Enqueue(new RouteRequestQueueItem(RunRouteRequest, routeRequest));
} }
/// <summary> /// <summary>
@@ -272,7 +273,8 @@ namespace PepperDash.Essentials.Core
audioOrSingleRoute.ExecuteRoutes(); audioOrSingleRoute.ExecuteRoutes();
videoRoute?.ExecuteRoutes(); videoRoute?.ExecuteRoutes();
} catch(Exception ex) }
catch (Exception ex)
{ {
Debug.LogMessage(ex, "Exception Running Route Request {request}", null, request); Debug.LogMessage(ex, "Exception Running Route Request {request}", null, request);
} }
@@ -305,9 +307,10 @@ namespace PepperDash.Essentials.Core
Debug.LogMessage(LogEventLevel.Information, "Releasing current route: {0}", destination, current.Source.Key); Debug.LogMessage(LogEventLevel.Information, "Releasing current route: {0}", destination, current.Source.Key);
current.ReleaseRoutes(clearRoute); current.ReleaseRoutes(clearRoute);
} }
} catch (Exception ex) }
catch (Exception ex)
{ {
Debug.LogMessage(ex, "Exception releasing route for '{destination}':'{inputPortKey}'",null, destination?.Key ?? null, string.IsNullOrEmpty(inputPortKey) ? "auto" : inputPortKey); Debug.LogMessage(ex, "Exception releasing route for '{destination}':'{inputPortKey}'", null, destination?.Key ?? null, string.IsNullOrEmpty(inputPortKey) ? "auto" : inputPortKey);
} }
} }

View File

@@ -1,8 +1,10 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using PepperDash.Core; using PepperDash.Core;
using PepperDash.Core.Logging; using PepperDash.Core.Logging;
using PepperDash.Essentials.Core; using PepperDash.Essentials.Core;
using PepperDash.Essentials.Core.Config; using PepperDash.Essentials.Core.Config;
using PepperDash.Essentials.Core.Routing;
using Serilog.Events; using Serilog.Events;
namespace PepperDash.Essentials.Devices.Common.Generic namespace PepperDash.Essentials.Devices.Common.Generic
@@ -10,8 +12,17 @@ namespace PepperDash.Essentials.Devices.Common.Generic
/// <summary> /// <summary>
/// Represents a GenericSink /// Represents a GenericSink
/// </summary> /// </summary>
public class GenericSink : EssentialsDevice, IRoutingSinkWithSwitchingWithInputPort public class GenericSink : EssentialsDevice, IRoutingSinkWithSwitchingWithInputPort, ICurrentSources
{ {
/// <inheritdoc/>
public Dictionary<eRoutingSignalType, SourceListItem> CurrentSources { get; private set; }
/// <inheritdoc/>
public Dictionary<eRoutingSignalType, string> CurrentSourceKeys { get; private set; }
/// <inheritdoc />
public event EventHandler CurrentSourcesChanged;
/// <summary> /// <summary>
/// Initializes a new instance of the GenericSink class /// Initializes a new instance of the GenericSink class
/// </summary> /// </summary>
@@ -24,6 +35,49 @@ namespace PepperDash.Essentials.Devices.Common.Generic
var inputPort = new RoutingInputPort(RoutingPortNames.AnyVideoIn, eRoutingSignalType.AudioVideo | eRoutingSignalType.SecondaryAudio, eRoutingPortConnectionType.Hdmi, null, this); var inputPort = new RoutingInputPort(RoutingPortNames.AnyVideoIn, eRoutingSignalType.AudioVideo | eRoutingSignalType.SecondaryAudio, eRoutingPortConnectionType.Hdmi, null, this);
InputPorts.Add(inputPort); InputPorts.Add(inputPort);
CurrentSources = new Dictionary<eRoutingSignalType, SourceListItem>
{
{ eRoutingSignalType.Audio, null },
{ eRoutingSignalType.Video, null },
};
CurrentSourceKeys = new Dictionary<eRoutingSignalType, string>
{
{ eRoutingSignalType.Audio, string.Empty },
{ eRoutingSignalType.Video, string.Empty },
};
}
/// <inheritdoc />
public void SetCurrentSource(eRoutingSignalType signalType, string sourceListKey, SourceListItem sourceListItem)
{
foreach (eRoutingSignalType type in Enum.GetValues(typeof(eRoutingSignalType)))
{
var flagValue = Convert.ToInt32(type);
// Skip if flagValue is 0 or not a power of two (i.e., not a single-bit flag).
// (flagValue & (flagValue - 1)) != 0 checks if more than one bit is set.
if (flagValue == 0 || (flagValue & (flagValue - 1)) != 0)
{
this.LogDebug("Skipping {type}", type);
continue;
}
this.LogDebug("setting {type}", type);
if (signalType.HasFlag(type))
{
UpdateCurrentSources(type, sourceListKey, sourceListItem);
}
}
// Raise the CurrentSourcesChanged event
CurrentSourcesChanged?.Invoke(this, EventArgs.Empty);
}
private void UpdateCurrentSources(eRoutingSignalType signalType, string sourceListKey, SourceListItem sourceListItem)
{
CurrentSources[signalType] = sourceListItem;
CurrentSourceKeys[signalType] = sourceListKey;
} }
/// <summary> /// <summary>

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Converters; using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
@@ -39,10 +40,14 @@ namespace PepperDash.Essentials.AppServer.Messengers
sourceDevice.CurrentSourcesChanged += (sender, e) => sourceDevice.CurrentSourcesChanged += (sender, e) =>
{ {
// need to copy the dictionaries to avoid enumeration issues
var currentSourceKeys = sourceDevice.CurrentSourceKeys.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
var currentSources = sourceDevice.CurrentSources.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
PostStatusMessage(JToken.FromObject(new PostStatusMessage(JToken.FromObject(new
{ {
currentSourceKeys = sourceDevice.CurrentSourceKeys, currentSourceKeys,
currentSources = sourceDevice.CurrentSources currentSources,
})); }));
}; };
} }

View File

@@ -130,34 +130,33 @@ namespace PepperDash.Essentials.AppServer.Messengers
feedback.MuteFeedback.OutputChange += (sender, args) => feedback.MuteFeedback.OutputChange += (sender, args) =>
{ {
PostStatusMessage(JToken.FromObject( var message = new VolumeStateMessage
new {
{ Volume = new Volume
volume = new {
{ Muted = args.BoolValue
muted = args.BoolValue }
} };
})
); PostStatusMessage(JToken.FromObject(message));
}; };
feedback.VolumeLevelFeedback.OutputChange += (sender, args) => feedback.VolumeLevelFeedback.OutputChange += (sender, args) =>
{ {
var rawValue = ""; var message = new VolumeStateMessage
if (feedback is IBasicVolumeWithFeedbackAdvanced volumeAdvanced)
{ {
rawValue = volumeAdvanced.RawVolumeLevel.ToString(); Volume = new Volume
}
var message = new
{
volume = new
{ {
level = args.IntValue, Level = args.IntValue,
rawValue
} }
}; };
if (device is IBasicVolumeWithFeedbackAdvanced volumeAdvanced)
{
message.Volume.RawValue = volumeAdvanced.RawVolumeLevel.ToString();
message.Volume.Units = volumeAdvanced.Units;
}
PostStatusMessage(JToken.FromObject(message)); PostStatusMessage(JToken.FromObject(message));
}; };
} }