1 Star 0 Fork 189

lzm2018 / nr_micro_shell

forked from Nrush / nr_micro_shell 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
readme.md 2.49 KB
一键复制 编辑 原始数据 按行查看 历史
Nrush 提交于 2019-10-29 15:51 . .

nr_micro_shell

中文版本

Author: Ji Youzhou

Licence: MIT

If you think this project will help you, please STAR Github or Gitee to encourage the author.

nr_micro_shell is designed to provide an interactive experience similar to the command line of Linux shell on MCU (e.g. stm32f103c8t6).

Following functions are provide:

  • Basic command line function.

  • Use the tab key to complete the command automatically.

  • Query history command with direction key.

  • Move cursor with direction key.

Attention: If you want to use the last three functions, you must use a serial terminal software that supports ANSI, such as Hypertrm.

The following is the test result under the condition of stm32f103c8t6 platform and hypertrm serial port terminal.

test

Configure:

All configuration work can be done in the nr_micro_shell_config.h. For details, see the comments in the file.

Usage:

  • Make sure all files have been added into your project.

  • Make sure the function 'printf(),putchar()' can be used in your project.

  • An example is given as follow

#include "nr_micro_shell.h"

int main(void)
{
    shell_init();

    while(1)
    {
        if(USART GET A CHAR 'c')
        {
            shell(c);
        }
    }
}

Add your own command

STEP1: You should realize a command function in nr_micro_shell_commands.c. The prototype of the command function is as follow

void your_command_funtion(char argc, char *argv)
{
    .....
}

argc is the number of parameters. argv stores the starting address and content of each parameter. If your input string is

test -a 1

then the argc will be 3 and the content of argv will be

-------------------------------------------------------------
0x03|0x08|0x0b|'t'|'e'|'s'|'t'|'\0'|'-'|'a'|'\0'|'1'|'\0'|
-------------------------------------------------------------

If you want to know the content of first or second parameter, you should use

/* "-a" */
printf(argv[argv[1]])
/* "1" */
printf(argv[argv[2]])

STEP2: Register you command in the table static_cmd[] as follow

const static_cmd_st static_cmd[] =
{
   .....
   {"your_command_name",your_command_funtion},
   .....
   {"\0",NULL}
};

Attention: DO NOT DELETE {"\0",NULL} !

1
https://gitee.com/lzm2018/nr_micro_shell.git
git@gitee.com:lzm2018/nr_micro_shell.git
lzm2018
nr_micro_shell
nr_micro_shell
master

搜索帮助