X-Git-Url: http://www.dxcluster.org/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2Fwsjtl.pl;h=7bfc8e7a8603ca45a211a78e6729f43bcb9c64d8;hb=refs%2Fheads%2Fstaging;hp=2fabfe9ed95cb335a514a466a43a283124134306;hpb=9c8f43f26a7db08c4ff6ef2213c95c9f509abe36;p=spider.git diff --git a/perl/wsjtl.pl b/perl/wsjtl.pl old mode 100644 new mode 100755 index 2fabfe9e..7bfc8e7a --- a/perl/wsjtl.pl +++ b/perl/wsjtl.pl @@ -1,4 +1,4 @@ -#!/usr/binenv perl +#!/usr/bin/env perl # # A basic listener and decoder of wsjtx packets # @@ -70,7 +70,7 @@ use DXUDP; use WSJTX; -our $udp_host = '0.0.0.0'; +our $udp_host = '::'; our $udp_port = 2237; our $tcp_host = '::'; our $tcp_port = 2238; @@ -78,22 +78,73 @@ our $tcp_port = 2238; my $uh; # the mojo handle for the UDP listener my $th; # ditto TCP my $wsjtx; # the wsjtx decoder - +my $cease; our %slot; # where the connected TCP client structures live dbginit('wsjtl'); -dbgadd('udp'); + +my @queue; $uh = DXUDP->new; $uh->start(host => $udp_host, port => $udp_port) or die "Cannot listen on $udp_host:$udp_port $!\n"; $wsjtx = WSJTX->new(); -$uh->on(read => sub {wstjx->handle(@_)}); +$uh->on(read => \&_udpread); + +$th = Mojo::IOLoop::Server->new; +$th->on(accept => \&_accept); +$th->listen(address => $tcp_host, port => $tcp_port); +$th->start; Mojo::IOLoop->start() unless Mojo::IOLoop->is_running; exit; +sub _udpread +{ + my ($handle, $data) = @_; + + my $host = $handle->peerhost; + my $port = $handle->peerport; + + my $in = $wsjtx->handle($handle, $data, "$host:$port"); + + distribute($in) if $in && length $in; +} + +sub _accept +{ + my ($id, $handle) = @_; + my $host = $handle->peerhost; + my $port = $handle->peerport; + + + my $s = $slot{"$host:$port"} = { addr => "$host:$port"}; + my $stream = $s->{stream} = Mojo::IOLoop::Stream->new($handle); + $stream->on(error => sub { $stream->close; delete $s->{addr}}); + $stream->on(close => sub { delete $s->{addr}}); + $stream->on(read => sub {_tcpread($s, $_[1])}); + $stream->timeout(0); + $stream->start; +} + +sub _tcpread +{ + my $s = shift; + my $data = shift; + + dbg("incoming: $data"); +} + +sub distribute +{ + my $in = shift; + foreach my $c (values %slot) { + $c->{stream}->write("$in\r\n"); + } +} + +