/// <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); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }