mrihtar / garmin-fit Goto Github PK
View Code? Open in Web Editor NEWPerl code for reading and conversion of Garmin FIT binary files
Perl code for reading and conversion of Garmin FIT binary files
I was just playing around with some sample FIT files and for most of them it "somehow" works but one was not parsed at all -> It is attached -> Maybe could you check on it what happened ?
Thanks,
TkTz
Laufen.zip
There are now 10 messages for bike_profile with message_number=6 in Settings.fit. Each of these messages has a message_index field which contains the sub-field mask which contains what appears to be a valid index value.
bike_profile (6, type: 0, length: 81 bytes):
name (0-16-STRING): "Bike 10"\n
message_index (254-1-UINT16): selected=0,reserved=0,mask=9 (9)
...
It's unclear how one might reference a specific index of a single message_number.
Is this supported?
Today I tried to import a virtual ride from zwift. The file was uploaded to garmin and I downloaded it from there as usual. But then I am always geting an error. (line 260)
I am looking forward to also import my virtual rides.
Thanks for your work on this tool!
2269877207.zip
I have converted FIT to SLF and viewed in sigma, see altitude displayed
Original FIT (from SUUNTO watch) and converted files are here:
https://github.com/ainthek/map-projects/tree/master/misc/fit2slf-bug
Thanx for your time and work.
fit2slf 2.14 Copyright (c) 2016-2020 Matjaz Rihtar (Sep 7, 2020)
Garmin::FIT Copyright (c) 2010-2017 Kiyokazu Suto
FIT protocol ver: 2.4, profile ver: 21.32
I am not skilled enough to make changes here (yet), but I found that editing my download of the FIT.pm file to make this diff then the fitdump output shows Di2 shifting counts and the Garmin Edge1030 sweat loss summary:
107 => +{'name' => 'unknown107'}, # unknown UINT16 108 => +{'name' => 'unknown108'}, # unknown UINT16
5291d5290
< 178 => +{'name' => 'sweat_loss', 'unit' => 'ml'},
I hope that someone might add this to the code so it would be useful to others.
Hello mrihtar,
I have a problem to convert a FIT-File exported from FitFileRepairTool (http://fitfilerepairtool.info/).
The FIT-File was original created as an export in BKOOL-Bike Trainer Software.
But it contains 2 Rounds, so I load this file inte the FitFileRepairTool, to concatinate the 2 Rounds to one. After this I make an export also into a new FIT-File.
When I start the pearl-script to convert the new File it stops whit an error-message:
"Use of uninitialized value in concatenation (.) or string at ./fit2slf_orig.pl line 258"
Can you anlyse this problem?
(See Fit-File inthe attachment)
a5520321.fit.zip
Best regards Walter
Please can you specify config file path as parameter ? If would be helpfull, instead of using current dir.
Thank you.
the string $p:: is interpreted as a variable name rather than the variable $p followed by two colons. Add braces to remove the ambiguity and avoid a warning.
first thank you to mrihtar for develop and programing this utility.
I use the perl-file fit2slf.pl to convert my workouts from fit-file-format to slf-file-format.
After converting, I import them into the Sigma Data Center. This works very fine till the last firmware update of the wahoo elemnt.
When I try to convert the fit-file now, I get an error:
"Can't use an undefined value as a HASH reference at ./fit2slf.pl line 414".
Can you please take a look at this problem?
I can sent you an example file in the old and the new export format of the wahoo elemnt.
best regards streamtec
The perl module has some problems with big endian values.
I can add a pull request for this, but I don't have a big endian system to check and a final confirmation that the last point fixes wrong ordering of arrayed-valued fields is still missing (see https://github.com/Runalyze/Runalyze/issues/1875#issuecomment-234050418).
PS: Thanks for having a repo for Kiyokazu's perl module!
Hi @mrihtar,
thanks a lot for the program.
I am trying to import a few files from the discontinued PC Sport software (VDO Z3+ PC-Link):
The exercise can be exported as Garmin FIT file.
After the import to Sigma Data Center 5.8.8 I have some problems with duration, calories, average speed and work done.
Could you give me advice what I have to adjust in the code?
Regards
Tobias
Hello mrihtar,
today I want to convert a fit file from my wahoo elemnt.
There was an firmware update since last converting a file.
I get this error-message:
"Use of uninitialized value $prev_timestamp in subtraction (-) at ./fit2slf_orig.pl line 1438.
Illegal division by zero at ./fit2slf_orig.pl line 1446."
Can you have a look where's the problem?
I have attached the FIT-File.
ELEMNT.fit.zip
Suunto does write a subjective feeling to the activity summary in their fit files as developer data. However, this module does not respect the developer field definition because of an "invalid base type". I don't see why fit_base_type_id=0=enum
should be invalid.
Uncommenting the if block at
Line 6843 in 800fffa
We got a file resulting in an endless loop: endless-loop.zip
I'm not sure what's wrong with the file, as Garmin's FitToCSV.bat
can't convert it:
FIT CSV Tool - Protocol 2.0 Profile 20.81 Release
Exception in thread "main" java.lang.RuntimeException: com.garmin.fit.FitRuntim
Exception: FIT decode error: Endian 118 not supported. Error at byte: 242
at com.garmin.fit.csv.CSVTool.run(CSVTool.java:238)
at com.garmin.fit.csv.CSVTool.main(CSVTool.java:324)
Caused by: com.garmin.fit.FitRuntimeException: FIT decode error: Endian 118 not
supported. Error at byte: 242
at com.garmin.fit.Decode.read(Decode.java:770)
at com.garmin.fit.Decode.resume(Decode.java:371)
at com.garmin.fit.Decode.read(Decode.java:348)
at com.garmin.fit.csv.CSVTool.run(CSVTool.java:212)
... 1 more
Still, having an endless loop crashes the whole process. The following patch fixes the issue for us:
diff --git a/Garmin/FIT.pm b/Garmin/FIT.pm
--- a/call/perl/Garmin/FIT.pm
+++ b/call/perl/Garmin/FIT.pm
@@ -7608,7 +7608,7 @@ sub fetch {
$desc_i = ($rechd & $rechd_mask_cth_local_message_type) >> $rechd_offset_cth_local_message_type;
}
elsif ($rechd & $rechd_mask_definition_message) {
- $self->fetch_definition_message;
+ $self->fetch_definition_message || return undef;
}
else {
$desc_i = $rechd & $rechd_mask_local_message_type;
@@ -7621,7 +7621,7 @@ sub fetch {
my $desc = $self->data_message_descriptor->[$desc_i];
if (ref $desc eq 'HASH') {
- $self->fetch_data_message($desc);
+ $self->fetch_data_message($desc) || return undef;
}
else {
$self->error(sprintf("%d at %ld: not defined", $rechd, $j));
Hi, I saw your entry in the German MTB news forum. Great tool. After installing Strawberry Perl on Win64 and the 3 Modules (and a reboot of the PC), I get the following error message. Any idea what went wrong ? Thank you.
C:>cd Strawberry
C:\Strawberry>dir
Volume in Laufwerk C: hat keine Bezeichnung.
Volumeseriennummer: 2099-FEC9
Verzeichnis von C:\Strawberry
16.10.2016 13:57
.C:\Strawberry>fitdump.pl
Bareword found where operator expected at C:\Strawberry\fitdump.pl line 6, near ""en" class"
(Missing operator before class?)
Bareword found where operator expected at C:\Strawberry\fitdump.pl line 22, near "<title>Garmin"
(Missing operator before Garmin?)
Can't modify numeric lt (<) in scalar assignment at C:\Strawberry\fitdump.pl line 6, near ""en" class"
syntax error at C:\Strawberry\fitdump.pl line 6, near ""en" class"
Unrecognized character \xC2; marked by <-- HERE after at master <-- HERE near column 44 at C:\Strawberry\fitdump.pl line 22.
C:\Strawberry>fit2slf.pl
Bareword found where operator expected at C:\Strawberry\fit2slf.pl line 6, near ""en" class"
(Missing operator before class?)
Bareword found where operator expected at C:\Strawberry\fit2slf.pl line 22, near "<title>Garmin"
(Missing operator before Garmin?)
Can't modify numeric lt (<) in scalar assignment at C:\Strawberry\fit2slf.pl line 6, near ""en" class"
syntax error at C:\Strawberry\fit2slf.pl line 6, near ""en" class"
Unrecognized character \xC2; marked by <-- HERE after at master <-- HERE near column 44 at C:\Strawberry\fit2slf.pl line 22.
C:\Strawberry>fit2slf.pl test.fit
Bareword found where operator expected at C:\Strawberry\fit2slf.pl line 6, near ""en" class"
(Missing operator before class?)
Bareword found where operator expected at C:\Strawberry\fit2slf.pl line 22, near "<title>Garmin"
(Missing operator before Garmin?)
Can't modify numeric lt (<) in scalar assignment at C:\Strawberry\fit2slf.pl line 6, near ""en" class"
syntax error at C:\Strawberry\fit2slf.pl line 6, near ""en" class"
Unrecognized character \xC2; marked by <-- HERE after at master <-- HERE near column 44 at C:\Strawberry\fit2slf.pl line 22.
Hi,
till last year the time_created element of the exported Garmin swim file had both a human readable date and a numeric version.
The latest file I downloaded however only provides me with the numeric version: how can I transform it to a date as before?
Thankx a lot!
@mrihtar: Great initiative and 100% what I´m looking since 1,5 years.
Unfortunatelly import of the created .slf file didn´t work, see screenshot.
Any ideas what went wrong?
I'm trying to do some data analysis of .fit
files and I love Garmin::FIT
for helping me with this. But not being a Perl developer by trade, it would be really slick if fitdump.pl
had a --json
option or some way to output the data as JSON. Ideally, you'd output basically an array of objects and each object would correspond with the type
of data it corresponds to. I will look into submitting a PR for this in the meantime but I figured I'd start here to get your opinion, and possibly save time by having an expert knock it out.
Thanks again for this awesome library.
Do you have an idea how to fix it?
@mrihtar , translation works now perfect but some information is missing in the .slf file.
The information about laps and break times are not visible in the Data Center.
Would that something be you could implement in your script?
Hi,
I convert a ride today with the "fit master", and I don't have a lap, no auto pause, and the power is wrong (I've a power metter)
Can you help me with this?
Regards
I have FIT files that show protocol ver: 1.00, profile ver: 20.44
and when dumping them there are quite a few unknown values... what's the process by which this library gets updated to newer versions?
For further analysis it is helpful to have the absolute timestamps in the monitoring messages. It can be calculated from the relative timestamp_16 fields. I have written a small gawk script to calculate and add this absolute timestamps. What do you think about an integration of this calculation in the perl scripts?
https://github.com/8cH9azbsFifZ/garmin_fit_timestamp16_2_timestamp
It would be nice if this distribution was also available on CPAN. If you agree with this, and need some help, then I can provide a pull request with the required changes (a Makefile.PL, maybe a basic test suite etc.)
In gpx files generated by fit2gpx.pl, I find points with zero longitude and zero latitude. Identifing the respective point in the fitdump.pl output via timestamp (timezone considered correctly) shows, that location information was not provided in this case. See below for respective data from dump and gpx file.
fitdump.pl output:
record (20, type: 1, length: 19 bytes):
timestamp (253-1-UINT32): 2019-02-13T12:39:05 (918992345)
distance (5-1-UINT32): 8060.45 m (806045)
altitude (2-1-UINT16): 521.8 m (5109)
xxx87 (87-1-UINT16): 0
xxx88 (88-1-UINT16): 300
heart_rate (3-1-UINT8): 157 bpm (157)
cadence (4-1-UINT8): 86 rpm (86)
temperature (13-1-SINT8): 17 deg.C (17)
fractional_cadence (53-1-UINT8): 0.00 rpm (0)
corresponding fit2gpx.pl output
<trkpt lat="0" lon="0"> <ele>521.8</ele> <time>2019-02-13T11:39:05Z</time> <extensions> <gpxtpx:TrackPointExtension> <gpxtpx:hr>157</gpxtpx:hr> <gpxtpx:cad>86</gpxtpx:cad> <gpxtpx:atemp>17</gpxtpx:atemp> </gpxtpx:TrackPointExtension> </extensions> </trkpt>
A today's conversion of a fit file using fit2gpx.pl and a German locale created an invalid XML file due to
<name>Track 19-Mär-23 11:58</name>
where the umlaut-a was in iso-8559-1 encoding, not in utf-8 encoding.
Suggestions:
Line 569 in f6ecc54
binmode(TMP, ':utf8')
or Encode::encode_utf8
or so.A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.