/// <summary> /// Convert the Osc Time Tag to a byte array. /// </summary> /// <returns>A byte array containing the Osc Time Tag.</returns> public byte[] ToByteArray() { List <byte> timeStamp = new List <byte>(); byte[] secondsSinceEpoch = BitConverter.GetBytes(SecondsSinceEpoch); byte[] fractionalSecond = BitConverter.GetBytes(FractionalSecond); if (BitConverter.IsLittleEndian) // != OscPacket.LittleEndianByteOrder) { secondsSinceEpoch = OSCPacket.swapEndian(secondsSinceEpoch); fractionalSecond = OSCPacket.swapEndian(fractionalSecond); } timeStamp.AddRange(secondsSinceEpoch); timeStamp.AddRange(fractionalSecond); return(timeStamp.ToArray()); }
/// <summary> /// Writes a packet to the socket. /// </summary> /// <param name="packet">The packet to be sent</param> public async Task SendAsync(OSCPacket packet) { byte[] data = packet.BinaryData; try { for (int i = 0; i < 1; i++) { oscWriter.WriteBytes(data); await oscWriter.StoreAsync(); Debug.WriteLine(packet.ToString() + DateTime.UtcNow.ToString() + DateTime.UtcNow.Millisecond.ToString()); } } catch (Exception e) { Debug.WriteLine(e.Message); Debug.WriteLine(e.StackTrace); } }
public static new OSCBundle Unpack(byte[] bytes, ref int start, int end) { string address = oscString.unpack(bytes, ref start); //Console.WriteLine("bundle: " + address); if (!address.Equals(BUNDLE)) { return(null); // TODO } DateTime timestamp = oscDateTime.unpack(bytes, ref start); OSCBundle bundle = new OSCBundle(timestamp); while (start < end) { int length = oscInt.unpack(bytes, ref start); int sub_end = start + length; bundle.Append(OSCPacket.Unpack(bytes, ref start, sub_end)); } return(bundle); }