Compare commits

...

9 Commits

Author SHA1 Message Date
Jason T Alborough
f77f36761f Rebuild with the latest PDCore Beta v0.0.26 2020-01-28 11:17:12 -05:00
Andrew Welker
4361fe6186 Merge branch 'development' of https://bitbucket.org/Pepperdash_Products/essentials into feature/ecs-1245 2020-01-23 13:06:29 -07:00
Andrew Welker
09bc84346d ECS-1245 Added C2nRths Controller and Bridge 2020-01-23 13:02:42 -07:00
Neil Dorin
00e3e6af35 Merged in bugfix/ecs-1246 (pull request #44)
ECS-1246 - Resolves issue where device factory was pulling CresnetIdInt instead of IpIdInt from config when trying to build CEN-IO-DIGIN-104

Approved-by: Neil Dorin <ndorin@pepperdash.com>
2020-01-23 19:43:19 +00:00
Neil Dorin
61f24321c3 ECS-1246 - Resolves issue where device factory was pulling CresnetIdInt instead of IpIdInt from config when trying to build CEN-IO-DIGIN-104 2020-01-23 12:41:47 -07:00
Andrew Welker
8f530aa7fe ECS-1244 Added StatusSignController Class and bridge 2020-01-23 12:33:28 -07:00
Neil Dorin
36cd356bc5 Merged in feature/ecs-1242 (pull request #43)
Feature/ecs 1242

Approved-by: Neil Dorin <ndorin@pepperdash.com>
2020-01-23 18:06:48 +00:00
Neil Dorin
b72f55228a Adds some debug statements to help with NoRouteText property on DmChassisController config 2020-01-23 10:53:41 -07:00
Neil Dorin
1017464980 Adds try/catch to Communication_BytesReceived callback to prevent exception from getting logged when malformed message is received 2020-01-16 16:40:02 -07:00
13 changed files with 427 additions and 67 deletions

View File

@@ -166,6 +166,16 @@ namespace PepperDash.Essentials.Bridges
(device as PepperDash.Essentials.Devices.Common.Occupancy.GlsOccupancySensorBaseController).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey);
continue;
}
else if (device is StatusSignController)
{
(device as StatusSignController).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey);
continue;
}
else if (device is C2nRthsController)
{
(device as C2nRthsController).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey);
continue;
}
}
}

View File

@@ -0,0 +1,29 @@
using Crestron.SimplSharpPro.DeviceSupport;
using Newtonsoft.Json;
using PepperDash.Core;
using PepperDash.Essentials.Core;
using PepperDash.Essentials.Core.CrestronIO;
namespace PepperDash.Essentials.Bridges
{
public static class C2nRthsControllerApiExtensions
{
public static void LinkToApi(this C2nRthsController device, BasicTriList triList, uint joinStart,
string joinMapKey)
{
var joinMap = new C2nRthsControllerJoinMap(joinStart);
var joinMapSerialized = JoinMapHelper.GetJoinMapForDevice(joinMapKey);
if (!string.IsNullOrEmpty(joinMapSerialized))
joinMap = JsonConvert.DeserializeObject<C2nRthsControllerJoinMap>(joinMapSerialized);
joinMap.OffsetJoinNumbers(joinStart);
Debug.Console(1, device, "Linking to Trilist '{0}'", triList.ID.ToString("X"));
triList.SetBoolSigAction(joinMap.TemperatureFormat, device.SetTemperatureFormat);
}
}
}

View File

@@ -0,0 +1,39 @@
using System.Linq;
using Crestron.SimplSharp.Reflection;
using PepperDash.Essentials.Core;
namespace PepperDash.Essentials.Bridges
{
public class C2nRthsControllerJoinMap:JoinMapBase
{
public uint IsOnline { get; set; }
public uint Temperature { get; set; }
public uint Humidity { get; set; }
public uint TemperatureFormat { get; set; }
public C2nRthsControllerJoinMap(uint joinStart)
{
//digital
IsOnline = 1;
TemperatureFormat = 2;
//Analog
Temperature = 2;
Humidity = 3;
OffsetJoinNumbers(joinStart);
}
public override void OffsetJoinNumbers(uint joinStart)
{
var joinOffset = joinStart - 1;
var properties =
GetType().GetCType().GetProperties().Where(p => p.PropertyType == typeof(uint)).ToList();
foreach (var propertyInfo in properties)
{
propertyInfo.SetValue(this, (uint)propertyInfo.GetValue(this, null) + joinOffset, null);
}
}
}
}

View File

@@ -0,0 +1,45 @@
using System.Linq;
using Crestron.SimplSharp.Reflection;
using PepperDash.Essentials.Core;
namespace PepperDash.Essentials.Bridges
{
public class StatusSignControllerJoinMap:JoinMapBase
{
public uint IsOnline { get; set; }
public uint RedLed { get; set; }
public uint GreenLed { get; set; }
public uint BlueLed { get; set; }
public uint RedControl { get; set; }
public uint GreenControl { get; set; }
public uint BlueControl { get; set; }
public StatusSignControllerJoinMap(uint joinStart)
{
//digital
IsOnline = 1;
RedControl = 2;
GreenControl = 3;
BlueControl = 4;
//Analog
RedLed = 2;
GreenLed = 3;
BlueLed = 4;
OffsetJoinNumbers(joinStart);
}
public override void OffsetJoinNumbers(uint joinStart)
{
var joinOffset = joinStart - 1;
var properties =
GetType().GetCType().GetProperties().Where(p => p.PropertyType == typeof (uint)).ToList();
foreach (var propertyInfo in properties)
{
propertyInfo.SetValue(this, (uint) propertyInfo.GetValue(this, null) + joinOffset, null);
}
}
}
}

View File

@@ -0,0 +1,53 @@
using Crestron.SimplSharpPro.DeviceSupport;
using Newtonsoft.Json;
using PepperDash.Core;
using PepperDash.Essentials.Core;
using PepperDash.Essentials.Core.CrestronIO;
namespace PepperDash.Essentials.Bridges
{
public static class StatusSignDeviceApiExtensions
{
public static void LinkToApi(this StatusSignController ssDevice, BasicTriList trilist, uint joinStart,
string joinMapKey)
{
var joinMap = new StatusSignControllerJoinMap(joinStart);
var joinMapSerialized = JoinMapHelper.GetJoinMapForDevice(joinMapKey);
if (!string.IsNullOrEmpty(joinMapSerialized))
joinMap = JsonConvert.DeserializeObject<StatusSignControllerJoinMap>(joinMapSerialized);
joinMap.OffsetJoinNumbers(joinStart);
Debug.Console(1, ssDevice, "Linking to Trilist '{0}'", trilist.ID.ToString("X"));
trilist.SetBoolSigAction(joinMap.RedControl, b => EnableControl(trilist, joinMap, ssDevice));
trilist.SetBoolSigAction(joinMap.GreenControl, b => EnableControl(trilist, joinMap, ssDevice));
trilist.SetBoolSigAction(joinMap.BlueControl, b => EnableControl(trilist, joinMap, ssDevice));
trilist.SetUShortSigAction(joinMap.RedLed, u => SetColor(trilist, joinMap, ssDevice));
trilist.SetUShortSigAction(joinMap.GreenLed, u => SetColor(trilist, joinMap, ssDevice));
trilist.SetUShortSigAction(joinMap.BlueLed, u => SetColor(trilist, joinMap, ssDevice));
}
private static void EnableControl(BasicTriList triList, StatusSignControllerJoinMap joinMap,
StatusSignController device)
{
var redEnable = triList.BooleanOutput[joinMap.RedControl].BoolValue;
var greenEnable = triList.BooleanOutput[joinMap.GreenControl].BoolValue;
var blueEnable = triList.BooleanOutput[joinMap.BlueControl].BoolValue;
device.EnableLedControl(redEnable, greenEnable, blueEnable);
}
private static void SetColor(BasicTriList triList, StatusSignControllerJoinMap joinMap,
StatusSignController device)
{
var redBrightness = triList.UShortOutput[joinMap.RedLed].UShortValue;
var greenBrightness = triList.UShortOutput[joinMap.GreenLed].UShortValue;
var blueBrightness = triList.UShortOutput[joinMap.BlueLed].UShortValue;
device.SetColor(redBrightness, greenBrightness, blueBrightness);
}
}
}

