What’s a CLI?
A command-line interface (CLI) is a way to interact directly with a software program in the form of text commands and responses. Just as source code is a typed set of commands to produce a result, the CLI is also a typed set of commands to produce a result. The difference is that the commands are typed in real-time by a person (although may be captured for replay later).
In embedded system development, a CLI is often developed to aid initial driver development and debugging. This CLI may become the interface (or one of the interfaces) used by a sophisticated end-user to interact with the product. Think of typing commands to control a machine, such as a spacecraft or NC mill, or perhaps for low-level access to the control system of an undersea ROV as a development tool, tweaking time-constants and monitoring low-level system performance during testing.
One of my current projects, a scientific instrument, incorporates a home-grown CLI that has evolved with the project. It has limited functionality and supports simple commands only. However, the potential exists that eventually a sophisticated end-user might appreciate more advanced functionality, including command history, variable substitution and simple scripting, akin to a unix shell such as csh or bash. Should that become true, the current CLI will need to evolve, which will have a cost in time and effort. There is no customer demand now that would justify the effort, but it made me wonder if there was any open-source off-the-shelf CLI code that could be used.
Some concerted web searching identified the following projects:
- CLI toolkit. The toolkit supports implementation of C++ and Java command line interfaces using an XML resource file that contains the command specifications. Although interesting, at 75K lines of code it does not appear suitable for an embedded application.
- Arduino CmdMessenger Library. CmdMessenger is a messaging library for the Arduino platform, using the serial port as transport layer. A list of command identifiers is defined, with callback or handler functions attached for received messages. Interesting, but likely too Arduino specific.
- Bitlash. Bitlash is a programmable command shell for Arduino. Bitlash is very polished, but also very Arduino-specific (and programmability isn’t a requirement).
- Command Interpreter Library. Although embedded-oriented and modular, I’m not a fan of modal interfaces. Commands can be grouped into “subsystems”, in which case the subsystem must specified first, before a command. However, global commands are supported, which could be a work-around to create a non-modal interface.
- eLua (embedded Lua). Blog post Running Embedded Lua on Microcontrollers.
- embedded Command Line Interpreter (eCLI). The concept for eCLI looks interesting, but unfortunately no documentation to review.
- MicroCLI. MicroCLI is described in a German blog post (English translation), but the screenshots look good!
- HCC Embedded CLI. Interesting because it includes support for XMODEM.
- ChibiOS command shell. Forum post.
- FreeRTOS command shell.
- Simple Command Interpreter (see reply post from Graynomad).
- SCPI (Standard Commands for Programmable Instruments).
- Arduino BASIC (port of TinyBASIC from 68K assembler to Arduino). Updated fork.
- Microcontroller Interconnect Network (MIN) Protocol.
Some general articles on creating a CLI interface are:
- Writing Command Line Interfaces for Embedded Devices
- Parsing simple USART commands
- EEVblog forum post “text command parsers?”
- Simply Embedded Lesson 9: UART
- HowTo: Write your own interface application for Arduino
- Framing in serial communications
- Help, My Serial Data Has Been Framed: How To Handle Packets When All You Have Are Streams
- How do you design a serial command protocol for an embedded system (stack overflow)
Once the project at hand has passed the basic data collection milestone, I think it will be time to think about the future of the CLI. The complexity of the home-grown solution will not have increased significantly, and there will be time to think through the amount of work to switch to any of the shortlist candidates.