tormoder / fit

A Go package for decoding and encoding Garmin FIT files
MIT License
243 stars 42 forks source link

Created files are invalid #69

Closed cloudlena closed 1 year ago

cloudlena commented 2 years ago

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 commented 2 years ago

For reference, here are both FIT files:

files.zip

cloudlena commented 2 years ago

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 commented 2 years ago

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..

tormoder commented 2 years ago

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.

cloudlena commented 2 years ago

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

cloudlena commented 1 year ago

@tormoder are there any news on this issue? Can I support in any way?

kalyan02 commented 1 year ago

@tormoder Hi. Could you please share if you've made decision about this MR? I see hammerhead is using it and I'd like to make use of it as well.

tormoder commented 1 year ago

Just released v0.15.0 with #67 included.

@cloudlena, if you're still interested, you can check if that change solves your issue.

cloudlena commented 1 year ago

Thanks, @tormoder. Indeed, that fixed it for me :tada: