CLI
Overview
CLI (Command Line Interface) is a method for interacting with devices or chips through a command line interface. Users can execute various operations by entering specific commands.
Basic Principle
The core of WM_CLI is the open-source project Letter-shell. Letter-shell is a shell written in C language that can be embedded in programs and called by the command line to run functions within the program. Its main functions include:
Support for tab key auto-completion;
Support for help to display command usage;
Command handling functions similar to Linux command line functions;
Easy to add and place anywhere;
Support for feature and partial command trimming.
Defining CLI Commands
Use WM_CLI_CMD_DEFINE
to define a command. Its usage is as follows:
WM_CLI_CMD_DEFINE(cmd, handler, description, usage)
Where cmd
is the command name, handler
is the command handling function, description
is the command description, and usage
is the detailed command usage. To reduce firmware size, the usage
feature can be disabled by menuconfig
.
Usage Example
Adding a command named test
:
static void cmd_test(int argc, char *argv[])
{
/* do somethings... */
}
WM_CLI_CMD_DEFINE(test, cmd_test, Display test information, test -- Display test information)
Its handler function is cmd_test
. Executing the help``command will display its ``description
as Display test information, and executing help test
will show its detailed usage
as test – Display test information.
In the handler function, argc
represents the number of arguments, and argv
is an array of argument pointers, pointing to the argument strings passed to the function. For example, argv[0] is the command name, argv[1] is the first argument, and argv[2] is the second argument.