xref: /nrf52832-nimble/packages/NimBLE-latest/porting/npl/rtthread/include/nimble/npl_shell.h (revision 042d53a763ad75cb1465103098bb88c245d95138)
1 /*
2  * SPDX-License-Identifier: Apache-2.0
3  *
4  * Date           Author       Notes
5  * 2019-02-14     ZeroFree     first implementation
6  */
7 
8 #ifndef __NPL_SHELL_H__
9 #define __NPL_SHELL_H__
10 
11 #include <rtthread.h>
12 
13 /** @brief Callback called when command is entered.
14  *
15  *  @param argc Number of parameters passed.
16  *  @param argv Array of option strings. First option is always command name.
17  *
18  * @return 0 in case of success or negative value in case of error.
19  */
20 typedef int (*shell_cmd_func_t)(int argc, char *argv[]);
21 
22 struct shell_param
23 {
24     const char *param_name;
25     const char *help;
26 };
27 
28 struct shell_cmd_help
29 {
30     const char *summary;
31     const char *usage;
32     const struct shell_param *params;
33 };
34 
35 struct shell_cmd
36 {
37     const char *sc_cmd;
38     shell_cmd_func_t sc_cmd_func;
39     const struct shell_cmd_help *help;
40 };
41 
42 struct shell_module
43 {
44     const char *name;
45     const struct shell_cmd *commands;
46 };
47 
48 /** @brief Register a shell_module object
49  *
50  *  @param shell_name Module name to be entered in shell console.
51  *
52  *  @param shell_commands Array of commands to register.
53  *  The array should be terminated with an empty element.
54  */
55 int shell_register(const char *shell_name,
56                    const struct shell_cmd *shell_commands);
57 
58 /** @brief Optionally register a default module, to avoid typing it in
59  *  shell console.
60  *
61  *  @param name Module name.
62  */
63 void shell_register_default_module(const char *name);
64 
65 /** @brief Callback to get the current prompt.
66  *
67  *  @returns Current prompt string.
68  */
69 typedef const char *(*shell_prompt_function_t)(void);
70 
71 void shell_process_command(char *line);
72 
73 #define console_printf rt_kprintf
74 
75 #define OS_TICKS_PER_SEC RT_TICK_PER_SECOND
76 
77 #define MYNEWT_VAL_SHELL_CMD_HELP 1
78 
79 #if MYNEWT
80 #include "bsp/bsp.h"
81 #else
82 #define bssnz_t
83 #endif
84 
85 void console_write(const char *str, int cnt);
86 
87 #endif
88