Author Topic: garmin reverse engineering  (Read 2677 times)

0 Members and 1 Guest are viewing this topic.

adarqui

  • Administrator
  • Hero Member
  • *****
  • Posts: 30211
  • who run it.
  • Respect: +7366
    • View Profile
    • Email
garmin reverse engineering
« on: January 16, 2016, 10:47:50 pm »
0
just some links to possible code/article/discussion for reverse engineering/mucking with garmin devices/protocols.

I wanted to access my data via their API, but they ask for a one time $5,000 fee to access their api.. uh..  :uhhhfacepalm:

adarqui

  • Administrator
  • Hero Member
  • *****
  • Posts: 30211
  • who run it.
  • Respect: +7366
    • View Profile
    • Email
Re: garmin reverse engineering
« Reply #1 on: January 16, 2016, 10:58:05 pm »
0
https://www.reddit.com/r/linux/comments/322fav/boring_story_time_my_progress_at/

http://code.google.com/p/garmintools/

https://github.com/Tigge/antfs-cli

https://github.com/kjkjava/garmin-connect-export



tcx parsing (these are the data files on the watch):

https://github.com/shiroandy/garmin-tcx-parser

Quote
Dataframe columns:

"lap" - points at which lap marker was pressed on watch
"time" - date and time in standard format
"UNIXtime" - UNIX time
"hrbpm" - heart rate (beats per minute)
"hrbpmx" - interpolated heart rate
"lat" - latitude
"latx" - interpolated latitude
"lon" - longitude
"lonx" - interpolated longitude
"alt" - altitude
"dist" - cumulative distance (meters)
"dist_interpol" - interpolated distance
"p2p_dist" - point to point distance (from previous to current point)
"tot_dist" - cumulative distance interpolated
"speed" - speed (km/hr)

https://github.com/vkurup/python-tcxparser

https://gist.github.com/HerbCSO/2519671

https://github.com/cjoakim/tcx-js
- nice

https://github.com/zzo/parseTCX

https://github.com/philhofer/tcx


lots of tcx parsers.. might write one in haskell/ocaml etc for fun.


adarqui

  • Administrator
  • Hero Member
  • *****
  • Posts: 30211
  • who run it.
  • Respect: +7366
    • View Profile
    • Email
Re: garmin reverse engineering
« Reply #3 on: January 17, 2016, 03:11:52 pm »
0
just copied everything from my garmin to parse some activity files.. turns out my files are .FIT files.

https://github.com/dtcooper/python-fitparse



a haskell .FIT parser already exists, word!

https://hackage.haskell.org/package/fit

https://github.com/mgiles/fit


Profile.xlsx is arcane, eh.

adarqui

  • Administrator
  • Hero Member
  • *****
  • Posts: 30211
  • who run it.
  • Respect: +7366
    • View Profile
    • Email
Re: garmin reverse engineering
« Reply #4 on: January 17, 2016, 05:24:20 pm »
0
trying to figure out the .FIT file.. I can extract all of the lat/long/speed fields from the file, but, can't figure out why I only have 619 data points for a 55 minute session (~3300 sec), unless my watch records dat points every 5 seconds wtf? that wouldn't make sense:

edit: it could be some form of compression, ie, consecutive speeds that are the same only get logged once, that would make sense.. need to parse these timestamps. once i do that, it'll confirm (or not) that theory.

Code: [Select]
liftM length $ fitFields "/Users/x/code/GARMIN/GARMIN/ACTIVITY/61G90344.FIT" 6
619

