public void SendDataGetReplyType(byte[] data, CloudPebbleCode code, OnGetReply callback, object d) { //All this does is register a type with the reply from this for the first reply. It is not reliable. InterruptOnRequest interr = new InterruptOnRequest(code, callback, d); interrupts.Add(interr); //Send the data now. SendData(data); }
public override void OnBinaryMessage(byte[] content) { MemoryStream ms = new MemoryStream(content); CloudPebbleCode code = GetCode(ms); //Reject all but signin if not authorized. if (code != CloudPebbleCode.AUTH_TOKEN && !authenticated) { return; } //Check if there is an interrupt for this. var inter_list = interrupts.FindAll(x => x.code == code); foreach (var inter in inter_list) { //Call the callback. AfterInterruptAction state = inter.callback(content, inter.d); if (state == AfterInterruptAction.PreventDefault_EndInterrupt || state == AfterInterruptAction.NoPreventDefault_EndInterrupt) { //Remove this from the interrupts list. interrupts.Remove(inter); } //Check if we should prevent default if (state == AfterInterruptAction.PreventDefault_ContinueInterrupt || state == AfterInterruptAction.PreventDefault_EndInterrupt) { return; } } //Decide what to do based on this code. Console.WriteLine("Got message of type " + code.ToString() + " with length " + content.Length.ToString() + "."); switch (code) { case CloudPebbleCode.AUTH_TOKEN: //This will contain a login request. DoAuth(ms); break; case CloudPebbleCode.PEBBLE_PROTOCOL_PHONE_TO_WATCH: OnPPMMessage(new PebbleProtocolMessage(ms, code)); break; case CloudPebbleCode.PEBBLE_PROTOCOL_WATCH_TO_PHONE: OnPPMMessage(new PebbleProtocolMessage(ms, code)); break; default: Console.WriteLine("Got unknown CloudPebble proxy code " + code.ToString() + "."); break; } }
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; }
public InterruptOnRequest(CloudPebbleCode _code, OnGetReply _callback, object _d) { code = _code; callback = _callback; d = _d; }