1
Microcontrollers / Re: primitive serial CLI / Console for embedded systems - Ideas for implementation?
« Last post by tooki on Today at 04:00:00 pm »https://interrupt.memfault.com/blog/firmware-shellThat is the code I started from to develop the CLI for a piece of lab equipment I built.
The use case is practically identical to yours: human use for development, but ultimately controlled by Python scripting for experiment automation.
In my case (a 6-channel capacitance meter built around Smartec’s UTI chip, with a PIC microcontroller to read the UTI’s weird period-modulated output and communicate over RS-422), I made some settings “modes” (verbose on/off, debug on/off, echo on/off, and fast/slow mode) that persist between measurements, while others are per-call, like the channel and number of measurements.
For example, “read 1 20” takes 20 sequential readings of channel 1 and returns them as a list, while “avg 1 20” takes 20 sequential readings of channel 1 and returns a single averaged value. In debug mode, the result includes statistics. Verbose mode outputs the units (pF), extra human-friendly info, and line numbers on lists. The idea is that in automated operation, echo, debug, and verbose are off and the unit returns bare numbers that are easy to parse.
I also added single-letter “aliases” of the commands, so that the two examples above can be typed as “r 1 20” and “a 1 20”, respectively.
The mode commands accept a Boolean value (true/false, t/f, 1/0, and on/off are all accepted), but function as a toggle if no value is passed. This allows the control script to positivity set a known configuration before sending commands. One of the things the CLI parser returns is the number of arguments received (including the command itself), so you can easily make your command handler do different things depending on the number of arguments.
Oh yeah, and I added backspace support (quite handy for us humans).