-
Notifications
You must be signed in to change notification settings - Fork 0
Message protocol
- On laptop-based systems there are two standards that are used in media art: MIDI and OSC
- However on Arduino and other embedded systems that use serial communication there is no equivalent: there are a bunch of protocols (it is messy)
- This is a challenge that we could address: a standard serial communication protocol for embedded devices designed specifically for artists/designers
A simple, flexible protocol inspired from OSC that would allow 3 modes:
- ASCII: more expressive, less efficient, for debugging
- binary: less expressive, faster, packed, based on SLIP
- binary + checksum: like binary but more robust
The libraries designed to take care of the protocol would allow easy switch between these modes. In a typical application, one would start with the ASCII mode to test their application and might later on switch to one of the binary modes if more efficiency is needed.
Each message reads as follow:
<cmd>[arg1][arg2]...[argN][checksum]<end>
-
cmd: single byte, determines both the message mode and a user-defined command which is represented as a single ASCII letter char in [A-Za-z]
- in ASCII mode cmd is the command char itself (ascii codes: 65-90, 97-122)
- in binary mode cmd is 128 + commandcode (commandcode = 0..25 for A-Z, 26..51 for a-z)
- in binary checksum mode cmd is 192 + commandcode
-
argX: argument to the command, size may vary depending on type
- in ASCII mode arguments are separated by spaces
- in binary modes arguments are "packed" (eg. booleans take 1 bit)
- checksum: checksum (for the binary+checksum mode)
-
end: single byte, marks the end of the message
- in ASCII mode it is endline (ASCII code 13)
- in binary modes it is 0xC0 (like in SLIP)
- in ASCII mode reserved characters such as newline and spaces can be escaped using '' (including '' itself)
- in binary mode reserved characters can be escaped like in SLIP
This is a bitwise view of the command header:
ASCII mode:
|0|1|2|3|4|5|6|7|
|0| command |
Binary mode:
|0|1|2|3|4|5|6|7|
|1|c|commandcode|
c = checksum?
Links:
- alignment techniques
- ByteStream Thomas's library for encoding messages for Arduino
- COBS looks like a very nice and simple way of aligning streams of byte
- COBS/R A variant that tries to save one byte, especially for short messages
The problem is that we need a way to differentiate ASCII messages from non-ASCII messages. This can only be done if we ensure that we have a special END or BEGIN bytecode that will never appear in binary messages and only appear in ASCII messages for its purpose (eg. \n). Conversely, we also need another END or BEGIN bytecode that will never appear in ASCII messages and only appear in binary messages for its intended purpose.