tormoder / fit

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

All values are default values in new fields added with fitgen #76

Open jsliacan opened 1 year ago

jsliacan commented 1 year ago

I'm not sure if this is an issue, but I need help figuring out why all values from radar_current, radar_speeds, etc. fields that I added with fitgen default to max uint8 or uint16 as I define them. The values from other fields are parsed correctly (e.g. HR or distance). I apologize in advance if this is a user error!

Let's focus on radar_current (which is the current count of cars coming up from behind registered by Garmin radar). See the file displayed below. The last entry is 20.

image

I defined radar_current as uint8. See SDK's Profile.xlxs screenshot:

Screenshot from 2023-01-26 12-09-25

Once I regenerate a few files with fitgen and I tell go about it with replace github.com/tormoder/fit => /home/jsliacan/Github/fit in go.mod, I run a modified example code from here: https://github.com/tormoder/fit/blob/14e5de2989b78f0219d390251791047b1ad629a9/example_test.go#L45 where I extract the last entry in the radar_current field in the record (snippet below). I expected to see 20 but I get 255. However, for hr field (which I didn't generate with fitgen) I get the correct value of 114.

var numCars, hr int
for _, record := range activity.Records {
    numCars = int(record.RadarCurrent)
    hr = int(record.HeartRate)
}
fmt.Println(hr, numCars)

Any help appreciated.

tormoder commented 1 year ago

I'll need to take a closer look, but you're sure field def numbers are correct? (190, 191 and 192.)

jsliacan commented 1 year ago

but you're sure field def numbers are correct? (190, 191 and 192.)

I chose them at will from between 0 and 255, paying attention to having them unique (within the Profile.xlsx file). I can't find any information on this, are they pre-defined somewhere? I'm not having much luck finding anything about radar_current, for instance. Either online, in SDK files, or in the repo. Thanks

tormoder commented 1 year ago

They'll need to match the field def numer they're encoded with in the file. It looks like these are undocumented/"hidden", and not present in the SDK specification.

What did you use to generate the file overview in your issue?

You can try to decode the file with debug logging, and then look at the different field defintions to get at hint about field def numbers. See this decode option: https://github.com/tormoder/fit/blob/a5da86ae366de3f250376a7997542c96d54ede53/opts.go#L27

jsliacan commented 1 year ago

Thanks for your time and all the info! I'll probably just transform the file to CSV and read it that way, seems easier at this point. I can see all the fields and correct values in a csv.

What did you use to generate the file overview in your issue?

I just loaded my file over here: https://www.fitfileviewer.com/. Seems to work OK, not sure what they do behind the scenes.

You can try to decode the file with debug logging, and then look at the different field defintions to get at hint about field def numbers.

Many thanks for the tip! The project is actually about the data in the fit files, so I'll move onto that now. I didn't know the radar fields are so non-standard, I expected it to work out of the box... And thanks for the fit module btw.

Feel free to close the issue any time.

jsliacan commented 1 year ago

Hi again,

So I looked at it a bit more and it seems that there is something called "Developer Data Fields", which you probably know, described here.. I can't work out how to access those using your fit module, e.g. developer field # 2 (with value 20 in the entry below, obtained in python).

{'timestamp': datetime.datetime(2023, 1, 12, 19, 49, 41, tzinfo=datetime.timezone.utc), 'position_lat': 696972206, 'position_long': 185899572, 'distance': 30808.85, 'altitude': 60.200000000000045, 'speed': 0.0, 88: 100, 'heart_rate': 114, 'temperature': 21, 'enhanced_speed': 0.0, 'enhanced_altitude': 60.200000000000045, 'developer_fields': {0: [0, 0, 0, 0, 0, 0, 0, 0], 1: [0, 0, 0, 0, 0, 0, 0, 0], 2: 20, 3: 0, 4: 0}}

They seem to have definition numbers which are "local" in the sense that if I use them in the Profile.xlsx file, then run fitgen to generate code, there is a duplicate index in the slice in profile.go. That makes sense (EDIT: esp since these dev fields are supposed to eliminate the need for going through editing Profile.xlsx, running fitgen, etc.), but I can't think of a way to access these developer fields with your fit module. I'm assuming this is possible, but I might be wrong. Could you please give me a few more pointers here? As usual, any help is much appreciated! Thanks

PS: when I decode the fit file with java -jar FitDecodeExample.jar file_from_Forerunner645.fit I get a very readable output (including all records and fields in it), and towards the top I see these Dev Field Descriptions:

New Developer Field Description
   App Id: c5d949c3-9acb-4e00-bb2d-c3b871e9e733
   App Version: 51
   Field Num: 0
New Developer Field Description
   App Id: c5d949c3-9acb-4e00-bb2d-c3b871e9e733
   App Version: 51
   Field Num: 1
New Developer Field Description
   App Id: c5d949c3-9acb-4e00-bb2d-c3b871e9e733
   App Version: 51
   Field Num: 2
New Developer Field Description
   App Id: c5d949c3-9acb-4e00-bb2d-c3b871e9e733
   App Version: 51
   Field Num: 5
New Developer Field Description
   App Id: c5d949c3-9acb-4e00-bb2d-c3b871e9e733
   App Version: 51
   Field Num: 6

Also, towards the end of the file, there's another one (an extra, which does not correspond to any of my radar fields):

New Developer Field Description
   App Id: c5d949c3-9acb-4e00-bb2d-c3b871e9e733
   App Version: 51
   Field Num: 3
tormoder commented 1 year ago

Data Developer Fields are not supported fully be this libary yet.

It supports parsing files containing them (i.e. parse files containing them without crashing), but they're not parsed/available yet.

I'm want and plan to support them, but have not had the time to work on the feature. There is a fork that supports them (I think), https://github.com/hammerheadnav/fit, and I hope I may integrate some of that work.

That being said, I'm not clear to me if the radar field you mention is a Data Developer Field or just an "undocumented" SDK profile field.

jsliacan commented 1 year ago

@tormoder thanks for the info and your work around here! Feel free to close this issue as you prefer.