Bluetooth pressure data parse

This commit is contained in:
denta58
2022-12-04 21:01:57 +01:00
committed by Dennis Guse
parent ebcc7dc46e
commit 0395394e26
2 changed files with 30 additions and 0 deletions
@@ -43,6 +43,20 @@ public class BluetoothUtilsTest {
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
public void parseCyclingSpeedCadence_crankOnly() {
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(
new UUID(0x181800001000L, 0x800000805f9b34fbL),
new UUID(0x2A6300001000L, 0x800000805f9b34fbL)
@@ -137,6 +142,17 @@ public class BluetoothUtils {
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) {
// 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;