Touching up comms on Sammy MDC

This commit is contained in:
Heath Volmer
2017-08-15 19:30:48 -06:00
parent 8586796a6d
commit 667c511515
10 changed files with 88 additions and 56 deletions

View File

@@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Text.RegularExpressions;
using Crestron.SimplSharp; using Crestron.SimplSharp;
using Crestron.SimplSharpPro; using Crestron.SimplSharpPro;
@@ -53,16 +54,21 @@ namespace PepperDash.Essentials.Core
} }
void Port_SerialDataReceived(ComPort ReceivingComPort, ComPortSerialDataEventArgs args) void Port_SerialDataReceived(ComPort ReceivingComPort, ComPortSerialDataEventArgs args)
{
OnDataReceived(args.SerialData);
}
void OnDataReceived(string s)
{ {
var bytesHandler = BytesReceived; var bytesHandler = BytesReceived;
if (bytesHandler != null) if (bytesHandler != null)
{ {
var bytes = Encoding.GetEncoding(28591).GetBytes(args.SerialData); var bytes = Encoding.GetEncoding(28591).GetBytes(s);
bytesHandler(this, new GenericCommMethodReceiveBytesArgs(bytes)); bytesHandler(this, new GenericCommMethodReceiveBytesArgs(bytes));
} }
var textHandler = TextReceived; var textHandler = TextReceived;
if (textHandler != null) if (textHandler != null)
textHandler(this, new GenericCommMethodReceiveTextArgs(args.SerialData)); textHandler(this, new GenericCommMethodReceiveTextArgs(s));
} }
public override bool Deactivate() public override bool Deactivate()
@@ -83,8 +89,6 @@ namespace PepperDash.Essentials.Core
Port.Send(text); Port.Send(text);
} }
//public BoolFeedback IsConnected { get; private set; }
public void Connect() public void Connect()
{ {
} }
@@ -94,5 +98,18 @@ namespace PepperDash.Essentials.Core
} }
#endregion #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);
}
} }
} }

View File

@@ -161,18 +161,22 @@ namespace PepperDash.Essentials.Devices.Displays
e.Bytes.CopyTo(newBytes, IncomingBuffer.Length); e.Bytes.CopyTo(newBytes, IncomingBuffer.Length);
Debug.Console(2, this, "Buffer+new: {0}", ComTextHelper.GetEscapedText(newBytes)); Debug.Console(2, this, "Buffer+new: {0}", ComTextHelper.GetEscapedText(newBytes));
ADD A while HERE TOMORROW. // Need to find AA FF and have
for (int i = 0; i < newBytes.Length; i++)
{
if (newBytes[i] == 0xAA && newBytes[i + 1] == 0xFF)
{
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, // If it's at least got the header, then process it,
if (newBytes.Length > 4 && newBytes[0] == 0xAA && newBytes[1] == 0xFF) while (newBytes.Length > 4 && newBytes[0] == 0xAA && newBytes[1] == 0xFF)
{ {
var msgLen = newBytes[3]; var msgLen = newBytes[3];
// if the buffer is shorter than the header (3) + message (msgLen) + checksum (1), // if the buffer is shorter than the header (3) + message (msgLen) + checksum (1),
// give and save it for next time // give and save it for next time
if (newBytes.Length < msgLen + 4) if (newBytes.Length < msgLen + 4)
{ break;
IncomingBuffer = newBytes;
return;
}
// Good length, grab the message // Good length, grab the message
var message = newBytes.Skip(4).Take(msgLen).ToArray(); var message = newBytes.Skip(4).Take(msgLen).ToArray();
@@ -211,10 +215,14 @@ namespace PepperDash.Essentials.Devices.Displays
} }
} }
// Skip over what we've used and save the rest for next time // Skip over what we've used and save the rest for next time
IncomingBuffer = newBytes.Skip(5 + msgLen).ToArray(); newBytes = newBytes.Skip(5 + msgLen).ToArray();
} }
// there's not even a full header in the event. Save it for next time.
else break; // parsing will mean we can stop looking for header in loop
}
}
// Save whatever partial message is here
IncomingBuffer = newBytes; IncomingBuffer = newBytes;
} }

View File

@@ -114,9 +114,14 @@ namespace PepperDash.Essentials
DefaultVolumeControls = (defaultAudio as IHasVolumeDevice).VolumeDevice; DefaultVolumeControls = (defaultAudio as IHasVolumeDevice).VolumeDevice;
CurrentVolumeControls = DefaultVolumeControls; CurrentVolumeControls = DefaultVolumeControls;
var disp = DefaultDisplay as DisplayBase;
OnFeedback = new BoolFeedback(() => OnFeedback = new BoolFeedback(() =>
{ return CurrentSourceInfo != null {
&& CurrentSourceInfo.Type == eSourceListItemType.Route; }); return CurrentSourceInfo != null
&& CurrentSourceInfo.Type == eSourceListItemType.Route
&& disp != null
&& disp.PowerIsOnFeedback.BoolValue;
});
SourceListKey = "default"; SourceListKey = "default";
EnablePowerOnToLastSource = true; EnablePowerOnToLastSource = true;
} }

View File

@@ -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"]}