[aprssig] Garmin Rino

Wes Johnston, AI4PX wes at kd4rdb.com
Thu Jan 11 07:33:43 EST 2007


I found it! By the way, I'm not kd4rdb anymore. <grin>  I don't think
this is the DAO version however.
Wes

#!/usr/local/bin/perl
################################################################################
# RINO GPS polling script by Wes Johnston KD4RDB.  April 07 2006               #
# This script uses GPSMan to poll a garmin rino gps unit and detects changes   #
# in the location or symbol used from one iteration to the next.  If a waypoint#
# moves, it will be published to xastir via the xastir_udp_client program      #
# Press <cntrl c> to stop execution                                            #
################################################################################
#use strict;
#use warnings;
#use LWP::Simple;
$mysourcecall="AI4PX";
$mysourcepath="WIDE1-1,WIDE2-1";
$mypasscode="24315";
my $gps_file_source="gps.txt";
my $gps_old_file_source="gpsold.txt";
##############################################
# Nothing below this line needs to be edited.#
##############################################
use POSIX qw(strftime);

# We call GPSman upon startup to establish a baseline of waypoints
# so that we don't generate bunches of aprs objects the first iteration
print "Initializing Waypoints...\n";
#Call gpsman to get waypoints with symbols and pipe the output to a
dummy file to keep screen clean.
my $cmd="gpsman getwrite WP GPSMan ".$gps_old_file_source." >gpsman.txt"	;
system $cmd;


