示例#1
0
		public async Task<List<OSCPacket>> Call (OSCPacket p)
		{
			// generate unique id
			var currentMessageId = Interlocked.Increment (ref safeMessageCount);
			var id = String.Concat (Name, "_", currentMessageId);

			// add result object
			var result = new MadMapperResult (id);
			while (!results.TryAdd (id, result)) {
			}

			// add id to message as parameter
			p.Address += "&id=" + id;

			// send message
			Send (p);

			// wait for all messages
			await Task.Run (() => {
				while (!result.Finished) {
					newMessageArrived.WaitOne ();
					newMessageArrived.Reset ();
				}
			});

			// remove result object
			MadMapperResult removedObject;

			while (!results.TryRemove (id, out removedObject)) {
			}

			return result.Packets;
		}
示例#2
0
		void MadMapperClient_PacketReceived (object sender, OSCPacket e)
		{
			var msg = e as OSCMessage;

			if (msg != null) {

				var address = new OSCAddress (e.Address);

				// get identifier
				var id = address.Id;

				// return if message is not relevant
				if (!results.ContainsKey (id))
					return;

				// check if this is the replayMessageCount address
				if (address.Root.Equals ("replyMessageCount")) {
					// set result count
					results [id].ResultCount = (int)msg.Values [0];
				} else {
					// add msg to result
					msg.Address = address.BaseAddress;
					results [id].Packets.Add (msg);
				}

				// fire lock to let waiters check
				newMessageArrived.Set ();
			}
		}
示例#3
0
		static void Communicator_PacketReceived (object sender, OSCPacket e)
		{
			var msg = e as OSCMessage;
		
			if (msg != null) {
				Console.Write (msg.Address + " ");
				Console.WriteLine (String.Join (", ", msg.Values.ToArray ()));
			}
		}
示例#4
0
		public int Send(OSCPacket packet)
		{
			int byteNum = 0;
			byte[] data = packet.BinaryData;
			try
			{
				byteNum = this.udpClient.Send(data, data.Length);
			}
			catch (Exception e)
			{
				Debug.WriteLine(e.Message);
				Debug.WriteLine(e.StackTrace);
			}

			return byteNum;
		}
示例#5
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());
        }
示例#6
0
        public static new OSCBundle Unpack(byte[] bytes, ref int start, int end, bool extendedMode = false)
        {
            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, extendedMode);

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

            return(bundle);
        }
示例#7
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
            }
            long      timestamp = unpackLong(bytes, ref start);
            OSCBundle bundle    = new OSCBundle(timestamp);

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

            return(bundle);
        }
		/// <summary>
		/// Sends a package to MadMapper.
		/// </summary>
		/// <param name="packet">Packet to send.</param>
		public void Send (OSCPacket packet)
		{
			client.Send (packet);
		}
示例#9
0
            /// Returns true if we got a full frame
            public bool Process(OSCPacket packet, Matrix4x4 transform)
            {
                switch (packet.Address)
                {
                    case "/frame":
                        if (packet.Values.Count >= 1)
                        {
                            this.Frame = (int)packet.Values[0];
                        }
                        break;
                    default:
                        //we're in it for the money!
                        var addressList = new List<string>(packet.Address.Split('/'));
                        var values = packet.Values;
						if (this.Root.Process(addressList, values, transform))
						{
							return true;
						}
                        break;
                }
                return false;
            }