With nRF5 SDK v14.0.0, we have significantly refactored the Command Line Interface (CLI) module to make it more useful and user friendly.
The new CLI has the following features:
The module can be connected to any transport. At this point, the following transport layers are implemented:
We noticed that the CLI that was provided in nRF5 SDK v13.0.0 had great potential to simplify work with our nRF5 chips. Unfortunately, in its previous shape, it only allowed for adding some simple commands, the handling of which required a lot of manual and repetitive work.
The main drawbacks that we noticed were:
if - else ifstatements to handle command parameters.
nrf_cli_fprintffunction buffer could cause an issue where full string was not printed.
Taking these assumptions into consideration, we started our work to deliver a new command line interface.
Commands in the new CLI are organized in a tree structure. Each module can register root commands (level 0) and corresponding dynamic or static subcommands (level > 0). Thanks to this approach, you can now use the Tab key to auto-complete or view all commands and their subcommands.
What is more, each and every command or subcommand can have or not have a handler. CLI will analyze the entered command line and it will execute the command or subcommand that has a handler and highest level. Higher-level subcommands without a handler will be passed as arguments.
An example command may look like that:
log enable info app
In such case, CLI will execute the handler for subcommand
enable and it will pass
app as arguments to it. Despite the fact that
app are subcommands without a handler, they can still be completed or prompted with the Tab key.
Another innovation we have introduced is the concept of dynamic subcommands. The advantage of using them is that their number and syntax might not be known during compile time.
Below, we present a practical example how you can use the new CLI with dynamic commands. Let us assume that we would like to scan for the available Bluetooth devices and then connect to one of them. To realize that, we can implement the following command trees:
After typing connect and hitting the Tab button, nothing happens because the list of dynamic commands is empty.
We need to scan for advertising devices first:
Now, dynamic subcommands are available and can be prompted with the Tab button.
Next, we can also connect to the selected device:
To be continued...