Skip to content

Commit

Permalink
feat: updates to how commMonitor is reported (moving to dedicated mes…
Browse files Browse the repository at this point in the history
…senger) and update to set matrixRoutingKey on RoomConfiguration in Ess Room Bridge
  • Loading branch information
ndorin committed Mar 28, 2024
1 parent 25fd26c commit ec67846
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 91 deletions.
61 changes: 0 additions & 61 deletions 3-series/Messengers/MessengerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,43 +138,7 @@ protected virtual void RegisterActions()
protected virtual void CustomRegisterWithAppServer(MobileControlSystemController appServerController)
#endif
{
if (_device is ICommunicationMonitor commMonitor)
{
//Debug.Console(2, this, "Subscribing to CommunicationMonitor.StatusChange on: ", _device.Key);
commMonitor.CommunicationMonitor.StatusChange += CommunicationMonitor_StatusChange;

GetCommunicationMonitorState();
}
}

private void CommunicationMonitor_StatusChange(object sender, MonitorStatusChangeEventArgs e)
{
var message = new DeviceStateMessageBase
{
CommMonitor = GetCommunicationMonitorState()
};


PostStatusMessage(message);
}

protected CommunicationMonitorState GetCommunicationMonitorState()
{
if (_device is ICommunicationMonitor commMonitor)
{
var state = new CommunicationMonitorState
{
IsOnline = commMonitor.CommunicationMonitor.IsOnline,
Status = commMonitor.CommunicationMonitor.Status
};
//Debug.Console(2, this, "******************GetCommunitcationMonitorState() IsOnline: {0} Status: {1}", state.IsOnline, state.Status);
return state;
}
else
{
//Debug.Console(2, this, "******************Device does not implement ICommunicationMonitor");
return null;
}
}

/// <summary>
Expand Down Expand Up @@ -256,12 +220,6 @@ public abstract class DeviceMessageBase
/// </summary>
public class DeviceStateMessageBase : DeviceMessageBase
{
/// <summary>
/// For devices that implement ICommunicationMonitor, reports the online status of the device
/// </summary>
[JsonProperty("commMonitor", NullValueHandling = NullValueHandling.Ignore)]
public CommunicationMonitorState CommMonitor { get; set; }

/// <summary>
/// The interfaces implmented by the device sending the messsage
/// </summary>
Expand All @@ -286,23 +244,4 @@ public abstract class DeviceEventMessageBase : DeviceMessageBase
public string EventType { get; set; }
}

/// <summary>
/// Represents the state of the communication monitor
/// </summary>
public class CommunicationMonitorState
{
/// <summary>
/// For devices that implement ICommunicationMonitor, reports the online status of the device
/// </summary>
[JsonProperty("isOnline", NullValueHandling = NullValueHandling.Ignore)]
public bool? IsOnline { get; set; }

/// <summary>
/// For devices that implement ICommunicationMonitor, reports the online status of the device
/// </summary>
[JsonProperty("status", NullValueHandling = NullValueHandling.Ignore)]
[JsonConverter(typeof(StringEnumConverter))]
public MonitorStatus Status { get; set; }

}
}
6 changes: 2 additions & 4 deletions 3-series/Messengers/VideoCodecBaseMessenger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -673,10 +673,8 @@ private void SendIsReady()
/// <returns></returns>
protected VideoCodecBaseStateMessage GetStatus()
{
var status = new VideoCodecBaseStateMessage
{
CommMonitor = GetCommunicationMonitorState()
};
var status = new VideoCodecBaseStateMessage();


if (Codec is IHasCodecCameras camerasCodec)
{
Expand Down
29 changes: 20 additions & 9 deletions 3-series/RoomBridges/MobileControlEssentialsRoomBridge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,8 @@ private RoomConfiguration GetRoomConfiguration(IEssentialsRoom room)
.Select(tp => tp.Key).ToList()
};



try
{
var zrcTp = DeviceManager.AllDevices.OfType<MobileControlTouchpanelController>().SingleOrDefault((tp) => tp.ZoomRoomController);
Expand Down Expand Up @@ -663,36 +665,43 @@ private RoomConfiguration GetRoomConfiguration(IEssentialsRoom room)
}
}


if (room is IHasMatrixRouting matrixRoutingRoom)
{
Debug.Console(2, this, "Getting matrix routing config");
configuration.MatrixRoutingKey = matrixRoutingRoom.MatrixRoutingDeviceKey;
}

if (room is IEnvironmentalControls envRoom)
{
Debug.Console(2, this, "Getting environmental controls config. RoomHasEnvironmentalControls: {0}", envRoom.HasEnvironmentalControlDevices);
configuration.HasEnvironmentalControls = envRoom.HasEnvironmentalControlDevices;

if (envRoom.HasEnvironmentalControlDevices)
{
Debug.Console(2, this, "**************************** Room Has {0} Environmental Control Devices", envRoom.EnvironmentalControlDevices.Count);
Debug.Console(2, this, "Room Has {0} Environmental Control Devices.", envRoom.EnvironmentalControlDevices.Count);

foreach (var dev in envRoom.EnvironmentalControlDevices)
{
Debug.Console(2, this, "Adding environmental device: {0}", dev.Key);

EEnvironmentalDeviceTypes type = EEnvironmentalDeviceTypes.None;
eEnvironmentalDeviceTypes type = eEnvironmentalDeviceTypes.None;

if (dev is ILightingScenes || dev is Devices.Common.Lighting.LightingBase)
{
type = EEnvironmentalDeviceTypes.Lighting;
type = eEnvironmentalDeviceTypes.Lighting;
}
else if (dev is ShadeBase || dev is IShadesOpenCloseStop || dev is IShadesOpenClosePreset)
{
type = EEnvironmentalDeviceTypes.Shade;
type = eEnvironmentalDeviceTypes.Shade;
}
else if (dev is IShades)
{
type = EEnvironmentalDeviceTypes.ShadeController;
type = eEnvironmentalDeviceTypes.ShadeController;
}
else if (dev is ISwitchedOutput)
{
type = EEnvironmentalDeviceTypes.Relay;
type = eEnvironmentalDeviceTypes.Relay;
}

Debug.Console(2, this, "Environmental Device Type: {0}", type);
Expand Down Expand Up @@ -836,6 +845,8 @@ public class RoomConfiguration
public string VideoCodecKey { get; set; }
[JsonProperty("audioCodecKey", NullValueHandling = NullValueHandling.Ignore)]
public string AudioCodecKey { get; set; }
[JsonProperty("matrixRoutingKey", NullValueHandling = NullValueHandling.Ignore)]
public string MatrixRoutingKey { get; set; }
[JsonProperty("defaultDisplayKey", NullValueHandling = NullValueHandling.Ignore)]
public string DefaultDisplayKey { get; set; }
[JsonProperty("destinations", NullValueHandling = NullValueHandling.Ignore)]
Expand Down Expand Up @@ -880,16 +891,16 @@ public class EnvironmentalDeviceConfiguration

[JsonConverter(typeof(StringEnumConverter))]
[JsonProperty("deviceType", NullValueHandling = NullValueHandling.Ignore)]
public EEnvironmentalDeviceTypes DeviceType { get; private set; }
public eEnvironmentalDeviceTypes DeviceType { get; private set; }

public EnvironmentalDeviceConfiguration(string key, EEnvironmentalDeviceTypes type)
public EnvironmentalDeviceConfiguration(string key, eEnvironmentalDeviceTypes type)
{
DeviceKey = key;
DeviceType = type;
}
}

public enum EEnvironmentalDeviceTypes
public enum eEnvironmentalDeviceTypes
{
None,
Lighting,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<DefineConstants>TRACE;SERIES4</DefineConstants>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="PepperDashEssentials" Version="2.0.0-alpha-2418" />
<PackageReference Include="PepperDashEssentials" Version="2.0.0-alpha-2423" />
<PackageReference Include="WebSocketSharp-netstandard" Version="1.0.1" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Linq;
using PepperDash.Core;
using PepperDash.Essentials.Core;
Expand All @@ -25,30 +26,54 @@ protected override void RegisterActions()

AddAction("/fullStatus", (id, content) =>
{
PostStatusMessage(new DeviceStateMessageBase
PostStatusMessage(new CommunicationMonitorState
{
CommMonitor = new CommunicationMonitorState
CommunicationMonitor = new CommunicationMonitorProps
{
IsOnline = _communicationMonitor.CommunicationMonitor.IsOnline,
Status = _communicationMonitor.CommunicationMonitor.Status
}
}); ;
});
});

_communicationMonitor.CommunicationMonitor.StatusChange += (sender, args) =>
{
PostStatusMessage(JToken.FromObject(new
{
CommunicationMonitorState = new
commMonitor = new CommunicationMonitorProps
{
IsOnline = _communicationMonitor.CommunicationMonitor.IsOnline,
status = _communicationMonitor.CommunicationMonitor.Status
Status = _communicationMonitor.CommunicationMonitor.Status
}
}));
};
}
}

