OSM Tools

Tips for Creating a GPX file from ANT+/Wahoo FIT files & Strava Segments

Fit-Tools
Fit Converter showing all blocks & data
converting FIT to GPX & CSV
Showing min/max heart data

Reading a FIT file without tears

The following should give you some understanding of the basic 'FIT protocols and structure'.

We assume that you are familiar with hex readers.

Yes, there are documents available which give a deeper understanding of the FIT structures but they are not written for beginners and the information is often hidden deep in a small file.

Header

We shall ignore the header for the time being; for our purpose it does not contain important information except the length of the data contained in the file.

0 x 0 length of header (&e) , meaning our main data starts at &he

0 x 4 size of data (4 bytes) , ie the block taken from &h0E

There are no pointers to specific fields in the header.

Let's begin

The structure is a stream of definition blocks and data blocks, nothing else. There are no pointers to 'special' blocks.

Data always follows a definition, not the other way around!

Both blocks do not have fixed sizes so it's essential to learn how to retrieve the length of a block.

The definition block includes the size of a data block - if it didn't, we would have real difficulty knowing where the data block starts and where it ends!

The definition tells you what type of data to expect and in what order , ie temperature,height, coordinates

You cannot assume that a data block immediately follows a definition . For that reason definitions are numbered and each data block starts with a number pointing to an earlier definition.

A data block starts with the first byte referring to the definition number (often zero)

Def1 Data1 Def 2 Data2 Def 3 Data 3        

You could also have a untidy mix of definitions and data

Def1 Def2 Data1 Def3 Data3 Data 1 Data 2

Data can contain values for longitude,latitude,allude,temperature,cadence etc

It can also contain details of a new LAP ie time, distance,calories etc ; these are shown as L in FIT Converter'

It can also tell you where you pressed the STOP and CONTINUE 'button' ; these are shown as R in FIT Converter.

It can also give you a specific Course Instruction (Point) , ie Turn Left at the next gate; these are shown as CP in FIT Converter.

Definition block with 6 bytes, always 6 bytes - we call this the 40 block

ANT+ FIT header

Highlighted in RED are the '40' blocks

Highlighted in Yellow are the Fields

Highlighted in GREEN : Data

Encircled in RED , number of fields

 

Example 40 00 01 00 00 4

In our case the File TYPE id=0

4D 00 01 etc is the start of File Type 13 (&d) etc

In fact,if you examine the picture above , immediately after the header ,one of those 40 blocks can be seen.

In the case above the data type is Zero, which for our purposes isn't very exciting.

If we want to locate longitude or latitude values we need to find definitions with 0x14 as the combined values of 4th & 5th bytes , ie

40 00 01 00 14

or

40 00 00 14 00 (3rd byte is set to 00 so we read the two bytes from left to right)

For more information see below.

Fields are always 3 bytes!

example : 01 02 84 , 02 04 86 , fd 04 86 , 00 01 00

middle byte

The middle byte tells you how many bytes are need,ie 2 , 4 , 4 , 1

last byte

The last byte tells you what type of variable you are dealing with, ie could it included negatives or it could be letters

02 23 07 (; 07 means string )

first byte

The first number refers to what is named the Field Definition Number, ie Speed, Latitude, Longitude, Temperature etc

However the meaning depends on 2 bytes in the 40 block - see below.

Fields are arranged numerically according to the first byte.

If the 40 block contains 14 (see below 40 00 01 00 14) ) then the numbers relate to Speed, Latitude, Longitude, Temperature

Data

A Data block starts with a type id which links it to a definition:

A definition beginning 42 (00 01 00 00) has a data block which starts with 02

A definition beginning 45 (00 01 00 00) has a data block which starts with 05

The FIT file consists of a series of defining blocks for various File ID Types , ie 1 ,2 6,12 - some numbers are not known

The length of the data block is the number of fields x 3

ANT / Garmin FIT files

FIT files look very complicated, it being difficult to see a structure of any kind.

However, it just contains a series of blocks strung together.

How do I know a block is a definition and not Data?

Answer : if the beginning of the block starts with a byte < 0x40 then its a data block else its a definition.

We can always determine the length of a definition because of the number of fields.

We can always determine the length of a data block by checking the first byte , as this points to a definition given earlier & the variables types

Where are the Coordinates,Latitude & Longitude?

If the definition block contains coordinates then they are generally/always 4 bytes (0x84)

Coordinates are represented in various ways

Here are the main ones

00 04 85 Position Lat - Latitude requires 4 bytes
01 04 85 Position Long - Longitude requires 4 bytes

The bytes are stored as semicircles and not Garmin units; they may be little or Big endian, meaning you may have to reverse the order.they are stored ( a bit is set in the 40 header box - see above)

