/* public static string PacketToStomp(Packet packet) { Hashtable sourceData = new Hashtable(); object[] samples = new object[packet.Samples.Length]; for (int i = 0; i < packet.Samples.Length; i++) { Sample sample = packet.Samples[i]; object[] sampleArray = new object[5]; sampleArray[0] = sample.Timestamp.ToBinary(); sampleArray[1] = sample.Index; sampleArray[2] = sample[0]; sampleArray[3] = sample[1]; sampleArray[4] = sample[2]; samples[i] = sampleArray; } sourceData.Add("Timestamp", packet.Timestamp.ToBinary()); sourceData.Add("DeviceId", packet.DeviceId); sourceData.Add("Version", packet.Version); sourceData.Add("Battery", packet.Battery); sourceData.Add("AdcSample", packet.AdcSample); sourceData.Add("SequenceId", packet.SequenceId); sourceData.Add("Format", packet.Format); sourceData.Add("SampleCount", packet.SampleCount); sourceData.Add("Samples", samples); string json = Json.JsonEncode(sourceData); return json; } */ /* public static Packet PacketFromOscBundle(OscBundle oscBundle, string topic) { List<Sample> sampleData = new List<Sample>(); 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 ? "/teddi" : 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); Sample waxSample = new Sample(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 Packet(OscMessage.DateTimeFromTimestamp(timestamp), deviceId, version, battery, adcSample, sequenceId, format, sampleCount, sampleData.ToArray()); } */ public static OscBundle PacketToOscBundle(Packet packet, string topic, bool cooked) { if (topic == null || topic.Length == 0) { topic = cooked ? "/teddi-cooked/@" : "/teddi/@"; } Sample[] samples = packet.Samples; OscMessage[] messages = new OscMessage[samples.Length]; for (int i = 0; i < samples.Length; i++) { string t = topic; t = t.Replace("@", "" + packet.DeviceId); ushort rawPir = (ushort)samples[i].V; ushort rawAudio = (ushort)samples[i].X; if (cooked) { float temp = Sample.ConvertC((ushort)packet.Temp); float light = Sample.ConvertLux((ushort)packet.Light); float battery = Sample.ConvertV((ushort)packet.Battery); float humidity = Sample.ConvertPercentage((ushort)packet.Humidity); float pir = Sample.ConvertV(rawPir); float audio = Sample.ConvertV(rawAudio); messages[i] = new OscMessage(t, packet.DeviceId, temp, light, battery, humidity, pir, audio, samples[i].Index); } else { messages[i] = new OscMessage(t, packet.DeviceId, packet.Temp, packet.Light, packet.Battery, packet.Humidity, rawPir, rawAudio, samples[i].Index); } } OscBundle bundle = new OscBundle(OscBundle.TIMESTAMP_NOW, messages); return bundle; }
public OscMessageEventArgs(DateTime timestamp, OscMessage oscMessage) { Timestamp = timestamp; Message = oscMessage; }