View File

@@ -119,9 +119,11 @@
<Compile Include="Bridges\AppleTvBridge.cs" />
<Compile Include="Bridges\BridgeBase.cs" />
<Compile Include="Bridges\BridgeFactory.cs" />
<Compile Include="Bridges\C2nRthsControllerBridge.cs" />
<Compile Include="Bridges\CameraControllerBridge.cs" />
<Compile Include="Bridges\AirMediaControllerBridge.cs" />
<Compile Include="Bridges\DmBladeChassisControllerBridge.cs" />
<Compile Include="Bridges\JoinMaps\C2nRthsControllerJoinMap.cs" />
<Compile Include="Bridges\JoinMaps\DmBladeChassisControllerJoinMap.cs" />
<Compile Include="Bridges\DmpsAudioOutputControllerBridge.cs" />
<Compile Include="Bridges\DmpsRoutingControllerBridge.cs" />
@@ -153,7 +155,9 @@
<Compile Include="Bridges\JoinMaps\IBasicCommunicationJoinMap.cs" />
<Compile Include="Bridges\JoinMaps\IDigitalInputJoinMap.cs" />
<Compile Include="Bridges\JoinMaps\GlsOccupancySensorBaseJoinMap.cs" />
<Compile Include="Bridges\JoinMaps\StatusSignControllerJoinMap.cs" />
<Compile Include="Bridges\JoinMaps\SystemMonitorJoinMap.cs" />
<Compile Include="Bridges\StatusSignControllerBridge.cs" />
<Compile Include="Bridges\SystemMonitorBridge.cs" />
<Compile Include="Configuration ORIGINAL\Builders\TPConfig.cs" />
<Compile Include="Configuration ORIGINAL\Configuration.cs" />

View File

@@ -0,0 +1,44 @@
using System;
using Crestron.SimplSharpPro;
using Crestron.SimplSharpPro.GeneralIO;
using PepperDash.Core;
using PepperDash.Essentials.Core;
namespace PepperDash.Essentials.Core.CrestronIO
{
public class C2nRthsController:CrestronGenericBaseDevice
{
private C2nRths _device;
public IntFeedback TemperatureFeedback { get; private set; }
public IntFeedback HumidityFeedback { get; private set; }
public C2nRthsController(string key, string name, GenericBase hardware) : base(key, name, hardware)
{
_device = hardware as C2nRths;
TemperatureFeedback = new IntFeedback(() => _device.TemperatureFeedback.UShortValue);
HumidityFeedback = new IntFeedback(() => _device.HumidityFeedback.UShortValue);
_device.BaseEvent += DeviceOnBaseEvent;
}
private void DeviceOnBaseEvent(GenericBase device, BaseEventArgs args)
{
switch (args.EventId)
{
case C2nRths.TemperatureFeedbackEventId:
TemperatureFeedback.FireUpdate();
break;
case C2nRths.HumidityFeedbackEventId:
HumidityFeedback.FireUpdate();
break;
}
}
public void SetTemperatureFormat(bool setToC)
{
_device.TemperatureFormat.BoolValue = setToC;
}
}
}

View File

