Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

calculate field index from flag bits in handleIndoorBikeDataUpdate #220

Open
dvmarinoff opened this issue Dec 8, 2022 · 0 comments
Open

Comments

@dvmarinoff
Copy link

const power = data.getUint8(6) + (data.getUint8(7) << 8);

The current approach may read power correctly in most cases, but some trainers won’t report cadence, or will report distance or something else, which will shift the index away from the current fixed value of 6.

In general the index of fields in indoor-bike-data is relative. It’s based on what other fields are present before it, which is determined by reading the flags. Some trainers might also have heart rate field in the indoor-bike-data which is useful to have from just one BLE connection.

Here is example data from Schwinn bike which reports heart rate at last position:

Schwinn 800IC:
(0x) 44-02-AA-05-2E-00-18-00-46
(10) [68, 2, 170, 5, 46, 0, 24, 0, 70]

"Instantanious Speed: 14.5 km/h
  Instantanious Cadence: 23.0 per min
  Instantanious Power: 24 W
  Heart Rate: 70 bpm"

Here is example from my code (you can also read the value of power with getUint16):

function powerIndex(flags) {
    let i = fields.Flags.size;
    if(speedPresent(flags))      i += fields.InstantaneousSpeed.size;
    if(avgSpeedPresent(flags))   i += fields.AverageSpeed.size;
    if(cadencePresent(flags))    i += fields.InstantaneousCandence.size;
    if(avgCadencePresent(flags)) i += fields.AverageCandence.size;
    if(distancePresent(flags))   i += fields.TotalDistance.size;
    if(resistancePresent(flags)) i += fields.ResistanceLevel.size;
    return i;
}

// and later:
if(powerPresent(flags)) {
    return dataview.getUint16(powerIndex(flags), true);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant