Exemplo n.º 1
0
        /// <summary>
        /// Get the GO+ key and blob.
        /// </summary>
        /// <returns>Async task to await.</returns>
        public async Task GetDeviceInfo(GoPlus device)
        {
            if (device == null)
            {
                throw new ArgumentNullException("device");
            }

            if (_stateManager.State != AppState.Idle)
            {
                return;
            }

            try
            {
                _stateManager.State = AppState.Getting;

                await _bleManager.ConnectDevice(device);

                byte[] key = await _bleManager.ReadCharacteristic(device, Constants.DeviceKeyCharacteristicUuid);

                device.DeviceKey = Helper.ByteArrayToString(key);

                byte[] blob = await _bleManager.ReadCharacteristic(device, Constants.BlobKeyCharacteristicUuid);

                device.BlobKey = Helper.ByteArrayToString(blob);

                await _bleManager.DisconnectDevice(device);
            }
            catch (Exception e)
            {
                _notifyManager.ShowDialogInfoBox($"Unable to get Device Information. Please try again. Error: {e.Message}");
            }
            finally
            {
                _stateManager.State = AppState.Idle;
            }
        }