Exemple #1
0
 public static OSCPacket Unpack(byte[] bytes, ref int start, int end)
 {
     if (bytes[start] == '#')
     {
         return(OSCBundle.Unpack(bytes, ref start, end));
     }
     else
     {
         return(OSCMessage.Unpack(bytes, ref start));
     }
 }
        public static Dictionary<int, Tuio2DCursor> GetCursors(OSCBundle pack)
        {
            Dictionary<int, Tuio2DCursor> result = new Dictionary<int, Tuio2DCursor>();

            List<OSCMessage> cursors = FindByCommand(pack, "/tuio/2Dcur", "set");
            foreach (OSCMessage msg in cursors)
            {
                Tuio2DCursor cur = new Tuio2DCursor(msg);
                result.Add(cur.SessionID, cur);
            }
            return result;
        }
        public static int GetSequenceNumber(OSCBundle pack)
        {
            int result = -1;

            List<OSCMessage> msgs = FindByCommand(pack, "/tuio/2Dcur","fseq");
            if (msgs.Count > 0)
            {
                result = Convert.ToInt32((int)msgs[0].Values[1]);
            }

            return result;
        }
        public static List<int> GetAliveCursors(OSCBundle pack)
        {
            List<int> result = new List<int>();

            List<OSCMessage> alivecmd = FindByCommand(pack, "/tuio/2Dcur", "alive");
            if (alivecmd.Count > 0)
            {
                for (int i = 1; i < alivecmd[0].Values.Count; i++)
                {
                    int id = (int)alivecmd[0].Values[i];
                    result.Add(id);

                }
            }

            return result;
        }
 static List<OSCMessage> FindByCommand(OSCBundle bundle, string address, string cmd)
 {
     List<OSCMessage> result = new List<OSCMessage>();
     foreach (object o in bundle.Values)
     {
         OSCMessage msg = (OSCMessage)o;
         if (msg.Address == address)
         {
             if (msg.Values.Count > 0)
             {
                 if (msg.Values[0].ToString() == cmd)
                 {
                     result.Add(msg);
                 }
             }
         }
     }
     return result;
 }
Exemple #6
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);
        }
		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;
		}