# start quick and EXTREMELY dirty xmodem transfert sub xmodemsend { # reading the file to be send open (BET ,"filename") || die "*** coudn't open filename ***\n"; $tosend = ; close BET || die "*** couldn't close filename ***\n"; # wait for #NAK WNAK: while(1) { if (sysread($sock,$buf,1) <= 0) { die "*** died$! ***\n"; } if ($buf eq "\x18") { die "*** CAN received from bs2000 ***\n"; } last WNAK if ( $buf eq "\x15" ); print "$buf"; # print characters bcs after A020 comes TRASEC OK text } # start of transfert $tel = 1; $ptr = 0; A000: while(1) { $ctel = pack("c",($tel & 255)); $mtel = pack("c",- ($tel & 255)); $sum = 0; $buf = ""; for ($i = 0; $i < 128; $i++) { $byte = substr($tosend,$i+$ptr,1); $buf = "$buf$byte"; $sum += unpack("c",$byte); } $sum = pack("c",($sum & 255)); # calculate checksum syswrite($sock,"\x01$ctel$mtel$buf$sum",132); # send complete block print "$buf"; if (sysread($sock,$buf,1) <= 0) { die "*** died$! ***\n"; } if ($buf ne "\x06" && $buf ne "\x15" && $buf ne "\x18") { die "*** no ACK, NAK nor CAN recevied after blocktransfert ***\n"; } if ($buf eq "\x18") { #CAN return; } if ($buf eq "\x06") { #ACK # packet ok $tel++; $ptr += 128; } last A000 if $ptr eq length($tosend); if ($ptr > length($tosend)) { die "*** cannot happen :) ***\n"; } if ($buf eq "\x15") { #NAK # packet nok - crc differs } } print $sock "\x04"; # EOT if (sysread($sock,$buf,1) <= 0) { die "*** died$! ***\n"; } if ($buf ne "\x06") { die "*** no ACK received after xmodem send ***\n"; } }