Command Line Interface

nRF5 SDK v13.0.0

Module for unified command line handling. More...

Data Structures

struct nrf_cli_cmd_t
CLI command descriptor. More...
struct nrf_cli_transport_t
Unified CLI transport interface. More...
struct nrf_cli_ctx_t
CLI instance context. More...
struct nrf_cli
CLI instance internals. More...
struct nrf_cli_getopt_option_t
Option descriptor. More...
struct nrf_cli_getopt_ctx_t
Getopt parser context. More...

Macros

#define NRF_CLI_CMD (_syntax, _help, _handler)
Initializes CLI command descriptor ( nrf_cli_cmd_t ). More...
#define NRF_CLI_DEF (name, cli_prefix, transport_iface, cmd_set_tab)
Macro for defining command line interface instance. More...
#define NRF_CLI_NORMAL VT100_COLOR_WHITE
#define NRF_CLI_INFO VT100_COLOR_GREEN
#define NRF_CLI_WARNING VT100_COLOR_YELLOW
#define NRF_CLI_ERROR VT100_COLOR_RED
#define NRF_CLI_OPT (_optname, _shortname, _type, _help)
Option structure initializer nrf_cli_getopt_option_t . More...
#define NRF_CLI_BUILTIN_CMD_SET
Built-in command set. More...

Typedefs

typedef struct nrf_cli nrf_cli_t
Alias to Command Line Interface . Must be created here to satisfy module declaration order dependencies.

Functions

ret_code_t nrf_cli_init ( nrf_cli_t const *p_cli)
Initializes a transport layer and internal CLI state. More...
ret_code_t nrf_cli_uninit ( nrf_cli_t const *p_cli)
Uninitializes a transport layer and internal CLI state. More...
ret_code_t nrf_cli_start ( nrf_cli_t const *p_cli)
Start CLI processing. More...
ret_code_t nrf_cli_stop ( nrf_cli_t const *p_cli)
Stop CLI processing. More...
void nrf_cli_fprintf ( nrf_cli_t const *p_cli, vt100_color_t color, const char *p_fmt,...)
Printf like function, which send formated data stream to CLI. More...
void nrf_cli_process ( nrf_cli_t const *p_cli)
Process function, which should be executed when data is ready in transport interface. More...
void nrf_cli_getopt_ctx_init (size_t argc, char **pp_argv, size_t opt_count, nrf_cli_getopt_option_t const *p_opt, nrf_cli_getopt_ctx_t *p_optctx)
Initializes getopt parser context. More...
int32_t nrf_cli_getopt ( nrf_cli_getopt_ctx_t *p_optctx)
Standard library getopt/getopt_long method replacement. More...
__STATIC_INLINE const char * nrf_cli_optarg_get ( nrf_cli_getopt_ctx_t *p_optctx)
Returns handle to current parsed argument (optarg variable replacement). More...
void nrf_cli_opt_help_show ( nrf_cli_t const *p_cli, nrf_cli_getopt_option_t const *p_opt, size_t opt_len)
Shows command help and options. May be used as default '-h' option handler. It will print actual command help and option description: More...
void nrf_cli_cmd_list ( nrf_cli_t const *p_cli, size_t argc, char **argv)
List command handler. More...
void nrf_cli_cmd_clear ( nrf_cli_t const *p_cli, size_t argc, char **argv)
Clear screen command handler. More...
void nrf_cli_cmd_history ( nrf_cli_t const *p_cli, size_t argc, char **argv)
Show history command handler. More...

Detailed Description

Module for unified command line handling.

Macro Definition Documentation

#define NRF_CLI_BUILTIN_CMD_SET
Value:
NRF_CLI_CMD ( "list" , "list all commands" , nrf_cli_cmd_list ), \
NRF_CLI_CMD( "clear" , "clear screen" , nrf_cli_cmd_clear ), \
NRF_CLI_CMD( "history" , "command history" , nrf_cli_cmd_history ) \

Built-in command set.

#define NRF_CLI_CMD ( _syntax,
_help,
_handler
)
Value:
{ \
.p_syntax = _syntax, \
.p_help = _help, \
.handler = _handler, \
}

Initializes CLI command descriptor ( nrf_cli_cmd_t ).

Parameters
_syntax Command syntax (for example: "history").
_help Command help string (string used in built-in help command).
_handler Handler function.
#define NRF_CLI_DEF ( name,
cli_prefix,
transport_iface,
cmd_set_tab
)
Value:
static nrf_cli_ctx_t CONCAT_2 (name, _ctx); \
static const nrf_cli_t name = { \
. p_name = cli_prefix, \
.p_iface = &transport_iface, \
.p_cmd_set = cmd_set_tab, \
.cmd_count = ARRAY_SIZE(cmd_set_tab), \
.p_ctx = & CONCAT_2 (name, _ctx), \
}

Macro for defining command line interface instance.

