-
-
Notifications
You must be signed in to change notification settings - Fork 95
The structure of a FIT file.
Dimitar Marinov edited this page Jan 28, 2021
·
2 revisions
The official FIT protocol docs are here.
- first download the FIT SDK
- it contains C# and Java example implementations. The C# one is about 60 000 LOC, so good luck.
- the most useful thing there is the java CSV tool which you can find at /java/FitCSVTool.jar. You can use it to explore existing .FIT files and to validate your implementation for errors using:
$ java -jar /fitsdk/java/FitCSVTool.jar /path/to/minimal-example.fit
This is a minimal example that is able to pass the validation. It has one Record with Power and Timestamp fields
The FIT file contains:
- FIT file header
[14,32, 8,40, 0, 0, 0,46,70,73,84,59,133]
0 1 2 3 4 5 6 7 8 9 10 11 12
0: size of header in bytes (12 or 14)
1: protocol version (16 for v1, 32 for v2)
2-3: profile version (21.40 * 100 = 2140)
4-7: size of data (only messages, no header or crc)
8-11: encodes the string '.FIT'
11-13: CRC of header (byte 0 to 11)
- File Id definition message
[64, 0, 0, 0, 0, 3, 0, 1, 0, 1, 2,152, 2, 2,132]
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
0: definition message header (0b01000000)
1: reserved
2: architecture (0 = Little Endian)
3-4: global message number
5: number of following field definitions
6-8: definition of File type field
- 0: field definition number under the global message numbers
- 1: size (how many bytes -> 1)
- 2: base type (the hex value from the table -> 0x00)
9-11: definition of Manufacturer field
12-14: definition of Product field
- File Id data message
[0, 4,255, 0, 0, 0]
0 1 2 3 4 5
0: data message header (0b00000000)
1: 4 is Activity file type
2-3: 255 is development 'manufacturer'
4-5: 0 for product
- Record definition message
[64, 0, 0,20, 0, 2, 7, 2,132,254, 4,134]
0 1 2 3 4 5 6 7 8 9 10 11
0: definition message header
...
6-8: definition of Power field
9-11: definition of Timestamp field
- Record data message
[0,44, 1,56,227,157,117]
0 1 2 3 4 5 6
0: data message header (0b00000000)
1-2: power value in watts resolution of 1
3-6: timestamp
- CRC
[80,65]
Now to be able to upload to Garmin Connect, the file must have a couple more message fields along with their definition messages. Those are:
- Event message field
- Lap message field
- Session message field
- Activity message field
If those are not present the file won't validate and the upload will be rejected.
... to be continued ...