MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / client_cli_parser

Function client_cli_parser

components/net/at/src/at_cli.c:194–289  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

192 return RT_EOK;
193}
194static void client_cli_parser(at_client_t client)
195{
196#define ESC_KEY 0x1B
197#define BACKSPACE_KEY 0x08
198#define DELECT_KEY 0x7F
199
200 char ch;
201 char cur_line[FINSH_CMD_SIZE] = { 0 };
202 rt_size_t cur_line_len = 0;
203 static rt_err_t (*client_odev_rx_ind)(rt_device_t dev, rt_size_t size) = RT_NULL;
204 rt_base_t level;
205 rt_thread_t at_client;
206 at_status_t client_odev_status;
207
208 if (client)
209 {
210 /* backup client status */
211 {
212 client_odev_status = client->status;
213 client->status = AT_STATUS_CLI;
214 }
215
216 rt_sem_init(&client_rx_notice, "cli_r", 0, RT_IPC_FLAG_FIFO);
217 client_rx_fifo = rt_ringbuffer_create(AT_CLI_FIFO_SIZE);
218
219 /* backup client device RX indicate */
220 {
221 level = rt_hw_interrupt_disable();
222 client_odev_rx_ind = client->device->rx_indicate;
223 rt_device_set_rx_indicate(client->device, client_getchar_rx_ind);
224 rt_hw_interrupt_enable(level);
225 }
226
227 at_client = rt_thread_create("at_cli", at_client_entry, RT_NULL, 512, 8, 8);
228 if (client_rx_fifo && at_client)
229 {
230 rt_kprintf("======== Welcome to using RT-Thread AT command client cli ========\n");
231 rt_kprintf("Cli will forward your command to server port(%s). Press 'ESC' to exit.\n", client->device->parent.name);
232 rt_thread_startup(at_client);
233 /* process user input */
234 while (ESC_KEY != (ch = console_getchar()))
235 {
236 if (ch == BACKSPACE_KEY || ch == DELECT_KEY)
237 {
238 if (cur_line_len)
239 {
240 cur_line[--cur_line_len] = 0;
241 rt_kprintf("\b \b");
242 }
243 continue;
244 }
245 else if (ch == '\r' || ch == '\n')
246 {
247 /* execute a AT request */
248 if (cur_line_len)
249 {
250 rt_kprintf("\n");
251 at_obj_exec_cmd(client, RT_NULL, "%.*s", cur_line_len, cur_line);

Callers 1

atFunction · 0.85

Calls 13

rt_sem_initFunction · 0.85
rt_ringbuffer_createFunction · 0.85
rt_thread_createFunction · 0.85
rt_kprintfFunction · 0.85
rt_thread_startupFunction · 0.85
console_getcharFunction · 0.85
at_obj_exec_cmdFunction · 0.85
rt_thread_deleteFunction · 0.85
rt_sem_detachFunction · 0.85
rt_ringbuffer_destroyFunction · 0.85
rt_hw_interrupt_disableFunction · 0.50

Tested by

no test coverage detected