📄 xymodem.htm
字号:
Developing technology is providing phone line data transmission at ever
higher speeds using very specialized techniques. These high speed modems,
as well as session protocols such as X.PC, provide high speed, nearly
error free communications at the expense of considerably increased delay
time.
This delay time is moderate compared to human interactions, but it
cripples the throughput of most error correcting protocols.
The g option to YMODEM has proven effective under these circumstances.
The g option is driven by the receiver, which initiates the batch transfer
by transmitting a G instead of C. When the sender recognizes the G, it
bypasses the usual wait for an ACK to each transmitted block, sending
succeeding blocks at full speed, subject to XOFF/XON or other flow control
exerted by the medium.
The sender expects an inital G to initiate the transmission of a
particular file, and also expects an ACK on the EOT sent at the end of
each file. This synchronization allows the receiver time to open and
Chapter 6 XMODEM Protocol Enhancements
X/YMODEM Protocol Reference June 18 1988 19
close files as necessary.
If an error is detected in a YMODEM-g transfer, the receiver aborts the
transfer with the multiple CAN abort sequence. The ZMODEM protocol should
be used in applications that require both streaming throughput and error
recovery.
Figure 8. YMODEM-g Transmission Session
SENDER RECEIVER
"sb foo.*<cr>"
"sending in batch mode etc..."
G (command:rb -g)
SOH 00 FF foo.c NUL[123] CRC CRC
G
SOH 01 FE Data[128] CRC CRC
STX 02 FD Data[1024] CRC CRC
SOH 03 FC Data[128] CRC CRC
SOH 04 FB Data[100] CPMEOF[28] CRC CRC
EOT
ACK
G
SOH 00 FF NUL[128] CRC CRC
Chapter 6 XMODEM Protocol Enhancements
X/YMODEM Protocol Reference June 18 1988 20
7. XMODEM PROTOCOL OVERVIEW
8/9/82 by Ward Christensen.
I will maintain a master copy of this. Please pass on changes or
suggestions via CBBS/Chicago at (312) 545-8086, CBBS/CPMUG (312) 849-1132
or by voice at (312) 849-6279.
7.1 Definitions
<soh> 01H
<eot> 04H
<ack> 06H
<nak> 15H
<can> 18H
<c> 43H
7.2 Transmission Medium Level Protocol
Asynchronous, 8 data bits, no parity, one stop bit.
The protocol imposes no restrictions on the contents of the data being
transmitted. No control characters are looked for in the 128-byte data
messages. Absolutely any kind of data may be sent - binary, ASCII, etc.
The protocol has not formally been adopted to a 7-bit environment for the
transmission of ASCII-only (or unpacked-hex) data , although it could be
simply by having both ends agree to AND the protocol-dependent data with
7F hex before validating it. I specifically am referring to the checksum,
and the block numbers and their ones- complement.
Those wishing to maintain compatibility of the CP/M file structure, i.e.
to allow modemming ASCII files to or from CP/M systems should follow this
data format:
+ ASCII tabs used (09H); tabs set every 8.
+ Lines terminated by CR/LF (0DH 0AH)
+ End-of-file indicated by ^Z, 1AH. (one or more)
+ Data is variable length, i.e. should be considered a continuous
stream of data bytes, broken into 128-byte chunks purely for the
purpose of transmission.
+ A CP/M "peculiarity": If the data ends exactly on a 128-byte
boundary, i.e. CR in 127, and LF in 128, a subsequent sector
containing the ^Z EOF character(s) is optional, but is preferred.
Some utilities or user programs still do not handle EOF without ^Zs.
Chapter 7 Xmodem Protocol Overview
X/YMODEM Protocol Reference June 18 1988 21
+ The last block sent is no different from others, i.e. there is no
"short block".
Figure 9. XMODEM Message Block Level Protocol
Each block of the transfer looks like:
<soh><blk #=""><255-blk #><--128 data bytes--><cksum>
in which:
<soh> = 01 hex
<blk #=""> = binary number, starts at 01 increments by 1, and
wraps 0FFH to 00H (not to 01)
<255-blk #> = blk # after going thru 8080 "CMA" instr, i.e.
each bit complemented in the 8-bit block number.
Formally, this is the "ones complement".
<cksum> = the sum of the data bytes only. Toss any carry.
7.3 File Level Protocol
7.3.1 Common_to_Both_Sender_and_Receiver
All errors are retried 10 times. For versions running with an operator
(i.e. NOT with XMODEM), a message is typed after 10 errors asking the
operator whether to "retry or quit".
Some versions of the protocol use <can>, ASCII ^X, to cancel transmission.
This was never adopted as a standard, as having a single "abort" character
makes the transmission susceptible to false termination due to an <ack>
<nak> or <soh> being corrupted into a <can> and aborting transmission.
The protocol may be considered "receiver driven", that is, the sender need
not automatically re-transmit, although it does in the current
implementations.
7.3.2 Receive_Program_Considerations
The receiver has a 10-second timeout. It sends a <nak> every time it
times out. The receiver's first timeout, which sends a <nak>, signals the
transmitter to start. Optionally, the receiver could send a <nak>
immediately, in case the sender was ready. This would save the initial 10
second timeout. However, the receiver MUST continue to timeout every 10
seconds in case the sender wasn't ready.
Once into a receiving a block, the receiver goes into a one-second timeout
for each character and the checksum. If the receiver wishes to <nak> a
block for any reason (invalid header, timeout receiving data), it must
wait for the line to clear. See "programming tips" for ideas
Synchronizing: If a valid block number is received, it will be: 1) the
expected one, in which case everything is fine; or 2) a repeat of the
previously received block. This should be considered OK, and only
indicates that the receivers <ack> got glitched, and the sender re-
transmitted; 3) any other block number indicates a fatal loss of
synchronization, such as the rare case of the sender getting a line-glitch
Chapter 7 Xmodem Protocol Overview
X/YMODEM Protocol Reference June 18 1988 22
that looked like an <ack>. Abort the transmission, sending a <can>
7.3.3 Sending_program_considerations
While waiting for transmission to begin, the sender has only a single very
long timeout, say one minute. In the current protocol, the sender has a
10 second timeout before retrying. I suggest NOT doing this, and letting
the protocol be completely receiver-driven. This will be compatible with
existing programs.
When the sender has no more data, it sends an <eot>, and awaits an <ack>,
resending the <eot> if it doesn't get one. Again, the protocol could be
receiver-driven, with the sender only having the high-level 1-minute
timeout to abort.
Here is a sample of the data flow, sending a 3-block message. It includes
the two most common line hits - a garbaged block, and an <ack> reply
getting garbaged. <xx> represents the checksum byte.
Figure 10. Data flow including Error Recovery
SENDER RECEIVER
times out after 10 seconds,
<--- <nak>
<soh> 01 FE -data- <xx> --->
<--- <ack>
<soh> 02 FD -data- xx ---> (data gets line hit)
<--- <nak>
<soh> 02 FD -data- xx --->
<--- <ack>
<soh> 03 FC -data- xx --->
(ack gets garbaged) <--- <ack>
<soh> 03 FC -data- xx ---> <ack>
<eot> --->
<--- <anything except="" ack="">
<eot> --->
<--- <ack>
(finished)
7.4 Programming Tips
+ The character-receive subroutine should be called with a parameter
specifying the number of seconds to wait. The receiver should first
call it with a time of 10, then <nak> and try again, 10 times.
After receiving the <soh>, the receiver should call the character
receive subroutine with a 1-second timeout, for the remainder of the
message and the <cksum>. Since they are sent as a continuous stream,
timing out of this implies a serious like glitch that caused, say,
127 characters to be seen instead of 128.
Chapter 7 Xmodem Protocol Overview
X/YMODEM Protocol Reference June 18 1988 23
+ When the receiver wishes to <nak>, it should call a "PURGE"
subroutine, to wait for the line to clear. Recall the sender tosses
any characters in its UART buffer immediately upon completing sending
a block, to ensure no glitches were mis- interpreted.
The most common technique is for "PURGE" to call the character
receive subroutine, specifying a 1-second timeout,[1] and looping
back to PURGE until a timeout occurs. The <nak> is then sent,
ensuring the other end will see it.
+ You may wish to add code recommended by John Mahr to your character
receive routine - to set an error flag if the UART shows framing
error, or overrun. This will help catch a few more glitches - the
most common of which is a hit in the high bits of the byte in two
consecutive bytes. The <cksum> comes out OK since counting in 1-byte
produces the same result of adding 80H + 80H as with adding 00H +
00H.
__________
1. These times should be adjusted for use with timesharing systems.
Chapter 7 Xmodem Protocol Overview
X/YMODEM Protocol Reference June 18 1988 24
8. XMODEM/CRC Overview
Original 1/13/85 by John Byrns -- CRC option.
Please pass on any reports of errors in this document or suggestions for
improvement to me via Ward's/CBBS at (312) 849-1132, or by voice at (312)
885-1105.
The CRC used in the Modem Protocol is an alternate form of block check
which provides more robust error detection than the original checksum.
Andrew S. Tanenbaum says in his book, Computer Networks, that the CRC-
CCITT used by the Modem Protocol will detect all single and double bit
errors, all errors with an odd number of bits, all burst errors of length
16 or less, 99.997% of 17-bit error bursts, and 99.998% of 18-bit and
longer bursts.[1]
The changes to the Modem Protocol to replace the checksum with the CRC are
straight forward. If that were all that we did we would not be able to
communicate between a program using the old checksum protocol and one
using the new CRC protocol. An initial handshake was added to solve this
problem. The handshake allows a receiving program with CRC capability to
determine whether the sending program supports the CRC option, and to
switch it to CRC mode if it does. This handshake is designed so that it
will work properly with programs which implement only the original
protocol. A description of this handshake is presented in section 10.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -