Minimalist message protocol in C to exchange messages between MCU's. Includes a python generation utility for the header and source files.
A frame consists of:
| STX | MSG_ID | PAYLOAD_BYTE_1 | PAYLOAD_BYTE_2 | ... | PAYLOAD_BYTE_N | CHECKSUM |
STX
bytes in MSG_ID
and PAYLOAD
are escaped by the sequence ESC STX_ESC
and ESC
bytes are escaped with ESC ESC_ESC
.
This is simple and very robust to parse, but causes worst case overhead of 100%
, if every payload byte is either STX
or ESC
.
- The
.yaml
files inside./msgs/
define message fields and the filename defines the message name. The filename (and, as a result, the message name) should be formatted as all-caps-snake-case, likeALL_CAPS_SNAKE_CASE.yaml
. - A configuration
.yaml
file in the root of this repo defines which messages should be included and if they are to be received, sent or both (RX
,TX
orRXTX
). Additionally, theglobal_mode
option can be set toRX
orTX
instead ofRXTX
if it is known that all messages areRX
orTX
-only. In that case, the mode flags of each message have no effect. - Python generates
c
-headers formjinja2
-templates and define the message serialization ("packing") and parsing for receiving (packing for serial sending, parsing for serial reading). - The resulting headers depend only on some standard libraries:
string.h
,stdint.h
andstdbool.h
. For testing and debugging output alsostdio.h
, of course.
Tested on Ubuntu 22.04. Install make
, python3
, pip
and then the required python modules for generation
sudo apt install make python3 python3-pip
pip install -r python/requirements.txt
Edit the yaml
files to your liking, they should be self-explanatory. You can copy the config.yaml
and give it a different name. Then generate the headers:
make clean && make CONFIG=config.yaml
Look at tester.c
. Especially note how the dummyWriter()
is passed to piSerialWrite()
. For TX
, this is the function that needs to be modified/replaced to actually get the bytes on the transmission line, byte-for-byte.
You need gcc
installed, then do
make clean && make CONFIG=config.yaml tester && ./tester
- 2024-08-27 -- Version 2.0.0 -- Initial release
- Till Blaha (@tblaha, Delft University of Technology, t.m.blaha - @ - tudelft.nl)
.
├── msgs/ # Message definitions
├── python/ # generation utility
├── src/ # static source files (only protocol implementation)
├── templates/ # source files to be generated
├── tests/
├── config.yaml # configurations of which messages should be generated
├── LICENSE
├── Makefile
├── README.md
The contents of this repository are licensed under a GNU Lesser General Public License v3.0, with the exception of the contents of src/
. The contents of src/
, as well as the generated output files are licensed under an MIT License. See the LICENSE
file.
Technische Universiteit Delft hereby disclaims all copyright interest in the program “Indiflight Support” (one line description of the content or function) written by the Author(s).
Henri Werij, Dean of the Faculty of Aerospace Engineering
Copyright © 2024, Till Blaha