nRF5 SDK v13.0.0
Modules | Data Structures | Macros | Typedefs | Enumerations | Functions
Command Line Interface

Module for unified command line handling. More...

Modules

 CDC ACM command line interface transport layer.
 
 Command line interface. configuration
 
 RTT command line interface transport layer.
 
 UART command line interface transport layer.
 

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.
 

Enumerations

enum  nrf_cli_state_t {
  NRF_CLI_STATE_UNINITIALIZED,
  NRF_CLI_STATE_INITIALIZED,
  NRF_CLI_STATE_COLLECT,
  NRF_CLI_STATE_EXECUTE
}
 Internal CLI state. More...
 
enum  nrf_cli_getopt_type_t {
  NRF_CLI_GETOPT_TYPE_NO_ARG,
  NRF_CLI_GETOPT_TYPE_REQUIRED,
  NRF_CLI_GETOPT_TYPE_OPTIONAL
}
 Option argument type. More...
 

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
_syntaxCommand syntax (for example: "history").
_helpCommand help string (string used in built-in help command).
_handlerHandler 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
nameInstance name.
cli_prefixCLI prefix string.
transport_ifaceTransport interface.
cmd_set_tabCommand 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
_optnameOption name long.
_shortnameOption name short.
_typeOption type nrf_cli_getopt_type_t.
_helpOption 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_cliCLI instance.
argcNumber of argv parameters.
argvParameter list.
void nrf_cli_cmd_history ( nrf_cli_t const *  p_cli,
size_t  argc,
char **  argv 
)

Show history command handler.

Parameters
p_cliCLI instance.
argcNumber of argv parameters.
argvParameter list.
void nrf_cli_cmd_list ( nrf_cli_t const *  p_cli,
size_t  argc,
char **  argv 
)

List command handler.

Parameters
p_cliCLI instance.
argcNumber of argv parameters.
argvParameter 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_cliCLI instance.
colorPrintf color.
p_fmtFormat 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_optctxOption parser context.
Returns
Parsed option (one letter options are supported by this parser).
Return values
'?'unknown option / no required argument.
-1if all options have been processed.
otherif 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
argcNumber of arguments.
pp_argvArgument list.
opt_countNumber of options.
p_optOption array.
p_optctxOption parser context.
ret_code_t nrf_cli_init ( nrf_cli_t const *  p_cli)

Initializes a transport layer and internal CLI state.

Parameters
p_cliCLI 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_cliCLI instance.
p_optOption array.
opt_lenOption 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_optctxOption 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_cliCLI instance.
ret_code_t nrf_cli_start ( nrf_cli_t const *  p_cli)

Start CLI processing.

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

Stop CLI processing.

Parameters
p_cliCLI 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_cliCLI instance.
Returns
Standard error code.

Documentation feedback | Developer Zone | Subscribe | Updated