介绍X-MODEM协议(转载)

XModem Protocol

XModem protocol was developed and first implemented by Ward Christensen in 1977 and placed in the public domain becoming one of the earliest and most popular protocols for file transfers between various hardware platforms.

XModem is the simplest and one of the slowest of the file transfer protocols. It uses data blocks of only 128 bytes, requires an acknowledgement of every single block transmitted and uses only a simple checksum for data validation.

XModem blocks have the following format:

<SOH> 1 byte
<BlockNo> 1 byte
<~BlockNo> 1 byte
<Data> 128 bytes
<Checksum> 1 byte
  • SOH marks start of the block.
  • BlockNo is a one byte block number. The block numbers have range [1, 255]. After 255, the block number cycle starts again.
  • ~BlockNo is a complement of the block number.
  • Data are a text long 128 characters. If the text is shorter than 128 characters, the data block is filled with padding characters (CtrlZ by default).
  • Checksum is an arithmetic sum (modulo-256) of all data bytes.

A typical XModem protocol transfer looks like this:

TransmitterReceiver
<-
<NAK>
handshake
<SOH><1><254><Data 128 bytes><CHK>
->
response
<-
<ACK>
acknowledgment
<SOH><2><253><Data 128 bytes><CHK>
->
<-
<ACK>
<EOT>
->
end of transmission
<-
<ACK>
  • Handshake: the receiver always begins communication in start-up phase by sending a handshake character (in this case a NAK character). It waits for 10 seconds for the response. If it does not receive a block within 10 seconds it sends another NAK. Receiver tries up to 10 times to establish the handshake when it gives up.
  • Response: transmitter sends requested data. Data are divided in blocks 128 characters long. Timeout for each character to be received is 1 second. Transmitter waits after first block up to 1 minute for the receiver's acknowledgement. This gives the receiver time for disk storage preparation.
  • Acknowledgement: receiver calculates the checksum and compares it to the checksum received. If checksums are the same, it sends positive acknowledgement ACK. If they differ, the receiver sends a NAK and the transmitter resends the current block. This continues until the all data is transmitted.
  • End of transmission: after the all data are transmitted, the transmitter notifies that by sending a EOT character. Either side can cancel transmission at any time by sending 3 CAN (CtrlX) characters.

Protocol does not support any additional information about the file being transmitted, like file name or file size. Hence, the received file size is always a multiple of the block size. Since XModem does not escape any binary data (like XON and XOFF), a software flow control is not possible. For binary data transfer hardware flow control (called also RTS/CTS Control - Ready to Send/Clear to Send) should be selected.

XModem Extensions

XModem CRC    improves error checking by substituting 1 byte checksum with 2 bytes cyclic redundancy check (CRC16). This offers much higher level of data integrity. The receiver indicates this protocol by sending the 'C' character as a handshake. Receiver tries up to 3 times to start data transfer when it concludes that transmiter is not capable.

<CRC16> 2 bytes
CRC HiByte
CRC LoByte
XModem uses a non-reversed CRC algorithm with divisor polynomial X16+X12+X5+X0.

TransmitterReceiver
<-
C
<SOH> 1 byte
<BlockNo> 1 byte
<~BlockNo> 1 byte
<Data> 128 bytes
<CRC16> 2 bytes
->
<-
<ACK>
<EOT>
->
<-
<ACK>

XModem 1k    improves data transfer speed by increasing block size up to 1024 bytes. Each block starts with an STX character rather than an SOH. A CRC16 is used for the checksum. Because of the larger block size, number of times the transmitter must wait for an acknowledgement is reduced and transmission speed is increased. With noisy lines throughput is reduced significantly, because the block must be retransmitted is bigger. If transmitter receives 5 NAK characters in a row, it should decrease block size to 128 bytes. Once the block size is reduced, it is never stepped back up to 1024 bytes.

TransmitterReceiver
<-
C
<STX> 1 byte
<BlockNo> 1 byte
<~BlockNo> 1 byte
<Data> 1024 bytes
<CRC16> 2 bytes
->
<-
<ACK>
<EOT>
->
<-
<ACK>

XModem 1kG    supports data streaming. The receiver request data by sending the 'G' character as a handshake. The transmiter continuously transmits blocks without waiting for acknowledgment. If the receiver does encounter a bad block, it aborts entire session by sending a NAK. To obtain this very high throughput, modems on both sides of the line must have enabled error correcting features.

TransmitterReceiver
<-
G
<STX> 1 byte
<BlockNo> 1 byte
<~BlockNo> 1 byte
<Data> 1024 bytes
<CRC16> 2 bytes
->
<STX> 1 byte
<BlockNo> 1 byte
<~BlockNo> 1 byte
<Data> 1024 bytes
<CRC16> 2 bytes
->
<EOT>
->

Reference:

  1. XModem / YModem Protocol Reference by Chuck Forsberg [10-14-88]

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值