Zephyr API Documentation 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
shell.h File Reference

Header file for the shell subsystem. More...

Go to the source code of this file.

Data Structures

union  shell_cmd_entry
 Shell command descriptor. More...
struct  shell_static_args
 Argument count constraints and remote routing for a shell command. More...
struct  shell_static_entry
 Shell static command descriptor. More...
struct  shell_cmd_help
 Shell structured help descriptor. More...
struct  shell_transport_api
 Unified shell transport interface. More...
struct  shell_transport
 Shell transport instance. More...
struct  shell_ctx
 Shell instance context. More...
struct  shell
 Shell instance internals. More...

Macros

#define SHELL_OPT_ARG_RAW   (0xFE)
 Flag indicates that optional arguments will be treated as one, unformatted argument.
#define SHELL_OPT_ARG_CHECK_SKIP   (0xFF)
 Flag indicating that number of optional arguments is not limited.
#define SHELL_OPT_ARG_MAX   (0xFD)
 Flag indicating maximum number of optional arguments that can be validated.
#define SHELL_CMD_FLAG_REMOTE_ROOT   BIT(0)
 Flag indicating a root remote command.
#define SHELL_CMD_FLAG_REMOTE_SUBCMD   BIT(1)
 Flag indicating a remote subcommand.
#define SHELL_HELP(_description, _usage)
 Helper macro to create structured help inline.
#define SHELL_CMD_ARG_REGISTER(syntax, subcmd, help, handler, mandatory, optional)
 Macro for defining and adding a root command (level 0) with required number of arguments.
#define SHELL_COND_CMD_ARG_REGISTER(flag, syntax, subcmd, help, handler, mandatory, optional)
 Macro for defining and adding a conditional root command (level 0) with required number of arguments.
#define SHELL_CMD_REGISTER(syntax, subcmd, help, handler)
 Macro for defining and adding a root command (level 0) with arguments.
#define SHELL_COND_CMD_REGISTER(flag, syntax, subcmd, help, handler)
 Macro for defining and adding a conditional root command (level 0) with arguments.
#define SHELL_STATIC_SUBCMD_SET_CREATE(name, ...)
 Macro for creating a subcommand set.
#define SHELL_SUBCMD_SET_CREATE(_name, _parent)
 Create set of subcommands.
#define SHELL_SUBCMD_COND_ADD(_flag, _parent, _syntax, _subcmd, _help, _handler, _mand, _opt)
 Conditionally add command to the set of subcommands.
#define SHELL_SUBCMD_ADD(_parent, _syntax, _subcmd, _help, _handler, _mand, _opt)
 Add command to the set of subcommands.
#define SHELL_SUBCMD_SET_END   {0}
 Define ending subcommands set.
#define SHELL_DYNAMIC_CMD_CREATE(name, get)
 Macro for creating a dynamic entry.
#define SHELL_CMD_ARG(syntax, subcmd, help, handler, mand, opt)
 Initializes a shell command with arguments.
#define SHELL_COND_CMD_ARG(flag, syntax, subcmd, help, handler, mand, opt)
 Initializes a conditional shell command with arguments.
#define SHELL_EXPR_CMD_ARG(_expr, _syntax, _subcmd, _help, _handler, _mand, _opt, _remote_cmd, _remote_id)
 Initializes a conditional shell command with arguments if expression gives non-zero result at compile time.
#define SHELL_CMD(_syntax, _subcmd, _help, _handler)
 Initializes a shell command.
#define SHELL_COND_CMD(_flag, _syntax, _subcmd, _help, _handler)
 Initializes a conditional shell command.
#define SHELL_EXPR_CMD(_expr, _syntax, _subcmd, _help, _handler)
 Initializes shell command if expression gives non-zero result at compile time.
#define SHELL_SUBCMD_DICT_SET_CREATE(_name, _handler, ...)
 Initializes shell dictionary commands.
#define SHELL_DEFINE(_name, _prompt, _transport_iface, _log_queue_size, _log_timeout, _shell_flag)
 Macro for defining a shell instance.
#define SHELL_NORMAL   SHELL_VT100_COLOR_DEFAULT
 Terminal default text color for shell_fprintf function.
#define SHELL_INFO   SHELL_VT100_COLOR_GREEN
 Green text color for shell_fprintf function.
#define SHELL_OPTION   SHELL_VT100_COLOR_CYAN
 Cyan text color for shell_fprintf function.
#define SHELL_WARNING   SHELL_VT100_COLOR_YELLOW
 Yellow text color for shell_fprintf function.
#define SHELL_ERROR   SHELL_VT100_COLOR_RED
 Red text color for shell_fprintf function.
#define shell_fprintf(sh, color, fmt, ...)
 printf-like function which sends formatted data stream to the shell.
#define shell_info(_sh, _ft, ...)
 Print info message to the shell.
#define shell_fprintf_info(_sh, _ft, ...)
 Print info message to the shell.
#define shell_print(_sh, _ft, ...)
 Print normal message to the shell.
#define shell_fprintf_normal(_sh, _ft, ...)
 Print normal message to the shell.
#define shell_warn(_sh, _ft, ...)
 Print warning message to the shell.
