diff --git a/QControlKit/QControlKit.csproj b/QControlKit/QControlKit.csproj
index 1f52d5e..7b7e97b 100644
--- a/QControlKit/QControlKit.csproj
+++ b/QControlKit/QControlKit.csproj
@@ -6,7 +6,7 @@
Joel Wetzell
1.0.0-devel
true
- 0.0.23
+ 0.0.24
QControlKit
MIT
Unofficial C# port of Figure53's QLabKit.objc
diff --git a/QControlKit/SharpOSC/SlipFrame.cs b/QControlKit/SharpOSC/SlipFrame.cs
new file mode 100644
index 0000000..e326a75
--- /dev/null
+++ b/QControlKit/SharpOSC/SlipFrame.cs
@@ -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 Decode(byte[] data)
+ {
+ List messages = new List();
+
+ List buffer = new List();
+ 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 slipData = new List();
+
+ 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();
+ }
+ }
+}
diff --git a/QControlKit/SharpOSC/TCPClient.cs b/QControlKit/SharpOSC/TCPClient.cs
index 2f430bf..3436e08 100644
--- a/QControlKit/SharpOSC/TCPClient.cs
+++ b/QControlKit/SharpOSC/TCPClient.cs
@@ -32,15 +32,11 @@ namespace SharpOSC
private Queue SendQueue = new Queue();
- private Thread receivingThread;
private Thread sendThread;
string _address;
- byte END = 0xc0;
- byte ESC = 0xdb;
- byte ESC_END = 0xDC;
- byte ESC_ESC = 0xDD;
+
SimpleTcpClient simpleClient;
@@ -64,7 +60,7 @@ namespace SharpOSC
private void DataReceived(object sender, DataReceivedEventArgs e)
{
- List messages = SlipDecode(e.Data);
+ List messages = SlipFrame.Decode(e.Data);
for(int i = 0; i < messages.Count; i++)
{
OscPacket packet = OscPacket.GetPacket(messages[i]);
@@ -122,7 +118,7 @@ namespace SharpOSC
public void Send(byte[] message)
{
- byte[] slipData = SlipEncode(message);
+ byte[] slipData = SlipFrame.Encode(message);
simpleClient.Send(slipData);
}
@@ -143,54 +139,6 @@ namespace SharpOSC
}
}
- public byte[] SlipEncode(byte[] data)
- {
- List slipData = new List();
-
- 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 SlipDecode(byte[] data)
- {
- List messages = new List();
-
- List buffer = new List();
- 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()
{
Log.Information("[tcpclient] Close() was requested");