Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SIMPL Bridge Updates #92

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
251 changes: 218 additions & 33 deletions 3-series/RoomBridges/MobileControlSIMPLRoomBridge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@
using PepperDash.Essentials.Devices.Common.Codec;
using PepperDash.Essentials.Devices.Common.Cameras;
using PepperDash.Essentials.Room.Config;
using PepperDash.Essentials.Core.DeviceTypeInterfaces;

using System.Linq;
using PepperDash.Essentials.Devices.Common.VideoCodec.ZoomRoom;
using PepperDash.Essentials.Core.Lighting;
using PepperDash.Essentials.Core.Shades;
using PepperDash.Essentials.Devices.Common;
using PepperDash.Essentials.Devices.Common.VideoCodec;
using PepperDash.Essentials.Devices.Common.AudioCodec;

namespace PepperDash.Essentials.Room.MobileControl
{
// ReSharper disable once InconsistentNaming
// ReSharper disable once InconsistentNaming
public class MobileControlSIMPLRoomBridge : MobileControlBridgeBase, IDelayedConfiguration
{
private const int SupportedDisplayCount = 10;
Expand All @@ -33,9 +38,6 @@ public class MobileControlSIMPLRoomBridge : MobileControlBridgeBase, IDelayedCon

public MobileControlSIMPLRoomJoinMap JoinMap { get; private set; }

public Dictionary<string, MessengerBase> DeviceMessengers { get; private set; }


/// <summary>
///
/// </summary>
Expand Down Expand Up @@ -82,7 +84,7 @@ public MobileControlSIMPLRoomBridge(string key, string name, uint ipId)
_sourceBridge = new MobileControlSimplDeviceBridge(key + "-sourceBridge", "SIMPL source bridge", Eisc);
DeviceManager.AddDevice(_sourceBridge);

CrestronConsole.AddNewConsoleCommand((s) => JoinMap.PrintJoinMapInfo(), "printmobilejoinmap", "Prints the MobileControlSIMPLRoomBridge JoinMap", ConsoleAccessLevelEnum.AccessOperator);
CrestronConsole.AddNewConsoleCommand((s) => JoinMap.PrintJoinMapInfo(), "mobileprintjoinmap", "Prints the MobileControlSIMPLRoomBridge JoinMap", ConsoleAccessLevelEnum.AccessOperator);

AddPostActivationAction(() =>
{
Expand Down Expand Up @@ -156,7 +158,7 @@ public override bool CustomActivate()

// TODO: Update Source Bridge to use new JoinMap scheme
//_sourceBridge.JoinMap.PrintJoinMapInfo();
}, "printmobilebridge", "Prints MC-SIMPL bridge EISC data", ConsoleAccessLevelEnum.AccessOperator);
}, "mobileprintbridge", "Prints MC-SIMPL bridge EISC data", ConsoleAccessLevelEnum.AccessOperator);

return base.CustomActivate();
}
Expand Down Expand Up @@ -466,6 +468,12 @@ private void LoadConfigValues()
Parent.SystemUrl = Eisc.StringOutput[JoinMap.PortalSystemUrl.JoinNumber].StringValue;
}


if(co.Info == null)
{
co.Info = new InfoConfig();
}

co.Info.RuntimeInfo.AppName = Assembly.GetExecutingAssembly().GetName().Name;
var version = Assembly.GetExecutingAssembly().GetName().Version;
co.Info.RuntimeInfo.AssemblyVersion = string.Format("{0}.{1}.{2}", version.Major, version.Minor,
Expand Down Expand Up @@ -500,21 +508,33 @@ private void LoadConfigValues()
Message = Eisc.StringOutput[JoinMap.ConfigHelpMessage.JoinNumber].StringValue
};

rmProps.HelpMessage = Eisc.StringOutput[JoinMap.ConfigHelpMessage.JoinNumber].StringValue;

rmProps.Environment = new EssentialsEnvironmentPropertiesConfig(); // enabled defaults to false

