mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-15 20:54:55 +00:00
Added Simulate receive on com port
This commit is contained in:
@@ -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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user