my $host = 'telnet.reversebeacon.net';
my $port = 7000;
-my $mycall = shift or die "usage:rbn.pl <callsign> [debug] [<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 = 15*60; # minimum length of time between successive spots
+my $minspottime = 30*60; # minimum length of time between successive spots
+my $showstats; # show RBN and Spot stats
my $attempts;
my $sock;
my $dbg;
-
+my $wantcw = 1;
+my $wantrtty = 1;
+my $wantpsk = 1;
+my $wantbeacon = 1;
+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;
+ $wantcw = $wantrtty = $wantpsk = $wantbeacon = 0;
+ }
+ ++$wantcw if $arg =~ /^cw$/i;
+ ++$wantpsk if $arg =~ /^psk$/i;
+ ++$wantrtty if $arg =~ /^rtty$/i;
+ ++$wantbeacon if $arg =~ /^beacon$/i;
}
for ($attempts = 1; $attempts <= 5; ++$attempts) {
my %d;
my %spot;
-my $last = time;
+my $last = 0;
+my $noraw = 0;
+my $norbn = 0;
+my $nospot = 0;
while (<$sock>) {
chomp;
my $tim = time;
-
+
# parse line
my (undef, undef, $origin, $qrg, $call, $mode, $s, $m, $spd, $u, $sort, $t) = split /[:\s]+/;
if ($t) {
# This works because the skimmers are NTP controlled (or should be) and will receive
# the spot at the same time (velocity factor of the atmosphere taken into account :-)
my $p = "$t|$call";
+ ++$noraw;
next if $d{$p};
# new RBN input
$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
my $nqrg = nearest(1, $qrg); # normalised to nearest Khz
my $sp = "$call|$nqrg"; # hopefully the skimmers will be calibrated at least this well!
my $ts = $spot{$sp};
+
if (!$ts || $tim - $ts >= $minspottime) {
+ if ($wantbeacon && $sort =~ /^BEA/) {
+ ;
+ } else {
+ # 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;
my $tag = $ts ? "RESPOT" : "SPOT";
say join(',', $tag, $origin, $qrg, $call, $mode, $s, $m, $spd, $u, $sort, $t);
$spot{$sp} = $tim;
say "data,$_" if $dbg;
}
+ periodic:
# periodic clearing out of the two caches
- if ($tim > $last+60) {
+ if (($tim % 60 == 0 && $tim > $last) || ($last && $tim >= $last + 60)) {
my $count = 0;
my $removed = 0;
}
}
say "admin,spot cache: $removed removed $count remain" if $dbg;
- $last = $tim;
+
+ say join(',', "STAT", $noraw, $norbn, $nospot) if $showstats;
+ $noraw = $norbn = $nospot = 0;
+
+ $last = int($tim / 60) * 60;
}
}