The basic format of a RSP packet is shown in Figure 2.2.
For almost all packets, binary data is represented as two hexadecimal digits per byte of data. The checksum is the unsigned sum of all the characters in the packet data modulo 256. It is represented as a pair of hexadecimal digits.
Where the characters '#' or '$' appear in the packet data, they must be escaped. The escape character is ASCII 0x7d ('}'), and is followed by the original character XORed with 0x20. The character '}' itself must also be escaped.
The small number of packets which transmit data as raw binary (thus requiring an 8-bit clean connection) must also escape the characters '#', '$' and '}' if they occur in the binary data.
Reply packets sent by the server may use run-length encoding. The
format is to follow the character being repeated by '*' and then the
character whose ASCII code is 28 greater than the total repeat, so
long as it remains a printable ASCII character (i.e. not greater than
126). Thus the string "XXXXX"
would be represented
as "X*!"
('!'
is ASCII 33).
This feature is suitable for run-lengths of 4, 5 and 8-97. Run lengths of 6 and 7 cannot be used, since the repeat characters would be '#' and '$' and interfere with the recognition of the packet itself before decoding. For these cases, a run length of 5 is used, followed by 1 or 2 instances of the repeated character as required. '*' and '}' cause no problem, since they are part of decoding, and their use in a run-length would be recognized as such.
Note | |
---|---|
There is no requirement for a server to use run length encoding. |