while (1==1){
	print qq|\nPolling RINO unit...\n|;
	
#Call gpsman to get waypoints with symbols and pipe the output to a
dummy file to keep screen clean.
	$cmd="gpsman getwrite WP GPSMan ".$gps_file_source." >gpsman.txt"	;
	system $cmd;
	print qq|Reading RINO waypoints...\n|;
	open (DB, "<$gps_file_source") or &cgierr("unable to open GPSMan
file: $gps_file_source.\nReason: $!");
		LINE: while (<DB>) {
			(/^#/)      and next LINE;		# Skip comment Lines.
			(/^!/)      and next LINE;		# Skip comment Lines.
			(/^%/)      and next LINE;		# Skip comment Lines.		
			(/^\s*$/)   and next LINE;		# Skip blank lines.
  		my $line = $_;	chomp ($line);		# Remove trailing new line.
	
# need to open the file used on the last time 'round and look for an
identical line.
# if such an identical line is found, then NEXT and skip processing...
nothing new.
			my $dupedataflag=0;

			open (OLD, "<$gps_old_file_source") or &cgierr("unable to open
GPSMan file: $gps_old_file_source.\nReason: $!");
				OLDGPS: while (<OLD>) {
					(/^#/)      and next OLDGPS;		# Skip comment Lines.
					(/^!/)      and next OLDGPS;		# Skip comment Lines.
					(/^%/)      and next OLDGPS;		# Skip comment Lines.		
					(/^\s*$/)   and next OLDGPS;		# Skip blank lines.
  				my $oldgps = $_;	chomp ($oldgps);		# Remove trailing new line.

  				if ($oldgps eq $line){
  					$dupedataflag=1;
					}
				}
			close OLD;

# split line into callsign, lat lon and symbol.
			my ($callsign,$null1,$lat,$lon,$symbol,$null2)= split (/\t/, $line);
# If callsign starts with APRS, truncate the APRS portion.			
					if (substr($callsign,0,4) eq "APRS"){
						$callsign=substr($callsign,4,100);
					}

# check to see if we did NOT find a duplicate line of text in the gpsman file.
			if ($dupedataflag eq "0"){

# Here we check that the particular waypoint has the correct form of a
rino contact symbol.
				$sym="";
				if (substr($symbol,0,7) eq "symbol="){
					$sym="1";
# First we set the default symbol.... just in case
					$aprssymbol="[";
					$aprssymbol="[" if ($symbol eq "symbol=cntct_smiley");
					$aprssymbol="b" if ($symbol eq "symbol=cntct_ball_cap");
					$aprssymbol="j" if ($symbol eq "symbol=cntct_big_ears");
					$aprssymbol="f" if ($symbol eq "symbol=cntct_spike");
					$aprssymbol="s" if ($symbol eq "symbol=cntct_goatee");
					$aprssymbol="U" if ($symbol eq "symbol=cntct_afro");
					$aprssymbol="Y" if ($symbol eq "symbol=cntct_dreads");
					$aprssymbol="R" if ($symbol eq "symbol=cntct_female1");
					$aprssymbol="v" if ($symbol eq "symbol=cntct_female2");
					$aprssymbol=">" if ($symbol eq "symbol=cntct_female3");
					$aprssymbol="," if ($symbol eq "symbol=cntct_ranger");
					$aprssymbol="u" if ($symbol eq "symbol=cntct_kung_fu");
					$aprssymbol="X" if ($symbol eq "symbol=cntct_sumo");
					$aprssymbol="<" if ($symbol eq "symbol=cntct_pirate");
					$aprssymbol="k" if ($symbol eq "symbol=cntct_biker");
					$aprssymbol="O" if ($symbol eq "symbol=cntct_alien");
					$aprssymbol="'" if ($symbol eq "symbol=cntct_bug");
					$aprssymbol="a" if ($symbol eq "symbol=cntct_cat");
					$aprssymbol="e" if ($symbol eq "symbol=cntct_dog");
					$aprssymbol="P" if ($symbol eq "symbol=cntct_pig");

			
# If callsign length greater than 9, we have to truncate it to be
within aprs spec for item reports.
					if (length($callsign) > 9){
						$callsign=substr($callsign,0,9);
					}

# split degrees mins and secs into individual variables.
 					my ($deg,$min,$sec)= split (/ /, $lat);
 					$hemi=substr($deg,0,1);  		
 					$deg=substr($deg,1,10);
# make certain the length of degrees is 2 by way of adding leading 0's.  		
 					if (length($deg)!=2){
 						$deg="0".$deg;
 					}
 					if (length($deg)!=2){
 						$deg="0".$deg;
 					}
 					$sec=substr($sec/60,1,3);
 					if ($sec eq ""){
 						$sec=".00";
 					}
 					if (length($sec) ne "3") {
 						$sec=$sec."0";
 					}
 					$min=$min.$sec;
# make certain the length of minutes is 2 by way of adding leading 0's.  		 		
 					if (substr($min,2,1) ne "."){
 						$min="0".$min;
 					}
 					$aprslat=$deg.$min.$hemi;
# split degrees mins and secs into individual variables.
			 		my ($deg,$min,$sec)= split (/ /, $lon);
 					$hemi=substr($deg,0,1);  		
 					$deg=substr($deg,1,10);
# make certain the length of degrees is 3 by way of adding leading 0's.  		
 					if (length($deg)!=3){
 						$deg="0".$deg;
 					}
 					if (length($deg)!=3){
 						$deg="0".$deg;
 					}
 					$sec=substr($sec/60,1,3);
 					if ($sec eq ""){
 						$sec=".00";
 					}
 					if (length($sec) ne "3") {
 						$sec=$sec."0";
 					}
 					$min=$min.$sec;
# make certain the length of minutes is 2 by way of adding leading 0's.  		 		
 					if (substr($min,2,1) ne "."){
 						$min="0".$min;
 					}
 					$aprslon=$deg.$min.$hemi;

# here is the format we're looking to create:
"KD4RDB>WIDE1-1,WIDE2-2:)" + Name$ + "!" + Lat$ + "/" + Lon$ + Symbol$
			    $packet=$mysourcecall.">".$mysourcepath .":)". $callsign . "!"
. $aprslat . "/" . $aprslon . $aprssymbol;


# shell out and make call to xastir udp client.
# This is a sample of the line to be sent: xastir_udp_client localhost
2023 ab7cd 1234 "APRS packet goes here"
					$cmd="xastir_udp_client localhost 2023 ".$mysourcecall."
".$mypasscode." -to_rf -to_inet \"".$packet."\" >udp.txt";
					system $cmd;
				}			
		
			}
			if (substr($symbol,0,7) eq "symbol=") {
				if ($dupedataflag eq "0" ){
					print qq|MOVED:|;
				}else{
					print qq|      |;
				}
				$callsign=$callsign."          ";
				$callsign=substr($callsign,0,10);
  			print qq|$callsign $lat $lon $symbol\n|;		
				}
			}
	close DB;
# copy current gps.txt file over the old one.. so we can use it for
dupe checks the next time thru.
	$cmd="cp gps.txt gpsold.txt";
  system $cmd;
	sleep 10
}

sub cgierr {
# --------------------------------------------------------
# Displays any errors and prints out ENVIRONMENT
# information. Useful for debugging.

    print "We encountered an internal error. ";
        print "\n\nCGI ERROR\n==========================================\n";
        $_[0]      and print "Error Message       : $_[0]\n";
        $0         and print "Script Location     : $0\n";
        $]         and print "Perl Version        : $]\n";
        print "\n";
    exit -1;
}




More information about the aprssig mailing list