1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
|
#!/usr/bin/perl
# Copyright (C) 2000-2012 Curt Mills, WE7U
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
# 02111-1307, USA.
#
# This script will ask for a name, then create a file
# with that name + ".log" in the ~/.xastir/logs directory. The
# file will contain APRS items created from the downloaded Garmin
# waypoints. Reading that log file with Xastir will result in one
# item appearing on the map screen for each waypoint, labeled with
# the name of that waypoint.
# This script uses the GPS::Garmin module which can be obtained
# from http://sourceforge.net/projects/perl-gps/
use GPS::Garmin;
use IO::File;
# Flush STDOUT
$| = 1;
# Hard-coded "from" callsign name. This becomes the "sending"
# callsign for the APRS Items.
$from = "SAR";
# Ask for the name. This gets changed into the complete log file name.
printf("\n\nEnter name for file: '.log' will get added to the end:\n\n");
$name = <>;
chomp $name;
if (length($name) < 1) {
die "Must be at least one character!\n";
}
$filename = "~/.xastir/logs/$name.log";
# Get rid of spaces in the filename
$filename =~ s/\s+//g;
# Expand the tilde into the home directory
$filename =~ s{ ^ ~ ( [^/]* ) }
{ $1
? (getpwnam($1))[7]
: ( $ENV{HOME} || $ENV{LOGDIR}
|| (getpwuid($>))[7]
)
}ex;
printf("\nThe output filename will be: ($filename)\n\n");
printf("Connect Garmin GPS to /dev/ttyS0 (COM1), set it to Garmin/Garmin mode.\n");
printf("Press <ENTER> to proceed with download, Ctrl-C to abort\n");
<>;
# Create a file to hold the data
$output = IO::File->new("> $filename")
or die "Couldn't open $filename for writing: $!\n";
$gps = new GPS::Garmin( 'Port' => '/dev/ttyS0',
'Baud' => 9600,
) or die "Unable to connect to receiver: $!";
# Transfer waypoints:
$i = 0;
$gps->prepare_transfer("wpt");
while ($gps->records)
{
($title,$lat,$lon,$desc) = $gps->grab;
#printf("%f\t%f\t%s\t%s\n",$lat,$lon,$desc,$title);
if ($lon < 0) {
$londeg = sprintf("%d",-$lon);
$lonmin = (-$lon - $londeg) * 60;
$lonchar = "W";
}
else {
$londeg = sprintf("%d",$lon);
$lonchar = "E";
$lonmin = ($lon - $londeg) * 60;
}
if ($lat < 0) {
$latdeg = sprintf("%d",-$lat);
$latmin = (-$lat - $latdeg) * 60;
$latchar = "S";
}
else {
$latdeg = sprintf("%d",$lat);
$latmin = ($lat - $latdeg) * 60;
$latchar = "N";
}
chomp $title;
if (length($title) < 1) {
die "Must be at least one character!\n";
}
if (length($title) > 9) {
$title =~ s/(.{9}).*/\1/; # Terminate it at 9 chars
}
if (length($title) < 3) {
$title = $title . " "; # Pad the title with spaces
$title =~ s/(.{3}).*/\1/; # Terminate it at 3 chars
}
# We need to enforce the naming restrictions for APRS Items. '!'
# and '_' are not allowed, anything else that's printable ASCII is
# ok.
@j = split(//, $title);
for ($k = 0; $k < length($title); $k++) {
#printf("$k $j[$k]\n");
if ( ($j[$k] lt ' ')
|| ($j[$k] gt '~')
|| ($j[$k] eq '!')
|| ($j[$k] eq '_') ) {
$j[$k] = ' ';
}
}
$title = join("",@j);
# Write an APRS Item for each waypoint
printf($output "%s>APRS:)%s!%02d%05.2f%s/%03d%05.2f%s%s\n",
$from,
$title,
$latdeg,
$latmin,
$latchar,
$londeg,
$lonmin,
$lonchar,
"/");
if (! ($i % 10) ) {
printf("$i ");
}
$i++;
}
printf("\n\nThe data has been saved in: ($filename)\n");
printf("Please open this logfile with Xastir to display the waypoints.\n");
printf("!!!Remember to set your GPS back to NMEA mode for APRS!!!\n");
|