Support also UDP client protocol

git-svn-id: http://repo.ham.fi/svn/aprsc/trunk@237 3ce903b1-3385-4e86-93cd-f9a4a239f7ac
This commit is contained in:
Matti Aarnio 2008-03-24 18:04:21 +00:00
parent 2995f6ffaa
commit 12df35afe2
3 changed files with 129 additions and 69 deletions

View File

@ -170,21 +170,25 @@ sub new {
bless ($self, $class);
# parse attrs
if ($url eq 'localhost:23000') {
$self->{sock} = IO::Socket::INET->new('localhost:10152');
if ($url =~ m/(.+?):(\d+?)u/) {
my $uurl = $1.":".$2;
$self->{sock} = IO::Socket::INET->new($uurl);
my $u = undef;
my $p = undef;
for ( $p = 30000; $p <= 64000; ++$p ) {
$u = IO::Socket::INET->new( Proto => 'udp',
PeerAddr => $url,
LocalAddr => 'localhost',
LocalPort => $p,
Blocking => 0 );
last if (defined($u));
}
$u = IO::Socket::INET->new( Proto => 'udp',
PeerAddr => $url,
Blocking => 0 );
if (defined($u)) {
$udp = " udp ".$p;
$self->{socku} = $u;
# Open local firewall...
$u->send("# pim\r\n");
$u->send("# pim\r\n");
# ..all right.. something was sent,
# and thus our udp socket was given
# a source address. Find it, and add
# on login message.
$p = $u->sockport();
$udp = " udp ".$p;
}
} else {
$self->{sock} = IO::Socket::INET->new($url);
@ -303,7 +307,7 @@ package main;
sub simspecs {
my $simdata =
"23000 jFindU-JS
"10152u jFindU-JS
23 findu
14580 OH2KKU-RO a/72/16/58/34 p/OF/OG/OH/OI/OJ
14580 OH2KKU-RO a/72/16/58/34 p/OF/OG/OH/OI/OJ

View File

@ -1,6 +1,6 @@
#!/usr/bin/perl
$VERSION = 'APRS-IS-XMIT version-1.0';
$VERSION = 'APRS-IS-FILE-FEED version-1.0';
use POSIX;
@ -10,7 +10,7 @@ select STDOUT; $| = 1;
my $quit = 0;
my $APRSIS;
my $mycall = 'OH2MQK-WR';
my $mycall = 'OH2MQK-FF';
my $filter = ''; 'p/OH2R -p/OH2 p/OH ';
$APRSIS = APRS::IS->new('127.0.0.1:10190', $mycall, $filter);

View File

@ -3,21 +3,24 @@
$VERSION = 'APRS-IS-RX version-1.0';
use POSIX;
use IO::Multiplex;
select STDOUT; $| = 1;
my $quit = 0;
my $APRSIS;
my $filter = undef;
my $mycall = 'OH2MQK-RR';
my $filter = 'p/OH2R -p/OH2 p/OH ';
#my $filter = 'p/OH2R';
$filter = 't/c*'; #'p/OH';
#$filter = undef;
#$filter = 'p/OH2R -p/OH2 p/OH ';
#$filter = 'p/OH2R';
#$filter = 't/c*'; #'p/OH';
#$filter = 'p/OH';
#$APRSIS = APRS::IS->new('finland.aprs2.net:10152', $mycall, $filter);
#$APRSIS = APRS::IS->new('rotate.aprs.net:23', $mycall, $filter);
$APRSIS = APRS::IS->new('localhost:14580', $mycall, $filter );
$APRSIS = APRS::IS->new('first.aprs.net:10152u', $mycall, $filter );
#$APRSIS = APRS::IS->new('localhost:10152u', $mycall, $filter );
#$APRSIS = APRS::IS->new('localhost:14580', $mycall, $filter );
if (!defined($APRSIS)) {
printf "aprsazel: Failed to open APRS-IS socket!\n";
@ -27,25 +30,45 @@ if (!defined($APRSIS)) {
my $now = time;
my $last = $now + 60*60;
while (! $quit && $now < $last) {
my $MUX = new IO::Multiplex;
$MUX->add( $APRSIS->sock() );
my $Uclient = $APRSIS->socku();
$MUX->add( $Uclient ) if (defined($Uclient));
local $line;
local %aprs;
$now = time;
$line = $APRSIS->getline;
next if (!defined $line);
chomp $line;
printf "%d\t%s\n", time, $line;
}
printf "\n";
$MUX->set_callback_object(__PACKAGE__);
$MUX->loop();
exit 0;
sub mux_input {
my $package = shift;
my $mux = shift;
my $fh = shift;
my $data = shift;
if (fileno($fh) == fileno($Uclient)) {
printf "%d\t%s\n", time, $$data;
$$data = '';
}
# Process each line in the input, leaving partial lines
# in the input buffer
while ($$data =~ s/^(.*?)\n//) {
printf "%d\t%s\n", time, $1;
}
}
sub mux_eof {
my $package = shift;
my $mux = shift;
my $fh = shift;
$MUX->close($fh);
}
# -------------------------------------------------------------------------
package APRS::IS;
@ -63,11 +86,19 @@ sub aprspass {
pop =~ m/./g);
return ($h ^ 29666);
}
sub sock {
my $self = shift;
return $self->{sock};
}
sub socku {
my $self = shift;
return $self->{socku};
}
sub new {
my $that = shift;
my $class = ref($that) || $that;
my $udp = '';
# my %atts = @_;
my ($url, $mycall, $target_filter_re) = @_; # Just one arg: APRS-IS URL (host:port)
@ -77,18 +108,41 @@ sub new {
bless ($self, $class);
# parse attrs
$self->{sock} = IO::Socket::INET->new($url);
if (!defined($self->{sock})) {
die(__PACKAGE__.": APRS::IS->new(".$url.") failure: ".$!."\n");
if ($url =~ m/(.+?):(\d+?)u/) {
my $uurl = $1.":".$2;
$self->{sock} = IO::Socket::INET->new($uurl);
my $u = undef;
my $p = undef;
$u = IO::Socket::INET->new( Proto => 'udp',
PeerAddr => $uurl,
Blocking => 0 );
if (defined($u)) {
$self->{socku} = $u;
# Open local firewall...
$u->send("# pim\r\n");
$u->send("# pim\r\n");
# ..all right.. something was sent,
# and thus our udp socket was given
# a source address. Find it, and add
# on login message.
$p = $u->sockport();
$udp = " udp ".$p;
}
} else {
$self->{sock} = IO::Socket::INET->new($url);
}
$self->{select} = IO::Select->new( $self->{sock} );
if (!defined($self->{sock})) {
die(__PACKAGE__.": APRS::IS->new(".$url.") failure: $!\n");
}
$self->{aprsmycall} = $mycall;
$mycall =~ s/-.*//;
$self->{aprspass} = aprspass( uc($mycall) );
if ($self->{aprsmycall} =~ m/CW\d{4}/o) {
$self->{aprspass} = -1;
}
$self->{filterre} = $target_filter_re;
@ -119,30 +173,33 @@ sub new {
$self->{sock}->blocking(1);
if (defined($self->{filterre})) {
$self->{sock}->printf( "user %s pass %s vers %s filter %s\r\n",
$self->{aprsmycall},
$self->{aprspass}, # -- but we are read-only !
$main::VERSION, $self->{filterre} );
printf( "user %s pass %s vers %s filter %s\n",
$self->{aprsmycall},
$self->{aprspass}, # -- but we are read-only !
$main::VERSION, $self->{filterre} );
$self->{sock}->printf( "user %s pass %s vers %s".$udp." filter %s\r\n",
$self->{aprsmycall},
$self->{aprspass}, # -- but we are read-only !
$main::VERSION, $self->{filterre} );
printf( "user %s pass %s vers %s filter %s".$udp."\n",
$self->{aprsmycall},
$self->{aprspass}, # -- but we are read-only !
$main::VERSION, $self->{filterre} );
} else {
$self->{sock}->printf( "user %s pass %s vers %s\r\n",
$self->{aprsmycall},
$self->{aprspass}, # -- but we are read-only !
$main::VERSION );
printf( "user %s pass %s vers %s\n",
$self->{aprsmycall},
$self->{aprspass}, # -- but we are read-only !
$main::VERSION );
$self->{sock}->printf( "user %s pass %s vers %s".$udp."\r\n",
$self->{aprsmycall},
$self->{aprspass}, # -- but we are read-only !
$main::VERSION );
printf( "user %s pass %s vers %s".$udp."\n",
$self->{aprsmycall},
$self->{aprspass}, # -- but we are read-only !
$main::VERSION );
}
$self->{sock}->flush;
$self->{sock}->blocking(1);
# $self->{rbuf} = ' ' x 16000; ############## grr.. not avaibale
# $self->{sock}->setbuf( $self->{rbuf} );
# my $discard = $self->getline();
$self->{sock}->blocking(0);
# my $discard = $self->getline();
$self;
}
@ -152,17 +209,16 @@ sub new {
sub getline {
my $self = shift;
my @ready;
if (@ready = $self->{select}->can_read(0.02)) { # Wait at most 0.02 seconds
# We have only one socket...
return $self->{sock}->getline;
my $l;
#if (@ready = $self->{select}->can_read(0.02)) { # Wait at most 0.02 seconds
# We have only one socket...
if (defined($self->{socku})) {
$self->{socku}->recv($l);
return $l if (defined($l));
}
return $self->{sock}->getline;
undef;
}