- # 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
- # before then "RESPOT" it.
- 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 || ($self->{minspottime} > 0 && $tim - $ts >= $self->{minspottime})) {
- ++$self->{nospot};
- my $tag = $ts ? "RESPOT" : "SPOT";
- $t .= ",$b" if $b;
- $sort ||= '';
- dbg "RBN:" . join(',', $tag, $origin, $qrg, $call, $mode, $s, $m, $spd, $u, $sort, $t);
-
- send_dx_spot($self, $line, $mode);
-
- $spot->{$sp} = $tim;
+ # here we either have an existing spot record buildup on the go, or we need to create the first one
+ unless ($spot) {
+ $spots->{$sp} = $spot = [clock_gettime(CLOCK_REALTIME)];;
+ dbg("RBN: key: '$sp' call: $call qrg: $qrg NEW" . ($respot ? ' RESPOT' : '')) if isdbg('rbn');
+ }
+
+ # add me to the display queue unless we are waiting for initial in rush to finish
+ return unless $noinrush || $self->{inrushpreventor} < $main::systime;
+
+ # build up a new record and store it in the buildup
+ # deal with the unix time
+ my ($hh,$mm) = $t =~ /(\d\d)(\d\d)Z$/;
+ my $utz = $hh*3600 + $mm*60 + $main::systime_daystart; # possible issue with late spot from previous day
+ $utz -= 86400 if $utz > $tim+3600; # too far ahead, drag it back one day
+
+ # create record and add into the buildup
+ my $r = [$origin, nearest(.1, $qrg), $call, $mode, $s, $t, $utz, $respot, $u];
+ my @s = Spot::prepare($r->[1], $r->[2], $r->[6], '', $r->[0]);
+ if ($s[5] == 666) {
+ dbg("RBN: ERROR invalid prefix/callsign $call from $origin-# on $qrg, dumped");
+ return;
+ }
+
+ if ($self->{inrbnfilter}) {
+ my ($want, undef) = $self->{inrbnfilter}->it($s);
+ return unless $want;
+ }
+ $r->[9] = \@s;
+
+ push @{$self->{queue}}, $sp if @$spot == 1; # queue the KEY (not the record)
+
+ dbg("RBN: key: '$sp' ADD RECORD call: $call qrg: $qrg origin: $origin") if isdbg('rbn');
+
+ push @$spot, $r;
+
+ # At this point we run the queue to see if anything can be sent onwards to the punter
+ my $now = clock_gettime(CLOCK_REALTIME);
+
+ # now run the waiting queue which just contains KEYS ($call|$qrg)
+ foreach $sp (@{$self->{queue}}) {
+ my $cand = $spots->{$sp};
+ unless ($cand && $cand->[0]) {
+ dbg "RBN Cand " . ($cand ? 'def' : 'undef') . " [0] " . ($cand->[0] ? 'def' : 'undef') . " dwell $dwelltime";
+ next;
+ }
+ if ($now >= $cand->[0] + $dwelltime ) {
+ # we have a candidate, create qualitee value(s);
+ unless (@$cand > 1) {
+ dbg "RBN: QUEUE key '$sp' MISSING RECORDS " . dd($cand) if isdbg 'rbn';
+ shift @{$self->{queue}};
+ next;
+ }
+ my $savedtime = shift @$cand; # save the start time
+ my $r = $cand->[0];
+ my $quality = @$cand;
+ $quality = 9 if $quality > 9;
+ $quality = "Q:$quality";
+ if (isdbg('progress')) {
+ my $s = "RBN: SPOT key: '$sp' = $r->[2] on $r->[1] by $r->[0] \@ $r->[5] $quality";
+ $s .= " route: $self->{call}";
+ dbg($s);
+ }
+
+ send_dx_spot($self, $quality, $cand);
+
+ # clear out the data and make this now just "spotted", but no further action required until respot time
+ dbg "RBN: QUEUE key '$sp' cleared" if isdbg 'rbn';
+
+ $spots->{$sp} = [$savedtime];
+ shift @{$self->{queue}};
+ } else {
+ dbg sprintf("RBN: QUEUE key: '$sp' SEND time not yet reached %.1f secs left", $spot->[0] + $dwelltime - $now) if isdbg 'rbnqueue';
+ }