Bit Framing
Bit Framed Message Format
SYNC | LEN | LEN | LEN | DATA |
Bit framing is accomplished by marking the start of a message with the byte sequence
(represented as hex values)
6f 48 65 59 21
Due to the requirement that these bytes be shifted out LSb first, the bit sync sequence seen on the wire would be:
1111011000010010101001101001101010000100
Immediately following that sequence, three copies of the length of the following data block (not including the bit framing header) are appended, as shown in the figure above. Each length is composed of a 16 bit little endian value indicating the number of bytes, followed by a length check, which is 16 bits calculated as (((2<<16)–(2*len))&0xffff)
. The data to be sent follows the three length plus check repetitions. For example, if the input sequence is "hello
", the hex dump of the sequence of bytes sent out would be:
6f 48 65 59 21 05 00 f6 ff 05 00 f6 ff 05 00 f6 ff 68 65 6c 6c 6f
When data is received from the radio, it is compared to the sync pattern by successive bit shifts, until the detection threshold has been met. A valid sync sequence is received when the number of bit differences between the target sequence and the received sequence is 4 or less (90% match). If the complement of the target sequence and the received sequence differ by 4 or less bits, then an inverted sync is detected, and all subsequent data read from the port following the sync sequence is inverted.
Once a good packet has been detected, which occurs if at least one length is received correctly (i.e., one in which the computed checksum agrees with the received checksum), the len
bytes immediately following the three encoded lengths are received and passed up to the next layer.
One consequence of the way in which the message length is encoded is that the maximum length of an individual message is 216-1, or 65535 bytes. In order to send messages longer than that, the message may be sent using the reliable delivery method (see the "Automatic Repeat Request" section), which will break the message up into smaller pieces prior to transmit. Note that there is no way to send a broadcast or best-effort delivery message with total size greater than 65535 bytes. Also note that this is the maximum size of the message body after all transforms performed by higher layers in the stack have been applied. This results in a maximum size for an unreliable message at approximately 43K bytes, assuming the FEC described in the section "Forward Error Correction" is in use.