mirror of
https://github.com/jwetzell/QControlKit.git
synced 2026-08-16 04:43:32 +00:00
* SlipFrame.cs:
* TCPClient.cs: Split SLIP frame stuff to separate class * QControlKit.csproj: Bump version number
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
<Authors>Joel Wetzell</Authors>
|
<Authors>Joel Wetzell</Authors>
|
||||||
<Version>1.0.0-devel</Version>
|
<Version>1.0.0-devel</Version>
|
||||||
<PackOnBuild>true</PackOnBuild>
|
<PackOnBuild>true</PackOnBuild>
|
||||||
<PackageVersion>0.0.23</PackageVersion>
|
<PackageVersion>0.0.24</PackageVersion>
|
||||||
<PackageId>QControlKit</PackageId>
|
<PackageId>QControlKit</PackageId>
|
||||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||||
<Summary>Unofficial C# port of Figure53's QLabKit.objc</Summary>
|
<Summary>Unofficial C# port of Figure53's QLabKit.objc</Summary>
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace SharpOSC
|
||||||
|
{
|
||||||
|
public static class SlipFrame
|
||||||
|
{
|
||||||
|
static readonly byte END = 0xc0;
|
||||||
|
static readonly byte ESC = 0xdb;
|
||||||
|
static readonly byte ESC_END = 0xDC;
|
||||||
|
static readonly byte ESC_ESC = 0xDD;
|
||||||
|
|
||||||
|
public static List<byte[]> Decode(byte[] data)
|
||||||
|
{
|
||||||
|
List<byte[]> messages = new List<byte[]>();
|
||||||
|
|
||||||
|
List<byte> buffer = new List<byte>();
|
||||||
|
for (int i = 0; i < data.Length; i++)
|
||||||
|
{
|
||||||
|
if (data[i] == END && buffer.Count > 0)
|
||||||
|
{
|
||||||
|
messages.Add(buffer.ToArray());
|
||||||
|
buffer.Clear();
|
||||||
|
}
|
||||||
|
else if (data[i] != END)
|
||||||
|
{
|
||||||
|
buffer.Add(data[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return messages;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] Encode(byte[] data)
|
||||||
|
{
|
||||||
|
List<byte> slipData = new List<byte>();
|
||||||
|
|
||||||
|
byte[] esc_end = { ESC, ESC_END };
|
||||||
|
byte[] esc_esc = { ESC, ESC_ESC };
|
||||||
|
byte[] end = { END };
|
||||||
|
|
||||||
|
int length = data.Length;
|
||||||
|
for (int i = 0; i < length; i++)
|
||||||
|
{
|
||||||
|
if (data[i] == END)
|
||||||
|
{
|
||||||
|
slipData.AddRange(esc_end);
|
||||||
|
}
|
||||||
|
else if (data[i] == ESC)
|
||||||
|
{
|
||||||
|
slipData.AddRange(esc_esc);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
slipData.Add(data[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
slipData.AddRange(end);
|
||||||
|
return slipData.ToArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -32,15 +32,11 @@ namespace SharpOSC
|
|||||||
|
|
||||||
private Queue<OscPacket> SendQueue = new Queue<OscPacket>();
|
private Queue<OscPacket> SendQueue = new Queue<OscPacket>();
|
||||||
|
|
||||||
private Thread receivingThread;
|
|
||||||
private Thread sendThread;
|
private Thread sendThread;
|
||||||
|
|
||||||
string _address;
|
string _address;
|
||||||
|
|
||||||
byte END = 0xc0;
|
|
||||||
byte ESC = 0xdb;
|
|
||||||
byte ESC_END = 0xDC;
|
|
||||||
byte ESC_ESC = 0xDD;
|
|
||||||
|
|
||||||
SimpleTcpClient simpleClient;
|
SimpleTcpClient simpleClient;
|
||||||
|
|
||||||
@@ -64,7 +60,7 @@ namespace SharpOSC
|
|||||||
|
|
||||||
private void DataReceived(object sender, DataReceivedEventArgs e)
|
private void DataReceived(object sender, DataReceivedEventArgs e)
|
||||||
{
|
{
|
||||||
List<byte[]> messages = SlipDecode(e.Data);
|
List<byte[]> messages = SlipFrame.Decode(e.Data);
|
||||||
for(int i = 0; i < messages.Count; i++)
|
for(int i = 0; i < messages.Count; i++)
|
||||||
{
|
{
|
||||||
OscPacket packet = OscPacket.GetPacket(messages[i]);
|
OscPacket packet = OscPacket.GetPacket(messages[i]);
|
||||||
@@ -122,7 +118,7 @@ namespace SharpOSC
|
|||||||
|
|
||||||
public void Send(byte[] message)
|
public void Send(byte[] message)
|
||||||
{
|
{
|
||||||
byte[] slipData = SlipEncode(message);
|
byte[] slipData = SlipFrame.Encode(message);
|
||||||
simpleClient.Send(slipData);
|
simpleClient.Send(slipData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,54 +139,6 @@ namespace SharpOSC
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] SlipEncode(byte[] data)
|
|
||||||
{
|
|
||||||
List<byte> slipData = new List<byte>();
|
|
||||||
|
|
||||||
byte[] esc_end = { ESC, ESC_END };
|
|
||||||
byte[] esc_esc = { ESC, ESC_ESC };
|
|
||||||
byte[] end = { END };
|
|
||||||
|
|
||||||
int length = data.Length;
|
|
||||||
for (int i = 0; i < length; i++)
|
|
||||||
{
|
|
||||||
if (data[i] == END)
|
|
||||||
{
|
|
||||||
slipData.AddRange(esc_end);
|
|
||||||
}
|
|
||||||
else if (data[i] == ESC)
|
|
||||||
{
|
|
||||||
slipData.AddRange(esc_esc);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
slipData.Add(data[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
slipData.AddRange(end);
|
|
||||||
return slipData.ToArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<byte[]> SlipDecode(byte[] data)
|
|
||||||
{
|
|
||||||
List<byte[]> messages = new List<byte[]>();
|
|
||||||
|
|
||||||
List<byte> buffer = new List<byte>();
|
|
||||||
for(int i = 0; i < data.Length; i++)
|
|
||||||
{
|
|
||||||
if(data[i] == END && buffer.Count > 0)
|
|
||||||
{
|
|
||||||
messages.Add(buffer.ToArray());
|
|
||||||
buffer.Clear();
|
|
||||||
}
|
|
||||||
else if (data[i] != END)
|
|
||||||
{
|
|
||||||
buffer.Add(data[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return messages;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Close()
|
public void Close()
|
||||||
{
|
{
|
||||||
Log.Information("[tcpclient] Close() was requested");
|
Log.Information("[tcpclient] Close() was requested");
|
||||||
|
|||||||
Reference in New Issue
Block a user