Esempio n. 1
0
 /// <summary>
 /// Called when a altitude value is being notified
 /// </summary>
 /// <param name="characteristic">Characteristic which notified the value</param>
 /// <param name="value">New characteristic value</param>
 private void OnAltitudeNotification(BleGattCharacteristic characteristic, BleValue value)
 {
     if (characteristic.Guid == MainAltiGuid)
     {
         MainAltitudeChanged?.Invoke(Altitude.MainAltitude, value.ToInt16());
     }
     else if (characteristic.Guid == Alti1Guid)
     {
         Altitude1Changed?.Invoke(Altitude.Altitude1, value.ToInt16());
     }
     else if (characteristic.Guid == Alti2Guid)
     {
         Altitude2Changed?.Invoke(Altitude.Altitude2, value.ToInt16());
     }
     else if (characteristic.Guid == Alti3Guid)
     {
         Altitude3Changed?.Invoke(Altitude.Altitude3, value.ToInt16());
     }
     else if (characteristic.Guid == Alti4Guid)
     {
         Altitude4Changed?.Invoke(Altitude.Altitude4, value.ToInt16());
     }
     else
     {
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Read a specified navigation value
        /// </summary>
        /// <param name="value">Navigation value to read</param>
        /// <returns>true if the operation succeeded, false otherwise</returns>
        public async Task <ReadNavigationValueResult> ReadNavigationValue(NavigationValue value)
        {
            ReadNavigationValueResult ret = new ReadNavigationValueResult();

            // List characteristics
            ret.Success = await InitCharacteristics();

            if (ret.Success)
            {
                // Look for the selected characteristic
                BleValue val = new BleValue();
                BleGattCharacteristic nav_characteristic = _navigation_characteristics[value];
                ret.Success = await BleDevice.ReadValueAsync(nav_characteristic, val);

                if (ret.Success)
                {
                    switch (value)
                    {
                    case NavigationValue.Speed:
                    {
                        ret.SpeedValue = val.ToUInt16();
                        break;
                    }

                    case NavigationValue.Latitude:
                    {
                        ret.LatitudeValue = val.ToFloat64();
                        break;
                    }

                    case NavigationValue.Longitude:
                    {
                        ret.LongitudeValue = val.ToFloat64();
                        break;
                    }

                    case NavigationValue.TrackAngle:
                    {
                        ret.TrackAngleValue = val.ToUInt16();
                        break;
                    }

                    default:
                    {
                        ret.Success = false;
                        break;
                    }
                    }
                }
            }

            return(ret);
        }
Esempio n. 3
0
 /// <summary>
 /// Called when a variometer value is being notified
 /// </summary>
 /// <param name="characteristic">Characteristic which notified the value</param>
 /// <param name="value">New characteristic value</param>
 private void OnVariometerNotification(BleGattCharacteristic characteristic, BleValue value)
 {
     if (characteristic.Guid == VarioGuid)
     {
         VarioChanged?.Invoke(value.ToInt16());
     }
     else if (characteristic.Guid == AccelerationGuid)
     {
         AccelerationChanged?.Invoke(value.ToUInt8());
     }
     else
     {
     }
 }
Esempio n. 4
0
 /// <summary>
 /// Called when a barometer value is being notified
 /// </summary>
 /// <param name="characteristic">Characteristic which notified the value</param>
 /// <param name="value">New characteristic value</param>
 private void OnBarometerNotification(BleGattCharacteristic characteristic, BleValue value)
 {
     if (characteristic.Guid == PressureGuid)
     {
         PressureChanged?.Invoke(value.ToUInt32());
     }
     else if (characteristic.Guid == TemperatureGuid)
     {
         TemperatureChanged?.Invoke(value.ToInt16());
     }
     else
     {
     }
 }
Esempio n. 5
0
        /// <summary>
        /// Read a specified variometer value
        /// </summary>
        /// <param name="value">Variometer value to read</param>
        /// <returns>true if the operation succeeded, false otherwise</returns>
        public async Task <ReadVariometerValueResult> ReadVariometerValue(VariometerValue value)
        {
            ReadVariometerValueResult ret = new ReadVariometerValueResult();

            // List characteristics
            ret.Success = await InitCharacteristics();

            if (ret.Success)
            {
                // Look for the selected characteristic
                BleValue val = new BleValue();
                BleGattCharacteristic vario_characteristic = _variometer_characteristics[value];
                ret.Success = await BleDevice.ReadValueAsync(vario_characteristic, val);

                if (ret.Success)
                {
                    switch (value)
                    {
                    case VariometerValue.Vario:
                    {
                        ret.VarioValue = val.ToInt16();
                        break;
                    }

                    case VariometerValue.Acceleration:
                    {
                        ret.AccelerationValue = val.ToUInt8();
                        break;
                    }

                    default:
                    {
                        ret.Success = false;
                        break;
                    }
                    }
                }
            }

            return(ret);
        }
Esempio n. 6
0
        /// <summary>
        /// Read a specified barometer value
        /// </summary>
        /// <param name="value">Barometer value to read</param>
        /// <returns>true if the operation succeeded, false otherwise</returns>
        public async Task <ReadBarometerValueResult> ReadBarometerValue(BarometerValue value)
        {
            ReadBarometerValueResult ret = new ReadBarometerValueResult();

            // List characteristics
            ret.Success = await InitCharacteristics();

            if (ret.Success)
            {
                // Look for the selected characteristic
                BleValue val = new BleValue();
                BleGattCharacteristic baro_characteristic = _barometer_characteristics[value];
                ret.Success = await BleDevice.ReadValueAsync(baro_characteristic, val);

                if (ret.Success)
                {
                    switch (value)
                    {
                    case BarometerValue.Pressure:
                    {
                        ret.PressureValue = val.ToUInt32();
                        break;
                    }

                    case BarometerValue.Temperature:
                    {
                        ret.TemperatureValue = val.ToInt16();
                        break;
                    }

                    default:
                    {
                        ret.Success = false;
                        break;
                    }
                    }
                }
            }

            return(ret);
        }
Esempio n. 7
0
 /// <summary>
 /// Called when a navigation value is being notified
 /// </summary>
 /// <param name="characteristic">Characteristic which notified the value</param>
 /// <param name="value">New characteristic value</param>
 private void OnNavigationNotification(BleGattCharacteristic characteristic, BleValue value)
 {
     if (characteristic.Guid == SpeedGuid)
     {
         SpeedChanged?.Invoke(value.ToUInt16());
     }
     else if (characteristic.Guid == LatitudeGuid)
     {
         LatitudeChanged?.Invoke(value.ToFloat64());
     }
     else if (characteristic.Guid == LongitudeGuid)
     {
         LongitudeChanged?.Invoke(value.ToFloat64());
     }
     else if (characteristic.Guid == TrackAngleGuid)
     {
         TrackAngleChanged?.Invoke(value.ToUInt16());
     }
     else
     {
     }
 }
Esempio n. 8
0
        /// <summary>
        /// Read a specified altitude value
        /// </summary>
        /// <param name="altitude">Altitude to read</param>
        /// <returns>true if the operation succeeded, false otherwise</returns>
        public async Task <ReadAltitudeResult> ReadAltitude(Altitude altitude)
        {
            ReadAltitudeResult ret = new ReadAltitudeResult();

            // List characteristics
            ret.Success = await InitCharacteristics();

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

                if (ret.Success)
                {
                    ret.Value = val.ToInt16();
                }
            }

            return(ret);
        }
Esempio n. 9
0
        private void OnNotification(BleGattCharacteristic characteristic, BleValue value)
        {
            string val = value.ToString();

            val += "";
        }
Esempio n. 10
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);
        }