Cycle Power BT 4.0 sensor implementation improvement

Started by mspider65, May 06, 2020, 05:22:23 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

mspider65

Hi,
i'm using the 7.4.22 version and I found a problem in the Cycle Power BT 4.0 sensor implementation.
I was trying to integrate a BT power sensor developed by me without success and I had to decompile the code of your application to understand why it didn't work.

I have seen that to read the values ​​sent by the sensor, the application read the optional values ​​from fixed positions instead of using an offset based on the values ​​actually present in the message.
I attach a piece of code example showing the correct way to read the sensor message content.

In this way the application will be compatible with all BT 4.0 Power Sensors (BT Cycle Power Profile standard) and not only the sensors you have tested and sends exactly the data you expect to receive.

Regards,
Massimo



private static final int PEDAL_POWER_BALANCE_PRESENT        = 0x0001;
private static final int ACCUMULATED_TORQUE_PRESENT         = 0x0004;
private static final int WHEEL_REVOLUTION_DATA_PRESENT      = 0x0010;
private static final int CRANK_REVOLUTION_DATA_PRESENT      = 0x0020;
private static final int EXTREME_FORCE_MAGNITUDES_PRESENT   = 0x0040;
private static final int EXTREME_TORQUE_MAGNITUDES_PRESENT  = 0x0080;
private static final int EXTREME_ANGLES_PRESENT             = 0x0100;
private static final int TOP_DEAD_SPOT_ANGLE_PRESENT        = 0x0200;
private static final int BOTTOM_DEAD_SPOT_ANGLE_PRESENT     = 0x0400;
private static final int ACCUMULATED_ENERGY_PRESENT         = 0x0800;

.
.
.

if (characteristic.getUuid().toString().equalsIgnoreCase(CHARACTERISTIC_UUID_CYCLING_POWER)) {
    // Read flags
    int flag =  characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, 0);
   
    // read istantaneous power (always present)
    int power = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_SINT16, 2);

    // Read optional fields
    int offset = 4;
    if ((flag & PEDAL_POWER_BALANCE_PRESENT) != 0) {
        power_balance = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, offset);
        offset +=1;
    }
    if ((flag & ACCUMULATED_TORQUE_PRESENT) != 0) {
        accumulatedTorque = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, offset);
        offset +=2;
    }
    if ((flag & WHEEL_REVOLUTION_DATA_PRESENT) != 0) {
        wheel_revolutions = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT32, offset);
        offset +=4;
        last_wheel_event_time = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, offset);
        offset +=2;
    }
    if ((flag & CRANK_REVOLUTION_DATA_PRESENT) != 0) {
        crank_revolutions = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, offset);
        offset +=2;
        last_crank_event_time = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, offset);
        offset +=2;
    }
    .
    .
    .
   
   
    then do the same for all the other fields in the following order:
   
    Extreme Force Magnitudes - Maximum Force Magnitude
    Etreme Force Magnitudes - Minimum Force Magnitude
   
    Extreme Torque Magnitudes- Maximum Torque Magnitude
    Extreme Torque Magnitudes- Minimum Torque Magnitude
   
    Extreme Angles - Maximum Angle
    Extreme Angles - Minimum Angle
   
    Top Dead Spot Angle
   
    Bottom Dead Spot Angle
   
    Accumulated Energy

}




orux

Quote from: mspider65 on May 06, 2020, 05:22:23 PM
Hi,
i'm using the 7.4.22 version and I found a problem in the Cycle Power BT 4.0 sensor implementation.
I was trying to integrate a BT power sensor developed by me without success and I had to decompile the code of your application to understand why it didn't work.

I have seen that to read the values ​​sent by the sensor, the application read the optional values ​​from fixed positions instead of using an offset based on the values ​​actually present in the message.
I attach a piece of code example showing the correct way to read the sensor message content.

In this way the application will be compatible with all BT 4.0 Power Sensors (BT Cycle Power Profile standard) and not only the sensors you have tested and sends exactly the data you expect to receive.

Regards,
Massimo


Hello!
I have no test device, and there are few users of such sensors. I think the implemented code came from an example, I will review it and include the changes in the next beta version.


orux

mspider65

#2
Hi Orux, thanks!
Since i also use your greath app i will be glad to help you in the fix (if you want).
In case, do not hesitate to contact me on my registration email.
You probably already know, but  below You could find the link to the GATT specification of the Cycling Power Measurement Characteristic.
https://www.bluetooth.com/xml-viewer/?src=https://www.bluetooth.com/wp-content/uploads/Sitecore-Media-Library/Gatt/Xml/Characteristics/org.bluetooth.characteristic.cycling_power_measurement.xml

Massimo

orux

Quote from: mspider65 on May 07, 2020, 09:13:30 AM
Hi Orux, thanks!
Since i also use your greath app i will be glad to help you in the fix (if you want).
In case, do not hesitate to contact me on my registration email.
You probably already know, but  below You could find the link to the GATT specification of the Cycling Power Measurement Characteristic.
https://www.bluetooth.com/xml-viewer/?src=https://www.bluetooth.com/wp-content/uploads/Sitecore-Media-Library/Gatt/Xml/Characteristics/org.bluetooth.characteristic.cycling_power_measurement.xml

Massimo

Thanks;

Current beta42 version should work, maybe you can test it.
If does not work OK, I can add a log to see what happens,


orux


mspider65

Hi Orux, Great Job!
I have just done a test sending Power, Speed, Cadence and Accumulated Energy (the last field)  and i can see all the correct values on the dashboard.
Is it possible to have also these values stored in the tour data ?

Massimo

orux

Quote from: mspider65 on May 08, 2020, 01:56:12 PM
Hi Orux, Great Job!
I have just done a test sending Power, Speed, Cadence and Accumulated Energy (the last field)  and i can see all the correct values on the dashboard.
Is it possible to have also these values stored in the tour data ?

Massimo

Hello!

I will try to add them in the .fit file export. That file type is the only with support to that data.


orux

mspider65

Thanks!

I've just given some useful links to Jose.
I hope it will be helpful.

Massimo