Welcome Guest,Register Now
Log In

ANT Forum

Welcome guest, please Login or Register

   

Over which bytes should CRC be calculated?

Rank

Total Posts: 3

Joined 2016-08-17

PM

Hi,

I'm debugging a ruby gem which is used to generate and parse FIT-files; https://github.com/scrapper/fit4ruby

I'm reading the Flexible and Interoperable Data Transfer Protocol Rev 2.2 document and specifically section 3.3.

The algorithm how to calculate the CRC is specified and has no uncertainties though the documentation does not mention explicitly over which bytes it should be applied. I have written several tests to verify the code in fit4ruby and when calculating the CRC for the 14 byte header the algorithm should obviously be iterated over the 12 header bytes, byte 0 to 11. And compared to byte 12 and 13 to check correctness. That works fine. And then calculating the file CRC over bytes 14 to end of file minus the 2 CRC bytes also seems correct.

But what about the two cases when there is a 12 byte sized header or the 14 byte header has CRC in the header set to 0000? It seems that the correct way to calculate the file CRC in these cases is over the whole file, from byte 0 to file size minus 2.

The later is not specified in the specification though analysing the SDK example files indicate this is the case and it makes sense. It would be great if the specification could be clarified in regards to this.

Best Regards,
Karl-Petter      
Rank

Total Posts: 3

Joined 2016-08-17

PM

And one more thing; none of the SDK example files is a FIT file with a 14 bytes header with CRC set to 0. Though implementing support for Garmin Connect API they provide with such a file. It would be great to include such a file in the ANT SDK as well.      
RankRankRank

Total Posts: 68

Joined 0

PM

You are correct, by including the CRC in the header you effectively reset the CRC for the file, (when you CRC-16 a value with itself the CRC returned is 0) If you do not include the CRC in the header or set it to 0 then the CRC should be run over the entire header and the data (0 -> file_size - 2).