#define shell_fprintf_warn(_sh, _ft, ...)
 Print warning message to the shell.
#define shell_error(_sh, _ft, ...)
 Print error message to the shell.
#define shell_fprintf_error(_sh, _ft, ...)
 Print error message to the shell.
#define SHELL_CMD_HELP_PRINTED   (1)
 Command's help has been printed.

Typedefs

typedef void(* shell_dynamic_get) (size_t idx, struct shell_static_entry *entry)
 Shell dynamic command descriptor.
typedef bool(* shell_device_filter_t) (const struct device *dev)
 Filter callback type, for use with shell_device_lookup_filter.
typedef int(* shell_cmd_handler) (const struct shell *sh, size_t argc, char **argv)
 Shell command handler prototype.
typedef int(* shell_dict_cmd_handler) (const struct shell *sh, size_t argc, char **argv, void *data)
 Shell dictionary command handler prototype.
typedef void(* shell_transport_handler_t) (enum shell_transport_evt evt, void *context)
 Shell transport event handler callback.
typedef void(* shell_uninit_cb_t) (const struct shell *sh, int res)
 Shell uninitialization completion callback.
typedef void(* shell_bypass_cb_t) (const struct shell *sh, uint8_t *data, size_t len, void *user_data)
 Bypass callback.

Enumerations

enum  shell_flag { SHELL_FLAG_CRLF_DEFAULT = (1<<0) , SHELL_FLAG_OLF_CRLF = (1<<1) }
 Flags for setting shell output newline sequence. More...

Functions

const struct deviceshell_device_lookup (size_t idx, const char *prefix)
 Get by index a device that matches .
const struct deviceshell_device_lookup_all (size_t idx, const char *prefix)
 Get by index a device that matches .
const struct deviceshell_device_lookup_non_ready (size_t idx, const char *prefix)
 Get by index a non-initialized device that matches .
const struct deviceshell_device_filter (size_t idx, shell_device_filter_t filter)
 Get a device by index and filter.
const struct deviceshell_device_get_binding (const char *name)
 Get a device reference from its device::name field or label.
const struct deviceshell_device_get_binding_all (const char *name)
 Get a device reference from its device::name field or label.
static bool shell_help_is_structured (const char *help)
 Check if help string is structured help.
int shell_init (const struct shell *sh, const void *transport_config, struct shell_backend_config_flags cfg_flags, bool log_backend, uint32_t init_log_level)
 Function for initializing a transport layer and internal shell state.
void shell_uninit (const struct shell *sh, shell_uninit_cb_t cb)
 Uninitializes the transport layer and the internal shell state.
int shell_start (const struct shell *sh)
 Function for starting shell processing.
int shell_stop (const struct shell *sh)
 Function for stopping shell processing.
void shell_vfprintf (const struct shell *sh, enum shell_vt100_color color, const char *fmt, va_list args)
 vprintf-like function which sends formatted data stream to the shell.
void shell_cbpprintf (const struct shell *sh, enum shell_vt100_color color, void *package)
 Function which formats cbprintf package and streams it to the shell.
void shell_hexdump_line (const struct shell *sh, unsigned int offset, const uint8_t *data, size_t len)
 Print a line of data in hexadecimal format.
void shell_hexdump (const struct shell *sh, const uint8_t *data, size_t len)
 Print data in hexadecimal format.
void shell_process (const struct shell *sh)
 Process function, which should be executed when data is ready in the transport interface.
int shell_prompt_change (const struct shell *sh, const char *prompt)
 Change displayed shell prompt.
static void shell_help (const struct shell *sh)
 Prints the current command help.
int shell_execute_cmd (const struct shell *sh, const char *cmd)
 Execute command.
int shell_set_root_cmd (const char *cmd)
 Set root command for all shell instances.
void shell_set_bypass (const struct shell *sh, shell_bypass_cb_t bypass, void *user_data)
 Set bypass callback.
bool shell_ready (const struct shell *sh)
 Get shell readiness to execute commands.
int shell_insert_mode_set (const struct shell *sh, bool val)
 Allow application to control text insert mode.
int shell_use_colors_set (const struct shell *sh, bool val)
 Allow application to control whether terminal output uses colored syntax.
int shell_use_vt100_set (const struct shell *sh, bool val)
 Allow application to control whether terminal is using vt100 commands.
int shell_echo_set (const struct shell *sh, bool val)
 Allow application to control whether user input is echoed back.
int shell_obscure_set (const struct shell *sh, bool obscure)
 Allow application to control whether user input is obscured with asterisks – useful for implementing passwords.
int shell_mode_delete_set (const struct shell *sh, bool val)
 Allow application to control whether the delete key backspaces or deletes.
int shell_get_return_value (const struct shell *sh)
 Retrieve return value of most recently executed shell command.
void shell_readline_prompt_set (const struct shell *sh, const char *prompt)
 Set a prompt string for the next shell_readline call.
int shell_readline (const struct shell *sh, uint8_t *buf, size_t len, k_timeout_t timeout)
 Read a line of input from the shell.

Detailed Description

Header file for the shell subsystem.