Running cpp/examples/decode/decode.cpp program and strange behavior with two FIT files from different devices

Hello:

I've downloaded the FIT SDK 21.38.00 and I'm trying to work with the decode example. I'm running in Linux and I've managed to compile the C++ example using g++ compiler and build the library as

$ cd FitSDKRelease_21.38.00/FitSDKRelease_21.38.00/cpp
$ for i in `ls *.cpp`; do g++ -Wall -O3 -c $i; done
$ ar rcs libcppfit.a *.o

After that I have the static FIT library called libcppfit.a in the FitSDKRelease_21.38.00/FitSDKRelease_21.38.00/cpp/ folder.

Then, I compile the decode program as (the order is called from the same folder as before)

$ g++ -Wall -O3 -I. -L. examples/decode/decode.cpp -o decode -lcppfit

I have now a working decode binary.

In this link (drive.google.com/.../1WlbPG-4KCB_dSAnks4vztoAp8ZHyC_TN you can download two FIT files:

  • file-garmin-edge530.fit: file logged with a Garmin Edge 530 with the cycling dynamics activated and with a Favero Assioma DUO powermeter
  • file-van-rysel500.fit: file logged with a Var Rysel 500 GPS with the cycling dynamics activated and with a Favero Assioma DUO powermeter

When I convert these files with the decode binary I obtain strange results related to the left_right_balance field. For the file-van-rysel500.fit I obtain logical results as, for example,

   Field10 (left_right_balance) has 1 value(s)
       Val0: 49 
   Field10 (left_right_balance) has 1 value(s)
       Val0: 51 
   Field10 (left_right_balance) has 1 value(s)
       Val0: 48 

But for the file file-garmin-edge530.fit I obtain values like

   Field11 (left_right_balance) has 1 value(s)
       Val0: 176 
   Field11 (left_right_balance) has 1 value(s)
       Val0: 181 
   Field11 (left_right_balance) has 1 value(s)
       Val0: 183 

These values are clearly wrong as it must be decoded with the mask 0x7F, and after that I obtain (in Python):

>>> 176&0x7F
48
>>> 181&0x7F
53
>>> 183&0x7F
55

wich are correct values.

So, the question is: is it a bug in decode.cpp program? How it is possible the difference in decoding, and the Garmin FIT file the wrong answer?

Thanks

  • See my answer to your other question here on how to decode left/right power values. 
    RE: Questions about left/right balance and its decodification 

  • Thank you for your answer. But in this case I have not modified the file decode.cpp, it is the one provided with the FIT SDK. And this file produces right values for left_right_balance for one file and wrong values for other. And curiously, the right values (49%, 51%, 48%) are the ones stored in the Van Rysel FIT file and the wrong values (176%, 181%, 183%) are the ones stored in the Garmin file.

  • The decode.cpp example just dumps all the field names and values for a mesg to the console. The example does not manipulate the values in anyway. You can see this in the PrintValues(FieldBase&) method. There is nothing specific about the left_right_power fields in that method. It prints out the value as is.

    If the left_right_power fields are of interest, then you can add code to the OnMesg( fit::RecordMesg& record ) method to apply the masks.


    For the example values from each file that you provided, when the masks are applied the values look as expected:

    49 & 0x80 = 0 = left side
    49 & 7F = 49% left side

    176 & 0x80 = 0x80 = right side
    176 & 0x7F = 48 % right side

  • Thank you for your answer. I reply here also your answer in the other thread (forums.garmin.com/.../questions-about-left-right-balance-and-its-decodification).

    If (left_right_balance & 0x80 == zero), then the value is the balance for the left leg

    Are you sure of that? As I understand, this is contrary to what standard says. In the file Profile.xlsx of FitSDKRelease_21.38.00 (and in prior versions) we can read:

    left_right_balance uint8
        mask  0x7F   % contribution
        right 0x80   data corresponds to right if set, otherwise unknownCode

    This means, as I can interpret, that if left_right_balance & 0x80 == zero the value is not the balance for the left leg, but it is unknown, i.e., useless.

    For example, for the two files I gave as example (drive.google.com/.../1WlbPG-4KCB_dSAnks4vztoAp8ZHyC_TN), if I upload them to GarminConnect I obtain correct balance values for the data contained in file-garmin-edge530.fit, i.e., for the file generated with Garmin device. But for the file-van-rysel500.fit the balance values are omitted, i.e., Garmin Connect discards them as left_right_balance & 0x80 == zero when it reads the file, so Garmin Connect applies what the FIT standard says in Profile.xslx