How does the new serial framing protocol in TOS 1.1.x work?
Previous versions of TOS sent a serial message without real framing: addr 2 bytes type 1 byte group 1 byte length 1 byte payload 29 bytes crc 2 bytes The trick was that since the addr field is not needed on a serial link, they made the first character 126, which happens to be the HDLC framing byte. Readers look for 126 and assume that the next 35 bytes are the rest of the TOS message. The new format adds some additional framing bytes: sync 1 byte (HDLC framing byte: 126) proto 1 byte (packet type: 66) previous_tos_message (36 bytes) sync 1 byte (HDLC framing byte: 126) The trick here is that within the previous_tos_message all instances of the HDLC framing byte (126) and the HDLC escape bytes (125) must be escaped. To escape a byte, the byte is replaced with a two byte sequence. The first byte of the sequence is the HDLC escape byte (125), and the second byte is the original byte xored with x20. Since the first byte of the previous_tos_message is always a 126, it must always be escaped