#!/bin/bash # Puts a route to GPS Handheld # The route is simplified to contain less points on the way # # This software is beta, use at your own risk! # Please update the settings below "Settungs" to suit your needs # # TODO # - currently nothing open # # Version: $LastChangedRevision: 330 $ # last change: $LastChangedDate: 2009-05-26 20:54:40 +0200 (Tue, 26 May 2009) $ # (c) 2009 by Robert Lange (robert.lange@s1999.tu-chemnitz.de) # GNU General Public Licence applies # # *** Settings *** # Simplification algorithm: Remove points in the range of 10m # deviation from projected line SIMPLIFY="crosstrack,error=0.010k" # Simplification algorithm: Reduce to 300 points # SIMPLIFY="count=300" # see gpsbabel documentation for details # GPS Device, as supported by gpsbabel GPS_TYPE="garmin" # GPS Port GPS_PORT="/dev/ttyUSB0" # *** Settings you usually don't wanna change *** # GPSbabel executable GPSBABEL=gpsbabel # wget executable WGET=wget # Program name (no need to change) PROGNAME=map2navi # Route name (set from command line) ROUTENAME= # URL/GPX File (set from command line) URL_GPX= # *** Functions *** # *** Command line parsing get_options() { local opt local argcounter=1 while [ -n "$*" ] ; do opt="$1" shift case $opt in -V|--version) # Version output REVISION='$LastChangedRevision: 330 $' REVISION=${REVISION#\$LastChangedRevision: } REVISION=${REVISION%\$} echo "$PROGNAME, Revision $REVISION" echo "(c) by Robert Lange (robert.lange@s1999.tu-chemnitz.de)" echo "GNU General Public Licence applies" exit 0 ;; -h|--help|'-?') # help text echo "$PROGNAME - Put a route to GPS Handheld" echo "This software is beta, use at your own risk!" echo echo "The route is simplified to contain less points on the way" echo "Performed steps: Fetch route, convert to gpx, store on device" echo "Used programs: gpsbabel, wget" echo "Input can be a Google Maps URL or a GPX file," echo "e.g. from http://openrouteservice.de/" echo echo "Call: $PROGNAME [OPTS] route_name {'url'|file.gpx}" echo echo "Options:" echo " [-h|--help] - This screen" echo " [-V|--version] - Print program version and exit" echo " route_name - Name of the resulting route" echo " url - Google Maps URL from the \"Link\" button" echo " Don't forget to quote this URL" echo " file.gpx - GPX file containing a track (called \"Route\"," echo " must end in .gpx" exit 0 ;; *) # Store into case $argcounter in 1) ROUTENAME=$opt ;; 2) URL_GPX=$opt ;; *) # Too many arguments echo "Too many arguments! See help text for usage" exit 1 ;; esac #increment argument counter let argcounter++ ;; esac done } # *** Call Command Line Parsing # When no options supplied then call help if [ -z "$1" ]; then get_options "--help" else get_options "$@" fi # *** Sanity Checks *** # Parameter if [ -z "$URL_GPX" ]; then echo "No URL or file suppled! See help text for usage" exit 1 fi # gpsbabel there? if [ $(which $GPSBABEL > /dev/null) ]; then echo "$GPSBABEL executable not found!" exit 1 fi # wget there? if [ $(which $WGET > /dev/null) ]; then echo "$WGET executable not found!" exit 1 fi if [ ${URL_GPX##*.} != "gpx" ]; then # *** For URL: Fetch Google MAPs URL to String echo "$WGET -o /dev/null -O - ${URL_GPX}&output=kml" KMLFILE="$($WGET -o /dev/null -O - ${URL_GPX}\&output=kml)" if [ $? -ne 0 ]; then echo "Failure invoking $WGET - Aborting" exit 1 fi # *** For URL: Convert & Simplify KML echo $GPSBABEL -i kml -f - -x simplify,$SIMPLIFY -o gpx -F - GPXFILE="$(echo $KMLFILE | $GPSBABEL -i kml -f - -x simplify,$SIMPLIFY -o gpx -F -)" if [ $? -ne 0 ]; then echo "Failure invoking $GPSBABEL - Aborting" exit 1 fi # *** For GPX: Simplify GPX else echo $GPSBABEL -i gpx -f $URL_GPX -x simplify,$SIMPLIFY -o gpx -F - GPXFILE="$($GPSBABEL -i gpx -f $URL_GPX -x simplify,$SIMPLIFY -o gpx -F -)" if [ $? -ne 0 ]; then echo "Failure invoking $GPSBABEL - Aborting" exit 1 fi fi # *** Rename route GPXFILE=${GPXFILE//Route<\/name>/${ROUTENAME}<\/name>} # *** Store to GPS Handheld echo -n "The track contains " echo -n $(echo "$GPXFILE" | grep "" | wc -l) echo " points" echo $GPSBABEL -D 1 -t -i gpx -f - -o $GPS_TYPE -F $GPS_PORT echo "$GPXFILE" | $GPSBABEL -D 1 -t -i gpx -f - -o $GPS_TYPE -F $GPS_PORT if [ $? -ne 0 ]; then echo "Failure invoking $GPSBABEL - Aborting" exit 1 fi # *** Done echo echo "Done - Downloaded track \"$ROUTENAME\" to $GPS_TYPE" echo