LwSHELL
- group LWSHELL
Lightweight shell.
Defines
-
LWSHELL_ARRAYSIZE(x)
Get size of statically allocated array.
- Parameters
x – [in] Object to get array size of
- Returns
Number of elements in array
-
lwshell_init()
Initialize shell interface.
Note
It applies to default shell instance
- Returns
lwshellOK on success, member of lwshellr_t otherwise
-
lwshell_set_output_fn(out_fn)
Set output function to use to print data from library to user.
Note
It applies to default shell instance
- Parameters
out_fn – [in] Output function to print library data. Set to
NULL
to disable the feature
- Returns
lwshellOK on success, member of lwshellr_t otherwise
-
lwshell_register_cmd(cmd_name, cmd_fn, desc)
Register new command to shell.
Note
It applies to default shell instance
Note
Available only when LWSHELL_CFG_USE_DYNAMIC_COMMANDS is enabled
- Parameters
cmd_name – [in] Command name. This one is used when entering shell command
cmd_fn – [in] Function to call on command match
desc – [in] Custom command description
- Returns
lwshellOK on success, member of lwshellr_t otherwise
-
lwshell_input(in_data, len)
Input data to shell processing.
Note
It applies to default shell instance
- Parameters
in_data – [in] Input data to process
len – [in] Length of data for input
- Returns
lwshellOK on success, member of lwshellr_t otherwise
-
lwshell_register_static_cmds(cmds, cmds_len)
Register new command to shell.
Note
It applies to default shell instance
Note
Available only when LWSHELL_CFG_USE_STATIC_COMMANDS is enabled
- Parameters
cmds – [in] Array of const static commands. It can be from non-volatile memory
cmds_len – [in] Length of array elements
- Returns
lwshellOK on success, member of lwshellr_t otherwise
-
lwshell_parse_int(str)
Parse input string as
integer
- Parameters
str – [in] String to parse
- Returns
String parsed as integer
-
lwshell_parse_double(str)
Parse input string as
double
- Parameters
str – [in] String to parse
- Returns
String parsed as
double
-
lwshell_parse_long(str)
Parse input string as
long
- Parameters
str – [in] String to parse
- Returns
String parsed as
long
-
lwshell_parse_long_long(str)
Parse input string as
long long
- Parameters
str – [in] String to parse
- Returns
String parsed as
long long
Typedefs
-
typedef int32_t (*lwshell_cmd_fn)(int32_t argc, char **argv)
Command function prototype.
- Param argc
[in] Number of arguments
- Param argv
[in] Pointer to arguments
- Return
0
on success,-1
otherwise
-
typedef void (*lwshell_output_fn)(const char *str, struct lwshell *lwobj)
Callback function for character output.
- Param str
[in] String to output
- Param lwobj
[in] LwSHELL instance
Enums
Functions
-
lwshellr_t lwshell_init_ex(lwshell_t *lwobj)
Initialize shell interface.
- Parameters
lwobj – [in] LwSHELL object instance. Set to
NULL
to use default one- Returns
lwshellOK on success, member of lwshellr_t otherwise
-
lwshellr_t lwshell_set_output_fn_ex(lwshell_t *lwobj, lwshell_output_fn out_fn)
Set output function to use to print data from library to user.
- Parameters
lwobj – [in] LwSHELL object instance. Set to
NULL
to use default oneout_fn – [in] Output function to print library data. Set to
NULL
to disable the feature
- Returns
lwshellOK on success, member of lwshellr_t otherwise
-
lwshellr_t lwshell_register_cmd_ex(lwshell_t *lwobj, const char *cmd_name, lwshell_cmd_fn cmd_fn, const char *desc)
Register new command to shell.
Note
Available only when LWSHELL_CFG_USE_DYNAMIC_COMMANDS is enabled
- Parameters
lwobj – [in] LwSHELL object instance. Set to
NULL
to use default onecmd_name – [in] Command name. This one is used when entering shell command
cmd_fn – [in] Function to call on command match
desc – [in] Custom command description
- Returns
lwshellOK on success, member of lwshellr_t otherwise
-
lwshellr_t lwshell_input_ex(lwshell_t *lwobj, const void *in_data, size_t len)
Input data to shell processing.
- Parameters
lwobj – [in] LwSHELL object instance. Set to
NULL
to use default onein_data – [in] Input data to process
len – [in] Length of data for input
- Returns
lwshellOK on success, member of lwshellr_t otherwise
-
lwshellr_t lwshell_register_static_cmds_ex(lwshell_t *lwobj, const lwshell_cmd_t *cmds, size_t cmds_len)
Register new command to shell.
Note
Available only when LWSHELL_CFG_USE_STATIC_COMMANDS is enabled
- Parameters
lwobj – [in] LwSHELL object instance. Set to
NULL
to use default onecmds – [in] Array of const static commands. It can be from non-volatile memory.
cmds_len – [in] Length of array elements
- Returns
lwshellOK on success, member of lwshellr_t otherwise
-
struct lwshell_cmd_t
- #include <lwshell.h>
Shell command structure.
Public Members
-
lwshell_cmd_fn fn
Command function to call on match
-
const char *name
Command name to search for match
-
const char *desc
Command description for help
-
lwshell_cmd_fn fn
-
struct lwshell_t
- #include <lwshell.h>
LwSHELL main structure.
Public Members
-
lwshell_output_fn out_fn
Optional output function
-
char buff[LWSHELL_CFG_MAX_INPUT_LEN + 1]
Shell command input buffer
-
size_t buff_ptr
Buffer pointer for input
-
int32_t argc
Number of arguments parsed in command
-
char *argv[LWSHELL_CFG_MAX_CMD_ARGS]
Array of pointers to all arguments
-
lwshell_cmd_t dynamic_cmds[LWSHELL_CFG_MAX_DYNAMIC_CMDS]
Shell registered dynamic commands
-
size_t dynamic_cmds_cnt
Number of registered dynamic commands
-
const lwshell_cmd_t *static_cmds
Pointer to an array of static commands
-
size_t static_cmds_cnt
Length of status commands array
-
lwshell_output_fn out_fn
-
LWSHELL_ARRAYSIZE(x)