[Dxspider-support] DX-Spider & CLX
Filip Jonckers
fjonckers at Interconnect.be
Mon Jun 24 20:10:17 BST 2002
As promised...
here is the modified script we use
it's the original CLX script but slightly modified for spider use
hope this works.. it's not coming from the cluster but
from my development archive
(cannot access the cluster at this time)
you should check the IP broadcast address used and the port numbers
the CT user can open a packet window and type cluster commands...
Filip
on1afn
------------------
#!/usr/bin/perl
#
use strict;
use IO::Socket;
use IPC::Open2;
use constant VERBOSE => 1; ### DEBUGGING SWITCH ###
use constant BUFLEN => 2048;
# defaults
my $node = shift || 'xx0xx'; # cluster node callsign
- first parameter when called by clx
my $mycall = shift || 'xx0xx'; # user callsign
my $bcaddr = shift || '192.168.254.255'; # CT network udp
broadcast address
my $port = shift || 9870; # CT network udp port
my $station = shift || 15; # CT network station id
(1-15)
# open a bidirectional pipe to net_usr
my $in = 0;
my $out = 0;
my $pid = open2(*in,*out,"telnet 127.0.0.1 9000") || die "Cannot open2()
$!";
# open UDP socket to CT clients
my $sock = IO::Socket::INET->new(Proto=>'udp',
Type=>SOCK_DGRAM,
LocalPort=>$port,
PeerAddr=>"$bcaddr:$port")
or die $@;
# fork child process
my $child = fork();
die "can't fork child process: $!" unless defined $child;
tx_data(*in,$sock,$child) unless $child;
rx_data(*out,$sock) if $child;
sub tx_data {
# parse params
my ($in,$sock,$child) = @_;
print "TX started\n" if VERBOSE;
# wait for data coming from net_usr process
while(<$in>) {
chomp;
# create CT udp packet
my $ct = 'B' . chr($station + 48) . $_;
# add checksum byte
my $checksum = unpack("%32C*",$ct);
$checksum |= 0x80;
$checksum &= 0xFF;
$ct .= chr($checksum) . "\n";
# send CT udp packet
$sock->send($ct) || die "send(): $!";
print "CT msg broadcast:$ct\n" if VERBOSE;
}
kill 'TERM',$child;
}
sub rx_data {
# parse params
my ($out,$sock) = @_;
print "RX started\n" if VERBOSE;
# wait for data coming from CT clients
my $buffer='';
while(1) {
my $from = recv($sock,$buffer,BUFLEN,0) or next;
chomp($buffer);
# check checksum if packet is valid
my $checksum = ord(substr($buffer,-1));
my $chkdata = substr($buffer,0,-1);
my $calc = unpack("%32C*",$chkdata);
$calc |= 0x80;
$calc &= 0xFF;
my $chk = ($calc ne $checksum) ? 'nok' : 'ok';
# extract additional data
my $type = substr($buffer,0,1);
my $stn = ord(substr($buffer,1,1))-48;
my $data = substr($buffer,2,-1);
if (VERBOSE) {
my ($port,$ip) = unpack_sockaddr_in($from);
$ip = inet_ntoa($ip);
print "$ip:$port type=$type station=$stn [$data]
checksum=$chk\n";
}
# send data if CT packet is for cluster (type A)
if ($type eq 'A' && $calc eq $checksum) {
print $out "$data\n";
print "** data send to cluster **\n" if VERBOSE;
}
}
}
More information about the Dxspider-support
mailing list