Device::Modem::Protocol::Xmodem
Class that represents a single Xmodem data block.
my $b = Xmodem::Block->new( 1, 'My Data...<until-128-chars>...' ); if( defined $b ) { # Ok, block instanced, verify its checksum if( $b->verify( 'checksum', <my_chksum> ) ) { ... } else { ... } } else { # No block } # Calculate checksum, crc16, 32, ... $crc16 = $b->crc16(); $crc32 = $b->crc32(); $chksm = $b->checksum();
Class that implements an Xmodem receive buffer of data blocks. Every block of data is represented by a Xmodem::Block object.
Xmodem::Block
Blocks can be pushed and popped from the buffer. You can retrieve the last block, or the list of blocks from buffer.
my $buf = Xmodem::Buffer->new(); my $b1 = Xmodem::Block->new(1, 'Data...'); $buf->push($b1); my $b2 = Xmodem::Block->new(2, 'More data...'); $buf->push($b2); my $last_block = $buf->last(); print 'now I have ', scalar($buf->blocks()), ' in the buffer'; # TODO document replace() function ???
Package that contains all useful Xmodem protocol constants used in handshaking and data blocks encoding procedures
Xmodem::Constants::soh ........... 'start of header' Xmodem::Constants::eot ........... 'end of trasmission' Xmodem::Constants::ack ........... 'acknowlegded' Xmodem::Constants::nak ........... 'not acknowledged' Xmodem::Constants::can ........... 'cancel' Xmodem::Constants::C ........... `C' ASCII char Xmodem::Constants::XMODEM ........ basic xmodem protocol Xmodem::Constants::XMODEM_1K ..... xmodem protocol with 1k blocks Xmodem::Constants::XMODEM_CRC .... xmodem protocol with CRC checks Xmodem::Constants::CHECKSUM ...... type of block checksum Xmodem::Constants::CRC16 ......... type of block crc16 Xmodem::Constants::CRC32 ......... type of block crc32
Control class to initiate and complete a X-modem file transfer in receive mode
X-modem
my $recv = Xmodem::Receiver->new( modem => {Device::Modem object}, filename => 'name of file', XXX protocol => 'xmodem' | 'xmodem-crc', | 'xmodem-1k' ); $recv->run();
Sends a cancel char (can), that signals to sender that transfer is aborted. This is issued if we receive a bad block number, which usually means we got a bad line.
can
Returns the underlying Device::Modem object.
Retreives message from modem and if a block is detected it breaks it into appropriate parts.
Starts a new transfer until file receive is complete. The only parameter accepted is the (optional) local filename to be written.
Sends an acknowledge (ack) char, to signal that we received and stored a correct block Resets count of timeouts and returns the Xmodem::Block object of the data block received.
ack
Sends a timeout (nak) char, to signal that we received a bad block header (either a bad start char or a bad block number), or a bad data checksum. Increments count of timeouts and at ten timeouts, aborts transfer.
nak
To install Device::Modem, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Device::Modem
CPAN shell
perl -MCPAN -e shell install Device::Modem
For more information on module installation, please visit the detailed CPAN module installation guide.