Esempio n. 1
0
        /// <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());
        }
Esempio n. 2
0
        public OSCPacket Receive()
        {
            try
            {
                IPEndPoint ip = new IPEndPoint(IPAddress.Any, localPort);
                if (this.udpClient.Available > 0)
                {
                    byte[] bytes = this.udpClient.Receive(ref ip);
                    if (bytes != null && bytes.Length > 0)
                    {
                        return(OSCPacket.Unpack(bytes));
                    }
                }
            } catch (Exception e) {
                //Debug.Log( e.ToString() );
                return(null);
            }

            return(null);
        }
Esempio n. 3
0
        public static new OSCBundle Unpack(byte[] bytes, ref int start, int end)
        {
            string address = unpackString(bytes, ref start);

            // Console.WriteLine("bundle: " + address);
            if (!address.Equals(BUNDLE))
            {
                return(null);                                    // TODO
            }
            DateTime  timestamp = unpackTimeTag(bytes, ref start);
            OSCBundle bundle    = new OSCBundle(timestamp);

            while (start < end)
            {
                int length  = unpackInt(bytes, ref start);
                int sub_end = start + length;
                bundle.Append(OSCPacket.Unpack(bytes, ref start, sub_end));
            }

            return(bundle);
        }