Merge pull request #1196 from PepperDash/feature-2.0.0/routing-cooldown-fixes

Feature 2.0.0/routing cooldown fixes
This commit is contained in:
Andrew Welker
2024-08-01 15:36:36 -04:00
committed by GitHub
18 changed files with 1061 additions and 765 deletions

View File

@@ -5,6 +5,7 @@ using System.Linq;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using PepperDash.Essentials.Core.Devices;
namespace PepperDash.Essentials.Core.Config namespace PepperDash.Essentials.Core.Config
{ {
@@ -28,6 +29,9 @@ namespace PepperDash.Essentials.Core.Config
[JsonProperty("audioControlPointLists")] [JsonProperty("audioControlPointLists")]
public Dictionary<string, AudioControlPointListItem> AudioControlPointLists { get; set; } public Dictionary<string, AudioControlPointListItem> AudioControlPointLists { get; set; }
[JsonProperty("cameraLists")]
public Dictionary<string, Dictionary<string, CameraListItem>> CameraLists { get; set; }
[JsonProperty("tieLines")] [JsonProperty("tieLines")]
public List<TieLineConfig> TieLines { get; set; } public List<TieLineConfig> TieLines { get; set; }
@@ -41,6 +45,7 @@ namespace PepperDash.Essentials.Core.Config
SourceLists = new Dictionary<string, Dictionary<string, SourceListItem>>(); SourceLists = new Dictionary<string, Dictionary<string, SourceListItem>>();
DestinationLists = new Dictionary<string, Dictionary<string, DestinationListItem>>(); DestinationLists = new Dictionary<string, Dictionary<string, DestinationListItem>>();
AudioControlPointLists = new Dictionary<string, AudioControlPointListItem>(); AudioControlPointLists = new Dictionary<string, AudioControlPointListItem>();
CameraLists = new Dictionary<string, Dictionary<string, CameraListItem>>();
TieLines = new List<TieLineConfig>(); TieLines = new List<TieLineConfig>();
JoinMaps = new Dictionary<string, JObject>(); JoinMaps = new Dictionary<string, JObject>();
} }
@@ -84,6 +89,17 @@ namespace PepperDash.Essentials.Core.Config
return AudioControlPointLists[key]; return AudioControlPointLists[key];
} }
/// <summary>
/// Checks CameraLists for a given list and returns it if found. Otherwise, returns null
/// </summary>
public Dictionary<string, CameraListItem> GetCameraListForKey(string key)
{
if (string.IsNullOrEmpty(key) || !CameraLists.ContainsKey(key))
return null;
return CameraLists[key];
}
/// <summary> /// <summary>
/// Checks Devices for an item with a Key that matches and returns it if found. Otherwise, retunes null /// Checks Devices for an item with a Key that matches and returns it if found. Otherwise, retunes null
/// </summary> /// </summary>

View File

@@ -0,0 +1,76 @@
using Newtonsoft.Json;
using PepperDash.Core;
namespace PepperDash.Essentials.Core
{
public class CameraListItem
{
[JsonProperty("deviceKey")]
public string DeviceKey { get; set; }
/// <summary>
/// Returns the source Device for this, if it exists in DeviceManager
/// </summary>
[JsonIgnore]
public Device CameraDevice
{
get
{
if (_cameraDevice == null)
_cameraDevice = DeviceManager.GetDeviceForKey(DeviceKey) as Device;
return _cameraDevice;
}
}
Device _cameraDevice;
/// <summary>
/// Gets either the source's Name or this AlternateName property, if
/// defined. If source doesn't exist, returns "Missing source"
/// </summary>
[JsonProperty("preferredName")]
public string PreferredName
{
get
{
if (string.IsNullOrEmpty(Name))
{
if (CameraDevice == null)
return "---";
return CameraDevice.Name;
}
return Name;
}
}
/// <summary>
/// A name that will override the source's name on the UI
/// </summary>
[JsonProperty("name")]
public string Name { get; set; }
/// <summary>
/// Specifies and icon for the source list item
/// </summary>
[JsonProperty("icon")]
public string Icon { get; set; }
/// <summary>
/// Alternate icon
/// </summary>
[JsonProperty("altIcon", NullValueHandling = NullValueHandling.Ignore)]
public string AltIcon { get; set; }
/// <summary>
/// Indicates if the item should be included in the user facing list
/// </summary>
[JsonProperty("includeInUserList")]
public bool IncludeInUserList { get; set; }
/// <summary>
/// Used to specify the order of the items in the source list when displayed
/// </summary>
[JsonProperty("order")]
public int Order { get; set; }
}
}

View File

@@ -1,17 +1,15 @@
using Crestron.SimplSharp;
using Newtonsoft.Json;
using PepperDash.Core;
using Serilog.Events;
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Crestron.SimplSharp;
using System.Reflection; using System.Reflection;
using Newtonsoft.Json; using System.Threading.Tasks;
using PepperDash.Core;
using Serilog.Events;
namespace PepperDash.Essentials.Core namespace PepperDash.Essentials.Core
@@ -36,7 +34,7 @@ namespace PepperDash.Essentials.Core
DoDeviceAction(action); DoDeviceAction(action);
} }
catch (Exception ex) catch (Exception)
{ {
CrestronConsole.ConsoleCommandResponse("Incorrect format for JSON. Please check that the format matches {\"deviceKey\":\"myDevice\", \"methodName\":\"someMethod\", \"params\": [\"param1\", true]}"); CrestronConsole.ConsoleCommandResponse("Incorrect format for JSON. Please check that the format matches {\"deviceKey\":\"myDevice\", \"methodName\":\"someMethod\", \"params\": [\"param1\", true]}");
} }
@@ -91,7 +89,7 @@ namespace PepperDash.Essentials.Core
Debug.LogMessage(LogEventLevel.Verbose, "Calling method {methodName} on device {deviceKey}", null, method.Name, action.DeviceKey); Debug.LogMessage(LogEventLevel.Verbose, "Calling method {methodName} on device {deviceKey}", null, method.Name, action.DeviceKey);
method.Invoke(obj, convertedParams); method.Invoke(obj, convertedParams);
} }
catch(Exception e) catch (Exception e)
{ {
Debug.LogMessage(e, "Error invoking method {methodName} on device {deviceKey}", null, method.Name, action.DeviceKey); Debug.LogMessage(e, "Error invoking method {methodName} on device {deviceKey}", null, method.Name, action.DeviceKey);
} }
@@ -103,7 +101,63 @@ namespace PepperDash.Essentials.Core
catch (Exception ex) catch (Exception ex)
{ {
CrestronConsole.ConsoleCommandResponse("Unable to call method with name {0}. {1}", action.MethodName, CrestronConsole.ConsoleCommandResponse("Unable to call method with name {0}. {1}", action.MethodName,
ex.Message);} ex.Message);
}
}
public static async Task DoDeviceActionAsync(DeviceActionWrapper action)
{
var key = action.DeviceKey;
var obj = FindObjectOnPath(key);
if (obj == null)
{
Debug.LogMessage(LogEventLevel.Warning, "Unable to find object at path {deviceKey}", null, key);
return;
}
if (action.Params == null)
{
//no params, so setting action.Params to empty array
action.Params = new object[0];
}
Type t = obj.GetType();
try
{
var methods = t.GetMethods().Where(m => m.Name == action.MethodName).ToList();
var method = methods.Count == 1 ? methods[0] : methods.FirstOrDefault(m => m.GetParameters().Length == action.Params.Length);
if (method == null)
{
Debug.LogMessage(LogEventLevel.Warning,
"Unable to find method with name {methodName} and that matches parameters {@parameters}", null, action.MethodName,
action.Params);
return;
}
var mParams = method.GetParameters();
var convertedParams = mParams
.Select((p, i) => ConvertType(action.Params[i], p.ParameterType))
.ToArray();
await Task.Run(() =>
{
try
{
Debug.LogMessage(LogEventLevel.Verbose, "Calling method {methodName} on device {deviceKey} with {@params}", null, method.Name, action.DeviceKey, action.Params);
method.Invoke(obj, convertedParams);
}
catch (Exception e)
{
Debug.LogMessage(e, "Error invoking method {methodName} on device {deviceKey}", null, method.Name, action.DeviceKey);
}
});
}
catch (Exception ex)
{
Debug.LogMessage(ex, "Unable to call method with name {methodName} with {@parameters}", null, action.MethodName, action.Params);
}
} }
private static object ConvertType(object value, Type conversionType) private static object ConvertType(object value, Type conversionType)
@@ -149,7 +203,7 @@ namespace PepperDash.Essentials.Core
public static object GetPropertyByName(string deviceObjectPath, string propertyName) public static object GetPropertyByName(string deviceObjectPath, string propertyName)
{ {
var dev = FindObjectOnPath(deviceObjectPath); var dev = FindObjectOnPath(deviceObjectPath);
if(dev == null) if (dev == null)
return "{ \"error\":\"No Device\"}"; return "{ \"error\":\"No Device\"}";
object prop = dev.GetType().GetType().GetProperty(propertyName).GetValue(dev, null); object prop = dev.GetType().GetType().GetProperty(propertyName).GetValue(dev, null);
@@ -320,13 +374,15 @@ namespace PepperDash.Essentials.Core
public class PropertyNameType public class PropertyNameType
{ {
object Parent; private object Parent;
[JsonIgnore] [JsonIgnore]
public PropertyInfo PropInfo { get; private set; } public PropertyInfo PropInfo { get; private set; }
public string Name { get { return PropInfo.Name; } } public string Name { get { return PropInfo.Name; } }
public string Type { get { return PropInfo.PropertyType.Name; } } public string Type { get { return PropInfo.PropertyType.Name; } }
public string Value { get public string Value
{
get
{ {
if (PropInfo.CanRead) if (PropInfo.CanRead)
{ {
@@ -341,7 +397,8 @@ namespace PepperDash.Essentials.Core
} }
else else
return null; return null;
} } }
}
public bool CanRead { get { return PropInfo.CanRead; } } public bool CanRead { get { return PropInfo.CanRead; } }
public bool CanWrite { get { return PropInfo.CanWrite; } } public bool CanWrite { get { return PropInfo.CanWrite; } }
@@ -360,10 +417,14 @@ namespace PepperDash.Essentials.Core
public MethodInfo MethodInfo { get; private set; } public MethodInfo MethodInfo { get; private set; }
public string Name { get { return MethodInfo.Name; } } public string Name { get { return MethodInfo.Name; } }
public IEnumerable<NameType> Params { get { public IEnumerable<NameType> Params
{
get
{
return MethodInfo.GetParameters().Select(p => return MethodInfo.GetParameters().Select(p =>
new NameType { Name = p.Name, Type = p.ParameterType.Name }); new NameType { Name = p.Name, Type = p.ParameterType.Name });
} } }
}
public MethodNameParams(MethodInfo info) public MethodNameParams(MethodInfo info)
{ {

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);
} }

View File

@@ -65,8 +65,8 @@ namespace PepperDash.Essentials.Core
[Flags] [Flags]
public enum eLevelControlType public enum eLevelControlType
{ {
Level = 0, Level = 1,
Mute = 1, Mute = 2,
LevelAndMute = Level | Mute, LevelAndMute = Level | Mute,
} }
} }

View File

@@ -1,15 +1,7 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using Crestron.SimplSharp;
using Crestron.SimplSharp.CrestronIO;
using Crestron.SimplSharpPro;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters; using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Linq;
using PepperDash.Core; using PepperDash.Core;
using System.Collections.Generic;
namespace PepperDash.Essentials.Core namespace PepperDash.Essentials.Core
{ {
@@ -42,7 +34,8 @@ namespace PepperDash.Essentials.Core
return _SourceDevice; return _SourceDevice;
} }
} }
Device _SourceDevice;
private Device _SourceDevice;
/// <summary> /// <summary>
/// Gets either the source's Name or this AlternateName property, if /// Gets either the source's Name or this AlternateName property, if
@@ -193,7 +186,12 @@ namespace PepperDash.Essentials.Core
defaultDisplay, defaultDisplay,
leftDisplay, leftDisplay,
rightDisplay, rightDisplay,
centerDisplay,
programAudio, programAudio,
codecContent codecContent,
frontLeftDisplay,
frontRightDisplay,
rearLeftDisplay,
rearRightDisplay,
} }
} }

