public WaxPacket FromOscBundle(OscBundle oscBundle, string topic) { List <WaxSample> sampleData = new List <WaxSample>(); ushort deviceId = 0xffff; ulong timestamp = oscBundle.Timestamp; foreach (OscData oscData in oscBundle.Parts) { OscMessage oscMessage = oscData as OscMessage; if (oscMessage == null) { continue; } string t = (topic == null ? "/wax" : topic); if (oscMessage.Address != t) { continue; } if (oscMessage.Arguments.Length < 5) { continue; } uint index; short x, y, z; deviceId = (ushort)(int)oscMessage.Arguments[0]; index = (uint)(int)oscMessage.Arguments[1]; x = (short)((float)oscMessage.Arguments[2] * 256.0f); y = (short)((float)oscMessage.Arguments[3] * 256.0f); z = (short)((float)oscMessage.Arguments[4] * 256.0f); WaxSample waxSample = new WaxSample(OscMessage.DateTimeFromTimestamp(timestamp), index, x, y, z); Console.WriteLine(waxSample.ToString()); sampleData.Add(waxSample); } byte version = 0; byte battery = 0; ushort adcSample = 0; ushort sequenceId = 0xffff; // TODO: Fix this to something sensible byte format = 0; byte sampleCount = (byte)sampleData.Count; return(new WaxPacket(OscMessage.DateTimeFromTimestamp(timestamp), deviceId, version, battery, adcSample, sequenceId, format, sampleCount, sampleData.ToArray())); }
public OscBundleEventArgs(DateTime timestamp, OscBundle oscBundle) { Timestamp = timestamp; Bundle = oscBundle; AutoUnpack = true; }
private void toolStripButtonConnect_Click(object sender, EventArgs e) { // Remove old wax manager if (waxManager != null) { waxManager.Dispose(); waxManager = null; } if (!toolStripButtonConnect.Checked) { // Find port name if (PortName.Length != 0) { string port = FindPort(PortName); if (port != null) { PortName = port; } } waxManager = new WaxManager(); if (PortName.Length > 0) { // Create WAX manager try { string initiallySend = null; if (checkBoxSetMode.Checked) { // Set SLIP mode... [0=NONE,1=SLIP,2=TEXT,3=OSC] initiallySend = "\r\nMODE=1\r\n"; } waxManager.AddPacketSource(new SlipSource<WaxPacket>(waxManager.WaxPacketConverter, SlipSource<WaxPacket>.OpenSerialPort(PortName, initiallySend))); if (checkBoxBroadcast.Checked) { waxManager.AddPacketDest(new StompDest<WaxPacket>(waxManager.WaxPacketConverter, "localhost")); } } catch (Exception ex) { MessageBox.Show(this, "Error: " + ex.Message, "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { //MessageBox.Show(this, "Error: Port not specified.", "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error); waxManager.AddPacketSource(new StompSource<WaxPacket>(waxManager.WaxPacketConverter, "localhost")); if (OscReceive) { waxManager.AddPacketSource(new OscSource<WaxPacket>(waxManager.WaxPacketConverter, "localhost:" + OscPort + "/wax")); } } if (waxManager != null) { // Set log file string file = LogFile; if (file != null && file.Length > 0) { DateTime now = DateTime.Now; string date = now.ToString(@"yyyy-MM-dd"); string time = now.ToString(@"HH-mm-ss"); file = file.Replace("{date}", date); file = file.Replace("{time}", time); waxManager.AddPacketDest(new LogDest<WaxPacket>(waxManager.WaxPacketConverter, new StreamWriter(new FileStream(file, FileMode.Append)))); } // Set WAX OSC transmission if (OscHost != null && OscHost.Length > 0 && OscPort > 0) { OscTransmitter tinyOscTransmitter = new OscTransmitter(OscHost, OscPort); waxManager.ReceivedPacket += (s, ea) => { try { WaxSample[] samples = ea.Packet.Samples; OscMessage[] messages = new OscMessage[samples.Length]; for (int i = 0; i < samples.Length; i++) { messages[i] = new OscMessage("/wax", (int)ea.Packet.DeviceId, samples[i].Index, samples[i].X / 256.0f, samples[i].Y / 256.0f, samples[i].Z / 256.0f); } OscBundle bundle = new OscBundle(OscBundle.TIMESTAMP_NOW, messages); tinyOscTransmitter.Send(bundle); } catch (Exception ex) { Console.Error.WriteLine("ERROR: Problem sending OSC packet - " + ex.Message); } }; } } // Set History panel to use WAX manager historyPanel.WaxManager = waxManager; // Update connection button toolStripButtonConnect.Checked = (waxManager != null); } else { // Update connection button toolStripButtonConnect.Checked = false; } // Update tool bar status bool connected = toolStripButtonConnect.Checked; toolStripLabelPort.Enabled = !connected; toolStripComboBoxPort.Enabled = !connected; toolStripLabelFile.Enabled = !connected; toolStripTextBoxLogFile.Enabled = !connected; toolStripButtonChooseFile.Enabled = !connected; // ... }