my $host = 'telnet.reversebeacon.net';
my $port = 7000;
-my $mycall = shift or die "usage:rbn.pl <callsign> [debug] [stats] [cw] [rtty] [psk] [beacon] [<time between repeat spots in minutes>]\n";
+my $mycall = shift or die "usage:rbn.pl <callsign> [debug] [stats] [cw] [rtty] [psk] [beacon] [<time between repeat spots in minutes>] [rbn]\n";
my $minspottime = 30*60; # minimum length of time between successive spots
my $showstats; # show RBN and Spot stats
my $wantrtty = 1;
my $wantpsk = 1;
my $wantbeacon = 1;
-my $override;
+my $override;
+my $showrbn;
while (@ARGV) {
my $arg = shift;
++$dbg if $arg =~ /^deb/i;
++$showstats if $arg =~ /^stat/i;
+ ++$showrbn if $arg =~ /^rbn/i;
$minspottime = $arg * 60 if $arg =~ /^\d+$/;
if (!$override && $arg =~ /^cw|rtty|psk|beacon$/i) {
$override = 1;
chomp;
my $tim = time;
- # periodic clearing out of the two caches
- if ($tim % 60 == 0 && $last != $tim) {
- my $count = 0;
- my $removed = 0;
-
- while (my ($k,$v) = each %d) {
- if ($tim-$v > 60) {
- delete $d{$k};
- ++$removed
- } else {
- ++$count;
- }
- }
- say "admin,rbn cache: $removed removed $count remain" if $dbg;
- $count = $removed = 0;
- while (my ($k,$v) = each %spot) {
- if ($tim-$v > $minspottime*2) {
- delete $spot{$k};
- ++$removed;
- } else {
- ++$count;
- }
- }
- say "admin,spot cache: $removed removed $count remain" if $dbg;
-
- say join(',', "STAT", $noraw, $norbn, $nospot) if $showstats;
- $noraw = $norbn = $nospot = 0;
-
- $last = $tim;
- }
-
# parse line
my (undef, undef, $origin, $qrg, $call, $mode, $s, $m, $spd, $u, $sort, $t) = split /[:\s]+/;
if ($t) {
$d{$p} = $tim;
++$norbn;
$qrg = sprintf('%.1f', nearest(.1, $qrg)); # to nearest 100Hz (to catch the odd multiple decpl QRG [eg '7002.07']).
- say join(',', "RBN", $origin, $qrg, $call, $mode, $s, $m, $spd, $u, $sort, $t) if $dbg;
+ say join(',', "RBN", $origin, $qrg, $call, $mode, $s, $m, $spd, $u, $sort, $t) if $dbg || $showrbn;
# Determine whether to "SPOT" it based on whether we have not seen it before (near this QRG) or,
# if we have, has it been a "while" since the last time we spotted it? If it has been spotted
if ($wantbeacon && $sort =~ /^BEA/) {
;
} else {
- next if !$wantcw && $mode =~ /^CW/;
- next if !$wantrtty && $mode =~ /^RTTY/;
- next if !$wantpsk && $mode =~ /^PSK/;
+ # Haven't used a perl 'goto' like this ever!
+ # Clearly I need to use an event driven framework :-)
+ goto periodic if !$wantcw && $mode =~ /^CW/;
+ goto periodic if !$wantrtty && $mode =~ /^RTTY/;
+ goto periodic if !$wantpsk && $mode =~ /^PSK/;
}
++$nospot;
} else {
say "data,$_" if $dbg;
}
+
+ periodic:
+ # periodic clearing out of the two caches
+ if (($tim % 60 == 0 && $tim > $last) || ($last && $tim >= $last + 60)) {
+ my $count = 0;
+ my $removed = 0;
+
+ while (my ($k,$v) = each %d) {
+ if ($tim-$v > 60) {
+ delete $d{$k};
+ ++$removed
+ } else {
+ ++$count;
+ }
+ }
+ say "admin,rbn cache: $removed removed $count remain" if $dbg;
+ $count = $removed = 0;
+ while (my ($k,$v) = each %spot) {
+ if ($tim-$v > $minspottime*2) {
+ delete $spot{$k};
+ ++$removed;
+ } else {
+ ++$count;
+ }
+ }
+ say "admin,spot cache: $removed removed $count remain" if $dbg;
+
+ say join(',', "STAT", $noraw, $norbn, $nospot) if $showstats;
+ $noraw = $norbn = $nospot = 0;
+
+ $last = int($tim / 60) * 60;
+ }
}