tormoder / fit

A Go package for decoding and encoding Garmin FIT files
MIT License
242 stars 41 forks source link

Offset and scale are not fixed values #87

Open jovandeginste opened 6 months ago

jovandeginste commented 6 months ago

I'm running into issues decoding fit-files downloaded from Garmin Connect. Specifically, the elevations are wrong. I believe the documentation says the elevation (like any numeric value) may have a scale and offset (those may be 1 and 0 respectively), and those are specified in the record message. In the code, I see those are fixed values.

Could you check my logic here?

The snippet from the documentation:

Scale/Offset

The FIT SDK supports applying a scale or offset to binary fields. This allows efficient representation of values within a particular range and provides a convenient method for representing floating point values in integer systems. A scale or offset may be specified in the FIT profile for binary fields (sint/uint etc.) only. When specified, the binary quantity is divided by the scale factor and then the offset is subtracted, yielding a floating point quantity. The field access functions within the SDK automatically handle this conversion. If no scale and offset are specified, the field is interpreted as the underlying type and no extra conversion is necessary.

...

Scale and offset must be specified for all components even if these are 1 and 0. However, scale and offset will not be applied to destination fields with types of string or enum.

jovandeginste commented 6 months ago

To be clear, I believe the values (5 and 500) in the documentation are meant as examples or maybe defaults, not as the definitive values:

image

tormoder commented 6 months ago

I believe the documentation says the elevation (like any numeric value) may have a scale and offset (those may be 1 and 0 respectively),

It is my understanding that the scale and offset values for a specific FIT profile field is fixed and defined "statically" in the global profile. There is no way to encode that information for a field "dynamically".

Scale and offset must be specified for all components even if these are 1 and 0. However, scale and offset will not be applied to destination fields with types of string or enum.

I think this is refering to that componments must expliclity have a scale of 1 and offset of 0 in the profile, even if they have no scale and offset. Every "regular" field without a scale and offset implicitly have 1 and 0 as scale and offset.

It's been a while since it looked at this, so I will be more than happy to be corrected.