forked from upstream-mirrors/OpenTracks
Bluetooth pressure data parse
This commit is contained in:
@@ -43,6 +43,20 @@ public class BluetoothUtilsTest {
|
|||||||
assertEquals(HeartRate.of(257), heartRate);
|
assertEquals(HeartRate.of(257), heartRate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void parsePressure_Pa() {
|
||||||
|
// given
|
||||||
|
BluetoothGattCharacteristic characteristic = new BluetoothGattCharacteristic(BluetoothUtils.PRESSURE.getServiceUUID(), 0, 0);
|
||||||
|
characteristic.setValue(new byte[]{(byte) 0xB2, (byte) 0x48, (byte) 0x0F, (byte) 0x00});
|
||||||
|
|
||||||
|
|
||||||
|
// when
|
||||||
|
int pressure = BluetoothUtils.parsePressure(characteristic);
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertEquals(1001650, pressure);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parseCyclingSpeedCadence_crankOnly() {
|
public void parseCyclingSpeedCadence_crankOnly() {
|
||||||
BluetoothGattCharacteristic characteristic = new BluetoothGattCharacteristic(BluetoothUtils.CYCLING_SPEED_CADENCE.getServiceUUID(), 0, 0);
|
BluetoothGattCharacteristic characteristic = new BluetoothGattCharacteristic(BluetoothUtils.CYCLING_SPEED_CADENCE.getServiceUUID(), 0, 0);
|
||||||
|
|||||||
@@ -69,6 +69,11 @@ public class BluetoothUtils {
|
|||||||
))
|
))
|
||||||
);
|
);
|
||||||
|
|
||||||
|
public static final ServiceMeasurementUUID PRESSURE = new ServiceMeasurementUUID(
|
||||||
|
new UUID(0x181A00001000L, 0x800000805f9b34fbL),
|
||||||
|
new UUID(0x2A6D00001000L, 0x800000805f9b34fbL)
|
||||||
|
);
|
||||||
|
|
||||||
public static final ServiceMeasurementUUID CYCLING_POWER = new ServiceMeasurementUUID(
|
public static final ServiceMeasurementUUID CYCLING_POWER = new ServiceMeasurementUUID(
|
||||||
new UUID(0x181800001000L, 0x800000805f9b34fbL),
|
new UUID(0x181800001000L, 0x800000805f9b34fbL),
|
||||||
new UUID(0x2A6300001000L, 0x800000805f9b34fbL)
|
new UUID(0x2A6300001000L, 0x800000805f9b34fbL)
|
||||||
@@ -137,6 +142,17 @@ public class BluetoothUtils {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Integer parsePressure(BluetoothGattCharacteristic characteristic) {
|
||||||
|
byte[] raw = characteristic.getValue();
|
||||||
|
|
||||||
|
if (raw.length < 4) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Float fPressure = characteristic.getFloatValue(BluetoothGattCharacteristic.FORMAT_FLOAT, 0);
|
||||||
|
return Math.round(fPressure);
|
||||||
|
}
|
||||||
|
|
||||||
public static SensorDataCyclingPower.Data parseCyclingPower(String address, String sensorName, BluetoothGattCharacteristic characteristic) {
|
public static SensorDataCyclingPower.Data parseCyclingPower(String address, String sensorName, BluetoothGattCharacteristic characteristic) {
|
||||||
// DOCUMENTATION https://www.bluetooth.com/wp-content/uploads/Sitecore-Media-Library/Gatt/Xml/Characteristics/org.bluetooth.characteristic.cycling_power_measurement.xml
|
// DOCUMENTATION https://www.bluetooth.com/wp-content/uploads/Sitecore-Media-Library/Gatt/Xml/Characteristics/org.bluetooth.characteristic.cycling_power_measurement.xml
|
||||||
int valueLength = characteristic.getValue().length;
|
int valueLength = characteristic.getValue().length;
|
||||||
|
|||||||
Reference in New Issue
Block a user