fit icon indicating copy to clipboard operation
fit copied to clipboard

Created files are invalid

Open cloudlena opened this issue 1 year ago • 5 comments

Problem on Strava

The files created by Encode are somehow invalid for some platforms. For example, if I upload the newly created file to Strava, it says "The upload contains bad data.".

I tried to debug them by having a valid FIT file (e.g., https://github.com/tormoder/fit/blob/master/testdata/me/activity-small-fenix2-run.fit) and running it through the following simple program:

package main

import (
	"bytes"
	"encoding/binary"
	"log"
	"os"

	"github.com/tormoder/fit"
)

func main() {
	testData, err := os.ReadFile("activity-small-fenix2-run.fit")
	if err != nil {
		log.Fatalln(err)
	}

	file, err := fit.Decode(bytes.NewReader(testData))
	if err != nil {
		log.Fatalln(err)
	}

	f, err := os.Create("new.fit")
	if err != nil {
		log.Fatalln(err)
	}
	defer f.Close()

	err = fit.Encode(f, file, binary.LittleEndian)
	if err != nil {
		log.Fatalln(err)
	}
}

Using FitFileViewer

When uploading the new.fit file to https://www.fitfileviewer.com/, it shows empty data (whereas the original activity-small-fenix2-run.fit file showed valid content):

screenshot-2022-09-04-19-49-09

Using GPXSee

Weirdly enough, https://www.gpxsee.org/ shows the new.fit file correctly.

Using RUNALYZE

Analyzing both files with https://runalyze.com/tool/fit-viewer, the main differences seem to be that new.fit has a lot of enhanced_speed, enhanced_max_speed, enhanced_altitude fields on its laps and records (whereas activity-small-fenix2-run.fit doesn't have any enhanced_* fields) and that new.fit always uses 0 as its local message type index.

Update: I did another test run where I removed the code that generates the enhanced_* field generation code from this library and even without those, neither Strava nor FitFileViewer would accept the file. So I'm guessing that those aren't the problem.

cloudlena avatar Sep 04 '22 17:09 cloudlena

For reference, here are both FIT files:

files.zip

cloudlena avatar Sep 05 '22 07:09 cloudlena

Using FIT File Tools

I just did another test, uploading the newly created file to https://www.fitfiletools.com/#/remover#remover. There, the shown data seems to be very weird:

screenshot-2022-09-05-09-41-37

I'm thinking, the issue might be that the timestamps are not encoded correctly.

cloudlena avatar Sep 05 '22 07:09 cloudlena

Using Garmin Online FIT Repair Tool

Uploading the new.fit file to http://garmin.kiesewetter.nl/ yields the following error: Upload status: The file could not be uploaded. The following error occured: Unexpected end of file while parsing Name has occurred. Line 151558, position 9..

cloudlena avatar Sep 05 '22 08:09 cloudlena

Thanks for the report.

I'll try to look into this if I have some available time (together with your other PRs), but it may take a while.

tormoder avatar Sep 06 '22 06:09 tormoder

Thanks, @tormoder! Is there any way I can support more or any more information you might need?

cloudlena avatar Sep 16 '22 15:09 cloudlena