Hi! Wanted to bring to your attention a bug in the C# code in the FIT SDK. If you attempt to encode a protocol v2 FIT file with the SDK 20.16.0.0 or greater, it will have a bad value in the protocol version section in the header.
The version header is divided into two parts, the upper 4 bits for the major protocol version and the lower 4 bits for the minor protocol version. The bug in the C# code is causing the minor PROFILE version to be stored in the lower 4 bits, instead of the minor PROTOCOL version. The Java code correctly stores the minor protocol version there, so it doesn't suffer from this bug.
The end result is that since the profile minor version in newer SDK versions exceeds 4 bits (15), it's bleeding into the major protocol version and causing the file to appear to be a protocol version that it's not. For instance, if you encode a protocol 2 FIT file with the 20.22.0.0 SDK, the bleeding will cause a protocol major version of 3 to be stored. That'll trigger the following exception upon decode:
Dynastream.Fit.FitException: FIT decode error: Protocol Version 3.X not supported by SDK Protocol Ver2.0
The fix is super easy. In the DetailedProtocolVersion class in Dynastream\Fit\Defines.cs, make the following change:
public byte Version
{
get
{
return (byte) ((MajorVersion << Fit.ProtocolVersionMajorShift) |
- Fit.ProfileMinorVersion);
+ MinorVersion);
}
}
Hope this helps!