mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-01-16 22:14:54 +00:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f77f36761f | ||
|
|
4361fe6186 | ||
|
|
09bc84346d | ||
|
|
00e3e6af35 | ||
|
|
61f24321c3 | ||
|
|
8f530aa7fe | ||
|
|
36cd356bc5 | ||
|
|
b72f55228a | ||
|
|
1017464980 |
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
29
PepperDashEssentials/Bridges/C2nRthsControllerBridge.cs
Normal file
29
PepperDashEssentials/Bridges/C2nRthsControllerBridge.cs
Normal 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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
53
PepperDashEssentials/Bridges/StatusSignControllerBridge.cs
Normal file
53
PepperDashEssentials/Bridges/StatusSignControllerBridge.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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" />
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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))
|
||||
|
||||
@@ -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" />
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user