MT7687 API Reference LinkIt SDK v4
This section introduces the MiniCLI APIs including terms and acronyms, supported features, details on how to use the MiniCLI, function groups, enums, structures and functions. More...
This section introduces the MiniCLI APIs including terms and acronyms, supported features, details on how to use the MiniCLI, function groups, enums, structures and functions.
MiniCLI is a CLI engine designed with the footprint in mind for the memory and resource constrained systems. The code size is less than 3kB including command history and line editing.
|CLI||Command line interface.|
This section provides a MiniCLI configuration example using the following handler functions:
The command handlers are listed and linked together using a C structure cmd_t. In this example, the array cli_cmds is the root of the commands, that is, there are two commands at the top-level: set and ver. The command set requires a sub-command. ) In this example, the sub-command could be ip or mac.
If "ver" is supplied as an input source (by calling #__io_getchar()), #cli_ver() will be called. The version information will be printed to the output using #__io_putchar().
Whatever is supplied to the CLI engine is parsed into tokens similar to main function. The only difference is, in main() function call, the first parameter is the name of the executable.
In MiniCLI, the parameter len indicates the number of tokens supplied to the handler. The parameters supplied by the user on the CLI are stored in the param array based on the order of input. The array counter starts from 0.
In #cli_config(), a member state specifies the initial authentication status. If state is set to 1, the CLI engine skips the login function. If it is set to 0, the CLI engine calls the function cli_hardcode_login() with the user ID and password for an authenticated access.
In #cli_config(), the member echo controls what to display. In this example echo is used when typing a password, to hide or show it. Default value is 0.
This section explains the key fields in the configuration structure. An example source code is provided in the cli_def.c source file.
|void||cli_init (cli_t *cli)|
|MiniCLI initialization. More...|
|void||cli_line (char *line)|
|Process one line of command in plain text format. More...|
|void||cli_tokens (uint8_t argc, char *argv)|
|Process a tokenized command in array of string pointers format. More...|
|The top-level function of the actual CLI. More...|
|uint8_t||cli_logout (uint8_t len, char *param)|
|This function implements the logout function. More...|
|uint8_t||cli_hardcode_login (char *id, char *password)|
|A sample login function implementation. More...|
|uint8_t cli_hardcode_login||(||char *||id,|
A sample login function implementation.
The login ID and password were both hardcoded in source code as '1'.
|[in]||ID||is not used.|
|[in]||password||is not used.|
|void cli_init||(||cli_t *||cli||)|
This function initializes the MiniCLI, call this function before applying other MiniCLI functions. To initialize, one parameter containing a declared table and the chains of commands is required. See cli_t for more information.
|void cli_line||(||char *||line||)|
Process one line of command in plain text format.
|[in]||line||a string with command in it.|
This function implements the logout function.
|[in]||len||is the number of elements in the array pointer param.|
|[in]||param||is an array of pointers remove to the parameters.|
The top-level function of the actual CLI.
This function will never exit unless the user logged out.
Process a tokenized command in array of string pointers format.
|[in]||argc||the number of elements in argv.|
|[in]||argv||the array of string pointers.|