Code: [Select]
liftM length $ fitFields "/Users/x/code/GARMIN/GARMIN/ACTIVITY/61G90344.FIT" 6
[11694,17773,3118,1304,949,1046,1683,1701,1910,1606,1494,1676,1669,1553,1471,1609,2150,2210,2242,2422,2492,2429,2088,2073
,2031,1901,1882,1816,1812,1789,1779,1751,1736,1767,1770,1746,1737,1698,1682,1667,1667,1645,1601,1592,1583,1582,1560,1559,
1560,1501,1503,1721,2656,3562,4835,4370,3828,3711,3645,2126,1473,1486,1560,1595,1570,1571,1546,1545,1789,3389,4214,4444 ...

Code: [Select]
*Data.Fit.Example Data.Time Data.Time.Clock.POSIX Fit Control.Monad> liftM (map (\x -> posixSecondsToUTCTime (fromIntegral x)) . map (+ 631065600)) $ fitFields "/Users/x/code/GARMIN/GARMIN/ACTIVITY/61G90344.FIT" 253

[.. 2016-01-16 14:56:12 UTC,2016-01-16 14:56:13 UTC,2016-01-16 14:56:14 UTC,2016-01-16 14:56:27 UTC,2016-01-16 14:56:28 UTC,2016-01-16 14:56:29 UTC]

weird.

adarqui

  • Administrator
  • Hero Member
  • *****
  • Posts: 30211
  • who run it.
  • Respect: +7366
    • View Profile
    • Email
Re: garmin reverse engineering
« Reply #5 on: January 17, 2016, 06:37:33 pm »
0
.FIT file timestamp format:

given a timestamp from the .FIT file, for example: 821890558

add it to the epoch constant they provide: Dec 31, 00:00:00, 1989: 631065600

821890558 + 631065600 = 1452956158

= 01/16/2016 @ 2:55pm (UTC)

2016-01-16T14:55:58+00:00 in ISO 8601

Sat, 16 Jan 2016 14:55:58 +0000 in RFC 822, 1036, 1123, 2822

Saturday, 16-Jan-16 14:55:58 UTC in RFC 2822

2016-01-16T14:55:58+00:00 in RFC 3339

according to: http://www.unixtimestamp.com/index.php

adarqui

  • Administrator
  • Hero Member
  • *****
  • Posts: 30211
  • who run it.
  • Respect: +7366
    • View Profile
    • Email
Re: garmin reverse engineering
« Reply #6 on: January 17, 2016, 09:03:33 pm »
0
latitude/longitude is given in semicircles.

conversions:

Code: [Select]
degrees semicircles = semicircles * (180 / 2^31)
semicircles degrees = degrees * (2^31 / 180)



example:

Code: [Select]
*Data.Fit.Example Data.Time Data.Time.Clock.POSIX Fit Control.Monad Data.List> degrees 312912155
26.22799384407699
*Data.Fit.Example Data.Time Data.Time.Clock.POSIX Fit Control.Monad Data.List> degrees (-957860992)
-80.28698086738586



lat/long tester:
- http://itouchmap.com/latlong.html

adarqui

  • Administrator
  • Hero Member
  • *****
  • Posts: 30211
  • who run it.
  • Respect: +7366
    • View Profile
    • Email
Re: garmin reverse engineering
« Reply #7 on: January 17, 2016, 10:08:26 pm »
0
pulling mph data out of the .FIT file:

Code: [Select]
liftM (take 5 . reverse . sort . map speedMPH) $ readEntries "/Users/x/code/GARMIN/GARMIN/ACTIVITY/61G90344.FIT"
[15.10155689379,15.09708302121,14.906943436559999]


test code on github: https://github.com/adarqui/toybox/blob/master/haskell/mgiles/fit/src/Data/Fit/Example.hs

maxent

  • Hero Member
  • *****
  • Posts: 2420
  • Respect: +1578
    • View Profile
Re: garmin reverse engineering
« Reply #8 on: January 18, 2016, 02:13:38 am »
0
This is cool. heart rate data! I like how it logs GPS data too! I have a fitbit zip but I don't really get very excited about hacking it.. fairly dumb device in comparison.
Training for sub 20 5K & 40" RVJ & 170kg BS @ 85kg bw. log entry template