Welcome Guest,Register Now
Log In

ANT Forum

Welcome guest, please Login or Register

   

Problem: Creating FIT file and saving data, C++

Rank

Total Posts: 1

Joined 2014-08-27

PM

Hello

Im trying to save data from a Heart rate sensor into a FIT file. This works great in java/android,
but not so good when Im trying in C++.

I have used the encode.cpp as a reference to my code.

So I got three buttons:

1. Create: To create the FIT file and writing down some fileIdmesg.

2. Record: Saves data from the Heart rate sensor.

3. Close: To close the file.

Create:
file.open("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");
   
}

   fit
::FileIdMesg fileIdMesg;
   
fileIdMesg.SetManufacturer(FIT_MANUFACTURER_DYNASTREAM);
   
fileIdMesg.SetProduct(0);
   
fileIdMesg.SetSerialNumber(12345);
   
   
encode.Open(file);
   
encode.Write(fileIdMesg);
   if (!
encode.Close())
   
{
      printf
("Error closing encode.\n");
   


Record:

recordMesg.SetTimestamp(timestamp);
recordMesg.SetHeartRate(11);
encode.Write(recordMesg); 


Close:

file.close(); 


The problem I have is when I click on the buttons in the order Create, Record and Close.
The FIT CSV tool gives me: File is not a FIT format. Check file header.

When I try click the buttons in the order Create and Close, works fine no errors. FIT file can be converted to a CSV file.

When I put the code in the Record to Create, everyting is working as normal. I want to write recordmesg data to the
FIT file when I choose to do it, not just when I creating the file. Why is it not working? :(

Thanks Macke      
RankRankRank

Total Posts: 91

Joined 2012-10-12

PM

Hi Macke,

I think you need to move
if (!encode.Close())
   
{
      printf
("Error closing encode.\n");
   


from your create to your close button, this call updates the header file size and computes the FIT files CRC when it is complete.