You are here: Forum Home → ANT Developers Forums → ANT+ FIT Forum Has Moved → Thread
int EncodeActivityFile()
{
fit::Encode encode( fit::ProtocolVersion::V20 );
std::fstream file;
file.open("ExampleActivity.fit", std::ios::in | std::ios::out | std::ios::binary | std::ios::trunc);
if (!file.is_open())
fit::FileIdMesg fileIdMesg; // Every FIT file requires a File ID message
fileIdMesg.SetType(FIT_FILE_ACTIVITY);
fileIdMesg.SetManufacturer(FIT_MANUFACTURER_DYNASTREAM);
fileIdMesg.SetProduct(1231);
fileIdMesg.SetSerialNumber(12345);
fit::Mesg mesg;
fit::Field stringField;
stringField.SetSTRINGValue(L"abcdefghijklmnopqrstuvwxyz");
mesg.AddField(stringField);
encode.Open(file);
encode.Write(fileIdMesg);
encode.Write(mesg);
encode.Close()
file.close();
return 0;
}
java -jar ./java/FitCSVTool.jar -d ExampleActivity.fit
Exception in thread "main" java.lang.RuntimeException: java.lang.ArrayIndexOutOfBoundsException: 31
at com.garmin.fit.csv.CSVTool.run(CSVTool.java:232)
at com.garmin.fit.csv.CSVTool.main(CSVTool.java:302)
Caused by: java.lang.ArrayIndexOutOfBoundsException: 31
at com.garmin.fit.csv.MesgCSVWriter.onMesgDefinition(MesgCSVWriter.java:84)
at com.garmin.fit.csv.MesgFilter.onMesgDefinition(MesgFilter.java:89)
at com.garmin.fit.Decode.resume(Decode.java:402)
at com.garmin.fit.Decode.read(Decode.java:344)
at com.garmin.fit.csv.CSVTool.run(CSVTool.java:206)
... 1 more
fit::Encode encode( fit::ProtocolVersion::V20 );
std::fstream file;
fit::FileIdMesg fileIdMesg; // Every FIT file requires a File ID message
fileIdMesg.SetType(FIT_FILE_ACTIVITY);
fileIdMesg.SetManufacturer(FIT_MANUFACTURER_DYNASTREAM);
fileIdMesg.SetProduct(1231);
fileIdMesg.SetSerialNumber(12345);
// Developer Ids are required for Developer Data.
fit::DeveloperDataIdMesg devIdMesg;
devIdMesg.SetDeveloperDataIndex(0);
// Create a Field Description so the decoder knows what our new field represents
fit::FieldDescriptionMesg fieldDescMesg;
fieldDescMesg.SetDeveloperDataIndex(0);
fieldDescMesg.SetFieldDefinitionNumber(0);
fieldDescMesg.SetFitBaseTypeId(FIT_BASE_TYPE_STRING);
fieldDescMesg.SetFieldName(0, L"A Custom Field");
// Create a new record. We will add our custom field as the only field here
fit::RecordMesg newRecord;
fit::DeveloperField aCustomField(fieldDescMesg, devIdMesg);
aCustomField.SetSTRINGValue( L"abcdefg" );
newRecord.AddDeveloperField(aCustomField);
// Write the File
encode.Open(file);
encode.Write(fileIdMesg);
encode.Write(devIdMesg);
encode.Write(fieldDescMesg);
encode.Write(newRecord);
if (!encode.Close())
{
printf("Error closing encode.\n");
return -1;
}
file.close();