@@ -0,0 +1,107 @@
using System;
using Crestron.SimplSharpPro;
using Crestron.SimplSharpPro.DeviceSupport;
using Crestron.SimplSharpPro.GeneralIO;
using PepperDash.Core;
namespace PepperDash.Essentials.Core.CrestronIO
{
public class StatusSignController:CrestronGenericBaseDevice
{
private StatusSign _device;
public BoolFeedback RedLedEnabledFeedback { get; private set; }
public BoolFeedback GreenLedEnabledFeedback { get; private set; }
public BoolFeedback BlueLedEnabledFeedback { get; private set; }
public IntFeedback RedLedBrightnessFeedback { get; private set; }
public IntFeedback GreenLedBrightnessFeedback { get; private set; }
public IntFeedback BlueLedBrightnessFeedback { get; private set; }
public StatusSignController(string key, string name, GenericBase hardware) : base(key, name, hardware)
{
_device = hardware as StatusSign;
RedLedEnabledFeedback =
new BoolFeedback(
() =>
_device.Leds[(uint) StatusSign.Led.eLedColor.Red]
.ControlFeedback.BoolValue);
GreenLedEnabledFeedback =
new BoolFeedback(
() =>
_device.Leds[(uint) StatusSign.Led.eLedColor.Green]
.ControlFeedback.BoolValue);
BlueLedEnabledFeedback =
new BoolFeedback(
() =>
_device.Leds[(uint) StatusSign.Led.eLedColor.Blue]
.ControlFeedback.BoolValue);
RedLedBrightnessFeedback =
new IntFeedback(() => (int) _device.Leds[(uint) StatusSign.Led.eLedColor.Red].BrightnessFeedback);
GreenLedBrightnessFeedback =
new IntFeedback(() => (int) _device.Leds[(uint) StatusSign.Led.eLedColor.Green].BrightnessFeedback);
BlueLedBrightnessFeedback =
new IntFeedback(() => (int) _device.Leds[(uint) StatusSign.Led.eLedColor.Blue].BrightnessFeedback);
_device.BaseEvent += _device_BaseEvent;
}
void _device_BaseEvent(GenericBase device, BaseEventArgs args)
{
switch (args.EventId)
{
case StatusSign.LedBrightnessFeedbackEventId:
RedLedBrightnessFeedback.FireUpdate();
GreenLedBrightnessFeedback.FireUpdate();
BlueLedBrightnessFeedback.FireUpdate();
break;
case StatusSign.LedControlFeedbackEventId:
RedLedEnabledFeedback.FireUpdate();
GreenLedEnabledFeedback.FireUpdate();
BlueLedEnabledFeedback.FireUpdate();
break;
}
}
public void EnableLedControl(bool red, bool green, bool blue)
{
_device.Leds[(uint) StatusSign.Led.eLedColor.Red].Control.BoolValue = red;
_device.Leds[(uint)StatusSign.Led.eLedColor.Green].Control.BoolValue = green;
_device.Leds[(uint)StatusSign.Led.eLedColor.Blue].Control.BoolValue = blue;
}
public void SetColor(uint red, uint green, uint blue)
{
try
{
_device.Leds[(uint)StatusSign.Led.eLedColor.Red].Brightness =
(StatusSign.Led.eBrightnessPercentageValues)SimplSharpDeviceHelper.PercentToUshort(red);
}
catch (InvalidOperationException)
{
Debug.Console(1, this, "Error converting value to Red LED brightness. value: {0}", red);
}
try
{
_device.Leds[(uint)StatusSign.Led.eLedColor.Green].Brightness =
(StatusSign.Led.eBrightnessPercentageValues)SimplSharpDeviceHelper.PercentToUshort(green);
}
catch (InvalidOperationException)
{
Debug.Console(1, this, "Error converting value to Green LED brightness. value: {0}", green);
}
try
{
_device.Leds[(uint)StatusSign.Led.eLedColor.Blue].Brightness =
(StatusSign.Led.eBrightnessPercentageValues)SimplSharpDeviceHelper.PercentToUshort(blue);
}
catch (InvalidOperationException)
{
Debug.Console(1, this, "Error converting value to Blue LED brightness. value: {0}", blue);
}
}
}
}

View File

