Extending the Serial Protocol
Edit on GitHubAdd new AEGIS: lines and serial commands to the firmware: where the code lives and the conventions to follow.
Extending the Serial Protocol
The serial protocol is deliberately small, but it is also easy to grow. This page shows where the code lives and the conventions that keep it parseable by the bridge and any other client.
Where the code lives
In AegisBeacon.ino, before setup():
serialPosReport(bool force)printsAEGIS:POS:lines (throttled unless forced).processSerialCommand(const char* cmd)handles inbound commands.serialPoll()reads newline-terminated lines fromSerialand callsprocessSerialCommand.serialPoll()is called from every mode loop: beacon sleep, search, config, and the GPS wait.
Adding an outgoing line
- Print with plain
Serial.printf- never the coloredLOG_*macros - so the line has no ANSI escapes. - Keep the
AEGIS:prefix and a singleTYPE:label. - Use
key=value;fields, ASCII only, one line per record. - Document the format in the Serial Command Protocol page.
Example:
Serial.printf("AEGIS:BAT:mv=%d;percent=%d\n", mv, pct);Adding an inbound command
- Add a
striStarts(s, "CMD ")branch inprocessSerialCommand. - Validate ranges the way
FREQdoes, and reply withAEGIS:CMD:...on success orAEGIS:ERR:...on failure. - Persist with
saveConfig()when the setting must survive reboot. - Document it in the protocol page and in the bridge README.
Conventions
| Rule | Why |
|---|---|
Plain Serial.printf only | Clients must not strip ANSI codes |
One record per line, \n terminated | readline() in any language works |
AEGIS: prefix on every line | The bridge ignores everything else |
| Lowercase keys | Clients parse case-sensitively |
| SI units in field names | alt in meters, freq in MHz |
| Throttle position spam | serialPosReport keeps a 5 s floor |
Testing
Flash, open a monitor, and exercise both directions: send HELP, POS, STATUS, and confirm the replies. Then run the bridge with --verbose and check the new lines pass through cleanly.