mirror of
https://github.com/PepperDash/PepperDashCore.git
synced 2026-01-11 19:44:44 +00:00
feat(essentials): #128 Adds ability for CommunicationGather to take multiple delimiters
This commit is contained in:
@@ -48,7 +48,7 @@ namespace PepperDash.Core
|
||||
/// </summary>
|
||||
char Delimiter;
|
||||
|
||||
string StringDelimiter;
|
||||
string[] StringDelimiters;
|
||||
|
||||
/// <summary>
|
||||
/// Fires up a gather, given a IBasicCommunicaion port and char for de
|
||||
@@ -68,12 +68,17 @@ namespace PepperDash.Core
|
||||
/// <param name="port"></param>
|
||||
/// <param name="delimiter"></param>
|
||||
public CommunicationGather(ICommunicationReceiver port, string delimiter)
|
||||
:this(port, new string[] { delimiter} )
|
||||
{
|
||||
Port = port;
|
||||
StringDelimiter = delimiter;
|
||||
port.TextReceived += Port_TextReceivedStringDelimiter;
|
||||
}
|
||||
|
||||
public CommunicationGather(ICommunicationReceiver port, string[] delimiters)
|
||||
{
|
||||
Port = port;
|
||||
StringDelimiters = delimiters;
|
||||
port.TextReceived += Port_TextReceivedStringDelimiter;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disconnects this gather from the Port's TextReceived event. This will not fire LineReceived
|
||||
/// after the this call.
|
||||
@@ -137,20 +142,24 @@ namespace PepperDash.Core
|
||||
// RX: \x0d\x0a+OK "value":"1234"\x0d\x0a
|
||||
// Split: (2) DEVICE get version, +OK "value":"1234"
|
||||
|
||||
var lines = Regex.Split(str, StringDelimiter);
|
||||
if (lines.Length > 1)
|
||||
{
|
||||
for (int i = 0; i < lines.Length - 1; i++)
|
||||
{
|
||||
string strToSend = null;
|
||||
if (IncludeDelimiter)
|
||||
strToSend = lines[i] + StringDelimiter;
|
||||
else
|
||||
strToSend = lines[i];
|
||||
handler(this, new GenericCommMethodReceiveTextArgs(strToSend));
|
||||
}
|
||||
ReceiveBuffer = new StringBuilder(lines[lines.Length - 1]);
|
||||
}
|
||||
// Iterate the delimiters and fire an event for any matching delimiter
|
||||
foreach (var delimiter in StringDelimiters)
|
||||
{
|
||||
var lines = Regex.Split(str, delimiter);
|
||||
if (lines.Length == 0)
|
||||
continue;
|
||||
|
||||
for (int i = 0; i < lines.Length - 1; i++)
|
||||
{
|
||||
string strToSend = null;
|
||||
if (IncludeDelimiter)
|
||||
strToSend = lines[i] + StringDelimiters;
|
||||
else
|
||||
strToSend = lines[i];
|
||||
handler(this, new GenericCommMethodReceiveTextArgs(strToSend, delimiter));
|
||||
}
|
||||
ReceiveBuffer = new StringBuilder(lines[lines.Length - 1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -130,4 +130,15 @@ namespace PepperDash.Core
|
||||
Tx = 2,
|
||||
Both = Rx | Tx
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The available settings for stream debugging response types
|
||||
/// </summary>
|
||||
[Flags]
|
||||
public enum eStreamDebuggingDataTypeSettings
|
||||
{
|
||||
Bytes = 0,
|
||||
Text = 1,
|
||||
Both = Bytes | Text,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,11 +110,18 @@ namespace PepperDash.Core
|
||||
public class GenericCommMethodReceiveTextArgs : EventArgs
|
||||
{
|
||||
public string Text { get; private set; }
|
||||
public string Delimiter { get; private set; }
|
||||
public GenericCommMethodReceiveTextArgs(string text)
|
||||
{
|
||||
Text = text;
|
||||
}
|
||||
|
||||
public GenericCommMethodReceiveTextArgs(string text, string delimiter)
|
||||
:this(text)
|
||||
{
|
||||
Delimiter = delimiter;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stupid S+ Constructor
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user