so 00 9d dc 23 may need to be read as 23 dc 9d 00

Data becomes 7F FF FF FF if no gps fix could be established

Which block contains crucial GPX data?

Coordinates are defined in a 40 block which contain the number (ANT speak : global message) for a 'record' - This number is 20 or &h14 (Some fit files contain (Strava) route segments - they have a different number - see below)

The 40 block include 2 bytes to define the global messages highlighted below:

40 00 01 00 00 ...

If there are several 40 blocks defined which ones contain the Latitude/Longitude data for our gpx file?

 

40 00 01 14

 

0x14 stands for 'record'

Below the results using our FIT - GPX for Windows

Fields (6)

00 '04' 85 PositionLat
01 '04' 85 PositionLong = 1
02 '02' 84 Altitude = 2
FD '04' 86 Timestamp
06 '02' 84 Speed = 6
05 '04' 86 Distance = 5

1) Latitude 2) Longitude 3) Height 4) Timestamp 5) speed 6) distance

gpx data

Most FIT files also include temperature readings, heart rate & cadence (steps per minute)

These can also be added to your gpx file.

Tip : Import your FIT file into Basecamp then export it as a gpx and check the code.

When you create your GPX file only start when the GPX has kicked in; ie check if the Latitude is not 7FFFFFFF

Check your gpx file in Basecamp/Mapsource for possible 'unknown' errors - Garmin's archaic parsers are known to be intolerant and unfriendly!

More on Global Messages in 40 blocks

The following explains the headings given in the FITtoCSV converter given our example in picture above.

FileID :4th byte=0

&E ******************************** FILE_ID (0) 40 00 00 00 00
Fields (7)
03 04 8C
04 04 86
07 04 86
01 02 84
02 02 84
05 02 84
00 01 00
&29 Data 00 06 BF AE C5 | 66 6E F4 38 | FF FF FF FF | 01 00 | 2C 0A | FF FF | 04 |

FILE_CREATOR : 4th byte = &31 ( dec 49)

&3D ******************************** FILE_CREATOR (49) 41 00 00 31 00
Fields (3)
02 14 07
00 02 84
01 01 02
&4C Data 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | 76 07 | FF |

EVENT 4th byte=&h15 (dec 21)

&64 ******************************** EVENT (21) 42 00 00 15 00
Fields (7)
FD 04 86
03 04 86

RECORD : fourth/fifth byte = &14 (dec 20)

******************************** RECORD (20) 4C 00 00 14 00 or 4C 00 01 00 14
Fields (9)
FD 04 86 Timestamp
00 04 85 PositionLat
01 04 85 PositionLong = 1
05 04 86 Distance = 5
02 02 84 Altitude = 2
06 02 84 Speed = 6
03 01 02 HeartRate = 3
04 01 02 Cadence = 4
0D 01 01 Temperature = &D (dec13)

60 Blocks

These occur in some FIT files ;they allow you to add extra fields using an almost Garminesk algorithm - The start of the data field ,therefore, has to be calculated differently.Our FIT Converter caters for such blocks.

Strava Segments

:RECORD (150) 40 00 00 96 00 or 40 00 01 00 96

Fields (6)

01 04 85 Position Lat
02 04 85 Position Long
04 02 84 Altitude
03 04 86| Distance
FE 02 84 message
05 08 86| Timestamp

Strava segments show &96 in the fourth byte

These segments are mostly short linear routes

Course Points

:RECORD (32) 40 00 00 20 00 or 40 00 01 00 20

01 04 86 Timestamp
02 04 85 Position Lat
03 04 85 Position Long
04 04 86 Distance
06 10 07 Instruction
FE 02 84 message
05 01 00| type

They behave more like waypoints and are fundamentally used for a turn by turn direction

The data blocks contain the coordinates for the point and an instruction.

These points represent parts of a track where a new instruction is given. From a gpx point of view such points are not very useful.

Often used on  Garmin Edge Devices.

These can be best described as instructions, ie turn left, turn sharp right , keep going, drink water etc

The instructions are numbered 0 to 255, each number representing particular instruction

here are some

0 = "Generic"
1= "Summit"
2 = "Valley"
3 = "Water"
4= "Food"
5 = "Danger"
6 = "Turn Left"
7 = "Turn Right"
8 = "Straight Ahead"
9 = "First Aid"
15= "Sprint"
16 = "Left Fork"
17 = "Right Fork"
18 = "Middle Fork"
19 = "Continue Bear Left"
20) = "Sharp Left"
21) = "Continue Bear Right"
22) = "Sharp Right"
23) = "UTurn"
24 = "Segment Start"
25 = "Segment End"
course points in a fit file

Picture shows course with coursepoints

The definition contains a string,longitude, latitude, instruction number