@@ -4,10 +4,11 @@ using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using Crestron.SimplSharpPro;
using Crestron.SimplSharpPro.GeneralIO;
using PepperDash.Core;
using PepperDash.Essentials.Core;
using PepperDash.Essentials.Core.Config;
using PepperDash.Essentials.Core.CrestronIO;
namespace PepperDash.Essentials.Core
{
@@ -55,10 +56,24 @@ namespace PepperDash.Essentials.Core
else if (typeName == "ceniodigin104")
{
var control = CommFactory.GetControlPropertiesConfig(dc);
var ipid = control.CresnetIdInt;
var ipid = control.IpIdInt;
return new CenIoDigIn104Controller(key, name, new Crestron.SimplSharpPro.GeneralIO.CenIoDi104(ipid, Global.ControlSystem));
}
if (typeName == "statussign")
{
var control = CommFactory.GetControlPropertiesConfig(dc);
var cresnetId = control.CresnetIdInt;
return new StatusSignController(key, name, new StatusSign(cresnetId, Global.ControlSystem));
}
if (typeName == "c2nrths")
{
var control = CommFactory.GetControlPropertiesConfig(dc);
var cresnetId = control.CresnetIdInt;
return new C2nRthsController(key, name, new C2nRths(cresnetId, Global.ControlSystem));
}
// then check for types that have been added by plugin dlls.
if (FactoryMethods.ContainsKey(typeName))

View File

@@ -64,7 +64,7 @@
</Reference>
<Reference Include="Crestron.SimplSharpPro.GeneralIO, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1099c178b3b54c3b, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\..\ProgramData\Crestron\SDK\SSPDevices\Crestron.SimplSharpPro.GeneralIO.dll</HintPath>
<HintPath>..\..\..\..\..\..\..\..\..\ProgramData\Crestron\SDK\SSPDevices\Crestron.SimplSharpPro.GeneralIO.dll</HintPath>
</Reference>
<Reference Include="Crestron.SimplSharpPro.Remotes, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1099c178b3b54c3b, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
@@ -118,6 +118,7 @@
<Compile Include="Config\Essentials\ConfigWriter.cs" />
<Compile Include="Config\Essentials\EssentialsConfig.cs" />
<Compile Include="Config\SourceDevicePropertiesConfigBase.cs" />
<Compile Include="Crestron IO\C2nRts\C2nRthsController.cs" />
<Compile Include="Crestron IO\Inputs\CenIoDigIn104Controller.cs" />
<Compile Include="Crestron IO\Inputs\GenericDigitalInputDevice.cs" />
<Compile Include="Crestron IO\Inputs\GenericVersiportInputDevice.cs" />
@@ -125,6 +126,7 @@
<Compile Include="Crestron IO\IOPortConfig.cs" />
<Compile Include="Crestron IO\Relay\GenericRelayDevice.cs" />
<Compile Include="Crestron IO\Relay\ISwitchedOutput.cs" />
<Compile Include="Crestron IO\StatusSign\StatusSignController.cs" />
<Compile Include="Devices\CodecInterfaces.cs" />
<Compile Include="Devices\CrestronProcessor.cs" />
<Compile Include="Devices\DeviceApiBase.cs" />

View File

@@ -135,7 +135,12 @@ namespace PepperDash.Essentials.DM
controller.OutputNames = properties.OutputNames;
if (!string.IsNullOrEmpty(properties.NoRouteText))
{
controller.NoRouteText = properties.NoRouteText;
Debug.Console(1, controller, "Setting No Route Text value to: {0}", controller.NoRouteText);
}
else
Debug.Console(1, controller, "NoRouteText not specified. Defaulting to blank string.", controller.NoRouteText);
controller.PropertiesConfig = properties;
return controller;

View File

@@ -167,84 +167,91 @@ namespace PepperDash.Essentials.Devices.Displays
/// <param name="sender"></param>
void Communication_BytesReceived(object sender, GenericCommMethodReceiveBytesArgs e)
{
// This is probably not thread-safe buffering
// Append the incoming bytes with whatever is in the buffer
var newBytes = new byte[IncomingBuffer.Length + e.Bytes.Length];
IncomingBuffer.CopyTo(newBytes, 0);
e.Bytes.CopyTo(newBytes, IncomingBuffer.Length);
if (Debug.Level == 2) // This check is here to prevent following string format from building unnecessarily on level 0 or 1
Debug.Console(2, this, "Received:{0}", ComTextHelper.GetEscapedText(newBytes));
// Need to find AA FF and have
for (int i = 0; i < newBytes.Length; i++)
try
{
if (newBytes[i] == 0xAA && newBytes[i + 1] == 0xFF)
// This is probably not thread-safe buffering
// Append the incoming bytes with whatever is in the buffer
var newBytes = new byte[IncomingBuffer.Length + e.Bytes.Length];
IncomingBuffer.CopyTo(newBytes, 0);
e.Bytes.CopyTo(newBytes, IncomingBuffer.Length);
if (Debug.Level == 2) // This check is here to prevent following string format from building unnecessarily on level 0 or 1
Debug.Console(2, this, "Received:{0}", ComTextHelper.GetEscapedText(newBytes));
// Need to find AA FF and have
for (int i = 0; i < newBytes.Length; i++)
{
newBytes = newBytes.Skip(i).ToArray(); // Trim off junk if there's "dirt" in the buffer
// parse it
// If it's at least got the header, then process it,
while (newBytes.Length > 4 && newBytes[0] == 0xAA && newBytes[1] == 0xFF)
if (newBytes[i] == 0xAA && newBytes[i + 1] == 0xFF)
{
var msgLen = newBytes[3];
// if the buffer is shorter than the header (3) + message (msgLen) + checksum (1),
// give and save it for next time
if (newBytes.Length < msgLen + 4)
break;
newBytes = newBytes.Skip(i).ToArray(); // Trim off junk if there's "dirt" in the buffer
// Good length, grab the message
var message = newBytes.Skip(4).Take(msgLen).ToArray();
// At this point, the ack/nak is the first byte
if (message[0] == 0x41)
// parse it
// If it's at least got the header, then process it,
while (newBytes.Length > 4 && newBytes[0] == 0xAA && newBytes[1] == 0xFF)
{
switch (message[1]) // type byte
var msgLen = newBytes[3];
// if the buffer is shorter than the header (3) + message (msgLen) + checksum (1),
// give and save it for next time
if (newBytes.Length < msgLen + 4)
break;
// Good length, grab the message
var message = newBytes.Skip(4).Take(msgLen).ToArray();
// At this point, the ack/nak is the first byte
if (message[0] == 0x41)
{
case 0x00: // General status
//UpdatePowerFB(message[2], message[5]); // "power" can be misrepresented when the display sleeps
switch (message[1]) // type byte
{
case 0x00: // General status
//UpdatePowerFB(message[2], message[5]); // "power" can be misrepresented when the display sleeps
// Handle the first power on fb when waiting for it.
if (IsPoweringOnIgnorePowerFb && message[2] == 0x01)
IsPoweringOnIgnorePowerFb = false;
// Ignore general-status power off messages when powering up
if (!(IsPoweringOnIgnorePowerFb && message[2] == 0x00))
UpdatePowerFB(message[2]);
UpdateVolumeFB(message[3]);
UpdateMuteFb(message[4]);
UpdateInputFb(message[5]);
break;
// Handle the first power on fb when waiting for it.
if (IsPoweringOnIgnorePowerFb && message[2] == 0x01)
IsPoweringOnIgnorePowerFb = false;
// Ignore general-status power off messages when powering up
if (!(IsPoweringOnIgnorePowerFb && message[2] == 0x00))
UpdatePowerFB(message[2]);
UpdateVolumeFB(message[3]);
UpdateMuteFb(message[4]);
UpdateInputFb(message[5]);
break;
case 0x11:
UpdatePowerFB(message[2]);
break;
case 0x11:
UpdatePowerFB(message[2]);
break;
case 0x12:
UpdateVolumeFB(message[2]);
break;
case 0x12:
UpdateVolumeFB(message[2]);
break;
case 0x13:
UpdateMuteFb(message[2]);
break;
case 0x13:
UpdateMuteFb(message[2]);
break;
case 0x14:
UpdateInputFb(message[2]);
break;
case 0x14:
UpdateInputFb(message[2]);
break;
default:
break;
default:
break;
}
}
// Skip over what we've used and save the rest for next time
newBytes = newBytes.Skip(5 + msgLen).ToArray();
}
// Skip over what we've used and save the rest for next time
newBytes = newBytes.Skip(5 + msgLen).ToArray();
}
break; // parsing will mean we can stop looking for header in loop
}
}
// Save whatever partial message is here
IncomingBuffer = newBytes;
break; // parsing will mean we can stop looking for header in loop
}
}
// Save whatever partial message is here
IncomingBuffer = newBytes;
}
catch (Exception err)
{
Debug.Console(2, this, "Error parsing feedback: {0}", err);
}
}
/// <summary>