Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The FIT C++ SDK can be [cloned from the FIT C++ SDK repository on GitHub](https:
Example implementations of the FIT SDK are provided and can be found in the examples/ folder.
* **Decode**: Demonstrates decoding a FIT file; and use of the Decode and Message Broadcaster classes and Message Listener event interfaces.

* **Encode**: Demonstrates encoding a FIT file and programmatic generation of messages. Three sample FIT files are created. ExampleActivity.fit, ExampleSettings.fit, and ExampleMonitoringFile.fit
* **Encode**: Demonstrates encoding an activity FIT file and programmatic generation of messages.

To compile the examples, leverage the makefiles. Note that the makefiles use the GNU g++ compiler.
```bash
Expand Down
22 changes: 11 additions & 11 deletions examples/decode/decode.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
////////////////////////////////////////////////////////////////////////////////
// The following FIT Protocol software provided may be used with FIT protocol
// devices only and remains the copyrighted property of Garmin Canada Inc.
// The software is being provided on an "as-is" basis and as an accommodation,
// and therefore all warranties, representations, or guarantees of any kind
// (whether express, implied or statutory) including, without limitation,
// warranties of merchantability, non-infringement, or fitness for a particular
// purpose, are specifically disclaimed.
//
// Copyright 2008 Garmin Canada Inc.
////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
// Copyright 2026 Garmin International, Inc.
// Licensed under the Flexible and Interoperable Data Transfer (FIT) Protocol License; you
// may not use this file except in compliance with the Flexible and Interoperable Data
// Transfer (FIT) Protocol License.
/////////////////////////////////////////////////////////////////////////////////////////////
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
// Profile Version = 21.195.0Release
// Tag = production/release/21.195.0-0-g569e7e5
/////////////////////////////////////////////////////////////////////////////////////////////


#include <fstream>
#include <iostream>
Expand Down
168 changes: 12 additions & 156 deletions examples/encode/encode.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
////////////////////////////////////////////////////////////////////////////////
// The following FIT Protocol software provided may be used with FIT protocol
// devices only and remains the copyrighted property of Garmin Canada Inc.
// The software is being provided on an "as-is" basis and as an accommodation,
// and therefore all warranties, representations, or guarantees of any kind
// (whether express, implied or statutory) including, without limitation,
// warranties of merchantability, non-infringement, or fitness for a particular
// purpose, are specifically disclaimed.
//
// Copyright 2008-2016 Garmin Canada Inc.
////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
// Copyright 2026 Garmin International, Inc.
// Licensed under the Flexible and Interoperable Data Transfer (FIT) Protocol License; you
// may not use this file except in compliance with the Flexible and Interoperable Data
// Transfer (FIT) Protocol License.
/////////////////////////////////////////////////////////////////////////////////////////////
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
// Profile Version = 21.195.0Release
// Tag = production/release/21.195.0-0-g569e7e5
/////////////////////////////////////////////////////////////////////////////////////////////


#include <fstream>
#include <cstdlib>
Expand All @@ -26,7 +26,7 @@
// Number of semicircles per meter at the equator
#define SC_PER_M 107.173

int EncodeActivityFile()
int main()
{
try
{
Expand Down Expand Up @@ -188,150 +188,6 @@ int EncodeActivityFile()
catch (...)
{
throw std::runtime_error("Exception encoding activity file");
}
}
int EncodeSettingsFile()
{
try
{
fit::Encode encode(fit::ProtocolVersion::V10);
std::fstream file;

file.open("ExampleSettings.fit", std::ios::in | std::ios::out | std::ios::binary | std::ios::trunc);

if (!file.is_open())
{
printf("Error opening file ExampleSettings.fit\n");
return -1;
}

fit::FileIdMesg fileIdMesg; // Every FIT file requires a File ID message
fileIdMesg.SetType(FIT_FILE_SETTINGS);
fileIdMesg.SetManufacturer(FIT_MANUFACTURER_DEVELOPMENT);
fileIdMesg.SetProduct(1);
fileIdMesg.SetSerialNumber(12345);

fit::UserProfileMesg userProfileMesg;
userProfileMesg.SetGender(FIT_GENDER_FEMALE);
userProfileMesg.SetWeight((FIT_FLOAT32)63.1);
userProfileMesg.SetAge(99);
std::wstring wstring_name(L"TestUser");
userProfileMesg.SetFriendlyName(wstring_name);

encode.Open(file);
encode.Write(fileIdMesg);
encode.Write(userProfileMesg);

if (!encode.Close())
{
printf("Error closing encode.\n");
return -1;
}
file.close();

printf("Encoded FIT file ExampleSettings.fit.\n");
return 0;
}
catch (...)
{
throw std::runtime_error("Exception encoding settings file.");
}
}

int EncodeMonitoringFile()
{
try
{
fit::Encode encode(fit::ProtocolVersion::V10);
std::fstream file;

time_t current_time_unix = time(0);
fit::DateTime initTime(current_time_unix);

file.open("ExampleMonitoringFile.fit", std::ios::in | std::ios::out | std::ios::binary | std::ios::trunc);

if (!file.is_open())
{
printf("Error opening file ExampleMonitoringFile.fit\n");
return -1;
}

encode.Open(file);

fit::FileIdMesg fileIdMesg; // Every FIT file requires a File ID message
fileIdMesg.SetType(FIT_FILE_MONITORING_B);
fileIdMesg.SetManufacturer(FIT_MANUFACTURER_DEVELOPMENT);
fileIdMesg.SetProduct(1);
fileIdMesg.SetSerialNumber(12345);

encode.Write(fileIdMesg);

fit::DeviceInfoMesg deviceInfoMesg;
deviceInfoMesg.SetTimestamp(initTime.GetTimeStamp()); // Convert to FIT time and write timestamp.
deviceInfoMesg.SetBatteryStatus(FIT_BATTERY_STATUS_GOOD);

encode.Write(deviceInfoMesg);

fit::MonitoringMesg monitoringMesg;

// By default, each time a new message is written the Local Message Type 0 will be redefined to match the new message.
// In this case,to avoid having a definition message each time there is a DeviceInfoMesg, we can manually set the Local Message Type of the MonitoringMessage to '1'.
// By doing this we avoid an additional 7 definition messages in our FIT file.
monitoringMesg.SetLocalNum(1);

monitoringMesg.SetTimestamp(initTime.GetTimeStamp()); // Initialise Timestamp to now
monitoringMesg.SetCycles(0); // Initialise Cycles to 0
for (int i = 0; i < 4; i++) // This loop represents 1/6 of a day
{
for (int j = 0; j < 4; j++) // Each one of these loops represent 1 hour
{
fit::DateTime walkingTime(current_time_unix);
monitoringMesg.SetTimestamp(walkingTime.GetTimeStamp());
monitoringMesg.SetActivityType(FIT_ACTIVITY_TYPE_WALKING); // By setting this to WALKING, the Cycles field will be interpretted as Steps
monitoringMesg.SetCycles(monitoringMesg.GetCycles() + (rand() % 1000 + 1)); // Cycles are accumulated (i.e. must be increasing)
encode.Write(monitoringMesg);
current_time_unix += (time_t)(3600); //Add an hour to our contrieved timestamp
}
fit::DateTime statusTime(current_time_unix);
deviceInfoMesg.SetTimestamp(statusTime.GetTimeStamp());
deviceInfoMesg.SetBatteryStatus(FIT_BATTERY_STATUS_GOOD);
encode.Write(deviceInfoMesg);

}

if (!encode.Close())
{
printf("Error closing encode.\n");
return -1;
}
file.close();

printf("Encoded FIT file ExampleMonitoringFile.fit.\n");
return 0;
}
catch (...)
{
throw std::runtime_error("Exception encoding monitoring file.");
}
}

int main()
{
printf("FIT Encode Example Application\n");

int returnValue = 0;

try
{
returnValue += EncodeSettingsFile();
returnValue += EncodeMonitoringFile();
returnValue += EncodeActivityFile();
}
catch (const std::runtime_error &e)
{
printf("Exception occurred while encoding example files: %s", e.what());
return -1;
}

return returnValue;
}
4 changes: 2 additions & 2 deletions src/fit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// Transfer (FIT) Protocol License.
/////////////////////////////////////////////////////////////////////////////////////////////
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
// Profile Version = 21.194.0Release
// Tag = production/release/21.194.0-0-g65135fc
// Profile Version = 21.195.0Release
// Tag = production/release/21.195.0-0-g569e7e5
/////////////////////////////////////////////////////////////////////////////////////////////


Expand Down
6 changes: 3 additions & 3 deletions src/fit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// Transfer (FIT) Protocol License.
/////////////////////////////////////////////////////////////////////////////////////////////
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
// Profile Version = 21.194.0Release
// Tag = production/release/21.194.0-0-g65135fc
// Profile Version = 21.195.0Release
// Tag = production/release/21.195.0-0-g569e7e5
/////////////////////////////////////////////////////////////////////////////////////////////


Expand Down Expand Up @@ -80,7 +80,7 @@ namespace fit
#define FIT_PROTOCOL_VERSION ::fit::versionMap.at( ::fit::ProtocolVersion::V20 ).GetVersionByte()

#define FIT_PROFILE_VERSION_MAJOR 21
#define FIT_PROFILE_VERSION_MINOR 194
#define FIT_PROFILE_VERSION_MINOR 195
#define FIT_PROFILE_VERSION_SCALE 1000
#define FIT_PROFILE_VERSION ((FIT_UINT16) (FIT_PROFILE_VERSION_MAJOR * FIT_PROFILE_VERSION_SCALE + FIT_PROFILE_VERSION_MINOR))

Expand Down
4 changes: 2 additions & 2 deletions src/fit_aad_accel_features_mesg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// Transfer (FIT) Protocol License.
/////////////////////////////////////////////////////////////////////////////////////////////
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
// Profile Version = 21.194.0Release
// Tag = production/release/21.194.0-0-g65135fc
// Profile Version = 21.195.0Release
// Tag = production/release/21.195.0-0-g569e7e5
/////////////////////////////////////////////////////////////////////////////////////////////


Expand Down
4 changes: 2 additions & 2 deletions src/fit_aad_accel_features_mesg_listener.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// Transfer (FIT) Protocol License.
/////////////////////////////////////////////////////////////////////////////////////////////
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
// Profile Version = 21.194.0Release
// Tag = production/release/21.194.0-0-g65135fc
// Profile Version = 21.195.0Release
// Tag = production/release/21.195.0-0-g569e7e5
/////////////////////////////////////////////////////////////////////////////////////////////


Expand Down
4 changes: 2 additions & 2 deletions src/fit_accelerometer_data_mesg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// Transfer (FIT) Protocol License.
/////////////////////////////////////////////////////////////////////////////////////////////
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
// Profile Version = 21.194.0Release
// Tag = production/release/21.194.0-0-g65135fc
// Profile Version = 21.195.0Release
// Tag = production/release/21.195.0-0-g569e7e5
/////////////////////////////////////////////////////////////////////////////////////////////


Expand Down
4 changes: 2 additions & 2 deletions src/fit_accelerometer_data_mesg_listener.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// Transfer (FIT) Protocol License.
/////////////////////////////////////////////////////////////////////////////////////////////
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
// Profile Version = 21.194.0Release
// Tag = production/release/21.194.0-0-g65135fc
// Profile Version = 21.195.0Release
// Tag = production/release/21.195.0-0-g569e7e5
/////////////////////////////////////////////////////////////////////////////////////////////


Expand Down
4 changes: 2 additions & 2 deletions src/fit_accumulated_field.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// Transfer (FIT) Protocol License.
/////////////////////////////////////////////////////////////////////////////////////////////
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
// Profile Version = 21.194.0Release
// Tag = production/release/21.194.0-0-g65135fc
// Profile Version = 21.195.0Release
// Tag = production/release/21.195.0-0-g569e7e5
/////////////////////////////////////////////////////////////////////////////////////////////


Expand Down
4 changes: 2 additions & 2 deletions src/fit_accumulated_field.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// Transfer (FIT) Protocol License.
/////////////////////////////////////////////////////////////////////////////////////////////
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
// Profile Version = 21.194.0Release
// Tag = production/release/21.194.0-0-g65135fc
// Profile Version = 21.195.0Release
// Tag = production/release/21.195.0-0-g569e7e5
/////////////////////////////////////////////////////////////////////////////////////////////


Expand Down
4 changes: 2 additions & 2 deletions src/fit_accumulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// Transfer (FIT) Protocol License.
/////////////////////////////////////////////////////////////////////////////////////////////
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
// Profile Version = 21.194.0Release
// Tag = production/release/21.194.0-0-g65135fc
// Profile Version = 21.195.0Release
// Tag = production/release/21.195.0-0-g569e7e5
/////////////////////////////////////////////////////////////////////////////////////////////


Expand Down
4 changes: 2 additions & 2 deletions src/fit_accumulator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// Transfer (FIT) Protocol License.
/////////////////////////////////////////////////////////////////////////////////////////////
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
// Profile Version = 21.194.0Release
// Tag = production/release/21.194.0-0-g65135fc
// Profile Version = 21.195.0Release
// Tag = production/release/21.195.0-0-g569e7e5
/////////////////////////////////////////////////////////////////////////////////////////////


Expand Down
4 changes: 2 additions & 2 deletions src/fit_activity_mesg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// Transfer (FIT) Protocol License.
/////////////////////////////////////////////////////////////////////////////////////////////
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
// Profile Version = 21.194.0Release
// Tag = production/release/21.194.0-0-g65135fc
// Profile Version = 21.195.0Release
// Tag = production/release/21.195.0-0-g569e7e5
/////////////////////////////////////////////////////////////////////////////////////////////


Expand Down
4 changes: 2 additions & 2 deletions src/fit_activity_mesg_listener.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// Transfer (FIT) Protocol License.
/////////////////////////////////////////////////////////////////////////////////////////////
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
// Profile Version = 21.194.0Release
// Tag = production/release/21.194.0-0-g65135fc
// Profile Version = 21.195.0Release
// Tag = production/release/21.195.0-0-g569e7e5
/////////////////////////////////////////////////////////////////////////////////////////////


Expand Down
4 changes: 2 additions & 2 deletions src/fit_ant_channel_id_mesg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// Transfer (FIT) Protocol License.
/////////////////////////////////////////////////////////////////////////////////////////////
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
// Profile Version = 21.194.0Release
// Tag = production/release/21.194.0-0-g65135fc
// Profile Version = 21.195.0Release
// Tag = production/release/21.195.0-0-g569e7e5
/////////////////////////////////////////////////////////////////////////////////////////////


Expand Down
4 changes: 2 additions & 2 deletions src/fit_ant_channel_id_mesg_listener.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// Transfer (FIT) Protocol License.
/////////////////////////////////////////////////////////////////////////////////////////////
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
// Profile Version = 21.194.0Release
// Tag = production/release/21.194.0-0-g65135fc
// Profile Version = 21.195.0Release
// Tag = production/release/21.195.0-0-g569e7e5
/////////////////////////////////////////////////////////////////////////////////////////////


Expand Down
4 changes: 2 additions & 2 deletions src/fit_ant_rx_mesg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// Transfer (FIT) Protocol License.
/////////////////////////////////////////////////////////////////////////////////////////////
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
// Profile Version = 21.194.0Release
// Tag = production/release/21.194.0-0-g65135fc
// Profile Version = 21.195.0Release
// Tag = production/release/21.195.0-0-g569e7e5
/////////////////////////////////////////////////////////////////////////////////////////////


Expand Down
Loading
Loading