Added Simulate receive on com port

This commit is contained in:
Heath Volmer
2017-08-16 11:15:49 -06:00
parent 667c511515
commit 7320f47d60
8 changed files with 37 additions and 4 deletions

View File

@@ -105,11 +105,18 @@ namespace PepperDash.Essentials.Core
/// <param name="s"></param> /// <param name="s"></param>
public void SimulateReceive(string s) public void SimulateReceive(string s)
{ {
var split = Regex.Split(s, @"(\\{Xx}{0-9a-fA-F}{0-9a-fA-F})"); // split out hex chars and build string
Debug.Console(2, this, "Tokens: {0}", string.Join("--", split)); var split = Regex.Split(s, @"(\\[Xx][0-9a-fA-F][0-9a-fA-F])");
StringBuilder b = new StringBuilder();
foreach (var t in split)
{
if (t.StartsWith(@"\") && t.Length == 4)
b.Append((char)(Convert.ToByte(t.Substring(2, 2), 16)));
else
b.Append(t);
}
//OnDataReceived(s); OnDataReceived(b.ToString());
} }
} }
} }

View File

@@ -53,6 +53,8 @@ namespace PepperDash.Essentials.Core
{ {
CrestronConsole.ConsoleCommandResponse(DeviceJsonApi.GetApiMethods(s)); CrestronConsole.ConsoleCommandResponse(DeviceJsonApi.GetApiMethods(s));
}, "apimethods", "", ConsoleAccessLevelEnum.AccessOperator); }, "apimethods", "", ConsoleAccessLevelEnum.AccessOperator);
CrestronConsole.AddNewConsoleCommand(SimulateComReceiveOnDevice, "devsimreceive",
"Simulates incoming data on a com device", ConsoleAccessLevelEnum.AccessOperator);
} }
/// <summary> /// <summary>
@@ -206,5 +208,29 @@ namespace PepperDash.Essentials.Core
return null; return null;
} }
/// <summary>
/// Console handler that simulates com port data receive
/// </summary>
/// <param name="s"></param>
public static void SimulateComReceiveOnDevice(string s)
{
// devcomsim:1 xyzabc
var match = Regex.Match(s, @"(\S*)\s*(.*)");
if (match.Groups.Count < 3)
{
CrestronConsole.ConsoleCommandResponse(" Format: devsimreceive:P <device key> <string to send>");
return;
}
//Debug.Console(2, "**** {0} - {1} ****", match.Groups[1].Value, match.Groups[2].Value);
ComPortController com = GetDeviceForKey(match.Groups[1].Value) as ComPortController;
if (com == null)
{
CrestronConsole.ConsoleCommandResponse("'{0}' is not a comm port device", match.Groups[1].Value);
return;
}
com.SimulateReceive(match.Groups[2].Value);
}
} }
} }