Java o C FIT SDK in PHP project?

Goodmorning, I have a php project and I need to parse fit files coming from garmin Health API.

Actually I'm using https://github.com/adriangibbons/php-fit-file-analysis and it works fine in 90% of cases. I have issues in two cases:

1) it doesn't support multisport activities

2) in very strange (and rare) cases, it happen that a fit file (apparently recorded like other fit file) has an unsupported file format and we cannot extract values. You can see this fit files at this link on my server http://www.coachpeaking.com/extra/fit-examples.zip . These swim activities are recorded by the same user with the same garmin device. One of them is supported, other one no.

In order to solve these issues, I try to understand how to use official Fit SDK over a php project.

My app is installed on a linux centus cloud server, so I think I can install a jre and use java FitCSVTool.jar to extract data in a csv temporary file and read it with php script.

I try to use jar launching a command line script like 

java -jar FitCSVTool.jar --defn none --data record <file>

but I see that gps lat/lng coordinates are extracted without decimals values, so lat = 56.3425353 becomes 563425353

Have you any suggestion for me?

Which could be the best way to parse fit files in a php project?
  • In a FIT file latitude and longitude values are stored as semicircles. The formulas to convert between semicircles and degrees are:

    degrees = semicircles * ( 180 / 2^31 )
    semicircles = degrees * ( 2^31 / 180 )

    If you are going to use the FITCSV Tool to convert FIT Files to CSV, you can filter the messages to only include the ones that you will use in your application. This will make the parsing of the CSV files easier, and it will execute faster.

    This command will give you a CSV file with just Record, Lap, Session, and Activity messages. You can add and remove message names from the list. The "-u" options will keep "unknown" values out of the CSV file. 

    java -jar $FitCSVToolJar -b inputfile outputfile --defn none --data record,lap,session,activity -u

    This command will output two CSV files: outputfile.csv and outputfile_data.csv. If there are more than one message type in the list I would use the first file (the one without "_data" in the name).

    The command line options for the FITCSV Tool can be found here:

    developer.garmin.com/.../

  • Hello Ben, thanks for your answer. It was very useful.

    So you think its a good idee to use java to read fit file in a php development?

    I need:
    - general data about activity (date, sport, total duration, total distance, avg hr, max hr, avg power, max power, ...)
    - track points (gps lat/lng, distance, elevation, speed, hr, power, cadence,...)
    - lap data (start gps lat/lng, end gps lat/lng, lap duration, lap distance, lap avg hr, lap max hr,....)

    I can have all of these data using fitCsvTool.


    What can I find in output csv file for multisport activity (for example bike+run) ? How sub-activities will be distingued?

    thanks a lot