Document fait avec Nvu Document made with Nvu
acceuilnouveautesintroductioncoeurmini_systemepages_techniquesrevue_de_presselienscourriel



Technical pages
XMODEM protocol

Instructions
Use
Example

Principe

The XMODEM protocol allows to make files transfers by blocks of 128 bytes with error detection and correction by rehearsal.

Here is an example of data transfer under protocol XMODEM protocol with:

<soh> = 0x01
<nak> = 0x15
<ack> = 0x06
<eot> = 0x04
<data> = 128 bytes of data
<xx > = checksum of the line (from <soh> to <data> include)

Transmiter
 
Receiver
   
Wait of 10 seconds at most
 
<<<
<nak>
<soh> 0x01 0xFE <data> <xx>
>>>
 
 
<<<
<ack>
<soh> 0x02 0xFD <data> <xx>
>>>
Error of transmission
 
<<<
<nak>
<soh> 0x02 0xFD <data> <xx>
>>>
Rehearsal successfully
 
<<<
<ack>
<soh> 0x03 0xFC <data> <xx>
>>>
 
 
<<<
<ack>
<eot>
>>>
 
 
<<<
<ack>


Instructions

- XMODEM_TAMPON address

128 bytes transmission/reception buffer adress

- XMODEM_BLOC address

Variable containing the number of block in the course of transfer

- XMODEM_TEMPO address

Variable for temporizations management bound to the protocol

- INPUT_FILE? nbr_bytes

Instruction giving the number of available bytes in INPUT_FILE

- RS232_RECEIVE_FILE? nbr_bytes

Instruction giving the number of available bytes in RS232_RECEIVE_FILE

- RS232_TRANSMIT_FILE? nbr_bytes

Instruction giving the number of available bytes in RS232_TRANSMIT_FILE

- OUTPUT_FILE? nbr_bytes

Instruction giving the number of available bytes in OUTPUT_FILE

- T_XMODEM_CONNECTE address

XMODEM management task (replace T_RS232_CONNECTE during the duration of the transfer)

rec/emi XMODEM_OUVRE error

Opening of a XMODEM transfer in transmission if rec/emi is zero or in reception otherwise.
error is zero when operation is correct

- XMODEM_OCTET_RECOIT byte,error

Reception of a byte.
error is zero if the byte is valid, otherwise reception is ended

byte XMODEM_OCTET_EMET error

Transmission of a byte.
error is zero if the transmission is correct

- XMODEM_FERME -

At the end of the transfer in transmission or in reception

address XMODEM_RECOIT length

Reception of a file at address specified on the length (in bytes) indicated at the end of transfer

address,length XMODEM_EMET -

Transmission of a file situated at address and on the length (in bytes) specified


Use

The transfer of a file requires the use of the following instructions:

  • XMODEM_OUVRE,
  • XMODEM_OCTET_RECOIT or XMODEM_OCTET_EMET,
  • XMODEM_FERME.

The user has to start a transfer by the instruction "XMODEM_OUVRE" with a value zero in the case of a transmission, and not zero in the case of a reception. A zero error code indicates that the transfer can be made correctly.

Instruction "XMODEM_FERME" must be necessarily executed in the end of a file transmission operation. The las block will be completed automatically with stuffing bytes (in 0), transferred and followed by the transmission of the end of text character ( eot ).

Files can be transferred by using "Hyperterminal" software on PC or " Apple works terminal" on MAC.


Example

To illustrate this page, here is the code of instructions "XMODEM_RECOIT" and "XMODEM_EMET":

: XMODEM_RECOIT ( address --> length )
 -1 XMODEM_OUVRE
 IF
  DROP 0
 ELSE
  0
  BEGIN
   XMODEM_OCTET_RECOIT
   IF
    DROP -1
   ELSE
    3 PICK C! >R 1+ R> 1+ 0
   THEN
  UNTIL
  SWAP DROP
 THEN
 XMODEM_FERME
;

: XMODEM_EMET ( address, length --> - )
 0 XMODEM_OUVRE
 IF
  DROP
 ELSE
  0 DO
   DUP C@ XMODEM_OCTET_EMET
   IF
    LEAVE
   THEN
   1+
  LOOP
 THEN
 DROP XMODEM_FERME
;