Parameters
name Instance name.
cli_prefix CLI prefix string.
transport_iface Transport interface.
cmd_set_tab Command set array.
#define NRF_CLI_ERROR   VT100_COLOR_RED

Error color printf.

#define NRF_CLI_INFO   VT100_COLOR_GREEN

Info color printf.

#define NRF_CLI_NORMAL   VT100_COLOR_WHITE

Normal color printf.

#define NRF_CLI_OPT ( _optname,
_shortname,
_type,
_help
)
Value:
{ \
.p_optname = _optname, \
.optname_short = _shortname, \
.type = _type, \
.p_optname_help = _help, \
}

Option structure initializer nrf_cli_getopt_option_t .

Parameters
_optname Option name long.
_shortname Option name short.
_type Option type nrf_cli_getopt_type_t .
_help Option help string.
#define NRF_CLI_WARNING   VT100_COLOR_YELLOW

Warning color printf.

Enumeration Type Documentation

Option argument type.

Enumerator
NRF_CLI_GETOPT_TYPE_NO_ARG

No argument required.

NRF_CLI_GETOPT_TYPE_REQUIRED

Argument required.

NRF_CLI_GETOPT_TYPE_OPTIONAL

Argument optional.

Internal CLI state.

Enumerator
NRF_CLI_STATE_UNINITIALIZED

State uninitialized.

NRF_CLI_STATE_INITIALIZED

State initialized.

NRF_CLI_STATE_COLLECT

State collect.

NRF_CLI_STATE_EXECUTE

State execute.

Function Documentation

void nrf_cli_cmd_clear ( nrf_cli_t const * p_cli ,
size_t argc ,
char ** argv
)

Clear screen command handler.

Parameters
p_cli CLI instance.
argc Number of argv parameters.
argv Parameter list.
void nrf_cli_cmd_history ( nrf_cli_t const * p_cli ,
size_t argc ,
char ** argv
)

Show history command handler.

Parameters
p_cli CLI instance.
argc Number of argv parameters.
argv Parameter list.
void nrf_cli_cmd_list ( nrf_cli_t const * p_cli ,
size_t argc ,
char ** argv
)

List command handler.

Parameters
p_cli CLI instance.
argc Number of argv parameters.
argv Parameter list.
void nrf_cli_fprintf ( nrf_cli_t const * p_cli ,
vt100_color_t color ,
const char * p_fmt ,
...
)

Printf like function, which send formated data stream to CLI.

Parameters
p_cli CLI instance.
color Printf color.
p_fmt Format string.
... List of parameters to print.
int32_t nrf_cli_getopt ( nrf_cli_getopt_ctx_t * p_optctx )

Standard library getopt/getopt_long method replacement.

Parameters
p_optctx Option parser context.
Returns
Parsed option (one letter options are supported by this parser).
Return values
'?' unknown option / no required argument.
-1 if all options have been processed.
other if option was successfully parsed.
void nrf_cli_getopt_ctx_init ( size_t argc ,
char ** pp_argv ,
size_t opt_count ,
nrf_cli_getopt_option_t const * p_opt ,
nrf_cli_getopt_ctx_t * p_optctx
)

Initializes getopt parser context.

Parameters
argc Number of arguments.
pp_argv Argument list.
opt_count Number of options.
p_opt Option array.
p_optctx Option parser context.
ret_code_t nrf_cli_init ( nrf_cli_t const * p_cli )

Initializes a transport layer and internal CLI state.

Parameters
p_cli CLI instance.
Returns
Standard error code.
void nrf_cli_opt_help_show ( nrf_cli_t const * p_cli ,
nrf_cli_getopt_option_t const * p_opt ,
size_t opt_len
)

Shows command help and options. May be used as default '-h' option handler. It will print actual command help and option description:

Example output:

nrf_cli :~$ list -h
list - list all commands
Options:
-h, --help show command help
-v, --verbose show all command help strings
Parameters
p_cli CLI instance.
p_opt Option array.
opt_len Option array size.
__STATIC_INLINE const char* nrf_cli_optarg_get ( nrf_cli_getopt_ctx_t * p_optctx )

Returns handle to current parsed argument (optarg variable replacement).

Warning
This call is only valid while nrf_cli_getopt is returning >= 0.
Parameters
p_optctx Option parser context.
Returns
Handle to option argument.
void nrf_cli_process ( nrf_cli_t const * p_cli )

Process function, which should be executed when data is ready in transport interface.

Parameters
p_cli CLI instance.
ret_code_t nrf_cli_start ( nrf_cli_t const * p_cli )

Start CLI processing.

Parameters
p_cli CLI instance.
Returns
Standard error code.
ret_code_t nrf_cli_stop ( nrf_cli_t const * p_cli )

Stop CLI processing.

Parameters
p_cli CLI instance.
Returns
Standard error code.
ret_code_t nrf_cli_uninit ( nrf_cli_t const * p_cli )

Uninitializes a transport layer and internal CLI state.

Parameters
p_cli CLI instance.
Returns
Standard error code.