Device::Modem::Protocol::Xmodem(3)

NAME
Device::Modem::Protocol::Xmodem

Xmodem::Block
Class that represents a single Xmodem data block.

  Synopsis
        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();

Xmodem::Buffer
Class that implements an Xmodem receive buffer of data blocks. Every block of data is represented by a "Xmodem::Block" object.

Blocks can be pushed and popped from the buffer. You can retrieve the last block, or the list of blocks from buffer.

  Synopsis
        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 ???

Xmodem::Constants
Package that contains all useful Xmodem protocol constants used in handshaking and data blocks encoding procedures

  Synopsis
        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

Xmodem::Receiver
Control class to initiate and complete a "X-modem" file transfer in receive mode

  Synopsis
        my $recv = Xmodem::Receiver->new(
                modem    => {Device::Modem object},
                filename => 'name of file',
                XXX protocol => 'xmodem' | 'xmodem-crc', | 'xmodem-1k'
        );

        $recv->run();

  Object methods

abort_transfer()
    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.

modem()
    Returns the underlying Device::Modem object.

receive_message()
    Retrieves message from modem and if a block is detected it breaks it into appropriate parts.

run()
    Starts a new transfer until file receive is complete. The only parameter accepted is the (optional) local filename to be written.

send_ack()
    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.

send_timeout()
    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.

  See also

- Device::Modem