1 /**
2  * @file cli_api.h
3  * @copyright Copyright (C) 2015-2021 Alibaba Group Holding Limited
4  */
5 
6 #ifndef CLI_API_H
7 #define CLI_API_H
8 
9 #include <stdint.h>
10 #include "k_api.h"
11 #include "aos/kernel.h"
12 #include "aos/cli.h"
13 
14 #define CLI_OK           0
15 #define CLI_ERR_NOMEM   -10000
16 #define CLI_ERR_DENIED  -10001
17 #define CLI_ERR_INVALID -10002
18 #define CLI_ERR_BADCMD  -10003
19 #define CLI_ERR_SYNTAX  -10004
20 #define CLI_ERR_CMDNOTEXIST -10005
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 /**
27  * @brief Initialize the CLI module
28  *
29  * @return 0 on success, otherwise failed
30  *
31  */
32 int32_t cli_init(void);
33 
34 /**
35  * @brief Stop the CLI task and carry out the cleanup
36  *
37  * @return 0 on success, otherwise failed
38  *
39  */
40 int32_t cli_stop(void);
41 
42 /**
43  * @brief Get CLI tag string for print
44  *
45  * @return CLI tag storing buffer
46  *
47  */
48 char *cli_tag_get(void);
49 
50 /**
51  * @brief This function registers a command with the command-line interface
52  *
53  * @param[in] cmd the structure to regiter one CLI command
54  *
55  * @return 0 on success, otherwise failed
56  *
57  */
58 int32_t cli_register_command(const struct cli_command *cmd);
59 
60 /**
61  * @brief This function unregisters a command from the command-line interface
62  *
63  * @param[in] cmd the structure to unregister one CLI command
64  *
65  * @return 0 on success, otherwise failed
66  *
67  */
68 int32_t cli_unregister_command(const struct cli_command *cmd);
69 
70 /**
71  * @brief This function registers a batch of CLI commands
72  *
73  * @param[in] cmds pointer to an array of commands
74  * @param[in] num  number of commands in the array
75  *
76  * @return 0 on success, otherwise failed
77  *
78  */
79 int32_t cli_register_commands(const struct cli_command *cmds, int32_t num);
80 
81 /**
82  * @brief This function unregisters a batch of CLI commands
83  *
84  * @param[in] cmds pointer to an array of commands
85  * @param[in] num  number of command in the array
86  *
87  * @return 0 on success, otherwise failed
88  *
89  */
90 int32_t cli_unregister_commands(const struct cli_command *cmds, int32_t num);
91 
92 /**
93  * @brief Print CLI message
94  *
95  * @param[in] fmt    string storing printf format
96  * @param[in] params list storing varialbe parameters
97  *
98  * @return 0 on success, otherwise failed
99  */
100 int32_t cli_va_printf(const char *fmt, va_list params);
101 
102 /**
103  * @brief Get the total number of CLI commands
104  *
105  * @return the total number
106  *
107  */
108 int32_t cli_get_commands_num(void);
109 
110 /**
111  * @brief Get the CLI command by index
112  *
113  * @param[in] index the command index
114  *
115  * @return the CLI command
116  *
117  */
118 struct cli_command *cli_get_command(int32_t index);
119 
120 /**
121  * @brief Get echo support status
122  *
123  * @return echo support status, 1: disable, 0: enable
124  *
125  */
126 int32_t cli_get_echo_status(void);
127 
128 /**
129  * @brief Set echo support status
130  *
131  * @param[in] status echo support status
132  *
133  * @return 0 on success, otherwise failed
134  *
135  */
136 int32_t cli_set_echo_status(int32_t status);
137 
138 /**
139 * @brief CLI task entry
140 *
141 */
142 void cli_main(void *arg);
143 
144 #if CLI_UAGENT_ENABLE
145 /**
146 * @brief CLI Uagent init
147 *
148 */
149 void cli_uagent_init(void);
150 #endif
151 
152 #ifdef __cplusplus
153 }
154 #endif
155 
156 #endif /* CLI_API_H */
157 
158