nr_micro_shell是一款为MCU编写的开源命令行工具
问题描述
串口输入命令后有反应,命令能解析,但是没有显示输入的内容。ansi_show_char
和shell_printf
均能正常使用。问题现象如下图所示
原因分析和解决方法
配置文件nr_micro_shell_config.h
定义了宏#define NR_MICRO_SHELL_SIMULATOR
。因为是裸机环境,所以移植时需要注释掉RTOS相关头文件。
应该直接将这部分代码删掉或注释掉,不要定义宏NR_MICRO_SHELL_SIMULATOR
因为命令行回显是在文件ansi_port.c
中的nr_ansi_common_char_slover
函数调用ansi_show_char
实现的
void nr_ansi_common_char_slover(ansi_st *ansi, char x)
{
unsigned int i;
if (ansi->counter < NR_ANSI_LINE_SIZE - 2) {
if (ansi->p < (short)(ansi->counter)) {
for (i = ansi->counter; (short)i > ansi->p; i--) {
ansi->current_line[i] = ansi->current_line[i - 1];
}
}
ansi->p++;
ansi->counter++;
ansi->current_line[ansi->p] = x;
ansi->current_line[ansi->counter] = '\0';
if (ansi->p + 1 < (short)(ansi->counter)) {
shell_printf("\033[1@");
}
#ifndef NR_MICRO_SHELL_SIMULATOR
ansi_show_char(x); // 这个地方
#endif
} else {
ansi->counter = NR_ANSI_LINE_SIZE - 3;
if (ansi->p >= (short)(ansi->counter)) {
ansi->p = ansi->counter - 1;
}
ansi->current_line[ansi->counter] = '\0';
}
}
删除宏后运行正常
移植参考以下文档