Skip to content

Commit b1120af

Browse files
committed
Fix issue of syscmd
1 parent 6272e23 commit b1120af

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

src/module/syscmd/cmd_mcn.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ static int echo_topic(struct optparse options)
257257
return EXIT_FAILURE;
258258
}
259259

260+
syscmd_flush();
260261
while (cnt) {
261262
/* type any key to exit */
262263
if (syscmd_has_input()) {

src/module/syscmd/syscmd.c

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,32 +89,27 @@ bool syscmd_is_num(const char* str)
8989

9090
char syscmd_getc(void)
9191
{
92-
char ch[SERIAL_RB_BUFSZ];
93-
// struct finsh_shell* shell = finsh_get_shell();
94-
92+
char ch;
9593
syscmd_flush();
96-
9794
if (rt_sem_take(&shell->rx_sem, RT_WAITING_FOREVER) != RT_EOK)
9895
return -1;
96+
rt_device_read(shell->device, RT_WAITING_NO, &ch, 1);
97+
syscmd_flush();
9998

100-
rt_device_read(shell->device, 0, &ch, SERIAL_RB_BUFSZ);
101-
102-
return ch[0];
99+
return ch;
103100
}
104101

105102
bool syscmd_has_input(void)
106103
{
107-
// struct finsh_shell* shell = finsh_get_shell();
108-
109104
return rt_sem_trytake(&shell->rx_sem) == RT_EOK;
110105
}
111106

112107
void syscmd_flush(void)
113108
{
114-
// struct finsh_shell* shell = finsh_get_shell();
109+
char buffer[SERIAL_RB_BUFSZ];
115110

116-
char ch[SERIAL_RB_BUFSZ];
117-
rt_device_read(shell->device, 0, &ch, SERIAL_RB_BUFSZ);
111+
rt_sem_trytake(&shell->rx_sem);
112+
rt_device_read(shell->device, RT_WAITING_NO, buffer, SERIAL_RB_BUFSZ);
118113
}
119114

120115
void syscmd_putc(const char c, int cnt)
@@ -252,7 +247,7 @@ int syscmd_process(int argc, char** argv, shell_handle_func func)
252247
opt_v[opt_cnt].val = NULL;
253248
}
254249

255-
//console_printf("opt:%s val:%s\n", opt_v[opt_cnt].opt, opt_v[opt_cnt].val);
250+
// console_printf("opt:%s val:%s\n", opt_v[opt_cnt].opt, opt_v[opt_cnt].val);
256251

257252
opt_cnt++;
258253
} else {
@@ -269,7 +264,7 @@ int syscmd_process(int argc, char** argv, shell_handle_func func)
269264
memcpy(arg_v[arg_cnt], argv[i], arg_len);
270265
arg_v[arg_cnt][arg_len] = '\0';
271266

272-
//console_printf("arg:%s\n", arg_v[arg_cnt]);
267+
// console_printf("arg:%s\n", arg_v[arg_cnt]);
273268

274269
arg_cnt++;
275270
}

0 commit comments

Comments
 (0)