View Single Post
Old 04-25-2009, 06:54 AM   #1 (permalink)
bwilson4web
Engineering first
 
bwilson4web's Avatar
 
Join Date: Mar 2009
Location: Huntsville, AL
Posts: 843

17 i3-REx - '14 BMW i3-REx
Last 3: 45.67 mpg (US)

Blue Bob's - '19 Tesla Std Rng Plus
Thanks: 94
Thanked 248 Times in 157 Posts
Sharing Garmin code

Hi,

This is a quick Perl hack used to convert the Garmin data file into text records that can be loaded into excel. Once in excel, macros can convert and reduce the data to useable representations:

#!/usr/bin/perl
#
# trace <file>
#
# This program decodes a Garmin nuvi trace data file.
# Found in the GARMIN\GPS\Current.gpx file.
#
open(FH, "<Current.gpx"); # Get the file
#
while ($line = <FH>) # Read all lines
{
printf("%d\tlength\n", length($line)); # Report size
#
# Convert raw block into records
#
$cc = index($line, ">"); # Find end of first record

while ($cc >= 0) # Pass through until all records found
{
$cc+=1; # Add ending, delimiter character
printf("%d\t%s\n", $cc, substr($line, 0, $cc)); # Each field
$line = substr($line, $cc, length($line)); # Grab rest
$cc = index($line, ">"); # Find end of next record
}

if ( length($line) > 0 ) # Check for any left-over text
{
printf("%d\t%s\n", length($line), $line); # Finish
}
printf("\n"); # Extra space to improve readibility
}
close(FH); # Done with file
# end source

There appears to be two legacy XML constructs that include a binary "NULL" character. This causes the read loop to see three blocks of text, not one huge block. Regardless, these legacy text are written as text records even though I don't have any use for them.

Macintosh and Linux systems have Perl but a Windows user may need to find a Perl system. The typical scenario is:
  1. Mount the Garmin on the computer with the USB cable
  2. Copy the 'GARMIN\GPS\Current.gpx' file to a directory with the Perl program
  3. Run the Perl program and redirect the output into a text file
  4. Use excel (or equivalent) to load the records
My plan is to add subroutines to assemble the trip data, <trkseq>, into files of tab delimited, data points, <trkpt>, with the format:
time_stamp - day and fraction
X axis miles - relative to the left or western most longitude
y axis miles - relative to the bottom or sourthern most latitude
mph - calculated from the preceding and following points and times
altitude - meters from GPS data
Another routine will extract the way-points with the names and X and Y axis miles. Eventually, I'll combine the trace data with the checkpoint so we can identify the start of each "coast down" segment, the ultimate goal.

Bob Wilson

__________________
2019 Tesla Model 3 Std. Range Plus - 215 mi EV
2017 BMW i3-REx - 106 mi EV, 88 mi mid-grade
Retired engineer, Huntsville, AL
  Reply With Quote