--- navilink.pl.orig 2007-04-22 12:31:49.000000000 +0100 +++ navilink.pl 2007-04-23 18:24:56.000000000 +0100 @@ -166,6 +166,19 @@ return %info; } +=head2 writeGPXheader + +Write the XML and GPX headers + +=cut +sub writeGPXheader { + print OUT "\n"; + print OUT "\n"; +} + =head2 downloadTrackData Reads all Trackpoints from the device and prints it as GPX data @@ -208,12 +221,7 @@ sendRawPacket(PID_ACK,""); } - # Creat GPX file - print OUT "\n"; - print OUT "\n"; + # write GPX track print OUT "\n"; print OUT "\n"; @@ -233,7 +241,48 @@ print OUT "\n"; print OUT "\n"; - print OUT "\n"; + + return 1; +} + +=head2 downloadWaypoints + +Reads all Waypoints from the device and prints them out + +=cut +sub downloadWaypoints { + my %info = downloadInfo(); + if(!defined(%info) || !$info{'waypoints'}){ + print STDERR "There are no waypoints available"; + return 0; + } + + my $count = $info{'waypoints'}; + + # request data + my $msg = pack("V",0).pack("v",$count)."\x01"; + sendRawPacket(PID_QRY_WAYPOINTS,$msg); + + # read answer + ($type,$data) = readPacket(); + if($type ne PID_DATA){ + # something went wrong + print STDERR "Did not receive expected Waypoint data"; + return 0; + } + $waypoints = $data; + + # send ACK + sendRawPacket(PID_ACK,""); + + # write GPX waypoints + for(my $i=0; $i<$count*32; $i+=32) { + my @wp = unpack("vvA7CiivCCCCCCCCCC",substr($waypoints,$i,32)); + printf OUT "\n", $wp[4] / 10000000, $wp[5] / 10000000; + printf OUT " %s\n", $wp[2]; + printf OUT " \n", 2000 + $wp[7], $wp[8], $wp[9], $wp[10], $wp[11], $wp[12]; + printf OUT "\n"; + } return 1; } @@ -293,6 +342,8 @@ info print number of waypoints, routes and trackpoints gettracks download track data as GPX + getwaypoints download waypoints as GPX + getall download everything as GPX EOT exit 0 @@ -337,7 +388,18 @@ # handle commands if($ARGV[0] eq 'gettracks'){ + writeGPXheader(); downloadTrackData(); + print OUT "\n"; +}elsif($ARGV[0] eq 'getwaypoints'){ + writeGPXheader(); + downloadWaypoints(); + print OUT "\n"; +}elsif($ARGV[0] eq 'getall'){ + writeGPXheader(); + downloadTrackData(); + downloadWaypoints(); + print OUT "\n"; }elsif($ARGV[0] eq 'info'){ my %info = downloadInfo(); print OUT 'waypoints : '.$info{'waypoints'}."\n";