tormoder / fit

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

fitgen only prints help output regardless of arguments #75

Closed jsliacan closed 1 year ago

jsliacan commented 1 year ago

PC info

$ uname -a
Linux workbox 6.0.8-300.fc37.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Nov 11 15:09:04 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

Go version

$ go version
go version go1.19.2 linux/amd64

I need to read file where record section looks as in the printscreen, i.e. it has extra radar fields that I need to access. Screenshot from 2023-01-22 08-50-36

From what I read it seems that the best way would be to use fitgen to regenerate the code in messages.go to include the fields I want. So I downloaded latest FIT SDK (FitSDKRelease_21.94.00.zip) unzipped, added rows in Profile.xlsx spreadsheet under record section and went to use fitgen. No matter what arguments I provide, or what flags I specify, I always get help docstring back:

$ fitgen ~/Downloads/FitSDKRelease_21.94.00/Profile.xlsx 
usage: fitgen [flags] [path to sdk zip, xls or xlsx file] [output directory]
  -hrst
        handle quirk where needed 'heart rate source type' field not set as active in official profile spreadsheet
  -sdk string
        provide or override SDK version printed in generated code
  -test
        run all tests in output directory after code has been generated
  -timestamp
        add generation timestamp to generated code
  -verbose
        print verbose debugging output for profile parsing and code generation

I made fitgen with make build and make fitgen. When I run tests, they fail as follows:

=== CONT  TestGenerator/16.20
    generator_test.go:240: profile fingerprint differs: got: 7895121194688969708, want 17457331584132431807
    generator_test.go:251: current output written to: testdata/16.20.xlsx.current
--- FAIL: TestGenerator (0.00s)
    --- FAIL: TestGenerator/21.40 (0.51s)
    --- PASS: TestGenerator/20.43 (0.58s)
    --- PASS: TestGenerator/20.27 (0.66s)
    --- PASS: TestGenerator/20.14 (0.69s)
    --- FAIL: TestGenerator/16.20 (1.06s)
FAIL
FAIL    github.com/tormoder/fit/cmd/fitgen/internal/profile 1.076s
=== RUN   TestGolden
--- PASS: TestGolden (0.00s)
=== RUN   TestRunningChecksum
--- PASS: TestRunningChecksum (0.00s)
PASS
ok      github.com/tormoder/fit/dyncrc16    (cached)
?       github.com/tormoder/fit/internal/types  [no test files]
=== RUN   ExampleSetLocalTimeZone
--- PASS: ExampleSetLocalTimeZone (0.01s)
PASS
ok      github.com/tormoder/fit/timeutil    0.012s
FAIL
make: *** [Makefile:29: test] Error 1

It's possible that I misunderstood something, so any help is appreciated. Thanks in advance!

tormoder commented 1 year ago

The error message should be improved, but I think you're missing the output directory argument.

Could your try $ fitgen ~/Downloads/FitSDKRelease_21.94.00/Profile.xlsx . ?

jsliacan commented 1 year ago

I did indeed miss the output dir, thanks for pointing it out. However, it doesn't seem to help.

$ fitgen -sdk ~/Downloads/FitSDKRelease_21.94.00/Profile.xlsx .
usage: fitgen [flags] [path to sdk zip, xls or xlsx file] [output directory]
  -hrst
        handle quirk where needed 'heart rate source type' field not set as active in official profile spreadsheet
  -sdk string
        provide or override SDK version printed in generated code
  -test
        run all tests in output directory after code has been generated
  -timestamp
        add generation timestamp to generated code
  -verbose
        print verbose debugging output for profile parsing and code generation

And if I don't provide the -sdk flag, I get a complaint about it.


$ fitgen ~/Downloads/FitSDKRelease_21.94.00/Profile.xlsx .
fitgen: fit source output directory: .
2023/01/22 17:06:11 -sdk flag required if input is .xls(x)
tormoder commented 1 year ago

Try $ fitgen -sdk 21.94 ~/Downloads/FitSDKRelease_21.94.00/Profile.xlsx .

-sdk is not the inuput file, but a ("manual") string for the version. The version is normally extracted from the ZIP filename.

jsliacan commented 1 year ago

Ah, I see, it's SDK version, not SDK. OK. That "worked" in that the code generation started. I got the following error though (it's unrelated to the title of this issue, not sure if I can keep asking here...).

fitgen: transforming message: ExdDataFieldConfiguration
fitgen: parsing components for field: ConceptField
fitgen: transforming message: ExdDataConceptConfiguration
fitgen: parsing components for field: ConceptField
fitgen: transforming message: DiveSummary
fitgen: transforming message: Hrv
fitgen: generating code
panic: genMsgs: could not find type for ref field name "HeartRateSourceType" for message "DiveSettings"

goroutine 1 [running]:
github.com/tormoder/fit/cmd/fitgen/internal/profile.(*codeGenerator).genDynamicGetter(0xc000ccf8b0?, 0xc000d62b40, 0x1?)
    /home/jsliacan/Github/fit/cmd/fitgen/internal/profile/codegen.go:295 +0x1305
github.com/tormoder/fit/cmd/fitgen/internal/profile.(*codeGenerator).genMsgs(0xc000ccf8b0?, {0xc000e5e400, 0x58, 0xc0002a8cc0?})
    /home/jsliacan/Github/fit/cmd/fitgen/internal/profile/codegen.go:164 +0x46c
github.com/tormoder/fit/cmd/fitgen/internal/profile.(*codeGenerator).generateMsgs(0xc000ccf8b0, {0xc000e5e400, 0x58, 0x80})
    /home/jsliacan/Github/fit/cmd/fitgen/internal/profile/codegen.go:51 +0x73
github.com/tormoder/fit/cmd/fitgen/internal/profile.(*Generator).genCode(0xc000128300)
    /home/jsliacan/Github/fit/cmd/fitgen/internal/profile/generator.go:179 +0xd5
github.com/tormoder/fit/cmd/fitgen/internal/profile.(*Generator).GenerateProfile(0xc000128300)
    /home/jsliacan/Github/fit/cmd/fitgen/internal/profile/generator.go:102 +0xcf
main.main()
    /home/jsliacan/Github/fit/cmd/fitgen/main.go:124 +0x9fd

Do you have a guess what I can try next? Just for clarity, I did not touch "HeartRateSourceType" or "DiveSettings" in the Profile.xlsx (or anywhere else). Thanks for the help so far!

tormoder commented 1 year ago

That's a "bug" in the offical profile spreadsheet. Try adding this flag:

-hrst
        handle quirk where needed 'heart rate source type' field not set as active in official profile spreadsheet
jsliacan commented 1 year ago

Oh no, I even read the help for that flag some time in the process but didn't pair it with the error. Now it worked seemingly without any failures. I'll close this issue, and thanks for all your quick help! Much appreciated.