Adds properties config for SIMPL Messenger classes and adds SetupDeviceMessengers() to MobileControlDdvc01RoomBridge to add individual device messengers

This commit is contained in:
Neil Dorin
2019-12-10 14:25:29 -07:00
parent ebc50f0caa
commit 5819ac78ec
7 changed files with 105 additions and 9 deletions

View File

@@ -95,7 +95,7 @@ namespace PepperDash.Essentials.AppServer.Messengers
: base(key, messagePath)
{
EISC = eisc;
JoinStart = joinStart;
JoinStart = joinStart - 1;
EISC.SetUShortSigAction(UshortJoin.CameraPresetCount + JoinStart, (u) => SendCameraFullMessageObject());
@@ -130,7 +130,7 @@ namespace PepperDash.Essentials.AppServer.Messengers
// camera presets
for (uint i = 1; i <= 6; i++)
{
addAction("/cameraPreset" + (i), BoolJoin.CameraPresetStart + JoinStart + i);
addAction("/cameraPreset" + (i), BoolJoin.CameraPresetStart + i + JoinStart);
}
asc.AddAction(MessagePath + "/fullStatus", new Action(SendCameraFullMessageObject));
@@ -150,7 +150,7 @@ namespace PepperDash.Essentials.AppServer.Messengers
{
for (uint i = 1; i <= EISC.GetUshort(UshortJoin.CameraPresetCount); i++)
{
var presetName = EISC.GetString(JoinStart + StringJoin.CameraPresetNameStart + i);
var presetName = EISC.GetString(StringJoin.CameraPresetNameStart + i + JoinStart);
var preset = new CameraPreset((int)i, presetName, string.IsNullOrEmpty(presetName), true);
presetList.Add(preset);
}

View File

@@ -29,7 +29,7 @@ namespace PepperDash.Essentials.AppServer.Messengers
: base(key, messagePath)
{
EISC = eisc;
JoinStart = joinStart;
JoinStart = joinStart - 1;
EISC.SetStringSigAction(JoinStart + StringJoin.CurrentSource, (s) => SendRoutingFullMessageObject(s));
}

View File

@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using PepperDash.Essentials.Bridges;
namespace PepperDash.Essentials.AppServer.Messengers
{
/// <summary>
/// Properties to configure a SIMPL Messenger
/// </summary>
public class SimplMessengerPropertiesConfig : EiscApiPropertiesConfig.ApiDevicePropertiesConfig
{
}
}

View File

@@ -110,7 +110,6 @@ namespace PepperDash.Essentials.Room.MobileControl
/// 621
/// </summary>
public const uint SourceIsEnabledJoinStart = 621;
}
public class UshortJoin
@@ -755,6 +754,8 @@ namespace PepperDash.Essentials.Room.MobileControl
co.Devices.Add(conf);
}
SetupDeviceMessengers();
Debug.Console(0, this, "******* CONFIG FROM DDVC: \r{0}", JsonConvert.SerializeObject(ConfigReader.ConfigObject, Formatting.Indented));
var handler = ConfigurationIsReady;
@@ -766,6 +767,63 @@ namespace PepperDash.Essentials.Room.MobileControl
ConfigIsLoaded = true;
}
/// <summary>
/// Iterates device config and adds messengers as neede for each device type
/// </summary>
void SetupDeviceMessengers()
{
try
{
foreach (var device in ConfigReader.ConfigObject.Devices)
{
if (device.Group.Equals("appServerMessenger"))
{
var props = JsonConvert.DeserializeObject<SimplMessengerPropertiesConfig>(device.Properties.ToString());
var messengerKey = string.Format("device-{0}-{1}", this.Key, Parent.Key);
MessengerBase messenger = null;
var dev = ConfigReader.ConfigObject.GetDeviceForKey(props.DeviceKey);
if (dev == null)
{
Debug.Console(1, this, "Unable to find device config for key: '{0}'", props.DeviceKey);
return;
}
var type = device.Type.ToLower();
if (type.Equals("simplcameramessenger"))
{
Debug.Console(2, this, "Adding SIMPLCameraMessenger for: '{0}'", props.DeviceKey);
messenger = new SIMPLCameraMessenger(messengerKey, EISC, "/device/" + props.DeviceKey, props.JoinStart);
}
else if (type.Equals("simplroutemessenger"))
{
Debug.Console(2, this, "Adding SIMPLRouteMessenger for: '{0}'", props.DeviceKey);
messenger = new SIMPLRouteMessenger(messengerKey, EISC, "/device/" + props.DeviceKey, props.JoinStart);
}
if (messenger != null)
{
DeviceManager.AddDevice(messenger);
messenger.RegisterWithAppServer(Parent);
}
else
{
Debug.Console(2, this, "Unable to add messenger for device: '{0}' of type: '{1}'", props.DeviceKey, type);
}
}
}
}
catch (Exception e)
{
Debug.Console(2, this, "Error Setting up Device Managers: {0}", e);
}
}
/// <summary>
///
/// </summary>

View File

@@ -269,10 +269,10 @@ namespace PepperDash.Essentials.Bridges
public EssentialsControlPropertiesConfig Control { get; set; }
[JsonProperty("devices")]
public List<ApiDevice> Devices { get; set; }
public List<ApiDevicePropertiesConfig> Devices { get; set; }
public class ApiDevice
public class ApiDevicePropertiesConfig
{
[JsonProperty("deviceKey")]
public string DeviceKey { get; set; }

View File

@@ -115,8 +115,9 @@
<Compile Include="AppServer\Messengers\Ddvc01VtcMessenger.cs" />
<Compile Include="AppServer\Messengers\IRunRouteActionMessenger.cs" />
<Compile Include="AppServer\Messengers\MessengerBase.cs" />
<Compile Include="AppServer\Messengers\SIMPLCameraBaseMessenger.cs" />
<Compile Include="AppServer\Messengers\SIMPLIRunRouteActionMessenger.cs" />
<Compile Include="AppServer\Messengers\SIMPLCameraMessenger.cs" />
<Compile Include="AppServer\Messengers\SimplMessengerPropertiesConfig.cs" />
<Compile Include="AppServer\Messengers\SIMPLRouteMessenger.cs" />
<Compile Include="AppServer\Messengers\SystemMonitorMessenger.cs" />
<Compile Include="AppServer\Messengers\VideoCodecBaseMessenger.cs" />
<Compile Include="Audio\EssentialsVolumeLevelConfig.cs" />

View File

@@ -39,5 +39,25 @@ namespace PepperDash.Essentials.Core.Config
return SourceLists[key];
}
/// <summary>
/// Checks Devices for an item with a Key that matches and returns it if found. Otherwise, retunes null
/// </summary>
/// <param name="key">Key of desired device</param>
/// <returns></returns>
public DeviceConfig GetDeviceForKey(string key)
{
if (string.IsNullOrEmpty(key))
return null;
var deviceConfig = Devices.FirstOrDefault(d => d.Key.Equals(key));
if (deviceConfig != null)
return deviceConfig;
else
{
return null;
}
}
}
}