Added ICommunicationReceiver Interface

This commit is contained in:
Heath Volmer
2017-06-02 10:50:39 -06:00
parent 2d3fb963fa
commit 9a597ee1e0
6 changed files with 27 additions and 8 deletions

Binary file not shown.

View File

@@ -135,10 +135,22 @@ namespace PepperDash.Core
var output = Regex.Replace(args.Text,
@"\p{Cc}",
a => string.Format("[{0:X2}]", (byte)a.Value[0]));
Debug.Console(2, Port, "RX: '{0}", output);
Debug.Console(2, Port, "RX: '{0}'", output);
}
ReceiveBuffer.Append(args.Text);
var str = ReceiveBuffer.ToString();
// Case: Receiving DEVICE get version\x0d\0x0a+OK "value":"1234"\x0d\x0a
// RX: DEV
// Split: (1) "DEV"
// RX: I
// Split: (1) "DEVI"
// RX: CE get version
// Split: (1) "DEVICE get version"
// 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)
{

View File

@@ -10,19 +10,26 @@ using Newtonsoft.Json.Linq;
namespace PepperDash.Core
{
/// <summary>
/// An incoming communication stream
/// </summary>
public interface ICommunicationReceiver : IKeyed
{
event EventHandler<GenericCommMethodReceiveBytesArgs> BytesReceived;
event EventHandler<GenericCommMethodReceiveTextArgs> TextReceived;
bool IsConnected { get; }
void Connect();
void Disconnect();
}
/// <summary>
/// Represents a device that uses basic connection
/// </summary>
public interface IBasicCommunication : IKeyed
public interface IBasicCommunication : ICommunicationReceiver
{
event EventHandler<GenericCommMethodReceiveBytesArgs> BytesReceived;
event EventHandler<GenericCommMethodReceiveTextArgs> TextReceived;
bool IsConnected { get; }
void SendText(string text);
void SendBytes(byte[] bytes);
void Connect();
void Disconnect();
}
/// <summary>