Exemplo n.º 1
0
        /// <summary>
        /// Modify a specified altitude value
        /// </summary>
        /// <param name="altitude">Altitude to modified</param>
        /// <param name="value">Altitude value</param>
        /// <returns>true if the operation succeeded, false otherwise</returns>
        public async Task <bool> WriteAltitude(Altitude altitude, Int16 value)
        {
            bool ret;

            // List characteristics
            ret = await InitCharacteristics();

            if (ret)
            {
                // Look for the selected characteristic
                BleGattCharacteristic alti_characteristic = _altitude_characteristics[altitude];
                ret = await BleDevice.WriteValueAsync(alti_characteristic, new BleValue(value));
            }

            return(ret);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get the Open Vario device identification information
        /// </summary>
        /// <returns>Identification information if the operation succeeded, null otherwise</returns>
        public async Task <IdentificationInfo> GetIdentificationInfo()
        {
            // Check if identification information has already been retrieved
            if (_identification_info == null)
            {
                // List characteristics
                await ListCharacteristics();

                // Look for the command and identification information characteristics
                bool found = true;
                BleGattCharacteristic command_char = null;
                BleGattCharacteristic info_char    = null;
                try
                {
                    command_char = BleCharacteristics[CommandGuid];
                    info_char    = BleCharacteristics[IdentificationInfoGuid];
                }
                catch (KeyNotFoundException)
                {
                    found = false;
                }
                if (found)
                {
                    // Read identification information
                    bool     success  = true;
                    BleValue read_val = new BleValue();
                    _identification_info = new IdentificationInfo();
                    success = success && await BleDevice.WriteValueAsync(command_char, new BleValue((byte)0u));

                    success = success && await BleDevice.ReadValueAsync(info_char, read_val);

                    if (success)
                    {
                        _identification_info.GattVersion = read_val.ToString();
                    }
                    success = success && await BleDevice.WriteValueAsync(command_char, new BleValue((byte)1u));

                    success = success && await BleDevice.ReadValueAsync(info_char, read_val);

                    if (success)
                    {
                        _identification_info.SoftwareVersion = read_val.ToString();
                    }
                    success = success && await BleDevice.WriteValueAsync(command_char, new BleValue((byte)2u));

                    success = success && await BleDevice.ReadValueAsync(info_char, read_val);

                    if (success)
                    {
                        _identification_info.SoftwareManufacturerName = read_val.ToString();
                    }
                    success = success && await BleDevice.WriteValueAsync(command_char, new BleValue((byte)3u));

                    success = success && await BleDevice.ReadValueAsync(info_char, read_val);

                    if (success)
                    {
                        _identification_info.HardwareVersion = read_val.ToString();
                    }
                    success = success && await BleDevice.WriteValueAsync(command_char, new BleValue((byte)4u));

                    success = success && await BleDevice.ReadValueAsync(info_char, read_val);

                    if (success)
                    {
                        _identification_info.HardwareManufacturerName = read_val.ToString();
                    }
                    success = success && await BleDevice.WriteValueAsync(command_char, new BleValue((byte)5u));

                    success = success && await BleDevice.ReadValueAsync(info_char, read_val);

                    if (success)
                    {
                        _identification_info.HardwareSerialNumber = read_val.ToString();
                    }
                    success = success && await BleDevice.WriteValueAsync(command_char, new BleValue((byte)6u));

                    success = success && await BleDevice.ReadValueAsync(info_char, read_val);

                    if (success)
                    {
                        _identification_info.HardwareManufacturingDate = read_val.ToString();
                    }
                    if (!success)
                    {
                        _identification_info = null;
                    }
                }
            }

            // Return a copy of the identification information
            IdentificationInfo identification_info = null;

            if (_identification_info != null)
            {
                identification_info = (_identification_info.Clone() as IdentificationInfo);
            }
            return(identification_info);
        }