You are here: Forum Home → ANT Developers Forums → ANT+ FIT Forum Has Moved → Thread
int EncodeSettingsFile()
{
fit::Encode encode;
std::fstream file;
file.open("/Users/utente/FIT_CPP/test.fit", std::ios::in | std::ios::out | std::ios::binary | std::ios::trunc);
if (!file.is_open())
{
printf("Error opening file test.fit\n");
return -1;
}
fit::FileIdMesg fileIdMesg; // Every FIT file requires a File ID message
fileIdMesg.SetType(FIT_FILE_SETTINGS);
fileIdMesg.SetManufacturer(FIT_MANUFACTURER_DYNASTREAM);
fileIdMesg.SetProduct(1000);
fileIdMesg.SetSerialNumber(12345);
fileIdMesg.SetNumber(87);
encode.Open(file);
encode.Write(fileIdMesg);
if (!encode.Close())
{
printf("Error closing encode.\n");
return -1;
}
file.close();
printf("Encoded FIT file test.fit.\n");
return 0;
}
"FIT decode error: File header signature mismatch. File is not FIT"
typedef struct
{
FIT_UINT8 header_size; // FIT_FILE_HDR_SIZE (size of this structure)
FIT_UINT8 protocol_version; // FIT_PROTOCOL_VERSION
FIT_UINT16 profile_version; // FIT_PROFILE_VERSION
FIT_UINT32 data_size; // Does not include file header or crc. Little endian format.
FIT_UINT8 data_type[4]; // ".FIT"
FIT_UINT16 crc; // CRC of this file header in little endian format.
} FIT_FILE_HDR;
file->write((const char *)&file;_header, FIT_FILE_HDR_SIZE);
0000000 016 020 x 005 ? ? ? ? ! \0 \0 \0 \0 \0 @ \0
0000010 \0 \0 \0 005 \0 001 \0 001 002 204 002 002 204 003 004 214
0000000 016 020 230 003 035 \0 \0 \0 . F I T 0 w @ \0
0000010 001 \0 \0 004 001 002 204 002 002 204 003 004 214 005 002 204
file->put(file_header.header_size);
file->put(file_header.protocol_version);
file->write((const char *)&file;_header.profile_version, 2);
file->write((const char *)&file;_header.data_size, 4);
file->write((const char *)&file;_header.data_type, 4);
file->write((const char *)&file;_header.crc, 2);
file->write((const char *)&file;_header, FIT_FILE_HDR_SIZE);
——————————————————
Free Indoor Cycling Software - https://maximumtrainer.com
Perfect, thanks!
void Encode::WriteFileHeader()
{
FIT_FILE_HDR file_header;
if (!file)
return;
file_header.header_size = FIT_FILE_HDR_SIZE;
file_header.profile_version = FIT_PROFILE_VERSION;
file_header.protocol_version = FIT_PROTOCOL_VERSION;
memcpy((FIT_UINT8 *)&file;_header.data_type, ".FIT", 4);
file_header.data_size = dataSize;
file_header.crc = CRC::Calc16(&file;_header, FIT_STRUCT_OFFSET(crc, FIT_FILE_HDR));
file->seekp(0, std::ios::beg);
// file->write((const char *)&file;_header, FIT_FILE_HDR_SIZE);
file->put(file_header.header_size);
file->put(file_header.protocol_version);
file->write((const char *)&file;_header.profile_version, 2);
file->write((const char *)&file;_header.data_size, 4);
file->write((const char *)&file;_header.data_type, 4);
file->write((const char *)&file;_header.crc, 2);
}
——————————————————
Free Indoor Cycling Software - https://maximumtrainer.com
You sir are my hero, I would have never found this error myself, lacking C++ skills.
I used your fix and now the FIT file can be generated on Mac and Windows without issues. ANT should hire you Using Qt 5.4.1
Hi Zanzarone,
FIT_USE_STDINT_H is now defined by default on Apple computers as of the 16.00 release. This fixes some type define issues which were causing you to see the header size of 24 bytes, and should allow for proper encoding of FIT files from the C++ SDK.
——————————————————
Free Indoor Cycling Software - https://maximumtrainer.com