How to Create a Fit File

Asked 2 years ago, Updated 2 years ago, 91 views

[Overview]


It has the function of dropping the bicycle's running log into a Fit file and uploading it to Strava. I am developing an Android app.
I am using fitSDK to create the Fit file.
I am having difficulty working with this library.

[Details]
The log retrieved while driving contains data that fitSDK does not support in advance.
For example, the file for recording cadences is pre-prepared with fitSDK.

record.cadence=hoge
encoder.write(record)

You can write as above, but
You will need to create your own address (assuming you use a string).

Currently, I am into adding this address field to the record myself.

[Code]
Below is the kotlin code currently being implemented.

val startAddressFieldDescMesg=FieldDescriptionMesg()
        startAddressFieldDescMesg.developerDataIndex=0.toShort()
        startAddressFieldDescMesg.fieldDefinitionNumber = 0.toShort()
        startAddressFieldDescMesg.fitBaseTypeId=Fit.BASE_TYPE_STRING.toShort()
        startAddressFieldDescMesg.setFieldName(0, "startAddress")
        encoder.write (startAddressFieldDescMesg)
        val startAddressField=DeveloperField(startAddressFieldDescMesg, developerIdMessage)
        record.addDeveloperField(startAddressField)

The error message is as follows, and it seems that the field has not been successfully added to the record.

com.garmin.fit.FitRuntimeException:Incompatible Protocol Features

[What's known?]
·Strava only supports version 1 of fitSDK, and if you specify version 2 and implement it above, the Fit file will be created correctly.
In other words, the way DeveloperField is added in version 1/2 is likely to be different.

·If you did not add an address, you could create a Fit file and upload it to Stava, so
The error may be caused by an additional part of the address field.

If you know how to add your own field to the Fit file, please let me know.
Thank you for your cooperation.

kotlin garmin

2022-09-30 14:12

1 Answers

Now I know how to add DeveloperFieldwp to the Fit file and upload it to Strava

Here's how to solve it

F Set Fit's Protocol version to 2

encoder=FileEncoder(file,Fit.ProtocolVersion.V2_0)

RAdd DeveloperField to Record

val startAddressFieldDescMesg=FieldDescriptionMesg()
        startAddressFieldDescMesg.developerDataIndex=0.toShort()
        startAddressFieldDescMesg.fieldDefinitionNumber = 0.toShort()
        startAddressFieldDescMesg.fitBaseTypeId=Fit.BASE_TYPE_STRING.toShort()
        startAddressFieldDescMesg.setFieldName(0, "startAddress")
        encoder.write (startAddressFieldDescMesg)
        val startAddressField=DeveloperField(startAddressFieldDescMesg, developerIdMessage)
        record.addDeveloperField(startAddressField)

You should be able to verify that the address (start) is written to the Fit file.
(Use the FitCSV tool included with FitSDK to convert to csv and open the file in Excel.)


2022-09-30 14:12

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.