Home
Name Modified Size InfoDownloads / Week
README 2023-03-18 2.9 kB
Totals: 1 Item   2.9 kB 0
A minimalist grammar can be used to generate a language for byte based communication typically used for Arduino type
devices. The grammar should be very simple to parse and easily extensible.
The grammar is based on an alphabet consisting of two unique symbols START and EXTEND and 253 other symbols which
would encode their own binary values.
The START symbol will only appear once at the start of a message. Its binary value would be encoded by the byte pair
EXTEND and another symbol other than START or EXTEND.
The EXTEND binary value would be encoded by the byte pair EXTEND, EXTEND.
The EXTEND symbol is used to create new symbols by following it with one or more symbols excluding the START symbol.
New symbols can also be created by adding one or more symbols after the START symbol. This is useful for identifying
message types.
An example language would be one where an Arduino has to send a signal that a particular event has occured, four
different parameter values and program error codes.
The different message types are encoded by using different byte values immediately after the START symbol.
START will be encoded as 0xFF, EXTEND as 0xFE, byte value 0xFF as the byte pair EXTEND, 0xFD, and byte value 0xFE as
the byte pair EXTEND, EXTEND. Byte values 0x00 to 0xFD will be encoded verbatim
The event message would simply be the byte pair START, 0x00.
The first parameter message would be encoded as START, 0x01 followed by the four byte values encoded as above.
The second parameter message would be encoded as START, 0x02 followed by the four byte values encoded as above.
The third parameter message would be encoded as START, 0x03 followed by the four byte values encoded as above.
The fourth parameter message would be encoded as START, 0x04 followed by the four byte values encoded as above.
Error code messages would be encoded as START, 0x05 followed by a single byte value for the error code.
A simple state machine can be used to receive and parse the messages. Incomplete messages can be ignored by having the
state machine start parsing only when it receives a START symbol. If a START symbol is received in the middle of a
message, the state machine would reset and start receiving the new message. This eliminates the need for a timeout to
determine if the communication connection is broken. When the connection is reestablished, as soon as a START symbol is
read, the previous message will be erased and the new message read.
Sending data such as variable length strings can be done by using a byte value immediately after the START symbol to
identify the message as a string and then the byte values encoded as above. The EXTEND symbol paired with a byte value
can be used to terminate the string.
By using this grammar to create a communication language, the absolute minimum number of bytes will be used to convey
information while keeping message parsing as simple as possible.

Source: README, updated 2023-03-18