Module for unified command line handling.
More...
|
#define | NRF_CLI_CMD_REGISTER(p_syntax, p_subcmd, p_help, p_handler) |
| Macro for defining and adding a root command (level 0). More...
|
|
#define | NRF_CLI_CREATE_STATIC_SUBCMD_SET(name) |
| Macro for creating a subcommand set. It must be used outside of any function body. More...
|
|
#define | NRF_CLI_SUBCMD_SET_END {NULL} |
| Define ending subcommands set.
|
|
#define | NRF_CLI_CREATE_DYNAMIC_CMD(name, p_get) |
| Macro for creating a dynamic entry. More...
|
|
#define | NRF_CLI_CMD(_p_syntax, _p_subcmd, _p_help, _p_handler) |
| Initializes a CLI command (nrf_cli_static_entry). More...
|
|
#define | NRF_LOG_BACKEND_CLI_DEF(_name_, _queue_sz_) |
|
#define | NRF_CLI_BACKEND_PTR(_name_) NULL |
|
#define | NRF_CLI_MEMOBJ_PTR(_name_) NULL |
|
#define | NRF_CLI_HISTORY_MEM_OBJ(name) |
|
#define | NRF_CLI_DEF(name, cli_prefix, p_transport_iface, newline_ch, log_queue_size) |
| Macro for defining a command line interface instance. More...
|
|
#define | NRF_CLI_DEFAULT NRF_CLI_VT100_COLOR_DEFAULT |
|
#define | NRF_CLI_NORMAL NRF_CLI_VT100_COLOR_WHITE |
|
#define | NRF_CLI_INFO NRF_CLI_VT100_COLOR_GREEN |
|
#define | NRF_CLI_OPTION NRF_CLI_VT100_COLOR_CYAN |
|
#define | NRF_CLI_WARNING NRF_CLI_VT100_COLOR_YELLOW |
|
#define | NRF_CLI_ERROR NRF_CLI_VT100_COLOR_RED |
|
#define | NRF_CLI_OPT(_p_optname, _p_shortname, _p_help) |
| Option structure initializer nrf_cli_getopt_option. More...
|
|
|
ret_code_t | nrf_cli_init (nrf_cli_t const *p_cli, void const *p_transport_config, bool use_colors, bool log_backend, nrf_log_severity_t init_lvl) |
| Function for initializing a transport layer and internal CLI state. More...
|
|
ret_code_t | nrf_cli_task_create (nrf_cli_t const *p_cli) |
|
ret_code_t | nrf_cli_uninit (nrf_cli_t const *p_cli) |
| Function for uninitializing a transport layer and internal CLI state. More...
|
|
ret_code_t | nrf_cli_start (nrf_cli_t const *p_cli) |
| Function for starting CLI processing. More...
|
|
ret_code_t | nrf_cli_stop (nrf_cli_t const *p_cli) |
| Function for stopping CLI processing. More...
|
|
void | nrf_cli_fprintf (nrf_cli_t const *p_cli, nrf_cli_vt100_color_t color, char const *p_fmt,...) |
| Printf-like function which sends formatted data stream to the CLI. This function shall not be used outside of the CLI module or CLI command context. More...
|
|
void | nrf_cli_process (nrf_cli_t const *p_cli) |
| Process function, which should be executed when data is ready in the transport interface. More...
|
|
__STATIC_INLINE bool | nrf_cli_help_requested (nrf_cli_t const *p_cli) |
| Informs that a command has been called with -h or –help option. More...
|
|
void | nrf_cli_help_print (nrf_cli_t const *p_cli, nrf_cli_getopt_option_t const *p_opt, size_t opt_len) |
| Prints actual command help if user called it with -h or –help option. More...
|
|
void | nrf_cli_print_stream (void const *p_user_ctx, char const *p_data, size_t data_len) |
| This function shall not be used directly, it is required by the nrf_fprintf module. More...
|
|
Module for unified command line handling.
#define NRF_CLI_CMD |
( |
|
_p_syntax, |
|
|
|
_p_subcmd, |
|
|
|
_p_help, |
|
|
|
_p_handler |
|
) |
| |
Value:{ \
.p_syntax = (const char *) STRINGIFY(_p_syntax), \
.p_subcmd = _p_subcmd, \
.p_help = (const char *) _p_help, \
.handler = _p_handler \
}
Initializes a CLI command (nrf_cli_static_entry).
- Parameters
-
[in] | _p_syntax | Command syntax (for example: history). |
[in] | _p_subcmd | Pointer to a subcommands array. |
[in] | _p_help | Pointer to a command help string. |
[in] | _p_handler | Pointer to a function handler. |
#define NRF_CLI_CMD_REGISTER |
( |
|
p_syntax, |
|
|
|
p_subcmd, |
|
|
|
p_help, |
|
|
|
p_handler |
|
) |
| |
Value:
NRF_CLI_CMD(p_syntax, p_subcmd, p_help, p_handler); \
NRF_SECTION_ITEM_REGISTER(cli_command, \
.is_dynamic = false, \
.u.p_static = &CONCAT_3(nrf_cli_, p_syntax, _raw) \
}; \
NRF_SECTION_ITEM_REGISTER(cli_sorted_cmd_ptrs,
char const *
CONCAT_2(p_syntax, _str_ptr))
Macro for defining and adding a root command (level 0).
- Note
- Each root command shall have unique syntax.
- Parameters
-
[in] | p_syntax | Command syntax (for example: history). |
[in] | p_subcmd | Pointer to a subcommands array. |
[in] | p_help | Pointer to a command help string. |
[in] | p_handler | Pointer to a function handler. |
#define NRF_CLI_CREATE_DYNAMIC_CMD |
( |
|
name, |
|
|
|
p_get |
|
) |
| |
Value: \
.is_dynamic = true, \
.u.p_dynamic_get = p_get \
};
Macro for creating a dynamic entry.
- Parameters
-
[in] | name | Name of the dynamic entry. |
[in] | p_get | Pointer to the function returning dynamic commands array nrf_cli_dynamic_get. |
#define NRF_CLI_CREATE_STATIC_SUBCMD_SET |
( |
|
name | ) |
|
Value: \
.is_dynamic = false, \
}; \
Macro for creating a subcommand set. It must be used outside of any function body.
- Parameters
-
[in] | name | Name of the subcommand set. |
#define NRF_CLI_DEF |
( |
|
name, |
|
|
|
cli_prefix, |
|
|
|
p_transport_iface, |
|
|
|
newline_ch, |
|
|
|
log_queue_size |
|
) |
| |
Value:
NRF_FPRINTF_DEF(
CONCAT_2(name, _fprintf_ctx), \
&name, \
false, \
NRF_LOG_BACKEND_CLI_DEF(
CONCAT_2(name, _log_backend), log_queue_size); \
NRF_CLI_HISTORY_MEM_OBJ(name); \
\
.p_iface = p_transport_iface, \
.p_log_backend = NRF_CLI_BACKEND_PTR(name), \
.p_fprintf_ctx = &
CONCAT_2(name, _fprintf_ctx), \
.p_cmd_hist_mempool = NRF_CLI_MEMOBJ_PTR(name), \
.newline_char = newline_ch \
}
Macro for defining a command line interface instance.
- Parameters
-
[in] | name | Instance name. |
[in] | cli_prefix | CLI prefix string. |
[in] | p_transport_iface | Pointer to the transport interface. |
[in] | newline_ch | New line character - only allowed values are '\n' or '\r'. |
[in] | log_queue_size | Logger processing queue size. |
#define NRF_CLI_DEFAULT NRF_CLI_VT100_COLOR_DEFAULT |
Turn off character attributes.
#define NRF_CLI_ERROR NRF_CLI_VT100_COLOR_RED |
#define NRF_CLI_INFO NRF_CLI_VT100_COLOR_GREEN |
#define NRF_CLI_NORMAL NRF_CLI_VT100_COLOR_WHITE |
#define NRF_CLI_OPT |
( |
|
_p_optname, |
|
|
|
_p_shortname, |
|
|
|
_p_help |
|
) |
| |
Value:{ \
.p_optname = _p_optname, \
.p_optname_short = _p_shortname, \
.p_optname_help = _p_help, \
}
Option structure initializer nrf_cli_getopt_option.
- Parameters
-
[in] | _p_optname | Option name long. |
[in] | _p_shortname | Option name short. |
[in] | _p_help | Option help string. |
#define NRF_CLI_OPTION NRF_CLI_VT100_COLOR_CYAN |
#define NRF_CLI_WARNING NRF_CLI_VT100_COLOR_YELLOW |
CLI dynamic command descriptor.
Function shall fill the received nrf_cli_static_entry structure with requested (idx) dynamic subcommand data. If there is more than one dynamic subcommand available, the function shall ensure that the returned commands: p_static->p_syntax are sorted in alphabetical order. If idx exceeds the available dynamic subcommands, the function must write to p_static->p_syntax NULL value. This will indicate to the CLI module that there are no more dynamic commands to read.
Internal CLI state.
Enumerator |
---|
NRF_CLI_STATE_UNINITIALIZED |
State uninitialized.
|
NRF_CLI_STATE_INITIALIZED |
State initialized but not active.
|
NRF_CLI_STATE_ACTIVE |
State active.
|
NRF_CLI_STATE_PANIC_MODE_ACTIVE |
State panic mode activated.
|
NRF_CLI_STATE_PANIC_MODE_INACTIVE |
State panic mode requested but not supported.
|
void nrf_cli_fprintf |
( |
nrf_cli_t const * |
p_cli, |
|
|
nrf_cli_vt100_color_t |
color, |
|
|
char const * |
p_fmt, |
|
|
|
... |
|
) |
| |
Printf-like function which sends formatted data stream to the CLI. This function shall not be used outside of the CLI module or CLI command context.
- Parameters
-
[in] | p_cli | Pointer to the CLI instance. |
[in] | color | Printf color. |
[in] | p_fmt | Format string. |
[in] | ... | List of parameters to print. |
Prints actual command help if user called it with -h or –help option.
Function will print a help string with: the currently entered command, its options, and subcommands (if they exist).
- Parameters
-
[in] | p_cli | Pointer to the CLI instance. |
[in] | p_opt | Pointer to the optional option array. |
[in] | opt_len | Option array size. |
__STATIC_INLINE bool nrf_cli_help_requested |
( |
nrf_cli_t const * |
p_cli | ) |
|
Informs that a command has been called with -h or –help option.
- Parameters
-
[in] | p_cli | Pointer to the CLI instance. |
- Returns
- True if help has been requested.
ret_code_t nrf_cli_init |
( |
nrf_cli_t const * |
p_cli, |
|
|
void const * |
p_transport_config, |
|
|
bool |
use_colors, |
|
|
bool |
log_backend, |
|
|
nrf_log_severity_t |
init_lvl |
|
) |
| |
Function for initializing a transport layer and internal CLI state.
- Parameters
-
[in] | p_cli | Pointer to CLI instance. |
[in] | p_transport_config | Configuration forwarded to the transport during initialization. |
[in] | use_colors | Enables colored prints. |
[in] | log_backend | If true, the console will be used as logger backend. |
[in] | init_lvl | Default severity level for the logger. |
- Returns
- Standard error code.
void nrf_cli_print_stream |
( |
void const * |
p_user_ctx, |
|
|
char const * |
p_data, |
|
|
size_t |
data_len |
|
) |
| |
This function shall not be used directly, it is required by the nrf_fprintf module.
- Parameters
-
[in] | p_user_ctx | Pointer to the context for the CLI instance. |
[in] | p_data | Pointer to the data buffer. |
[in] | data_len | Data buffer size. |
void nrf_cli_process |
( |
nrf_cli_t const * |
p_cli | ) |
|
Process function, which should be executed when data is ready in the transport interface.
- Parameters
-
[in] | p_cli | Pointer to the CLI instance. |
Function for starting CLI processing.
- Parameters
-
p_cli | Pointer to the CLI instance. |
- Returns
- Standard error code.
Function for stopping CLI processing.
- Parameters
-
p_cli | Pointer to CLI instance. |
- Returns
- Standard error code.
Function for uninitializing a transport layer and internal CLI state.
- Parameters
-
p_cli | Pointer to CLI instance. |
- Returns
- Standard error code.