mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-06 00:05:05 +00:00
Touching up comms on Sammy MDC
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using Crestron.SimplSharp;
|
||||
using Crestron.SimplSharpPro;
|
||||
|
||||
@@ -54,17 +55,22 @@ namespace PepperDash.Essentials.Core
|
||||
|
||||
void Port_SerialDataReceived(ComPort ReceivingComPort, ComPortSerialDataEventArgs args)
|
||||
{
|
||||
var bytesHandler = BytesReceived;
|
||||
if (bytesHandler != null)
|
||||
{
|
||||
var bytes = Encoding.GetEncoding(28591).GetBytes(args.SerialData);
|
||||
bytesHandler(this, new GenericCommMethodReceiveBytesArgs(bytes));
|
||||
}
|
||||
var textHandler = TextReceived;
|
||||
if (textHandler != null)
|
||||
textHandler(this, new GenericCommMethodReceiveTextArgs(args.SerialData));
|
||||
OnDataReceived(args.SerialData);
|
||||
}
|
||||
|
||||
void OnDataReceived(string s)
|
||||
{
|
||||
var bytesHandler = BytesReceived;
|
||||
if (bytesHandler != null)
|
||||
{
|
||||
var bytes = Encoding.GetEncoding(28591).GetBytes(s);
|
||||
bytesHandler(this, new GenericCommMethodReceiveBytesArgs(bytes));
|
||||
}
|
||||
var textHandler = TextReceived;
|
||||
if (textHandler != null)
|
||||
textHandler(this, new GenericCommMethodReceiveTextArgs(s));
|
||||
}
|
||||
|
||||
public override bool Deactivate()
|
||||
{
|
||||
return Port.UnRegister() == eDeviceRegistrationUnRegistrationResponse.Success;
|
||||
@@ -83,8 +89,6 @@ namespace PepperDash.Essentials.Core
|
||||
Port.Send(text);
|
||||
}
|
||||
|
||||
//public BoolFeedback IsConnected { get; private set; }
|
||||
|
||||
public void Connect()
|
||||
{
|
||||
}
|
||||
@@ -94,5 +98,18 @@ namespace PepperDash.Essentials.Core
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="s"></param>
|
||||
public void SimulateReceive(string s)
|
||||
{
|
||||
var split = Regex.Split(s, @"(\\{Xx}{0-9a-fA-F}{0-9a-fA-F})");
|
||||
Debug.Console(2, this, "Tokens: {0}", string.Join("--", split));
|
||||
|
||||
|
||||
//OnDataReceived(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
@@ -161,61 +161,69 @@ namespace PepperDash.Essentials.Devices.Displays
|
||||
e.Bytes.CopyTo(newBytes, IncomingBuffer.Length);
|
||||
Debug.Console(2, this, "Buffer+new: {0}", ComTextHelper.GetEscapedText(newBytes));
|
||||
|
||||
ADD A while HERE TOMORROW.
|
||||
// If it's at least got the header, then process it,
|
||||
if (newBytes.Length > 4 && newBytes[0] == 0xAA && newBytes[1] == 0xFF)
|
||||
// Need to find AA FF and have
|
||||
for (int i = 0; i < newBytes.Length; i++)
|
||||
{
|
||||
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)
|
||||
if (newBytes[i] == 0xAA && newBytes[i + 1] == 0xFF)
|
||||
{
|
||||
IncomingBuffer = newBytes;
|
||||
return;
|
||||
}
|
||||
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();
|
||||
Debug.Console(0, this, "Parsing: {0}", ComTextHelper.GetEscapedText(message));
|
||||
|
||||
// At this point, the ack/nak is the first byte
|
||||
if (message[0] == 0x41)
|
||||
{
|
||||
switch (message[1]) // type byte
|
||||
// parse it
|
||||
// If it's at least got the header, then process it,
|
||||
while (newBytes.Length > 4 && newBytes[0] == 0xAA && newBytes[1] == 0xFF)
|
||||
{
|
||||
case 0x00: // General status
|
||||
UpdatePowerFB(message[2]);
|
||||
UpdateVolumeFB(message[3]);
|
||||
UpdateMuteFb(message[4]);
|
||||
UpdateInputFb(message[5]);
|
||||
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;
|
||||
|
||||
case 0x11:
|
||||
UpdatePowerFB(message[2]);
|
||||
break;
|
||||
// Good length, grab the message
|
||||
var message = newBytes.Skip(4).Take(msgLen).ToArray();
|
||||
Debug.Console(0, this, "Parsing: {0}", ComTextHelper.GetEscapedText(message));
|
||||
|
||||
case 0x12:
|
||||
UpdateVolumeFB(message[2]);
|
||||
break;
|
||||
// At this point, the ack/nak is the first byte
|
||||
if (message[0] == 0x41)
|
||||
{
|
||||
switch (message[1]) // type byte
|
||||
{
|
||||
case 0x00: // General status
|
||||
UpdatePowerFB(message[2]);
|
||||
UpdateVolumeFB(message[3]);
|
||||
UpdateMuteFb(message[4]);
|
||||
UpdateInputFb(message[5]);
|
||||
break;
|
||||
|
||||
case 0x13:
|
||||
UpdateMuteFb(message[2]);
|
||||
break;
|
||||
case 0x11:
|
||||
UpdatePowerFB(message[2]);
|
||||
break;
|
||||
|
||||
case 0x14:
|
||||
UpdateInputFb(message[2]);
|
||||
break;
|
||||
case 0x12:
|
||||
UpdateVolumeFB(message[2]);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
case 0x13:
|
||||
UpdateMuteFb(message[2]);
|
||||
break;
|
||||
|
||||
case 0x14:
|
||||
UpdateInputFb(message[2]);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
// 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
|
||||
}
|
||||
// Skip over what we've used and save the rest for next time
|
||||
IncomingBuffer = newBytes.Skip(5 + msgLen).ToArray();
|
||||
}
|
||||
// there's not even a full header in the event. Save it for next time.
|
||||
else
|
||||
IncomingBuffer = newBytes;
|
||||
|
||||
// Save whatever partial message is here
|
||||
IncomingBuffer = newBytes;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -114,9 +114,14 @@ namespace PepperDash.Essentials
|
||||
DefaultVolumeControls = (defaultAudio as IHasVolumeDevice).VolumeDevice;
|
||||
CurrentVolumeControls = DefaultVolumeControls;
|
||||
|
||||
var disp = DefaultDisplay as DisplayBase;
|
||||
OnFeedback = new BoolFeedback(() =>
|
||||
{ return CurrentSourceInfo != null
|
||||
&& CurrentSourceInfo.Type == eSourceListItemType.Route; });
|
||||
{
|
||||
return CurrentSourceInfo != null
|
||||
&& CurrentSourceInfo.Type == eSourceListItemType.Route
|
||||
&& disp != null
|
||||
&& disp.PowerIsOnFeedback.BoolValue;
|
||||
});
|
||||
SourceListKey = "default";
|
||||
EnablePowerOnToLastSource = true;
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -1 +1,3 @@
|
||||
devjson:1 {"deviceKey":"display-1-comMonitor","methodName":"PrintStatus"}
|
||||
devjson:1 {"deviceKey":"display-1-comMonitor","methodName":"PrintStatus"}
|
||||
|
||||
devjson:1 {"deviceKey":"display-1-com","methodName":"SimulateReceive", "params": ["taco"]}
|
||||
Reference in New Issue
Block a user