Exemplo n.º 1
0
 public void SendEndpointMsg(PebbleEndpointType type, byte[] data, EndpointMsgCallback callback)
 {
     byte[] buf = new byte[data.Length + 5];
     //The first byte is the message type, which is PEBBLE_PROTOCOL_PHONE_TO_WATCH
     buf[0] = (byte)CloudPebbleCode.PEBBLE_PROTOCOL_PHONE_TO_WATCH;
     byte[] length    = FromShort((short)data.Length);
     byte[] typeBytes = FromShort((short)type);
     //Next two bytes are length of the message.
     length.CopyTo(buf, 1);
     //Next two bytes are the type.
     typeBytes.CopyTo(buf, 3);
     //The remainder is the message itself
     data.CopyTo(buf, 5);
     //Send this message and wait for a reply.
     SendDataGetReplyType(buf, CloudPebbleCode.PEBBLE_PROTOCOL_WATCH_TO_PHONE, (byte[] reply, object user) =>
     {
         //Read this in and see if the reply type matches the one we requested.
         using (MemoryStream ms = new MemoryStream(reply))
         {
             ms.Position += 1;
             PebbleProtocolMessage msg = new PebbleProtocolMessage(ms, CloudPebbleCode.PEBBLE_PROTOCOL_WATCH_TO_PHONE);
             if (msg.id == type)
             {
                 //This is what we wanted. Prevent the default and call callback.
                 return(callback(msg));
             }
             else
             {
                 //Not what we wanted.
                 return(AfterInterruptAction.NoPreventDefault_ContinueInterrupt);
             }
         }
     }, null);
 }
Exemplo n.º 2
0
            public PebbleProtocolMessage(MemoryStream ms, CloudPebbleCode code)
            {
                //Set direction.
                direction = PebbleProtocolDirection.PhoneToWatch;
                if (code == CloudPebbleCode.PEBBLE_PROTOCOL_WATCH_TO_PHONE)
                {
                    direction = PebbleProtocolDirection.WatchToPhone;
                }
                //Get length
                short length = ReadShort(ms);

                //Get the ID
                id = (PebbleEndpointType)ReadShort(ms);
                Console.WriteLine("Got type " + id.ToString());
                //Read the data.
                data = new byte[length];
                ms.Read(data, 0, length);
                //Convert that to a string.
                stringData = Encoding.ASCII.GetString(data);
                //Set time
                time = DateTime.UtcNow;
            }