Understanding BLE characteristic values for cycle power measurement 0x2A63

1,949

Based on section 3.55 of the Bluetooth GATT specs:

DEC - [52,24,40,0,58,29,59,0,0,0,107,136,23, 0,214, 81, 1,0]
BIT -   0  1  2 3  4  5  6 7 8 9  10  11 12 13  14  15 16 17 
Flag field = 24,52 (bit0 and bit1)

2452 = 00001001 10010100

section 3.55.2.1 the corresponding (1) equates to

- bit2  = Accumulated Torque Present 
- bit4  = Wheel Revolution Data Present
- bit7  = Extreme Torque Magnitudes Present
- bit8  = Extreme Angles Present
- bit11 = Accumulated Energy Present

Then from section 3.55.2, you go down the list of bits based on the flags: Instant Power is bits2 (40) and bit3 (0)

(Dec) 0040 == 00000000 00101000 == 40w

to decipher the rest of the bits, we then have to refer to the flags field since the remaining bits after the flags field and instant power have to depend on what the flags field says that the trainer is supporting.

Based on bit2 of the flags field which says that "Accumulated Torque Present" ( Present if bit 2 of Flags field set to 1) Hence the next 2 bits represents Accumulated Torque

Dec (2958)

The next data would then be based on bit4 of the flags field - Wheel Rev Data Present (Present if bit 4 of Flags field set to 1). This is wheel speed which would translate into speed once you taken into account wheel circumference. For Wheel Rev Data, this is represented by the next 6 bits.

Cumulative Wheel Revolutions - 4 bits
Last Wheel Event Time - 2 bits

like you mentioned, this trainer does not offer cadence service, hence that's why you do not see the flags field (bit5) to be 1. Hence you cannot infer cadence from this data set.

For Wheel speed, you would then decode the data from the 6 bits based on Cum Wheel Rev and Last Wheel Event Time. I can't offer you code on how to decode the 6 bits as you're using flutter and I've no experience in flutter language. (I do Swift) but can likely take a look at this code from GoldenCheetah and convert accordingly.

BT40Device::getWheelRpm(QDataStream& ds)
{
    quint32 wheelrevs;
    quint16 wheeltime;
    ds >> wheelrevs;
    ds >> wheeltime;

    double rpm = 0.0;

    if(!prevWheelStaleness) {
        quint16 time = wheeltime - prevWheelTime;
        quint32 revs = wheelrevs - prevWheelRevs;
        // Power sensor uses 1/2048 second time base and CSC sensor 1/1024
        if (time) rpm = (has_power ? 2048 : 1024)*60*revs / double(time);
    }
    else prevWheelStaleness = false;

    prevWheelRevs = wheelrevs;
    prevWheelTime = wheeltime;
    dynamic_cast<BT40Controller*>(parent)->setWheelRpm(rpm);
}
Share:
1,949
Yonkee
Author by

Yonkee

Updated on December 09, 2022

Comments

  • Yonkee
    Yonkee over 1 year

    I am currently using Dart/Flutter BLE plugin to better understand BLE devices.

    Plugin:

    https://pub.dartlang.org/packages/flutter_blue

    When I connect to my virtual cycle trainer I select the 0x1818 service and then I subscribe to the 0x2A63 characteristic for Cycle Power Measurement.

    I am struggling to align the response list I get with the GATT documentation for this service/characteristics below. There is 18 values in this list, however there is only 17 in the GATTS list. Also the values don't seem to make any sense.

    I also tried to convert the first two values '52','24' to a 16 bit binary to see if that aligns with the flags for the first field, but the result was the below which again makes no sense.

    0x3418 = 11010000011000
    

    https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.cycling_power_measurement.xml

    This screenshot is when I first connect to the trainer.

    enter image description here

    This screenshot is when I am cycling lightly on the bike

    enter image description here

    This screenshot is when I stop cycling but the pedals and wheel are still turning.

    enter image description here

    The cycle trainer is the Cycleops Magnus, which doesn't have the Cycle Speed Cadence service 1816, but can provide virtual speed based on power.

    My Question is this:

    Which of the values in the list corresponding with the GATTS characteristics and bonus question is, how would I infer speed or cadence from the values in this service?