View File

@@ -1,9 +1,5 @@
using System; using PepperDash.Core;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using PepperDash.Core;
namespace PepperDash.Essentials.Core namespace PepperDash.Essentials.Core
{ {
@@ -26,6 +22,11 @@ namespace PepperDash.Essentials.Core
{ {
get get
{ {
if (IsInAutoMode)
{
return _partitionSensor.PartitionPresentFeedback.BoolValue;
}
return _partitionPresent; return _partitionPresent;
} }
set set
@@ -73,11 +74,11 @@ namespace PepperDash.Essentials.Core
PartitionPresentFeedback.FireUpdate(); PartitionPresentFeedback.FireUpdate();
} }
void PartitionPresentFeedback_OutputChange(object sender, FeedbackEventArgs e) private void PartitionPresentFeedback_OutputChange(object sender, FeedbackEventArgs e)
{ {
if (IsInAutoMode) if (IsInAutoMode)
{ {
PartitionPresentFeedback.FireUpdate(); PartitionPresent = e.BoolValue;
} }
} }
@@ -87,6 +88,8 @@ namespace PepperDash.Essentials.Core
public void SetAutoMode() public void SetAutoMode()
{ {
Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, $"Setting {Key} to Auto Mode", this);
IsInAutoMode = true; IsInAutoMode = true;
if (PartitionPresentFeedback != null) if (PartitionPresentFeedback != null)
{ {
@@ -101,11 +104,16 @@ namespace PepperDash.Essentials.Core
{ {
_partitionSensor.PartitionPresentFeedback.OutputChange -= PartitionPresentFeedback_OutputChange; _partitionSensor.PartitionPresentFeedback.OutputChange -= PartitionPresentFeedback_OutputChange;
_partitionSensor.PartitionPresentFeedback.OutputChange += PartitionPresentFeedback_OutputChange; _partitionSensor.PartitionPresentFeedback.OutputChange += PartitionPresentFeedback_OutputChange;
PartitionPresent = _partitionSensor.PartitionPresentFeedback.BoolValue;
} }
PartitionPresentFeedback.FireUpdate();
} }
public void SetManualMode() public void SetManualMode()
{ {
Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, $"Setting {Key} to Manual Mode", this);
IsInAutoMode = false; IsInAutoMode = false;
if (PartitionPresentFeedback != null) if (PartitionPresentFeedback != null)
{ {
@@ -119,7 +127,10 @@ namespace PepperDash.Essentials.Core
if (_partitionSensor != null) if (_partitionSensor != null)
{ {
_partitionSensor.PartitionPresentFeedback.OutputChange -= PartitionPresentFeedback_OutputChange; _partitionSensor.PartitionPresentFeedback.OutputChange -= PartitionPresentFeedback_OutputChange;
PartitionPresent = _partitionSensor.PartitionPresentFeedback.BoolValue;
} }
PartitionPresentFeedback.FireUpdate();
} }

View File

@@ -1,11 +1,12 @@
using System; using Crestron.SimplSharp;
using PepperDash.Core;
using PepperDash.Core.Logging;
using Serilog.Events;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Crestron.SimplSharp; using System.Threading;
using System.Threading.Tasks;
using PepperDash.Core;
using Serilog.Events;
using Newtonsoft.Json;
namespace PepperDash.Essentials.Core namespace PepperDash.Essentials.Core
{ {
@@ -35,7 +36,7 @@ namespace PepperDash.Essentials.Core
} }
set set
{ {
if(value == _isInAutoMode) if (value == _isInAutoMode)
{ {
return; return;
} }
@@ -49,6 +50,8 @@ namespace PepperDash.Essentials.Core
private int _scenarioChangeDebounceTimeSeconds = 10; // default to 10s private int _scenarioChangeDebounceTimeSeconds = 10; // default to 10s
private Mutex _scenarioChange = new Mutex();
public EssentialsRoomCombiner(string key, EssentialsRoomCombinerPropertiesConfig props) public EssentialsRoomCombiner(string key, EssentialsRoomCombinerPropertiesConfig props)
: base(key) : base(key)
{ {
@@ -93,7 +96,7 @@ namespace PepperDash.Essentials.Core
}); });
} }
void CreateScenarios() private void CreateScenarios()
{ {
foreach (var scenarioConfig in _propertiesConfig.Scenarios) foreach (var scenarioConfig in _propertiesConfig.Scenarios)
{ {
@@ -102,21 +105,29 @@ namespace PepperDash.Essentials.Core
} }
} }
void SetRooms() private void SetRooms()
{ {
_rooms = new List<IEssentialsRoom>(); _rooms = new List<IEssentialsRoom>();
foreach (var roomKey in _propertiesConfig.RoomKeys) foreach (var roomKey in _propertiesConfig.RoomKeys)
{ {
var room = DeviceManager.GetDeviceForKey(roomKey) as IEssentialsRoom; var room = DeviceManager.GetDeviceForKey(roomKey);
if (room != null)
if (DeviceManager.GetDeviceForKey(roomKey) is IEssentialsRoom essentialsRoom)
{ {
_rooms.Add(room); _rooms.Add(essentialsRoom);
}
} }
} }
void SetupPartitionStateProviders() var rooms = DeviceManager.AllDevices.OfType<IEssentialsRoom>().Cast<Device>();
foreach (var room in rooms)
{
room.Deactivate();
}
}
private void SetupPartitionStateProviders()
{ {
foreach (var pConfig in _propertiesConfig.Partitions) foreach (var pConfig in _propertiesConfig.Partitions)
{ {
@@ -130,18 +141,18 @@ namespace PepperDash.Essentials.Core
} }
} }
void PartitionPresentFeedback_OutputChange(object sender, FeedbackEventArgs e) private void PartitionPresentFeedback_OutputChange(object sender, FeedbackEventArgs e)
{ {
StartDebounceTimer(); StartDebounceTimer();
} }
void StartDebounceTimer() private void StartDebounceTimer()
{ {
// default to 500ms for manual mode // default to 500ms for manual mode
var time = 500; var time = 500;
// if in auto mode, debounce the scenario change // if in auto mode, debounce the scenario change
if(IsInAutoMode) time = _scenarioChangeDebounceTimeSeconds * 1000; if (IsInAutoMode) time = _scenarioChangeDebounceTimeSeconds * 1000;
if (_scenarioChangeDebounceTimer == null) if (_scenarioChangeDebounceTimer == null)
{ {
@@ -156,7 +167,7 @@ namespace PepperDash.Essentials.Core
/// <summary> /// <summary>
/// Determines the current room combination scenario based on the state of the partition sensors /// Determines the current room combination scenario based on the state of the partition sensors
/// </summary> /// </summary>
void DetermineRoomCombinationScenario() private void DetermineRoomCombinationScenario()
{ {
if (_scenarioChangeDebounceTimer != null) if (_scenarioChangeDebounceTimer != null)
{ {
@@ -164,14 +175,20 @@ namespace PepperDash.Essentials.Core
_scenarioChangeDebounceTimer = null; _scenarioChangeDebounceTimer = null;
} }
this.LogInformation("Determining Combination Scenario");
var currentScenario = RoomCombinationScenarios.FirstOrDefault((s) => var currentScenario = RoomCombinationScenarios.FirstOrDefault((s) =>
{ {
this.LogDebug("Checking scenario {scenarioKey}", s.Key);
// iterate the partition states // iterate the partition states
foreach (var partitionState in s.PartitionStates) foreach (var partitionState in s.PartitionStates)
{ {
this.LogDebug("checking PartitionState {partitionStateKey}", partitionState.PartitionKey);
// get the partition by key // get the partition by key
var partition = Partitions.FirstOrDefault((p) => p.Key.Equals(partitionState.PartitionKey)); var partition = Partitions.FirstOrDefault((p) => p.Key.Equals(partitionState.PartitionKey));
this.LogDebug("Expected State: {partitionPresent} Actual State: {partitionState}", partitionState.PartitionPresent, partition.PartitionPresentFeedback.BoolValue);
if (partition != null && partitionState.PartitionPresent != partition.PartitionPresentFeedback.BoolValue) if (partition != null && partitionState.PartitionPresent != partition.PartitionPresentFeedback.BoolValue)
{ {
// the partition can't be found or the state doesn't match // the partition can't be found or the state doesn't match
@@ -184,10 +201,41 @@ namespace PepperDash.Essentials.Core
if (currentScenario != null) if (currentScenario != null)
{ {
CurrentScenario = currentScenario; this.LogInformation("Found combination Scenario {scenarioKey}", currentScenario.Key);
ChangeScenario(currentScenario);
} }
} }
private async Task ChangeScenario(IRoomCombinationScenario newScenario)
{
if (newScenario == _currentScenario)
{
return;
}
// Deactivate the old scenario first
if (_currentScenario != null)
{
Debug.LogMessage(LogEventLevel.Information, "Deactivating scenario {currentScenario}", this, _currentScenario.Name);
await _currentScenario.Deactivate();
}
_currentScenario = newScenario;
// Activate the new scenario
if (_currentScenario != null)
{
Debug.LogMessage(LogEventLevel.Debug, $"Current Scenario: {_currentScenario.Name}", this);
await _currentScenario.Activate();
}
RoomCombinationScenarioChanged?.Invoke(this, new EventArgs());
}
#region IEssentialsRoomCombiner Members #region IEssentialsRoomCombiner Members
public event EventHandler<EventArgs> RoomCombinationScenarioChanged; public event EventHandler<EventArgs> RoomCombinationScenarioChanged;
@@ -198,33 +246,6 @@ namespace PepperDash.Essentials.Core
{ {
return _currentScenario; return _currentScenario;
} }
private set
{
if (value != _currentScenario)
{
// Deactivate the old scenario first
if (_currentScenario != null)
{
_currentScenario.Deactivate();
}
_currentScenario = value;
// Activate the new scenario
if (_currentScenario != null)
{
_currentScenario.Activate();
Debug.LogMessage(LogEventLevel.Debug, $"Current Scenario: {_currentScenario.Name}", this);
}
var handler = RoomCombinationScenarioChanged;
if (handler != null)
{
handler(this, new EventArgs());
}
}
}
} }
public BoolFeedback IsInAutoModeFeedback { get; private set; } public BoolFeedback IsInAutoModeFeedback { get; private set; }
@@ -232,16 +253,35 @@ namespace PepperDash.Essentials.Core
public void SetAutoMode() public void SetAutoMode()
{ {
IsInAutoMode = true; IsInAutoMode = true;
foreach (var partition in Partitions)
{
partition.SetAutoMode();
}
DetermineRoomCombinationScenario();
} }
public void SetManualMode() public void SetManualMode()
{ {
IsInAutoMode = false; IsInAutoMode = false;
foreach (var partition in Partitions)
{
partition.SetManualMode();
}
} }
public void ToggleMode() public void ToggleMode()
{ {
IsInAutoMode = !IsInAutoMode; if (IsInAutoMode)
{
SetManualMode();
}
else
{
SetAutoMode();
}
} }
public List<IRoomCombinationScenario> RoomCombinationScenarios { get; private set; } public List<IRoomCombinationScenario> RoomCombinationScenarios { get; private set; }

View File

@@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks;
using Newtonsoft.Json; using Newtonsoft.Json;
using PepperDash.Core; using PepperDash.Core;
@@ -87,12 +88,12 @@ namespace PepperDash.Essentials.Core
/// <summary> /// <summary>
/// Activates this room combination scenario /// Activates this room combination scenario
/// </summary> /// </summary>
void Activate(); Task Activate();
/// <summary> /// <summary>
/// Deactivates this room combination scenario /// Deactivates this room combination scenario
/// </summary> /// </summary>
void Deactivate(); Task Deactivate();
/// <summary> /// <summary>
/// The state of the partitions that would activate this scenario /// The state of the partitions that would activate this scenario

View File

@@ -1,22 +1,16 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using PepperDash.Core; using PepperDash.Core;
using PepperDash.Core.Logging;
using Newtonsoft.Json;
using Serilog.Events; using Serilog.Events;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace PepperDash.Essentials.Core namespace PepperDash.Essentials.Core
{ {
/// <summary> /// <summary>
/// Represents a room combination scenario /// Represents a room combination scenario
/// </summary> /// </summary>
public class RoomCombinationScenario: IRoomCombinationScenario, IKeyName public class RoomCombinationScenario : IRoomCombinationScenario, IKeyName
{ {
private RoomCombinationScenarioConfig _config; private RoomCombinationScenarioConfig _config;
@@ -40,7 +34,7 @@ namespace PepperDash.Essentials.Core
get { return _isActive; } get { return _isActive; }
set set
{ {
if(value == _isActive) if (value == _isActive)
{ {
return; return;
} }
@@ -76,33 +70,43 @@ namespace PepperDash.Essentials.Core
IsActiveFeedback = new BoolFeedback(() => _isActive); IsActiveFeedback = new BoolFeedback(() => _isActive);
} }
public void Activate() public async Task Activate()
{ {
Debug.LogMessage(LogEventLevel.Debug, "Activating Scenario: '{0}' with {1} action(s) defined", Name, activationActions.Count); this.LogInformation("Activating Scenario {name} with {activationActionCount} action(s) defined", Name, activationActions.Count);
List<Task> tasks = new List<Task>();
if (activationActions != null) if (activationActions != null)
{ {
foreach (var action in activationActions) foreach (var action in activationActions)
{ {
DeviceJsonApi.DoDeviceAction(action); this.LogInformation("Running Activation action {@action}", action);
tasks.Add(DeviceJsonApi.DoDeviceActionAsync(action));
} }
} }
await Task.WhenAll(tasks);
IsActive = true; IsActive = true;
} }
public void Deactivate() public async Task Deactivate()
{ {
Debug.LogMessage(LogEventLevel.Debug, "Deactivating Scenario: '{0}' with {1} action(s) defined", Name, deactivationActions.Count); this.LogInformation("Deactivating Scenario {name} with {deactivationActionCount} action(s) defined", Name, deactivationActions.Count);
List<Task> tasks = new List<Task>();
if (deactivationActions != null) if (deactivationActions != null)
{ {
foreach (var action in deactivationActions) foreach (var action in deactivationActions)
{ {
DeviceJsonApi.DoDeviceAction(action); this.LogInformation("Running deactivation action {actionDeviceKey}:{actionMethod}", action.DeviceKey, action.MethodName);
tasks.Add( DeviceJsonApi.DoDeviceActionAsync(action));
} }
} }
await Task.WhenAll(tasks);
IsActive = false; IsActive = false;
} }

View File

@@ -200,6 +200,9 @@ namespace PepperDash.Essentials.Room.Config
public string DestinationListKey { get; set; } public string DestinationListKey { get; set; }
[JsonProperty("audioControlPointListKey")] [JsonProperty("audioControlPointListKey")]
public string AudioControlPointListKey { get; set; } public string AudioControlPointListKey { get; set; }
[JsonProperty("cameraListKey")]
public string CameraListKey { get; set; }
[JsonProperty("defaultSourceItem")] [JsonProperty("defaultSourceItem")]
public string DefaultSourceItem { get; set; } public string DefaultSourceItem { get; set; }

View File

@@ -133,7 +133,28 @@ namespace PepperDash.Essentials.Core
} }
} }
private string _cameraListKey;
public string CameraListKey
{
get
{
if (string.IsNullOrEmpty(_cameraListKey))
{
return _defaultListKey;
}
else
{
return _cameraListKey;
}
}
protected set
{
if (value != _cameraListKey)
{
_cameraListKey = value;
}
}
}
/// <summary> /// <summary>
/// Timer used for informing the UIs of a shutdown /// Timer used for informing the UIs of a shutdown

View File

@@ -31,6 +31,8 @@ namespace PepperDash.Essentials.Core
string AudioControlPointListKey { get; } string AudioControlPointListKey { get; }
string CameraListKey { get; }
SecondsCountdownTimer ShutdownPromptTimer { get; } SecondsCountdownTimer ShutdownPromptTimer { get; }
int ShutdownPromptSeconds { get; } int ShutdownPromptSeconds { get; }
int ShutdownVacancySeconds { get; } int ShutdownVacancySeconds { get; }

View File

@@ -1,8 +1,9 @@
using PepperDash.Core; using Serilog.Events;
using Serilog.Events;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using Debug = PepperDash.Core.Debug;
namespace PepperDash.Essentials.Core namespace PepperDash.Essentials.Core
@@ -23,18 +24,33 @@ namespace PepperDash.Essentials.Core
/// </summary> /// </summary>
public static void ReleaseAndMakeRoute(this IRoutingInputs destination, IRoutingOutputs source, eRoutingSignalType signalType, string destinationPortKey = "", string sourcePortKey = "") public static void ReleaseAndMakeRoute(this IRoutingInputs destination, IRoutingOutputs source, eRoutingSignalType signalType, string destinationPortKey = "", string sourcePortKey = "")
{ {
// Remove this line before committing!!!!!
var frame = new StackFrame(1, true);
Debug.LogMessage(LogEventLevel.Information, "ReleaseAndMakeRoute Called from {method} with params {destinationKey}:{sourceKey}:{signalType}:{destinationPortKey}:{sourcePortKey}", frame.GetMethod().Name, destination.Key, source.Key, signalType.ToString(), destinationPortKey, sourcePortKey);
var inputPort = string.IsNullOrEmpty(destinationPortKey) ? null : destination.InputPorts.FirstOrDefault(p => p.Key == destinationPortKey); var inputPort = string.IsNullOrEmpty(destinationPortKey) ? null : destination.InputPorts.FirstOrDefault(p => p.Key == destinationPortKey);
var outputPort = string.IsNullOrEmpty(sourcePortKey) ? null : source.OutputPorts.FirstOrDefault(p => p.Key == sourcePortKey); var outputPort = string.IsNullOrEmpty(sourcePortKey) ? null : source.OutputPorts.FirstOrDefault(p => p.Key == sourcePortKey);
ReleaseAndMakeRoute(destination, source, signalType, inputPort, outputPort); ReleaseAndMakeRoute(destination, source, signalType, inputPort, outputPort);
} }
public static void RemoveRouteRequestForDestination(string destinationKey)
{
Debug.LogMessage(LogEventLevel.Information, "Removing route request for {destination}", null, destinationKey);
var result = RouteRequests.Remove(destinationKey);
var messageTemplate = result ? "Route Request for {destination} removed" : "Route Request for {destination} not found";
Debug.LogMessage(LogEventLevel.Information, messageTemplate, null, destinationKey);
}
private static void ReleaseAndMakeRoute(IRoutingInputs destination, IRoutingOutputs source, eRoutingSignalType signalType, RoutingInputPort destinationPort = null, RoutingOutputPort sourcePort = null) private static void ReleaseAndMakeRoute(IRoutingInputs destination, IRoutingOutputs source, eRoutingSignalType signalType, RoutingInputPort destinationPort = null, RoutingOutputPort sourcePort = null)
{ {
if (destination == null) throw new ArgumentNullException(nameof(destination)); if (destination == null) throw new ArgumentNullException(nameof(destination));
if (source == null) throw new ArgumentNullException(nameof(source)); if (source == null) throw new ArgumentNullException(nameof(source));
if (destinationPort == null) Debug.LogMessage(LogEventLevel.Verbose, "Destination port is null"); if (destinationPort == null) Debug.LogMessage(LogEventLevel.Information, "Destination port is null");
if (sourcePort == null) Debug.LogMessage(LogEventLevel.Verbose, "Source port is null"); if (sourcePort == null) Debug.LogMessage(LogEventLevel.Information, "Source port is null");
var routeRequest = new RouteRequest var routeRequest = new RouteRequest
{ {
@@ -57,7 +73,7 @@ namespace PepperDash.Essentials.Core
RouteRequests[destination.Key] = routeRequest; RouteRequests[destination.Key] = routeRequest;
Debug.LogMessage(LogEventLevel.Verbose, "Device: {0} is cooling down and already has a routing request stored. Storing new route request to route to source key: {1}", null, destination.Key, routeRequest.Source.Key); Debug.LogMessage(LogEventLevel.Information, "Device: {destination} is cooling down and already has a routing request stored. Storing new route request to route to source key: {sourceKey}", null, destination.Key, routeRequest.Source.Key);
return; return;
} }
@@ -71,17 +87,17 @@ namespace PepperDash.Essentials.Core
RouteRequests.Add(destination.Key, routeRequest); RouteRequests.Add(destination.Key, routeRequest);
Debug.LogMessage(LogEventLevel.Verbose, "Device: {0} is cooling down. Storing route request to route to source key: {1}", null, destination.Key, routeRequest.Source.Key); Debug.LogMessage(LogEventLevel.Information, "Device: {destination} is cooling down. Storing route request to route to source key: {sourceKey}", null, destination.Key, routeRequest.Source.Key);
return; return;
} }
if (RouteRequests.ContainsKey(destination.Key) && coolingDevice != null && coolingDevice.IsCoolingDownFeedback.BoolValue == false) if (RouteRequests.ContainsKey(destination.Key) && coolingDevice != null && coolingDevice.IsCoolingDownFeedback.BoolValue == false)
{ {
RouteRequests.Remove(destination.Key); RouteRequests.Remove(destination.Key);
Debug.LogMessage(LogEventLevel.Verbose, "Device: {0} is NOT cooling down. Removing stored route request and routing to source key: {1}", 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);
} }
destination.ReleaseRoute(); destination.ReleaseRoute(destinationPort?.Key ?? string.Empty);
RunRouteRequest(routeRequest); RunRouteRequest(routeRequest);
} }
@@ -109,14 +125,21 @@ namespace PepperDash.Essentials.Core
videoRoute?.ExecuteRoutes(); videoRoute?.ExecuteRoutes();
} }
public static void ReleaseRoute(this IRoutingInputs destination)
{
ReleaseRoute(destination, string.Empty);
}
/// <summary> /// <summary>
/// Will release the existing route on the destination, if it is found in /// Will release the existing route on the destination, if it is found in
/// RouteDescriptorCollection.DefaultCollection /// RouteDescriptorCollection.DefaultCollection
/// </summary> /// </summary>
/// <param name="destination"></param> /// <param name="destination"></param>
public static void ReleaseRoute(this IRoutingInputs destination) public static void ReleaseRoute(this IRoutingInputs destination, string inputPortKey)
{ {
Debug.LogMessage(LogEventLevel.Information, "Release route for {inputPortKey}", destination, string.IsNullOrEmpty(inputPortKey) ? "auto" : inputPortKey);
if (RouteRequests.TryGetValue(destination.Key, out RouteRequest existingRequest) && destination is IWarmingCooling) if (RouteRequests.TryGetValue(destination.Key, out RouteRequest existingRequest) && destination is IWarmingCooling)
{ {
var coolingDevice = destination as IWarmingCooling; var coolingDevice = destination as IWarmingCooling;
@@ -126,7 +149,7 @@ namespace PepperDash.Essentials.Core
RouteRequests.Remove(destination.Key); RouteRequests.Remove(destination.Key);
var current = RouteDescriptorCollection.DefaultCollection.RemoveRouteDescriptor(destination); var current = RouteDescriptorCollection.DefaultCollection.RemoveRouteDescriptor(destination, inputPortKey);
if (current != null) if (current != null)
{ {
Debug.LogMessage(LogEventLevel.Debug, "Releasing current route: {0}", destination, current.Source.Key); Debug.LogMessage(LogEventLevel.Debug, "Releasing current route: {0}", destination, current.Source.Key);
@@ -146,7 +169,7 @@ namespace PepperDash.Essentials.Core
// 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))
{ {
var singleTypeRouteDescriptor = new RouteDescriptor(source, destination, signalType); var singleTypeRouteDescriptor = new RouteDescriptor(source, destination, destinationPort, signalType);
Debug.LogMessage(LogEventLevel.Debug, "Attempting to build source route from {sourceKey} of type {type}", destination, source.Key, signalType); Debug.LogMessage(LogEventLevel.Debug, "Attempting to build source route from {sourceKey} of type {type}", destination, source.Key, signalType);
if (!destination.GetRouteToSource(source, null, null, signalType, 0, singleTypeRouteDescriptor, destinationPort, sourcePort)) if (!destination.GetRouteToSource(source, null, null, signalType, 0, singleTypeRouteDescriptor, destinationPort, sourcePort))
@@ -163,14 +186,14 @@ namespace PepperDash.Essentials.Core
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 {sourceKey} of type {type}", destination, source.Key);
var audioRouteDescriptor = new RouteDescriptor(source, destination, eRoutingSignalType.Audio); var audioRouteDescriptor = new RouteDescriptor(source, destination, destinationPort, eRoutingSignalType.Audio);
var audioSuccess = destination.GetRouteToSource(source, null, null, eRoutingSignalType.Audio, 0, audioRouteDescriptor, destinationPort, sourcePort); var audioSuccess = destination.GetRouteToSource(source, null, null, eRoutingSignalType.Audio, 0, audioRouteDescriptor, destinationPort, sourcePort);
if (!audioSuccess) if (!audioSuccess)
Debug.LogMessage(LogEventLevel.Debug, "Cannot find audio route to {0}", destination, source.Key); Debug.LogMessage(LogEventLevel.Debug, "Cannot find audio route to {0}", destination, source.Key);
var videoRouteDescriptor = new RouteDescriptor(source, destination, eRoutingSignalType.Video); var videoRouteDescriptor = new RouteDescriptor(source, destination, destinationPort, eRoutingSignalType.Video);
var videoSuccess = destination.GetRouteToSource(source, null, null, eRoutingSignalType.Video, 0, videoRouteDescriptor, destinationPort, sourcePort); var videoSuccess = destination.GetRouteToSource(source, null, null, eRoutingSignalType.Video, 0, videoRouteDescriptor, destinationPort, sourcePort);

View File

@@ -14,16 +14,24 @@ namespace PepperDash.Essentials.Core
public class RouteDescriptor public class RouteDescriptor
{ {
public IRoutingInputs Destination { get; private set; } public IRoutingInputs Destination { get; private set; }
public RoutingInputPort InputPort { get; private set; }
public IRoutingOutputs Source { get; private set; } public IRoutingOutputs Source { get; private set; }
public eRoutingSignalType SignalType { get; private set; } public eRoutingSignalType SignalType { get; private set; }
public List<RouteSwitchDescriptor> Routes { get; private set; } public List<RouteSwitchDescriptor> Routes { get; private set; }
public RouteDescriptor(IRoutingOutputs source, IRoutingInputs destination, eRoutingSignalType signalType) public RouteDescriptor(IRoutingOutputs source, IRoutingInputs destination, eRoutingSignalType signalType):this(source,destination, null, signalType)
{
}
public RouteDescriptor(IRoutingOutputs source, IRoutingInputs destination, RoutingInputPort inputPort, eRoutingSignalType signalType)
{ {
Destination = destination; Destination = destination;
Source = source; Source = source;
SignalType = signalType; SignalType = signalType;
InputPort = inputPort;
Routes = new List<RouteSwitchDescriptor>(); Routes = new List<RouteSwitchDescriptor>();
} }
@@ -60,10 +68,12 @@ namespace PepperDash.Essentials.Core
/// </summary> /// </summary>
public void ReleaseRoutes() public void ReleaseRoutes()
{ {
foreach (var route in Routes) foreach (var route in Routes.Where(r => r.SwitchingDevice is IRouting))
{ {
if (route.SwitchingDevice is IRouting) if (route.SwitchingDevice is IRouting switchingDevice)
{ {
switchingDevice.ExecuteSwitch(null, route.OutputPort.Selector, SignalType);
// Pull the route from the port. Whatever is watching the output's in use tracker is // Pull the route from the port. Whatever is watching the output's in use tracker is
// responsible for responding appropriately. // responsible for responding appropriately.
route.OutputPort.InUseTracker.RemoveUser(Destination, "destination-" + SignalType); route.OutputPort.InUseTracker.RemoveUser(Destination, "destination-" + SignalType);

View File

@@ -1,8 +1,7 @@
using System.Collections.Generic; using PepperDash.Core;
using System.Linq;
using PepperDash.Core;
using Serilog.Events; using Serilog.Events;
using System.Collections.Generic;
using System.Linq;
namespace PepperDash.Essentials.Core namespace PepperDash.Essentials.Core
@@ -33,7 +32,13 @@ namespace PepperDash.Essentials.Core
/// <param name="descriptor"></param> /// <param name="descriptor"></param>
public void AddRouteDescriptor(RouteDescriptor descriptor) public void AddRouteDescriptor(RouteDescriptor descriptor)
{ {
if (RouteDescriptors.Any(t => t.Destination == descriptor.Destination)) if (descriptor == null)
{
return;
}
if (RouteDescriptors.Any(t => t.Destination == descriptor.Destination)
&& RouteDescriptors.Any(t => t.Destination == descriptor.Destination && t.InputPort != null && descriptor.InputPort != null && t.InputPort.Key == descriptor.InputPort.Key))
{ {
Debug.LogMessage(LogEventLevel.Debug, descriptor.Destination, Debug.LogMessage(LogEventLevel.Debug, descriptor.Destination,
"Route to [{0}] already exists in global routes table", descriptor.Source.Key); "Route to [{0}] already exists in global routes table", descriptor.Source.Key);
@@ -48,18 +53,33 @@ namespace PepperDash.Essentials.Core
/// <returns>null if no RouteDescriptor for a destination exists</returns> /// <returns>null if no RouteDescriptor for a destination exists</returns>
public RouteDescriptor GetRouteDescriptorForDestination(IRoutingInputs destination) public RouteDescriptor GetRouteDescriptorForDestination(IRoutingInputs destination)
{ {
Debug.LogMessage(LogEventLevel.Debug, "Getting route descriptor", destination);
return RouteDescriptors.FirstOrDefault(rd => rd.Destination == destination); return RouteDescriptors.FirstOrDefault(rd => rd.Destination == destination);
} }
public RouteDescriptor GetRouteDescriptorForDestinationAndInputPort(IRoutingInputs destination, string inputPortKey)
{
Debug.LogMessage(LogEventLevel.Debug, "Getting route descriptor for {inputPortKey}", destination, string.IsNullOrEmpty(inputPortKey) ? "auto" : inputPortKey);
return RouteDescriptors.FirstOrDefault(rd => rd.Destination == destination && rd.InputPort != null && rd.InputPort.Key == inputPortKey);
}
/// <summary> /// <summary>
/// Returns the RouteDescriptor for a given destination AND removes it from collection. /// Returns the RouteDescriptor for a given destination AND removes it from collection.
/// Returns null if no route with the provided destination exists. /// Returns null if no route with the provided destination exists.
/// </summary> /// </summary>
public RouteDescriptor RemoveRouteDescriptor(IRoutingInputs destination) public RouteDescriptor RemoveRouteDescriptor(IRoutingInputs destination, string inputPortKey = "")
{ {
var descr = GetRouteDescriptorForDestination(destination); Debug.LogMessage(LogEventLevel.Debug, "Removing route descriptor for {inputPortKey}", destination, string.IsNullOrEmpty(inputPortKey) ? "auto" : inputPortKey);
var descr = string.IsNullOrEmpty(inputPortKey)
? GetRouteDescriptorForDestination(destination)
: GetRouteDescriptorForDestinationAndInputPort(destination, inputPortKey);
if (descr != null) if (descr != null)
RouteDescriptors.Remove(descr); RouteDescriptors.Remove(descr);
Debug.LogMessage(LogEventLevel.Debug, "Found route descriptor {routeDescriptor}", destination, descr);
return descr; return descr;
} }
} }

View File

@@ -1,4 +1,7 @@
namespace PepperDash.Essentials.Core using PepperDash.Core;
using Serilog.Events;
namespace PepperDash.Essentials.Core
{ {
public class RouteRequest public class RouteRequest
{ {
@@ -11,37 +14,21 @@
public void HandleCooldown(object sender, FeedbackEventArgs args) public void HandleCooldown(object sender, FeedbackEventArgs args)
{ {
var coolingDevice = sender as IWarmingCooling; Debug.LogMessage(LogEventLevel.Information, "Handling cooldown route request: {destination}:{destinationPort} -> {source}:{sourcePort} {type}", null, Destination.Key, DestinationPort.Key, Source.Key, SourcePort.Key, SignalType.ToString());
if (args.BoolValue == false) if (args.BoolValue == true)
{ {
Destination.ReleaseAndMakeRoute(Source, SignalType); return;
}
if (sender == null) return; Debug.LogMessage(LogEventLevel.Information, "Cooldown complete. Making route from {destination} to {source}", Destination.Key, Source.Key);
Destination.ReleaseAndMakeRoute(Source, SignalType, DestinationPort?.Key ?? string.Empty, SourcePort?.Key ?? string.Empty);
if (sender is IWarmingCooling coolingDevice)
{
Debug.LogMessage(LogEventLevel.Debug, "Unsubscribing from cooling feedback for {destination}", null, Destination.Key);
coolingDevice.IsCoolingDownFeedback.OutputChange -= HandleCooldown; coolingDevice.IsCoolingDownFeedback.OutputChange -= HandleCooldown;
} }
} }
} }
/*public class RouteRequest<TInputSelector, TOutputSelector>
{
public IRoutingSink<TInputSelector> Destination { get; set; }
public IRoutingOutputs<TOutputSelector> Source { get; set; }
public eRoutingSignalType SignalType { get; set; }
public void HandleCooldown(object sender, FeedbackEventArgs args)
{
var coolingDevice = sender as IWarmingCooling;
if (args.BoolValue == false)
{
Destination.ReleaseAndMakeRoute(Source, SignalType);
if (sender == null) return;
coolingDevice.IsCoolingDownFeedback.OutputChange -= HandleCooldown;
}
}
}*/
} }

View File

@@ -0,0 +1,31 @@
using Crestron.SimplSharpPro;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PepperDash.Essentials.Devices.Common.Codec
{
/// <summary>
/// Describes a cisco codec device that can allow configuration of cameras
/// </summary>
public interface ICiscoCodecCameraConfig
{
void SetCameraAssignedSerialNumber(uint cameraId, string serialNumber);
void SetCameraName(uint videoConnectorId, string name);
void SetInputSourceType(uint videoConnectorId, eCiscoCodecInputSourceType sourceType);
}
public enum eCiscoCodecInputSourceType
{
PC,
camera,
document_camera,
mediaplayer,
other,
whiteboard
}
}