X-Git-Url: http://gb7djk.dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2Fwsjtl.pl;fp=perl%2Fwsjtl.pl;h=2fabfe9ed95cb335a514a466a43a283124134306;hb=9c8f43f26a7db08c4ff6ef2213c95c9f509abe36;hp=0000000000000000000000000000000000000000;hpb=d235b0d777f1a90c65d5dcf8cd6adaeb9f2b7e99;p=spider.git diff --git a/perl/wsjtl.pl b/perl/wsjtl.pl new file mode 100644 index 00000000..2fabfe9e --- /dev/null +++ b/perl/wsjtl.pl @@ -0,0 +1,99 @@ +#!/usr/binenv perl +# +# A basic listener and decoder of wsjtx packets +# +# + +our ($systime, $root, $local_data); + +BEGIN { + umask 002; + $SIG{'__WARN__'} = sub { warn $_[0] if $DOWARN }; + + # take into account any local::lib that might be present + eval { + require local::lib; + }; + unless ($@) { +# import local::lib; + import local::lib qw(/spider/perl5lib); + } + + # root of directory tree for this system + $root = "/spider"; + $root = $ENV{'DXSPIDER_ROOT'} if $ENV{'DXSPIDER_ROOT'}; + + unshift @INC, "$root/perl5lib" unless grep {$_ eq "$root/perl5lib"} @INC; + unshift @INC, "$root/perl"; # this IS the right way round! + unshift @INC, "$root/local"; + + # do some validation of the input + die "The directory $root doesn't exist, please RTFM" unless -d $root; + + # locally stored data lives here + $local_data = "$root/local_data"; + mkdir $local_data, 02774 unless -d $local_data; + + # try to create and lock a lockfile (this isn't atomic but + # should do for now + $lockfn = "$root/local_data/wsjtxl.lck"; # lock file name + if (-w $lockfn) { + open(CLLOCK, "$lockfn") or die "Can't open Lockfile ($lockfn) $!"; + my $pid = ; + if ($pid) { + chomp $pid; + if (kill 0, $pid) { + warn "Lockfile ($lockfn) and process $pid exist, another cluster running?\n"; + exit 1; + } + } + unlink $lockfn; + close CLLOCK; + } + open(CLLOCK, ">$lockfn") or die "Can't open Lockfile ($lockfn) $!"; + print CLLOCK "$$\n"; + close CLLOCK; + + $is_win = ($^O =~ /^MS/ || $^O =~ /^OS-2/) ? 1 : 0; # is it Windows? + $systime = time; +} + +use strict; +use warnings; +use 5.22.0; + +use Mojolicious 8.1; +use Mojo::IOLoop; +use Mojo::IOLoop::Server; +use DXDebug; +use DXUDP; + +use WSJTX; + +our $udp_host = '0.0.0.0'; +our $udp_port = 2237; +our $tcp_host = '::'; +our $tcp_port = 2238; + +my $uh; # the mojo handle for the UDP listener +my $th; # ditto TCP +my $wsjtx; # the wsjtx decoder + + +our %slot; # where the connected TCP client structures live + + +dbginit('wsjtl'); +dbgadd('udp'); + +$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(@_)}); + +Mojo::IOLoop->start() unless Mojo::IOLoop->is_running; + +exit; + +