Exemplo n.º 1
0
        /// <summary>
        /// Unpacks an OSC bundle from a data stream.
        /// </summary>
        /// <param name="data">
        /// A <see cref="System.Byte[]"/>
        /// </param>
        /// <param name="start">
        /// A <see cref="System.Int32"/>
        /// </param>
        /// <param name="end">
        /// A <see cref="System.Int32"/>
        /// </param>
        /// <returns>
        /// A <see cref="OSCBundle"/>
        /// </returns>
        public new static OSCBundle Unpack(byte[] data, ref int start, int end)
        {
            string address = OSCPacket.UnpackValue <string>(data, ref start);

            Trace.Assert(address == BUNDLE);

            long      timeStamp = OSCPacket.UnpackValue <long>(data, ref start);
            OSCBundle bundle    = new OSCBundle(timeStamp);

            while (start < end)
            {
                int length    = OSCPacket.UnpackValue <int>(data, ref start);
                int packetEnd = start + length;
                bundle.Append(OSCPacket.Unpack(data, ref start, packetEnd));
            }

            return(bundle);
        }
Exemplo n.º 2
0
        void didRecievedEvent(OSCServer sender, OSCPacket packet)
        {
            lock (_queue)
            {
                if (packet.IsBundle())
                {
                    var bundle = packet as OSCBundle;

                    foreach (object obj in bundle.Data)
                    {
                        OSCMessage msg = obj as OSCMessage;
                        _queue.Enqueue(msg);
                    }
                }
                else
                {
                    _queue.Enqueue(packet as OSCMessage);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Receives and unpacks an OSC packet.
        /// A <see cref="OSCPacket"/>
        /// </summary>
        private void Receive()
        {
            IPEndPoint ip = null;

            try
            {
                byte[] bytes = _udpClient.Receive(ref ip);
                if (bytes != null && bytes.Length > 0)
                {
                    OSCPacket packet = OSCPacket.Unpack(bytes);

                    _lastReceivedPacket = packet;

                    PacketReceivedEvent(this, _lastReceivedPacket);
                }
            }
            catch (Exception e) {
                Debug.LogError(String.Format("Receive error at port {0} : {1}", _localPort, e.StackTrace));
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Packs the OSC message to binary data.
        /// </summary>
        override public void Pack()
        {
            List <byte> data = new List <byte>();

            data.AddRange(OSCPacket.PackValue(_address));
            OSCPacket.PadNull(data);

            data.AddRange(OSCPacket.PackValue(_typeTag));
            OSCPacket.PadNull(data);

            foreach (object value in _data)
            {
                data.AddRange(OSCPacket.PackValue(value));
                if (value is string || value is byte[])
                {
                    OSCPacket.PadNull(data);
                }
            }

            this._binaryData = data.ToArray();
        }