X-Git-Url: http://www.dxcluster.org/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FDXProt.pm;h=ab023866cc96c322b918711a86b1d976e52d3861;hb=6f566611af29f5c7af653abf8cec2760a0c25b6e;hp=3001d263f5dc60878ec65a91a6ea733601b5989f;hpb=1cf4bd14be226274d5deb05da8480ab91a5dac52;p=spider.git diff --git a/perl/DXProt.pm b/perl/DXProt.pm index 3001d263..ab023866 100644 --- a/perl/DXProt.pm +++ b/perl/DXProt.pm @@ -49,7 +49,8 @@ sub start # send initialisation string $self->send($self->pc38()) if DXNode->get_all(); $self->send($self->pc18()); - $self->{state} = 'incoming'; + $self->state('normal'); + $self->pc50_t(time); } # @@ -69,7 +70,10 @@ sub normal SWITCH: { if ($pcno == 10) {last SWITCH;} - if ($pcno == 11) {last SWITCH;} + if ($pcno == 11) { # dx spot + + last SWITCH; + } if ($pcno == 12) {last SWITCH;} if ($pcno == 13) {last SWITCH;} if ($pcno == 14) {last SWITCH;} @@ -92,9 +96,12 @@ sub normal $self->send($out); } $self->send($self->pc22()); + return; + } + if ($pcno == 21) { # delete a cluster from the list + last SWITCH; } - if ($pcno == 21) {last SWITCH;} if ($pcno == 22) {last SWITCH;} if ($pcno == 23) {last SWITCH;} if ($pcno == 24) {last SWITCH;} @@ -123,8 +130,22 @@ sub normal if ($pcno == 47) {last SWITCH;} if ($pcno == 48) {last SWITCH;} if ($pcno == 49) {last SWITCH;} - if ($pcno == 50) {last SWITCH;} - if ($pcno == 51) {last SWITCH;} + if ($pcno == 50) { + last SWITCH; + } + if ($pcno == 51) { # incoming ping requests/answers + + # is it for us? + if ($field[1] eq $main::mycall) { + my $flag = $field[3]; + $flag ^= 1; + $self->send($self->pc51($field[2], $field[1], $flag)); + } else { + # route down an appropriate thingy + $self->route($field[1], $line); + } + return; + } } # if get here then rebroadcast the thing with its Hop count decremented (if @@ -138,11 +159,11 @@ sub normal my $hopfield = pop @field; push @field, $hopfield; - if ($hopfield =~ /H\d\d./o) { - my ($hops) = $hopfield =~ /H(\d+)/o; - $hops--; - if ($hops > 0) { - $line =~ s/\^H\d+(\^\~.)$/\^H$hops$1/; # change the hop count + my $hops; + if (($hops) = $hopfield =~ /H(\d+)\^\~?$/o) { + my $newhops = $hops - 1; + if ($newhops > 0) { + $line =~ s/\^H$hops(\^\~?)$/\^H$newhops$1/; # change the hop count DXProt->broadcast($line, $self); # send it to everyone but me } } @@ -162,9 +183,9 @@ sub process next if !$chan->is_ak1a(); # send a pc50 out on this channel - if ($t >= $chan->t + $DXProt::pc50_interval) { + if ($t >= $chan->pc50_t + $DXProt::pc50_interval) { $chan->send(pc50()); - $chan->t($t); + $chan->pc50_t($t); } } } @@ -216,6 +237,21 @@ sub delnode # some active measures # +# +# route a message down an appropriate interface for a callsign +# +# expects $self to indicate 'from' and is called $self->route(to, pcline); +# +sub route +{ + my ($self, $call, $line) = @_; + my $cl = DXCluster->get($call); + if ($cl) { + my $dxchan = $cl->{dxchan}; + $cl->send($line) if $dxchan; + } +} + # broadcast a message to all clusters [except those mentioned after buffer] sub broadcast { @@ -351,11 +387,18 @@ sub pc38 return "PC38^" . join(',', @nodes) . "^~"; } +# periodic update of users, plus keep link alive device (always H99) sub pc50 { my $n = DXNodeuser->count; return "PC50^$main::mycall^$n^H99^"; } +# generate pings +sub pc51 +{ + my ($self, $to, $from, $val) = @_; + return "PC51^$to^$from^$val^"; +} 1; __END__