ChessLink protocol¶
Helper functions for the Chess Link protocol for character-based odd-parity and message-block-parity.
The chess link protocol sends ASCII messages. Each ASCII character gets an additional odd-parity-bit. Each block of ASCII+odd-parity bytes gets an additional block parity.
Details of the Chess Link protocol are documented in magic-board.md.
-
chess_link_protocol.
add_block_crc
(msg)[source]¶ Add block parity at the end of the message
- Parameters
msg – a message byte array (each byte must have already been encoded with odd parity). This function adds two bytes of block CRC at the end of the message.
msg – byte array with a message (incl. odd-parity bits set already)
- Returns
two byte longer message that includes 2 CRC bytes.
-
chess_link_protocol.
add_odd_par
(b)[source]¶ The chess link protocol is 7-Bit ASCII. This adds an odd-parity-bit to an ASCII char
- Parameters
b – an ASCII character (0..127)
- Returns
a byte (0..255) with odd parity in most significant bit.
-
chess_link_protocol.
check_block_crc
(msg)[source]¶ Chess link messages consist of 7-bit-ASCII characters with odd parity. At the end of each message, an additional block-parity is added. Valid chess link messages must have correct odd parity for each character and a valid block parity at the end.
- Parameters
msg – a byte array with the message.
- Returns
True, if the last two bytes of msg contain a correct CRC, False otherwise.