Files
fit-parser/example
Thomas Klaehn 2945d90d24 Initial commit
Signed-off-by: Thomas Klaehn <thomas.klaehn@perinet.io>
2026-02-08 07:30:31 +00:00
..
2026-02-08 07:30:31 +00:00
2026-02-08 07:30:31 +00:00
2026-02-08 07:30:31 +00:00

FIT Parser Example

This directory contains a complete example application that demonstrates how to use the FIT parser.

Running the Example

# From the example directory
go run main.go testdata/Activity.fit

# Or from the repository root
go run example/main.go example/testdata/Activity.fit

Available Test Files

The testdata/ directory contains several example FIT files:

  • Activity.fit - Full activity file with GPS, heart rate, power, and cadence data
  • Settings.fit - Simple device settings file
  • MonitoringFile.fit - Daily monitoring data
  • WorkoutIndividualSteps.fit - Workout definition
  • RealWorld_Cycling.fit - Real-world cycling activity from Wahoo ELEMNT

What the Example Does

The example program:

  1. Reads and validates the FIT file
  2. Decodes all messages with CRC validation
  3. Displays file information (type, manufacturer, timestamps)
  4. Shows activity summaries (distance, time, heart rate, power, etc.)
  5. Prints sample data records with GPS coordinates, speed, and sensor data

Example Output

File: testdata/Activity.fit (94096 bytes)
============================================================

Header Information:
  FIT Header: Protocol v2.0, Profile v21158, DataSize=94080 bytes

Decoded 3611 messages

Message Type Summary:
  FileId              :     1 messages
  Record              :  3601 messages
  Session             :     1 messages
  Lap                 :     1 messages
  Event               :     2 messages
  DeviceInfo          :     1 messages
  Activity            :     1 messages

📊 Session Summary:
  Sport: Unknown
  Total Time: 60.02 minutes
  Average Heart Rate: 145 bpm
  Max Heart Rate: 178 bpm

Using in Your Own Code

package main

import (
    "fmt"
    "log"
    "os"
    "git.blackfinn.de/go/fit-parser/fitparser"
)

func main() {
    // Read FIT file
    data, err := os.ReadFile("activity.fit")
    if err != nil {
        log.Fatal(err)
    }

    // Create decoder
    decoder, err := fitparser.NewDecoder(data)
    if err != nil {
        log.Fatal(err)
    }

    // Decode with CRC validation (enabled by default)
    messages, err := decoder.Decode()
    if err != nil {
        log.Fatal(err)
    }

    // Process messages
    for _, msg := range messages {
        switch msg.Num {
        case fitparser.MesgNumRecord:
            // Process data records
            if hr, ok := msg.GetFieldValueUint8(fitparser.FieldRecordHeartRate); ok {
                fmt.Printf("Heart Rate: %d bpm\n", hr)
            }
        }
    }
}