Beispiel #1
0
 private async Task <T> SendMessageAsync <T>(Endpoint endpoint, byte[] payload)
     where T : class, IResponse, new()
 {
     return(await Task.Run(() =>
     {
         try
         {
             lock ( _PebbleProt )
             {
                 using (
                     IResponseTransaction <T> responseTransaction =
                         _responseManager.GetTransaction <T>())
                 {
                     _PebbleProt.SendMessage((ushort)endpoint, payload);
                     return responseTransaction.AwaitResponse(ResponseTimeout);
                 }
             }
         }
         catch (TimeoutException)
         {
             var result = new T();
             result.SetError("TimeoutException occurred");
             Disconnect();
             return result;
         }
         catch (Exception e)
         {
             var result = new T();
             result.SetError(e.Message);
             return result;
         }
     }));
 }
Beispiel #2
0
        /// <summary>
        ///     Connect with the Pebble.
        /// </summary>
        /// <exception cref="System.IO.IOException">Passed on when no connection can be made.</exception>
        public async Task ConnectAsync()
        {
            PhoneVersionResponse response;

            //PhoneVersionResponse is received immediately after connecting, and we must respond to it before making any other calls
            using (IResponseTransaction <PhoneVersionResponse> responseTransaction =
                       _responseManager.GetTransaction <PhoneVersionResponse>())
            {
                await _PebbleProt.ConnectAsync();

                response = responseTransaction.AwaitResponse(ResponseTimeout);
            }

            if (response != null)
            {
                byte[] prefix  = { PEBBLE_CLIENT_VERSION, 0xFF, 0xFF, 0xFF, 0xFF };
                byte[] session = Util.GetBytes(_SessionCaps);
                byte[] remote  = Util.GetBytes(_RemoteCaps);

                byte[] msg = Util.CombineArrays(prefix, session, remote);
                //\x01\xff\xff\xff\xff\x80\x00\x00\x00\x00\x00\x002
                await SendMessageNoResponseAsync(Endpoint.PhoneVersion, msg);

                IsAlive = true;
            }
            else
            {
                Disconnect();
            }
        }
Beispiel #3
0
        /// <summary>
        ///     Connect with the Pebble.
        /// </summary>
        /// <exception cref="System.IO.IOException">Passed on when no connection can be made.</exception>
        public async Task ConnectAsync()
        {
            PhoneVersionResponse response;

            //PhoneVersionResponse is received immediately after connecting, and we must respond to it before making any other calls
            using (IResponseTransaction <PhoneVersionResponse> responseTransaction =
                       _responseManager.GetTransaction <PhoneVersionResponse>())
            {
                await _PebbleProt.ConnectAsync();

                response = responseTransaction.AwaitResponse(ResponseTimeout);
            }

            if (response != null)
            {
                var message = new AppVersionResponse();
                await SendMessageNoResponseAsync(Endpoint.PhoneVersion, message.GetBytes());

                IsAlive = true;

                //get the firmware details, we'll need to know the platform and version for possible future actions
                var firmwareResponse = await this.GetFirmwareVersionAsync();

                this.Firmware = firmwareResponse.Firmware;
            }
            else
            {
                Disconnect();
            }
        }