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

record HRV data from compatible devices #192

Open
dvmarinoff opened this issue May 1, 2024 · 6 comments
Open

record HRV data from compatible devices #192

dvmarinoff opened this issue May 1, 2024 · 6 comments

Comments

@dvmarinoff
Copy link
Owner

dvmarinoff commented May 1, 2024

  • read from the Polar H10 strap
  • record to .FIT file
@fab33
Copy link

fab33 commented Jan 16, 2025

DFA alpha1 will be fine too. With same custom fields from Garmin AlphaHRV app.

@dvmarinoff
Copy link
Owner Author

Posting here some notes I got from implementing this for iOS.

Data

Here are some Data examples of full Heart Rate Measurement messages. These can become test cases:

[16, 67, 114, 3, 138, 3]
[16, 68, 146, 3]
[16, 60, 140, 4]
[0, 64]

Spec

Here is the Hear Rate Measurement message as defined by the bluetooth spec:

Field 0, Flags

16
0b00010000

0 bit, HeartRateValueFormat, 0 -> UInt8, 1 -> UInt16
1 bit, SensorContactStatus, 0 -> no contact, 1 -> contact
2 bit, SensorContactSupport, 0 -> not suppoted, 1 -> supported
3 bit, EnergyExpenditureStatus, 0 -> not present , 1 -> present
4 bit, RRInterval, 0 -> not present , 1 -> present

Field 1, Heart Rate

Field 2, Energy Expenditure

If present should be included once every 10 measurements
If value is 0xFFFF the value needs to be reset by the client

Field 3, RRInterval

length is up to 8 if EnergyExpenditure is present
lenght is up to 9 if EnergyExpenditure is not present
Resolution of 1/1024 second

HR = 60 / RR Interval in seconds

FIT File

 HRV messages are used to record heart rate variability data. The HRV messages contain an array of RR
 intervals and are interleaved with record and event messages in chronological order. Note that HRV data is
 not timestamped, and shall be synchronized by checking successive RR intervals as they occur between other
 timestamped messages.
Image

Inside the fit file hrv is not recorded as part of the record message, but as a separate message. But the HRV message does not have timestamp. It's timestamp must be derived from the previous message (preferably a record message). Another oddity is that the it has only one field which is fixed size array of length 5 which contains the RRIntervals, and is filled up with 0xFFFF where value is not available.

Therefore in the current implementation HRV messages must be recorded together with Record messages in db.records.
The FIT Parser will need to implement support for array type too.

Also note that while the Heart Rate Measurement message uses resolution of 1024 the FIT File format uses resolution of 1000.

@EnricoFerro
Copy link
Contributor

Ok, I'm working on this solution too...

I've created an implementation on https://github.com/EnricoFerro/Flux/tree/hrv2-wip

It write something.. ...there only some problem with the empty fields:
Image

@dvmarinoff
Copy link
Owner Author

I am going to try to implement the FIT Parser logic in a more general way. Ideally the global definition files should be read only.
They are generated with a script from the official spec document.

@mgibbs189
Copy link

@dvmarinoff fyi the fit-javascript-sdk now supports both encoding and decoding.

It's still quite a bit of extra overhead (namely profile.js), but might be a worthwhile trade-off...

@dvmarinoff
Copy link
Owner Author

@mgibbs189 Hey, thanks for the update!

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

4 participants