mirror of
https://github.com/jwetzell/qController.git
synced 2026-08-06 16:03:48 +00:00
fix up SLIP decoding and data-less qlab replies
This commit is contained in:
@@ -81,21 +81,41 @@ namespace qController.Communication
|
||||
public void ParseCueUpdateInfo(OscMessage msg)
|
||||
{
|
||||
JToken cueUpdate = OSC2JSON(msg);
|
||||
QCue cue = JsonConvert.DeserializeObject<QCue>(cueUpdate.ToString());
|
||||
OnCueInfoUpdated(cue);
|
||||
if(cueUpdate != null)
|
||||
{
|
||||
QCue cue = JsonConvert.DeserializeObject<QCue>(cueUpdate.ToString());
|
||||
OnCueInfoUpdated(cue);
|
||||
}else
|
||||
{
|
||||
Log.Debug("QPARSER - cue update info does not have any data");
|
||||
}
|
||||
}
|
||||
|
||||
public void ParseSelectedCueInfo(OscMessage msg){
|
||||
JToken selectedCue = OSC2JSON(msg);
|
||||
QCue cue = JsonConvert.DeserializeObject<QCue>(selectedCue.ToString());
|
||||
OnSelectedCueUpdated(cue);
|
||||
if (selectedCue != null)
|
||||
{
|
||||
QCue cue = JsonConvert.DeserializeObject<QCue>(selectedCue.ToString());
|
||||
OnSelectedCueUpdated(cue);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Debug("QPARSER - selected does not have any data");
|
||||
}
|
||||
}
|
||||
|
||||
public void ParseQInfo(OscMessage msg)
|
||||
{
|
||||
JToken qInfo = OSC2JSON(msg);
|
||||
List<QWorkspaceInfo> qWorkspaceInfo = JsonConvert.DeserializeObject<List<QWorkspaceInfo>>(qInfo.ToString());
|
||||
OnWorkspaceInfoReceived(qWorkspaceInfo);
|
||||
if (qInfo != null)
|
||||
{
|
||||
List<QWorkspaceInfo> qWorkspaceInfo = JsonConvert.DeserializeObject<List<QWorkspaceInfo>>(qInfo.ToString());
|
||||
OnWorkspaceInfoReceived(qWorkspaceInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Debug("QPARSER - selected does not have any data");
|
||||
}
|
||||
}
|
||||
|
||||
public void ParseWorkspaceInfo(OscMessage msg)
|
||||
@@ -131,8 +151,15 @@ namespace qController.Communication
|
||||
{
|
||||
string cue_id = msg.Address.Split('/')[3];
|
||||
JToken children_obj = OSC2JSON(msg);
|
||||
List<QCue> children = JsonConvert.DeserializeObject<List<QCue>>(children_obj.ToString());
|
||||
OnChildrenUpdated(cue_id, children);
|
||||
if(children_obj != null)
|
||||
{
|
||||
List<QCue> children = JsonConvert.DeserializeObject<List<QCue>>(children_obj.ToString());
|
||||
OnChildrenUpdated(cue_id, children);
|
||||
}else
|
||||
{
|
||||
Log.Debug("QPARSER - children info message does not have any data");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,6 +184,7 @@ namespace qController.Communication
|
||||
|
||||
protected virtual void OnPlaybackPositionUpdated(string id)
|
||||
{
|
||||
Log.Error(id);
|
||||
PlaybackPositionUpdated?.Invoke(this, new PlaybackPositionArgs() { PlaybackPosition = id });
|
||||
}
|
||||
protected virtual void OnConnectionStatusChanged(string status, string workspace_id)
|
||||
|
||||
@@ -15,9 +15,14 @@ namespace SharpOSC
|
||||
this.Address = address;
|
||||
Arguments = new List<object>();
|
||||
Arguments.AddRange(args);
|
||||
}
|
||||
|
||||
public override byte[] GetBytes()
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "Address: " + Address + " Args: " + string.Join(",", Arguments);
|
||||
}
|
||||
|
||||
public override byte[] GetBytes()
|
||||
{
|
||||
List<byte[]> parts = new List<byte[]>();
|
||||
|
||||
|
||||
@@ -15,6 +15,11 @@ namespace SharpOSC
|
||||
return parseMessage(OscData);
|
||||
}
|
||||
|
||||
public static OscMessage GetMessage(byte[] OscData)
|
||||
{
|
||||
return parseMessage(OscData);
|
||||
}
|
||||
|
||||
public abstract byte[] GetBytes();
|
||||
|
||||
#region Parse OSC packages
|
||||
|
||||
@@ -8,12 +8,12 @@ namespace SharpOSC
|
||||
public static readonly byte ESC = 0xdb;
|
||||
public static readonly byte ESC_END = 0xDC;
|
||||
public static readonly byte ESC_ESC = 0xDD;
|
||||
private static List<byte> buffer = new List<byte>();
|
||||
|
||||
public static List<byte[]> Decode(byte[] data)
|
||||
{
|
||||
List<byte[]> messages = new List<byte[]>();
|
||||
|
||||
List<byte> buffer = new List<byte>();
|
||||
bool escapeNext = false;
|
||||
for (int i = 0; i < data.Length; i++)
|
||||
{
|
||||
|
||||
@@ -36,8 +36,6 @@ namespace SharpOSC
|
||||
|
||||
TcpSharpSocketClient? tcpClient;
|
||||
|
||||
private List<byte> frameStream = new List<byte>();
|
||||
|
||||
public TCPClient(string address, int port)
|
||||
{
|
||||
_port = port;
|
||||
@@ -78,38 +76,27 @@ namespace SharpOSC
|
||||
|
||||
private void DataReceived(object sender, OnClientDataReceivedEventArgs e)
|
||||
{
|
||||
frameStream.AddRange(e.Data);
|
||||
|
||||
int i = 0;
|
||||
int frameEnd = frameStream.FindIndex(1, frameByte => frameByte.Equals(SlipFrame.END));
|
||||
while (frameEnd > 0)
|
||||
List<byte[]> messages = SlipFrame.Decode(e.Data);
|
||||
_log.Debug("tcpclient: " + messages.Count + " messages pulled from slip");
|
||||
foreach (var message in messages)
|
||||
{
|
||||
List<byte> frame = frameStream.GetRange(0, frameEnd + 1);
|
||||
frameStream.RemoveRange(0, frameEnd + 1);
|
||||
List<byte[]> messages = SlipFrame.Decode(frame.ToArray());
|
||||
foreach (var message in messages)
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
OscPacket packet = OscPacket.GetPacket(message);
|
||||
OscMessage responseMessage = (OscMessage)packet;
|
||||
if (packet == null)
|
||||
{
|
||||
_log.Error("packet is null");
|
||||
}
|
||||
|
||||
if (responseMessage == null)
|
||||
{
|
||||
_log.Error("responeMessage is null");
|
||||
}
|
||||
OscMessage responseMessage = OscPacket.GetMessage(message);
|
||||
if (responseMessage == null)
|
||||
{
|
||||
_log.Error("responseMessage is null");
|
||||
} else
|
||||
{
|
||||
OnMessageReceived(responseMessage);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_log.Error($"Exception parsing OSC message: {ex.ToString()}");
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_log.Error($"Exception parsing OSC message: {ex.ToString()}");
|
||||
}
|
||||
frameEnd = frameStream.FindIndex(0, frameByte => frameByte.Equals(SlipFrame.END));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -289,6 +289,9 @@ namespace qController
|
||||
}
|
||||
qCell.UpdateSelectedCue(cue);
|
||||
});
|
||||
} else
|
||||
{
|
||||
Log.Error("Playback Position has been updated but cue is null?");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user