/// <summary>
/// Represents the state of the communication monitor
/// </summary>
public class CommunicationMonitorState : DeviceStateMessageBase
{
[JsonProperty("commMonitor", NullValueHandling = NullValueHandling.Ignore)]
public CommunicationMonitorProps CommunicationMonitor { get; set; }

}

public class CommunicationMonitorProps
{ /// <summary>
/// For devices that implement ICommunicationMonitor, reports the online status of the device
/// </summary>
[JsonProperty("isOnline", NullValueHandling = NullValueHandling.Ignore)]
public bool? IsOnline { get; set; }

/// <summary>
/// For devices that implement ICommunicationMonitor, reports the online status of the device
/// </summary>
[JsonProperty("status", NullValueHandling = NullValueHandling.Ignore)]
[JsonConverter(typeof(StringEnumConverter))]
public MonitorStatus Status { get; set; }

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@
using PepperDash.Core;
using PepperDash.Essentials.Core;
using PepperDash.Essentials.Core.Routing;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Channels;
using System.Text;
using System.Threading.Tasks;

namespace PepperDash.Essentials.AppServer.Messengers
{
Expand Down Expand Up @@ -36,7 +31,7 @@ protected override void RegisterActions()
{
var request = content.ToObject<MatrixRouteRequest>();

matrixDevice.Route(request.inputKey, request.outputKey, request.RouteType);
matrixDevice.Route(request.InputKey, request.OutputKey, request.RouteType);
});

foreach(var output in matrixDevice.OutputSlots)
Expand Down Expand Up @@ -73,19 +68,19 @@ protected override void RegisterActions()
public class MatrixStateMessage:DeviceStateMessageBase
{
[JsonProperty("outputs")]
public Dictionary<string, IRoutingOutputSlot> Outputs;
public Dictionary<string, RoutingOutputSlotBase> Outputs;

[JsonProperty("inputs")]
public Dictionary<string, IRoutingInputSlot> Inputs;
public Dictionary<string, RoutingInputSlotBase> Inputs;
}

public class MatrixRouteRequest
{
[JsonProperty("outputKey")]
public string outputKey { get; set; }
public string OutputKey { get; set; }

[JsonProperty("inputKey")]
public string inputKey { get; set; }
public string InputKey { get; set; }

[JsonProperty("routeType")]
public eRoutingSignalType RouteType { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@
<Folder Include="SIMPLJoinMaps\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="PepperDashEssentials" Version="2.0.0-alpha-2418" />
<PackageReference Include="PepperDashEssentials" Version="2.0.0-alpha-2423" />
</ItemGroup>
</Project>

0 comments on commit ec67846

Please sign in to comment.