The .fit File Format

We cannot open and read raw .fit files in the form generated by sports sensor devices — we will just see a jumble of symbols. It is a binary file consisting of a continuous stream of structured data.

It is organised into three sections:

1. File Header: The first 12 or 14 bytes of the file containing metadata about the file itself, including:
  1. Header size (1 byte).
  2. Protocol and profile version numbers (1 byte each).
  3. Data size (4 bytes): The length of the subsequent Data Records section in bytes.
  4. The ASCII string ".FIT" (4 bytes): Used to identify the file type.
  5. An optional CRC (2 bytes) for the header itself.

2. Data Records Section: This is the section we will parse and is the main body of the file. It contains a sequence of encoded messages. The records vary in length and consist of two types that appear sequentially:
  1. Definition Messages: These act as templates for the subsequent data messages. A definition message specifies the global message type ('record', 'lap'), the number of fields, and the format (data type, size, etc).
  2. Data Messages: These contain the actual sensor data and events (heart rate, GPS coordinates, speed, time, power, etc) formatted as described by the preceding definition message.

3. File CRC: The final 2 bytes of the file contain a 16-bit CRC (checksum) for the entire file content, used for data integrity verification.

The raw data is stored in an optimised, compact binary format, which is why I used the fitparse library to parse and interpret the messages into a structured, readable format.


← Back to previous

← Back to Home