mirror of
https://github.com/PepperDash/PepperDashCore.git
synced 2026-01-11 19:44:44 +00:00
Merge pull request #129 from PepperDash/feature/add-multiple-delimiters-for-communicationGather
Feature/add multiple delimiters for communication gather
This commit is contained in:
@@ -48,7 +48,7 @@ namespace PepperDash.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
char Delimiter;
|
char Delimiter;
|
||||||
|
|
||||||
string StringDelimiter;
|
string[] StringDelimiters;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Fires up a gather, given a IBasicCommunicaion port and char for de
|
/// 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="port"></param>
|
||||||
/// <param name="delimiter"></param>
|
/// <param name="delimiter"></param>
|
||||||
public CommunicationGather(ICommunicationReceiver port, string delimiter)
|
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>
|
/// <summary>
|
||||||
/// Disconnects this gather from the Port's TextReceived event. This will not fire LineReceived
|
/// Disconnects this gather from the Port's TextReceived event. This will not fire LineReceived
|
||||||
/// after the this call.
|
/// after the this call.
|
||||||
@@ -137,20 +142,24 @@ namespace PepperDash.Core
|
|||||||
// RX: \x0d\x0a+OK "value":"1234"\x0d\x0a
|
// RX: \x0d\x0a+OK "value":"1234"\x0d\x0a
|
||||||
// Split: (2) DEVICE get version, +OK "value":"1234"
|
// Split: (2) DEVICE get version, +OK "value":"1234"
|
||||||
|
|
||||||
var lines = Regex.Split(str, StringDelimiter);
|
// Iterate the delimiters and fire an event for any matching delimiter
|
||||||
if (lines.Length > 1)
|
foreach (var delimiter in StringDelimiters)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < lines.Length - 1; i++)
|
var lines = Regex.Split(str, delimiter);
|
||||||
{
|
if (lines.Length == 1)
|
||||||
string strToSend = null;
|
continue;
|
||||||
if (IncludeDelimiter)
|
|
||||||
strToSend = lines[i] + StringDelimiter;
|
for (int i = 0; i < lines.Length - 1; i++)
|
||||||
else
|
{
|
||||||
strToSend = lines[i];
|
string strToSend = null;
|
||||||
handler(this, new GenericCommMethodReceiveTextArgs(strToSend));
|
if (IncludeDelimiter)
|
||||||
}
|
strToSend = lines[i] + delimiter;
|
||||||
ReceiveBuffer = new StringBuilder(lines[lines.Length - 1]);
|
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,
|
Tx = 2,
|
||||||
Both = Rx | Tx
|
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 class GenericCommMethodReceiveTextArgs : EventArgs
|
||||||
{
|
{
|
||||||
public string Text { get; private set; }
|
public string Text { get; private set; }
|
||||||
|
public string Delimiter { get; private set; }
|
||||||
public GenericCommMethodReceiveTextArgs(string text)
|
public GenericCommMethodReceiveTextArgs(string text)
|
||||||
{
|
{
|
||||||
Text = text;
|
Text = text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GenericCommMethodReceiveTextArgs(string text, string delimiter)
|
||||||
|
:this(text)
|
||||||
|
{
|
||||||
|
Delimiter = delimiter;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Stupid S+ Constructor
|
/// Stupid S+ Constructor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user