Welcome Guest,Register Now
Log In

ANT Forum

Welcome guest, please Login or Register

   

Create new message type without rebuilding FIT SDK?

Rank

Total Posts: 25

Joined 2016-08-16

PM

Is it possible to create a new message type without rebuilding the SDK? We're supporting multiple binary platforms and would like to know if we can create a new message type in code, rather than by rebuilding the FIT SDK for the different platforms.

Here is an example with a mesg with a string field that works in encoder.cpp but crashes FitVCSTool.jar

int EncodeActivityFile()
{
   fit
::Encode encodefit::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;


Put the string into the output FIT file, but the decoder chokes on the FIT file with an arrary out of bounds exception:

java -jar ./java/FitCSVTool.jar -d ExampleActivity.fit
Exception in thread 
"main" java.lang.RuntimeExceptionjava.lang.ArrayIndexOutOfBoundsException31
 at com
.garmin.fit.csv.CSVTool.run(CSVTool.java:232)
 
at com.garmin.fit.csv.CSVTool.main(CSVTool.java:302)
Caused byjava.lang.ArrayIndexOutOfBoundsException31
 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 

     
Rank

Total Posts: 25

Joined 2016-08-16

PM

Perhaps what I need to know is how to create a "local message type" as referenced in the "D00001309 FIT File Types Description Rev 2.1 .pdf"      
RankRankRank

Total Posts: 68

Joined 0

PM

It is not a good idea to programmatically create new message types. Message Types are a key component of the Interoperable component of FIT. If Message Numbers are assigned without sharing the assigned number or if there is confusion about what the message number means it may confuse decoders.

What is it you are trying to do? Do you need to dynamically add fields? What use case requires you to dynamically create messages?

The FIT SDKs are not setup to allow for this kind file creation.

Thanks      
Rank

Total Posts: 25

Joined 2016-08-16

PM

I understand that this isn't the best approach. However my understanding was that if the message type was unknown then the decoder would ignore the message.

We're trying to experiment with the FIT SDK, and encode some device/app/version identifiers that aren't possible with the Garmin based DeviceInfoMesg. Though we could add fields programmatically to that message type.

We'd also like to add debugging information while we develop our translator between FIT and our existing data formats. It seemed like it would be easier to programmatically create new message types within our group rather than run FitGen and rebuild the SDK for four plus OSes on each revision. Once things are nailed down a bit more we can run FitGen.

Thanks

     
RankRankRank

Total Posts: 68

Joined 0

PM

Sounds like Developer Data might fit into your use-case. Developer Data allows for the file to specify extended fields by including some additional meta-data in the file that the decoders can then use.

We have however found a bug in the C++ implementation of Developer Data Encode that will be fixed in the next SDK release planned for 2016-09-04

The code below will create a new Activity File with a custom field in the Record Message in C++ once the bug is fixed.

fit::Encode encodefit::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(0L"A Custom Field");

// Create a new record. We will add our custom field as the only field here
fit::RecordMesg newRecord;
fit::DeveloperField aCustomField(fieldDescMesgdevIdMesg);
aCustomField.SetSTRINGValueL"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(); 


     
Rank

Total Posts: 25

Joined 2016-08-16

PM

Thank you. Are Developer Fields limited in length or number in any way? If I wanted to add 1000 developer fields to every RecordMesg would that work with the FIT SDK? Are there any limits on the length of the FIT_BASE_TYPE_STRING fields?
     
RankRankRank

Total Posts: 68

Joined 0

PM

We limit to 254 unique developer fields (based on SetFieldDefinitionNumber) per developer, and 16 developers per file (based on SetDeveloperDataIndex)

Each field in developer data can have a MaxSize of 254 bytes. (Beware the SDK does not provide checks for this)

So theoretically there is a way to use 4 developers with the full set of developer fields to get 1000 developer fields per message.

The same applies for string types. Where the max size of the string is 254 including the '\0' at the end of the string.

Native fields have a max size of 254 for the entire message. This is a holdover from the C SDK which provides a static memory footprint useful for embedded platforms with limited memory      
Rank

Total Posts: 25

Joined 2016-08-16

PM

Thanks. Just to confirm: the maximum length of FIT message is 254 bytes. Does this include the record header (one byte)?
     
Rank

Total Posts: 25

Joined 2016-08-16

PM

Having re-read "D00001275 Flexible & Interoperable Data Transfer (FIT) Protocol Rev 2.2.pdf"
Section 4.8.3 Re-defining Local Message Types and having had looked at the source code I now also understand that "Local Message Types" are really just "4 bit identifiers" that avoid extra definition messages. They aren't actually new message types. Just aliases.