var environmentKeySigs = Eisc.StringOutput.Where(s => s.Number >= JoinMap.EnvironmentalDevicesKey.JoinNumber && s.Number < JoinMap.EnvironmentalDevicesKey.JoinNumber + JoinMap.EnvironmentalDevicesKey.JoinSpan);

if (environmentKeySigs.Any(s => !string.IsNullOrEmpty(s.StringValue)))
{
rmProps.Environment.Enabled = true;
rmProps.Environment.DeviceKeys = environmentKeySigs.Where(s => !string.IsNullOrEmpty(s.StringValue)).Select(s => s.StringValue).ToList();
}

rmProps.RoomPhoneNumber = Eisc.StringOutput[JoinMap.ConfigRoomPhoneNumber.JoinNumber].StringValue;
rmProps.RoomURI = Eisc.StringOutput[JoinMap.ConfigRoomUri.JoinNumber].StringValue;
rmProps.SpeedDials = new List<SimplSpeedDial>();

var essentialsAudioCodecKey = Eisc.StringOutput[JoinMap.AudioCodecKey.JoinNumber].StringValue;
var essentialsVideoCodecKey = Eisc.StringOutput[JoinMap.VideoCodecKey.JoinNumber].StringValue;
// This MAY need a check
if (Eisc.BooleanOutput[JoinMap.ActivityPhoneCallEnable.JoinNumber].BoolValue)
{
rmProps.AudioCodecKey = "audioCodec";
{
rmProps.AudioCodecKey = string.IsNullOrEmpty(essentialsAudioCodecKey) ? "audioCodec" : essentialsAudioCodecKey;
}

if (Eisc.BooleanOutput[JoinMap.ActivityVideoCallEnable.JoinNumber].BoolValue)
{
rmProps.VideoCodecKey = "videoCodec";
{
rmProps.VideoCodecKey = string.IsNullOrEmpty(essentialsVideoCodecKey) ? "videoCodec" : essentialsVideoCodecKey;
}

// volume control names
Expand All @@ -530,7 +550,7 @@ private void LoadConfigValues()
if (co.Devices == null)
co.Devices = new List<DeviceConfig>();

// clear out previous SIMPL devices
// clear out previous SIMPL devices
co.Devices.RemoveAll(d =>
d.Key.StartsWith("source-", StringComparison.OrdinalIgnoreCase)
|| d.Key.Equals("audioCodec", StringComparison.OrdinalIgnoreCase)
Expand Down Expand Up @@ -636,7 +656,7 @@ private void LoadConfigValues()

// Build "audioCodec" config if we need
if (!string.IsNullOrEmpty(rmProps.AudioCodecKey))
{
{
var acFavs = new List<CodecActiveCallItem>();
for (uint i = 0; i < 4; i++)
{
Expand Down Expand Up @@ -849,9 +869,7 @@ private void CreateDestinationList(BasicConfig co)
/// Iterates device config and adds messengers as neede for each device type
/// </summary>
private void SetupDeviceMessengers()
{
DeviceMessengers = new Dictionary<string, MessengerBase>();

{
try
{
foreach (var device in ConfigReader.ConfigObject.Devices)
Expand Down Expand Up @@ -895,9 +913,7 @@ private void SetupDeviceMessengers()

if (messenger != null)
{
DeviceManager.AddDevice(messenger);
DeviceMessengers.Add(device.Key, messenger);
messenger.RegisterWithAppServer(Parent);
Parent.AddDeviceMessenger(messenger);
}
else
{
Expand All @@ -915,13 +931,63 @@ private void SetupDeviceMessengers()
{
var camDevice = dev as CameraBase;
Debug.Console(1, this, "Adding CameraBaseMessenger for device: {0}", dev.Key);
var cameraMessenger = new CameraBaseMessenger(device.Key + "-" + Parent.Key, camDevice,
var messenger = new CameraBaseMessenger(device.Key + "-" + Parent.Key, camDevice,
"/device/" + device.Key);
DeviceMessengers.Add(device.Key, cameraMessenger);
DeviceManager.AddDevice(cameraMessenger);
cameraMessenger.RegisterWithAppServer(Parent);
Parent.AddDeviceMessenger(messenger);
continue;
}

if (dev is ZoomRoom)
{
var zoomDevice = dev as ZoomRoom;

Debug.Console(1, this, "Adding ZoomRoomMessenger for device: {0}", dev.Key);

var zoomMessenger = new ZoomRoomMessenger(device.Key + "-" + Parent.Key, zoomDevice, "/device/" + dev.Key);
Parent.AddDeviceMessenger(zoomMessenger);
continue;
}

if(dev is VideoCodecBase)
{
var vcBase = dev as VideoCodecBase;

var messenger = new VideoCodecBaseMessenger(dev.Key + "-" + Parent.Key, vcBase, string.Format("/devices/{0}", dev.Key));
Parent.AddDeviceMessenger(messenger);
continue;
}

if(dev is AudioCodecBase)
{
var acBase = dev as AudioCodecBase;

var messenger = new AudioCodecBaseMessenger(dev.Key + "-" + Parent.Key, acBase, string.Format("/devices/{0}", dev.Key));
Parent.AddDeviceMessenger(messenger);
continue;
}

if (dev is LightingBase)
{
var deviceKey = device.Key;
var lightingDevice = dev as LightingBase;
Debug.Console(1, this, "Adding LightingBaseMessenger for device: {0}", deviceKey);
var messenger = new LightingBaseMessenger(deviceKey + "-" + Parent.Key,
lightingDevice, string.Format("/device/{0}", deviceKey));
Parent.AddDeviceMessenger(messenger);
continue;
}

if (dev is ShadeBase)
{
var deviceKey = device.Key;
var shadeDevice = dev as ShadeBase;
Debug.Console(1, this, "Adding ShadeBaseMessenger for device: {0}", deviceKey);
var messenger = new ShadeBaseMessenger(deviceKey + "-" + Parent.Key,
shadeDevice, string.Format("/device/{0}", deviceKey));
Parent.AddDeviceMessenger(messenger);
continue;
}

}
}
}
Expand Down Expand Up @@ -975,19 +1041,31 @@ private void SendFullStatus()
},
AuxFaders = auxFaderDict,
NumberOfAuxFaders = Eisc.UShortInput[JoinMap.NumberOfAuxFaders.JoinNumber].UShortValue
};

var state = new RoomStateMessage
{
Configuration = GetRoomConfiguration(ConfigReader.ConfigObject),
ActivityMode = GetActivityMode(),
IsOn = Eisc.BooleanOutput[JoinMap.RoomIsOn.JoinNumber].BoolValue,
SelectedSourceKey = Eisc.StringOutput[JoinMap.CurrentSourceKey.JoinNumber].StringValue,
Volumes = volumes,
};

// TODO: Add property to status message to indicate if advanced sharing is supported and if users can change share mode
if (_vtcMessenger != null)
{
state.IsInCall = Eisc.BooleanOutput[_vtcMessenger.JoinMap.HookState.JoinNumber].BoolValue;
}

PostStatus(new
var messageObject = new MobileControlResponseMessage
{
activityMode = GetActivityMode(),
isOn = Eisc.BooleanOutput[JoinMap.RoomIsOn.JoinNumber].BoolValue,
selectedSourceKey = Eisc.StringOutput[JoinMap.CurrentSourceKey.JoinNumber].StringValue,
volumes,
supportsAdvancedSharing = Eisc.BooleanOutput[JoinMap.SupportsAdvancedSharing.JoinNumber].BoolValue,
userCanChangeShareMode = Eisc.BooleanOutput[JoinMap.UserCanChangeShareMode.JoinNumber].BoolValue,
});
Type = MessagePath,
Content = state,
};

// TODO: Add property to status message to indicate if advanced sharing is supported and if users can change share mode

PostStatus(messageObject);
}
else
{
Expand Down Expand Up @@ -1100,5 +1178,112 @@ protected override void UserCodeChange()
Eisc.StringInput[JoinMap.QrCodeUrl.JoinNumber].StringValue = QrCodeUrl;

}

private RoomConfiguration GetRoomConfiguration(EssentialsConfig config)
{
var roomConfiguration = new RoomConfiguration();

if(config.Rooms.Count ==0 )
{
Debug.Console(0, this, "No SIMPL Rooms configured");

return roomConfiguration;
}

if (config.Rooms[0].Properties == null)
{
Debug.Console(0, this, "Room Properties Missing.");
return roomConfiguration;
}

var properties = config.Rooms[0].Properties.ToObject<SimplRoomPropertiesConfig>();

if(properties == null)
{
Debug.Console(0, this, "Unable to convert properties");
return roomConfiguration;
}

roomConfiguration.HelpMessage = properties.HelpMessage;

if (!string.IsNullOrEmpty(properties.VideoCodecKey)) //has video codec
{
roomConfiguration.HasVideoConferencing = true;
roomConfiguration.VideoCodecKey = properties.VideoCodecKey;

var vcDev = DeviceManager.GetDeviceForKey(properties.VideoCodecKey);

roomConfiguration.VideoCodecIsZoomRoom = vcDev != null && vcDev is ZoomRoom;
}

if (!string.IsNullOrEmpty(properties.AudioCodecKey))
{
roomConfiguration.HasAudioConferencing = true;
roomConfiguration.AudioCodecKey = properties.AudioCodecKey;
}

if (properties.Environment.Enabled)
{
roomConfiguration.HasEnvironmentalControls = true;

var dev = properties.Environment.DeviceKeys
.Select(k => DeviceManager.GetDeviceForKey(k))
.Select(d =>
{
if (d != null && (d is LightingBase || d is ShadeBase))
{
return d;
} else
{
return null;
}
});

var shadeConfigs = dev
.Cast<ShadeBase>()
.Where(d => d != null)
.Select(d => new EnvironmentalDeviceConfiguration(d.Key, eEnvironmentalDeviceTypes.Shade));
var shadeControllerConfigs = dev
.Cast<ShadeController>()
.Where(d => d != null)
.Select(d => new EnvironmentalDeviceConfiguration(d.Key, eEnvironmentalDeviceTypes.ShadeController));
var lightingConfigs = dev
.Cast<LightingBase>()
.Where(d => d != null)
.Select(d => new EnvironmentalDeviceConfiguration(d.Key, eEnvironmentalDeviceTypes.Lighting));

roomConfiguration.EnvironmentalDevices = shadeConfigs.Concat(shadeControllerConfigs).Concat(lightingConfigs).ToList();
}

if (!string.IsNullOrEmpty(properties.DefaultDisplayKey))
{
roomConfiguration.DefaultDisplayKey = properties.DefaultDisplayKey;
}

if (!string.IsNullOrEmpty(properties.DestinationListKey)) //assuming having a destination list means having multiple destinations
{
Dictionary<string, DestinationListItem> destList;

if(config.DestinationLists.TryGetValue(properties.DestinationListKey, out destList))
{
roomConfiguration.DisplayKeys = destList.Values.Select(dl => dl.SinkKey).ToList();
}
}

var sourceList = ConfigReader.ConfigObject.GetSourceListForKey(properties.SourceListKey);

if (sourceList != null)
{
roomConfiguration.SourceList = sourceList;
roomConfiguration.HasRoutingControls = true;

roomConfiguration.HasSetTopBoxControls = sourceList.Values.Any(sl => sl.SourceDevice is IRSetTopBoxBase);

roomConfiguration.HasCameraControls = sourceList.Values.Any(sl => sl.SourceDevice is CameraBase);
}


return roomConfiguration;
}
}
}
Loading