From 037d263779f0bd8cd6af17b3215f21528e57da91 Mon Sep 17 00:00:00 2001 From: hqm <13720409820@163.com> Date: Sun, 7 Aug 2022 20:08:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=EF=BC=9A=201.=20=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E6=94=AF=E6=8C=81XCMD=5FEXPORT=5FCMD()/XCMD=5FEXPORT?= =?UTF-8?q?=5FKEY()=E6=96=B9=E6=B3=95=E7=9B=B4=E6=8E=A5=E5=AF=BC=E5=87=BA?= =?UTF-8?q?=E5=91=BD=E4=BB=A4=E6=88=96=E6=8C=89=E9=94=AE=EF=BC=8C=E4=B8=8D?= =?UTF-8?q?=E9=9C=80=E8=A6=81=E9=A2=9D=E5=A4=96=E8=BF=90=E8=A1=8C=E6=B3=A8?= =?UTF-8?q?=E5=86=8C=E5=87=BD=E6=95=B0=202.=20=E6=96=B0=E5=A2=9Eqemu-stm32?= =?UTF-8?q?=E4=BE=8B=E5=AD=90=203.=20=E4=BF=AE=E6=94=B9arduino=E4=BE=8B?= =?UTF-8?q?=E5=AD=90=EF=BC=8C=E6=B7=BB=E5=8A=A0init.py=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E7=94=A8=E4=BA=8E=E5=88=9D=E5=A7=8B=E5=8C=96arduino=204.=20?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=9C=A8=E6=AF=8F=E4=B8=AA=E4=BE=8B=E5=AD=90?= =?UTF-8?q?=E4=B8=8B=E5=8F=AF=E5=8D=95=E7=8B=AC=E9=85=8D=E7=BD=AExcmd=5Fco?= =?UTF-8?q?nfg.h=20=E6=B5=8B=E8=AF=95:=201.=20qemu-stm32=20=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E9=80=9A=E8=BF=87=202.=20arduino=20=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E9=80=9A=E8=BF=87=203.=20linux=20=E6=B5=8B=E8=AF=95=E9=80=9A?= =?UTF-8?q?=E8=BF=87=204.=20stm32=20MDK=E6=9C=AA=E6=B5=8B=E8=AF=95=205.=20?= =?UTF-8?q?ext32=E6=9C=AA=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 10 +- .vscode/c_cpp_properties.json | 3 +- .vscode/launch.json | 21 +++ .vscode/settings.json | 13 +- README.md | 132 ++++++------------ example/arduino/README.md | 10 ++ example/arduino/arduino.ino | 3 - example/arduino/ex_cmds.c | 1 - example/arduino/ex_cmds.h | 1 - example/arduino/ex_keys.c | 1 - example/arduino/ex_keys.h | 1 - example/arduino/init.py | 33 +++++ example/arduino/test.c | 1 - example/arduino/test.h | 1 - example/arduino/xcmd.c | 1 - example/arduino/xcmd.h | 1 - example/arduino/xcmd_confg.h | 30 +++- example/arduino/xcmd_default_cmds.c | 1 - example/arduino/xcmd_default_cmds.h | 1 - example/arduino/xcmd_default_keys.c | 1 - example/arduino/xcmd_default_keys.h | 1 - example/arduino/xcmd_define.h | 1 - example/esp_idf/main/esp_idf.c | 2 - example/esp_idf/main/xcmd_confg.h | 29 ++++ example/linux/Makefile | 4 +- example/linux/xcmd_confg.h | 29 ++++ example/stm32/MDK/stm32f1xx/User/xcmd_confg.h | 29 ++++ example/stm32/MDK/stm32f4xx/user/xcmd_confg.h | 29 ++++ extensions/ex_cmds/ex_cmds.c | 4 + extensions/ex_keys/ex_keys.c | 13 ++ extensions/ex_list/ex_list.c | 14 +- extensions/fs_cmds/fs_cmds.c | 37 +++-- extensions/net_cmds/socket_cmds.c | 4 + extensions/test/test.c | 8 ++ inc/xcmd.h | 97 ++++++++++--- inc/{xcmd_confg.h => xcmd_default_confg.h} | 20 ++- inc/xcmd_define.h | 2 +- src/xcmd.c | 57 ++++---- src/xcmd_default_cmds.c | 19 ++- src/xcmd_default_keys.c | 20 ++- 40 files changed, 495 insertions(+), 190 deletions(-) create mode 100644 example/arduino/README.md mode change 100755 => 100644 example/arduino/arduino.ino delete mode 120000 example/arduino/ex_cmds.c delete mode 120000 example/arduino/ex_cmds.h delete mode 120000 example/arduino/ex_keys.c delete mode 120000 example/arduino/ex_keys.h create mode 100644 example/arduino/init.py delete mode 120000 example/arduino/test.c delete mode 120000 example/arduino/test.h delete mode 120000 example/arduino/xcmd.c delete mode 120000 example/arduino/xcmd.h mode change 120000 => 100755 example/arduino/xcmd_confg.h delete mode 120000 example/arduino/xcmd_default_cmds.c delete mode 120000 example/arduino/xcmd_default_cmds.h delete mode 120000 example/arduino/xcmd_default_keys.c delete mode 120000 example/arduino/xcmd_default_keys.h delete mode 120000 example/arduino/xcmd_define.h create mode 100755 example/esp_idf/main/xcmd_confg.h create mode 100755 example/linux/xcmd_confg.h create mode 100755 example/stm32/MDK/stm32f1xx/User/xcmd_confg.h create mode 100755 example/stm32/MDK/stm32f4xx/user/xcmd_confg.h rename inc/{xcmd_confg.h => xcmd_default_confg.h} (71%) diff --git a/.gitignore b/.gitignore index 55f12be..d756665 100755 --- a/.gitignore +++ b/.gitignore @@ -5,9 +5,17 @@ *Listings/ *OBJ/ +example/stm32/qemu + #file xcmder *.map +*.bin +*.elf +*.list +*.log *.uvoptx *.uvguix* -*fatfs.img \ No newline at end of file +*fatfs.img +example/stm32/qemu/DAC_OUT_PUT1.txt +example/stm32/qemu/DAC_OUT_PUT2.txt \ No newline at end of file diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 0388a4f..a0a1f34 100755 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -9,7 +9,8 @@ "compilerPath": "/opt/gcc-arm-none-eabi-9-2020-q2-update/bin/arm-none-eabi-gcc", "cStandard": "gnu17", "cppStandard": "gnu++14", - "intelliSenseMode": "linux-gcc-arm" + "intelliSenseMode": "linux-gcc-arm", + "configurationProvider": "ms-vscode.makefile-tools" } ], "version": 4 diff --git a/.vscode/launch.json b/.vscode/launch.json index 140e1f9..a5deb6b 100755 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -4,6 +4,27 @@ // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ + { + "name": "debug qemu", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/example/stm32/qemu/demos/main/main.elf", + "args": [], + "stopAtEntry": false, + "cwd": "${fileDirname}", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "miDebuggerPath": "/usr/bin/arm-none-eabi-gdb", + "miDebuggerServerAddress": "localhost:3333", + "setupCommands": [ + { + "description": "为 gdb 启用整齐打印", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] + }, { "name": "(gdb) 启动", "type": "cppdbg", diff --git a/.vscode/settings.json b/.vscode/settings.json index d115d6b..e64aa1e 100755 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -17,9 +17,18 @@ "C_Cpp_Runner.enableWarnings": true, "C_Cpp_Runner.warningsAsError": false, "files.associations": { - "*.json": "c", + "*.json": "jsonc", "cmath": "c", "complex": "c", - "xcmd_default_keys.h": "c" + "xcmd_default_keys.h": "c", + "xcmd.h": "c", + "xcmd_default_cmds.h": "c", + "typeinfo": "c", + "xcmd_define.h": "c", + "xcmd_default_confg.h": "c", + "ex_keys.h": "c", + "ex_cmds.h": "c", + "test.h": "c", + "ctype.h": "c" } } \ No newline at end of file diff --git a/README.md b/README.md index f249e02..07dd70d 100755 --- a/README.md +++ b/README.md @@ -7,50 +7,34 @@ xcmd是一款单片机命令行工具,移植十分方便,并且对flash与ram占用很小,旨在为单片机提供一个能够快速搭建且占用资源很小的命令行工具,可以大大加快单片机程序调试工作,它有一下几个优点。 1. **移植十分简单** 2. **资源占用约8K rom 1K ram** -1. **支持历史记录** -2. **支持命令自动补全** -3. **支持注册快捷键** +3. **支持历史记录** +4. **支持命令自动补全** +5. **支持注册快捷键** +5. **支持`xcmd_cmd_register()/xcmd_key_register`方法注册命令或按键** +5. **支持`XCMD_EXPORT_CMD()/XCMD_EXPORT_KEY()`方法直接导出命令或按键,不需要额外运行注册函数** #### 支持的平台 1. linux 2. arduino 3. stm32 +4. esp32 +5. qemu-stm32 #### 测试过的串口软件 +2. (win/linux推荐)putty +3. (win推荐)MobaXterm +5. (linux端推荐)cu 1. SecureCRT:请设置成Xterm模式 -2. (推荐)putty -3. (推荐)MobaXterm 4. Xshell +6. nc(支持性很差) +7. minicom(支持性很差) #### 支持的扩展功能 1. 类linux风格的快捷键:ctr+left、ctr+right、ctr+a、ctr+e、ctr+u、ctr+k、ctr+l快捷键 2. 支持字体、背景颜色显示 3. 支持类linux的文件操作(Fatfs文件系统):ls、cd、rm、df、mv、mkdir、touch、read、write 4. 支持基于socket的udp server、udp client测试程序 -5. #### 移植 -- 移植十分简单,只需要在初始化的时候提供字符输入输出函数即可 -```C - /* 例如移植到linux平台 */ - int cmd_get_char(uint8_t *ch) - { - *ch = getch(); - return 1; - } - - int cmd_put_char(uint8_t ch) - { - putchar(ch); - return 1; - } - - int main(void) - { - /*调用初始化函数的时候传入字符输入输出函数*/ - xcmd_init(cmd_get_char, cmd_put_char); - while(1) - { - xcmd_task(); - } - } -``` +- 移植十分简单,可在example中查看各平台移植结果 +1. 在初始化的时候提供字符输入输出函数即可 +2. 从example中拷贝一个xcmd_confg.h到自己的项目 ```C /* 例如移植到Arduino平台 */ int cmd_get_char(uint8_t *ch) @@ -83,14 +67,19 @@ void loop() { } ``` #### 配置 -配置文件位于src/xcmd_config.h +配置xcmd_config.h + +**注意**: 如果不知道如何修改连接脚本,建议不要使能ENABLE_XCMD_EXPORT。不使能ENABLE_XCMD_EXPORT的情况下有更好的兼容性移植更加简单 ```C -#define XCMD_LINE_MAX_LENGTH (32) /* 命令行支持的最大字符数 */ -#define XCMD_HISTORY_MAX_NUM (8) /* 支持的历史记录个数,0为不支持 */ -#define XCMD_PARAM_MAX_NUM (4) /* 支持输入的参数个数 */ +#define XCMD_LINE_MAX_LENGTH (128) /* 命令行支持的最大字符数 */ +#define XCMD_HISTORY_MAX_NUM (16) /* 支持的历史记录个数, 这个参数对内存的影响很大,建议arduino设置为0,0为不支持 */ +#define XCMD_PARAM_MAX_NUM (8) /* 支持输入的参数个数 */ +// #define XCMD_DEFAULT_PROMPT "->" /* 提示符 */ +// #define XCMD_DEFAULT_PROMPT_CLOLR TX_GREEN /* 提示符颜色 */ +// #define ENABLE_XCMD_EXPORT /* 需要修改lds,启用后支持XCMD_EXPORT_CMD和XCMD_EXPORT_KEY方法导出命令 */ ``` #### 使用说明 -##### 注册自定义命令 +##### xcmd_register()方法注册自定义命令 ```C static int cmd_echo(int argc, char* argv[]) { @@ -101,40 +90,9 @@ static int cmd_echo(int argc, char* argv[]) return 0; } -static int cmd_example(int argc, char* argv[]) -{ - uint8_t i; - if(param_check(1, argc, argv)) - { - if(strcmp(argv[1], "str") == 0) - { - for(i=2; i #include "xcmd.h" -#include "test.h" int cmd_get_char(uint8_t *ch) { @@ -32,8 +31,6 @@ int cmd_put_char(uint8_t ch) void setup() { Serial.begin(115200); xcmd_init(cmd_get_char, cmd_put_char); - test_cmd_init(); - test_keys_init(); } void loop() { diff --git a/example/arduino/ex_cmds.c b/example/arduino/ex_cmds.c deleted file mode 120000 index e05b39a..0000000 --- a/example/arduino/ex_cmds.c +++ /dev/null @@ -1 +0,0 @@ -../../extensions/ex_cmds/ex_cmds.c \ No newline at end of file diff --git a/example/arduino/ex_cmds.h b/example/arduino/ex_cmds.h deleted file mode 120000 index 483e0ac..0000000 --- a/example/arduino/ex_cmds.h +++ /dev/null @@ -1 +0,0 @@ -../../extensions/ex_cmds/ex_cmds.h \ No newline at end of file diff --git a/example/arduino/ex_keys.c b/example/arduino/ex_keys.c deleted file mode 120000 index ff19f25..0000000 --- a/example/arduino/ex_keys.c +++ /dev/null @@ -1 +0,0 @@ -../../extensions/ex_keys/ex_keys.c \ No newline at end of file diff --git a/example/arduino/ex_keys.h b/example/arduino/ex_keys.h deleted file mode 120000 index af567d8..0000000 --- a/example/arduino/ex_keys.h +++ /dev/null @@ -1 +0,0 @@ -../../extensions/ex_keys/ex_keys.h \ No newline at end of file diff --git a/example/arduino/init.py b/example/arduino/init.py new file mode 100644 index 0000000..f8532b7 --- /dev/null +++ b/example/arduino/init.py @@ -0,0 +1,33 @@ +#! /usr/bin/python3 +from shutil import copy +import os, sys +#diw 需拷贝的文件夹,newdir是拷贝的地方 +def copy_dir(dir,newdir): + for p in os.listdir(dir): + print(p) + filepath=newdir+'/'+p + oldpath=dir+'/'+p + if os.path.isdir(oldpath): + print('是目录') + os.mkdir(filepath) + copy_dir(oldpath,filepath) + if os.path.isfile(oldpath): + copy(oldpath,filepath) + +if __name__ == "__main__": + if(len(sys.argv) == 2): + if(sys.argv[1] == "clean"): + remove_list = ['arduino.ino', 'README.md', 'xcmd_confg.h', 'init.py'] + files = os.listdir("./") + for f in remove_list: + files.remove(f) + for f in files: + os.remove(f) + else: + print("Usage init project: python3 init.py") + print("Usage clean project: python3 init.py clean") + + else: + copy_dir("../../src", "./") + copy_dir("../../inc", "./") + diff --git a/example/arduino/test.c b/example/arduino/test.c deleted file mode 120000 index e56ede0..0000000 --- a/example/arduino/test.c +++ /dev/null @@ -1 +0,0 @@ -../../extensions/test/test.c \ No newline at end of file diff --git a/example/arduino/test.h b/example/arduino/test.h deleted file mode 120000 index 43808b6..0000000 --- a/example/arduino/test.h +++ /dev/null @@ -1 +0,0 @@ -../../extensions/test/test.h \ No newline at end of file diff --git a/example/arduino/xcmd.c b/example/arduino/xcmd.c deleted file mode 120000 index 617857c..0000000 --- a/example/arduino/xcmd.c +++ /dev/null @@ -1 +0,0 @@ -../../src/xcmd.c \ No newline at end of file diff --git a/example/arduino/xcmd.h b/example/arduino/xcmd.h deleted file mode 120000 index 02e2e49..0000000 --- a/example/arduino/xcmd.h +++ /dev/null @@ -1 +0,0 @@ -../../inc/xcmd.h \ No newline at end of file diff --git a/example/arduino/xcmd_confg.h b/example/arduino/xcmd_confg.h deleted file mode 120000 index 0abcc6b..0000000 --- a/example/arduino/xcmd_confg.h +++ /dev/null @@ -1 +0,0 @@ -../../inc/xcmd_confg.h \ No newline at end of file diff --git a/example/arduino/xcmd_confg.h b/example/arduino/xcmd_confg.h new file mode 100755 index 0000000..633c34a --- /dev/null +++ b/example/arduino/xcmd_confg.h @@ -0,0 +1,29 @@ +/* + * @Author: your name + * @Date: 2021-09-17 23:03:06 + * @LastEditTime: 2021-10-11 21:40:01 + * @LastEditors: Please set LastEditors + * @Description: In User Settings Edit + * @FilePath: /xcmd/inc/xcmd_confg.h + */ +#ifndef XCMD_CONFG_H +#define XCMD_CONFG_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "xcmd_define.h" + +#define XCMD_LINE_MAX_LENGTH (32) /* 命令行支持的最大字符数 */ +#define XCMD_HISTORY_MAX_NUM (0) /* 支持的历史记录个数, 这个参数对内存的影响很大,建议arduino设置为0,0为不支持 */ +#define XCMD_PARAM_MAX_NUM (8) /* 支持输入的参数个数 */ +// #define XCMD_DEFAULT_PROMPT "->" /* 提示符 */ +// #define XCMD_DEFAULT_PROMPT_CLOLR TX_GREEN /* 提示符颜色 */ +// #define ENABLE_XCMD_EXPORT /* 需要修改lds,启用后支持XCMD_EXPORT_CMD和XCMD_EXPORT_KEY方法导出命令 */ + +#ifdef __cplusplus + } +#endif + +#endif /* XCMD_CONFG_H */ diff --git a/example/arduino/xcmd_default_cmds.c b/example/arduino/xcmd_default_cmds.c deleted file mode 120000 index fe722cd..0000000 --- a/example/arduino/xcmd_default_cmds.c +++ /dev/null @@ -1 +0,0 @@ -../../src/xcmd_default_cmds.c \ No newline at end of file diff --git a/example/arduino/xcmd_default_cmds.h b/example/arduino/xcmd_default_cmds.h deleted file mode 120000 index e240ef6..0000000 --- a/example/arduino/xcmd_default_cmds.h +++ /dev/null @@ -1 +0,0 @@ -../../inc/xcmd_default_cmds.h \ No newline at end of file diff --git a/example/arduino/xcmd_default_keys.c b/example/arduino/xcmd_default_keys.c deleted file mode 120000 index 8c556f2..0000000 --- a/example/arduino/xcmd_default_keys.c +++ /dev/null @@ -1 +0,0 @@ -../../src/xcmd_default_keys.c \ No newline at end of file diff --git a/example/arduino/xcmd_default_keys.h b/example/arduino/xcmd_default_keys.h deleted file mode 120000 index 5947bfc..0000000 --- a/example/arduino/xcmd_default_keys.h +++ /dev/null @@ -1 +0,0 @@ -../../inc/xcmd_default_keys.h \ No newline at end of file diff --git a/example/arduino/xcmd_define.h b/example/arduino/xcmd_define.h deleted file mode 120000 index 816af6e..0000000 --- a/example/arduino/xcmd_define.h +++ /dev/null @@ -1 +0,0 @@ -../../inc/xcmd_define.h \ No newline at end of file diff --git a/example/esp_idf/main/esp_idf.c b/example/esp_idf/main/esp_idf.c index b77a499..40b2687 100755 --- a/example/esp_idf/main/esp_idf.c +++ b/example/esp_idf/main/esp_idf.c @@ -10,8 +10,6 @@ #include #include #include "xcmd.h" -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" #include "test.h" int cmd_get_char(unsigned char *ch) diff --git a/example/esp_idf/main/xcmd_confg.h b/example/esp_idf/main/xcmd_confg.h new file mode 100755 index 0000000..cf3819c --- /dev/null +++ b/example/esp_idf/main/xcmd_confg.h @@ -0,0 +1,29 @@ +/* + * @Author: your name + * @Date: 2021-09-17 23:03:06 + * @LastEditTime: 2021-10-11 21:40:01 + * @LastEditors: Please set LastEditors + * @Description: In User Settings Edit + * @FilePath: /xcmd/inc/xcmd_confg.h + */ +#ifndef XCMD_CONFG_H +#define XCMD_CONFG_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "xcmd_define.h" + +#define XCMD_LINE_MAX_LENGTH (128) /* 命令行支持的最大字符数 */ +#define XCMD_HISTORY_MAX_NUM (16) /* 支持的历史记录个数, 这个参数对内存的影响很大,建议arduino设置为0,0为不支持 */ +#define XCMD_PARAM_MAX_NUM (8) /* 支持输入的参数个数 */ +// #define XCMD_DEFAULT_PROMPT "->" /* 提示符 */ +// #define XCMD_DEFAULT_PROMPT_CLOLR TX_GREEN /* 提示符颜色 */ +// #define ENABLE_XCMD_EXPORT /* 需要修改lds,启用后支持XCMD_EXPORT_CMD和XCMD_EXPORT_KEY方法导出命令 */ + +#ifdef __cplusplus + } +#endif + +#endif /* XCMD_CONFG_H */ diff --git a/example/linux/Makefile b/example/linux/Makefile index 2fba5d9..61fa7f5 100755 --- a/example/linux/Makefile +++ b/example/linux/Makefile @@ -40,7 +40,7 @@ all: mkbuilddir $(OBJ_WITH_BUILD_DIR) gcc $(OBJ_WITH_BUILD_DIR) -o $(BIN) -Wl,-Map,$(BIN).map build/%.o:%.c - gcc -g -Wall -c $(INC) -o $@ $< + gcc -g -O0 -Wall -c $(INC) -o $@ $< .PHONY:mkbuilddir mkbuilddir: @@ -48,6 +48,6 @@ mkbuilddir: .PHONY:clean clean: - rm -rf build xcmder + rm -rf build xcmder fatfs.img xcmder.map diff --git a/example/linux/xcmd_confg.h b/example/linux/xcmd_confg.h new file mode 100755 index 0000000..cff342d --- /dev/null +++ b/example/linux/xcmd_confg.h @@ -0,0 +1,29 @@ +/* + * @Author: your name + * @Date: 2021-09-17 23:03:06 + * @LastEditTime: 2021-10-11 21:40:01 + * @LastEditors: Please set LastEditors + * @Description: In User Settings Edit + * @FilePath: /xcmd/inc/xcmd_confg.h + */ +#ifndef XCMD_CONFG_H +#define XCMD_CONFG_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "xcmd_define.h" + +#define XCMD_LINE_MAX_LENGTH (128) /* 命令行支持的最大字符数 */ +#define XCMD_HISTORY_MAX_NUM (16) /* 支持的历史记录个数, 这个参数对内存的影响很大,建议arduino设置为0,0为不支持 */ +#define XCMD_PARAM_MAX_NUM (8) /* 支持输入的参数个数 */ +// #define XCMD_DEFAULT_PROMPT "->" /* 提示符 */ +// #define XCMD_DEFAULT_PROMPT_CLOLR TX_GREEN /* 提示符颜色 */ +// #define ENABLE_XCMD_EXPORT /* 需要修改lds,启用后支持XCMD_EXPORT_CMD和XCMD_EXPORT_KEY方法导出命令 */ + +#ifdef __cplusplus + } +#endif + +#endif /* XCMD_CONFG_H */ diff --git a/example/stm32/MDK/stm32f1xx/User/xcmd_confg.h b/example/stm32/MDK/stm32f1xx/User/xcmd_confg.h new file mode 100755 index 0000000..2c14d2b --- /dev/null +++ b/example/stm32/MDK/stm32f1xx/User/xcmd_confg.h @@ -0,0 +1,29 @@ +/* + * @Author: your name + * @Date: 2021-09-17 23:03:06 + * @LastEditTime: 2021-10-11 21:40:01 + * @LastEditors: Please set LastEditors + * @Description: In User Settings Edit + * @FilePath: /xcmd/inc/xcmd_confg.h + */ +#ifndef XCMD_CONFG_H +#define XCMD_CONFG_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "xcmd_define.h" + +#define XCMD_LINE_MAX_LENGTH (64) /* 命令行支持的最大字符数 */ +#define XCMD_HISTORY_MAX_NUM (4) /* 支持的历史记录个数, 这个参数对内存的影响很大,建议arduino设置为0,0为不支持 */ +#define XCMD_PARAM_MAX_NUM (8) /* 支持输入的参数个数 */ +// #define XCMD_DEFAULT_PROMPT "->" /* 提示符 */ +// #define XCMD_DEFAULT_PROMPT_CLOLR TX_GREEN /* 提示符颜色 */ +// #define ENABLE_XCMD_EXPORT /* 需要修改lds,启用后支持XCMD_EXPORT_CMD和XCMD_EXPORT_KEY方法导出命令 */ + +#ifdef __cplusplus + } +#endif + +#endif /* XCMD_CONFG_H */ diff --git a/example/stm32/MDK/stm32f4xx/user/xcmd_confg.h b/example/stm32/MDK/stm32f4xx/user/xcmd_confg.h new file mode 100755 index 0000000..2c14d2b --- /dev/null +++ b/example/stm32/MDK/stm32f4xx/user/xcmd_confg.h @@ -0,0 +1,29 @@ +/* + * @Author: your name + * @Date: 2021-09-17 23:03:06 + * @LastEditTime: 2021-10-11 21:40:01 + * @LastEditors: Please set LastEditors + * @Description: In User Settings Edit + * @FilePath: /xcmd/inc/xcmd_confg.h + */ +#ifndef XCMD_CONFG_H +#define XCMD_CONFG_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "xcmd_define.h" + +#define XCMD_LINE_MAX_LENGTH (64) /* 命令行支持的最大字符数 */ +#define XCMD_HISTORY_MAX_NUM (4) /* 支持的历史记录个数, 这个参数对内存的影响很大,建议arduino设置为0,0为不支持 */ +#define XCMD_PARAM_MAX_NUM (8) /* 支持输入的参数个数 */ +// #define XCMD_DEFAULT_PROMPT "->" /* 提示符 */ +// #define XCMD_DEFAULT_PROMPT_CLOLR TX_GREEN /* 提示符颜色 */ +// #define ENABLE_XCMD_EXPORT /* 需要修改lds,启用后支持XCMD_EXPORT_CMD和XCMD_EXPORT_KEY方法导出命令 */ + +#ifdef __cplusplus + } +#endif + +#endif /* XCMD_CONFG_H */ diff --git a/extensions/ex_cmds/ex_cmds.c b/extensions/ex_cmds/ex_cmds.c index 118d0a1..6e4d8a6 100644 --- a/extensions/ex_cmds/ex_cmds.c +++ b/extensions/ex_cmds/ex_cmds.c @@ -24,9 +24,13 @@ static int cmd_run(int argc, char* argv[]) return 0; } +XCMD_EXPORT_CMD(run, cmd_run, HELP_RUN) + static xcmd_t cmds[] = { +#ifndef ENABLE_XCMD_EXPORT {"run", cmd_run, HELP_RUN, NULL}, +#endif }; void ex_cmds_init(void) diff --git a/extensions/ex_keys/ex_keys.c b/extensions/ex_keys/ex_keys.c index 49f9609..a5f9a5f 100644 --- a/extensions/ex_keys/ex_keys.c +++ b/extensions/ex_keys/ex_keys.c @@ -29,6 +29,7 @@ static int xcmd_ctr_u(void *pv) return 0; } + static int xcmd_ctr_k(void *pv) { /* 删除光标右边的所有字符 */ @@ -51,6 +52,7 @@ static int xcmd_ctr_l(void *pv) return 0; } + static int xcmd_ctr_left(void *pv) { char *line = xcmd_display_get(); @@ -76,6 +78,7 @@ static int xcmd_ctr_left(void *pv) return 0; } + static int xcmd_ctr_right(void *pv) { char *line = xcmd_display_get(); @@ -99,8 +102,17 @@ static int xcmd_ctr_right(void *pv) return 0; } +XCMD_EXPORT_KEY(KEY_CTR_A, xcmd_ctr_a, "ctr+a") +XCMD_EXPORT_KEY(KEY_CTR_E, xcmd_ctr_e, "ctr+e") +XCMD_EXPORT_KEY(KEY_CTR_U, xcmd_ctr_u, "ctr+u") +XCMD_EXPORT_KEY(KEY_CTR_K, xcmd_ctr_k, "ctr+k") +XCMD_EXPORT_KEY(KEY_CTR_L, xcmd_ctr_l, "ctr+l") +XCMD_EXPORT_KEY(KEY_CTR_LEFT, xcmd_ctr_left, "ctr+lelf") +XCMD_EXPORT_KEY(KEY_CTR_RIGHT, xcmd_ctr_right, "ctr+lelf") + static xcmd_key_t ex_keys[] = { +#ifndef ENABLE_XCMD_EXPORT {KEY_CTR_A, xcmd_ctr_a, "ctr+a", NULL}, {KEY_CTR_E, xcmd_ctr_e, "ctr+e", NULL}, {KEY_CTR_U, xcmd_ctr_u, "ctr+u", NULL}, @@ -108,6 +120,7 @@ static xcmd_key_t ex_keys[] = {KEY_CTR_L, xcmd_ctr_l, "ctr+l", NULL}, {KEY_CTR_LEFT, xcmd_ctr_left, "ctr+lelf", NULL}, {KEY_CTR_RIGHT, xcmd_ctr_right, "ctr+right", NULL}, +#endif }; diff --git a/extensions/ex_list/ex_list.c b/extensions/ex_list/ex_list.c index 73655c6..c098dbe 100644 --- a/extensions/ex_list/ex_list.c +++ b/extensions/ex_list/ex_list.c @@ -53,7 +53,6 @@ static int list_test(int argc, char* argv[]) return 0; } - static int list_note_del(int argc, char* argv[]) { struct student *p; @@ -268,17 +267,24 @@ static int List_traverse(int argc, char* argv[]) return 0; } -static xcmd_t cmds[] = -{ +XCMD_EXPORT_CMD(list, list_test, "list test demo") //链表增加节点 +XCMD_EXPORT_CMD(list1, list_note_del, "list note del demo") //链表删除节点 +XCMD_EXPORT_CMD(list2, list_note_rep, "list note replace demo") //链表替换节点 +XCMD_EXPORT_CMD(list3, list_note_del_insert, "list note del and insert demo") //链表删除并插入节点 +XCMD_EXPORT_CMD(list4, List_to_merge, "List to merge") //链表的合并 +XCMD_EXPORT_CMD(list5, List_traverse, "List to merge") //链表的遍历 + +static xcmd_t cmds[] = { +#ifndef ENABLE_XCMD_EXPORT {"list", list_test, "list test demo", NULL}, //链表增加节点 {"list1", list_note_del, "list note del demo", NULL}, //链表删除节点 {"list2", list_note_rep, "list note replace demo", NULL}, //链表替换节点 {"list3", list_note_del_insert, "list note del and insert demo", NULL}, //链表删除并插入节点 {"list4", List_to_merge, "List to merge", NULL}, //链表的合并 {"list5", List_traverse, "List to merge", NULL}, //链表的遍历 +#endif }; - void ex_list_init(void) { xcmd_cmd_register(cmds, sizeof(cmds)/sizeof(xcmd_t)); diff --git a/extensions/fs_cmds/fs_cmds.c b/extensions/fs_cmds/fs_cmds.c index 3ef4d7c..de6de95 100644 --- a/extensions/fs_cmds/fs_cmds.c +++ b/extensions/fs_cmds/fs_cmds.c @@ -437,18 +437,33 @@ static int cmd_write(int argc, char *argv[]) return 0; } + + +XCMD_EXPORT_CMD(ls, cmd_ls, HELP_LS) +XCMD_EXPORT_CMD(df, cmd_df, HELP_DF) +XCMD_EXPORT_CMD(cd, cmd_cd, HELP_CD) +XCMD_EXPORT_CMD(read, cmd_read, HELP_READ) +XCMD_EXPORT_CMD(rm, cmd_rm, HELP_RM) +XCMD_EXPORT_CMD(mv, cmd_mv, HELP_MV) +XCMD_EXPORT_CMD(sync, cmd_sync, HELP_SYNC) +XCMD_EXPORT_CMD(mkdir, cmd_mkdir, HELP_MKDIR) +XCMD_EXPORT_CMD(touch, cmd_touch, HELP_TOUCH) +XCMD_EXPORT_CMD(write, cmd_write, HELP_WRITE) + static xcmd_t cmds[] = - { - {"ls", cmd_ls, HELP_LS, NULL}, - {"df", cmd_df, HELP_DF, NULL}, - {"cd", cmd_cd, HELP_CD, NULL}, - {"read", cmd_read, HELP_READ, NULL}, - {"rm", cmd_rm, HELP_RM, NULL}, - {"mv", cmd_mv, HELP_MV, NULL}, - {"sync", cmd_sync, HELP_SYNC, NULL}, - {"mkdir", cmd_mkdir, HELP_MKDIR, NULL}, - {"touch", cmd_touch, HELP_TOUCH, NULL}, - {"write", cmd_write, HELP_WRITE, NULL}, +{ +#ifndef ENABLE_XCMD_EXPORT + {"ls", cmd_ls, HELP_LS, NULL}, + {"df", cmd_df, HELP_DF, NULL}, + {"cd", cmd_cd, HELP_CD, NULL}, + {"read", cmd_read, HELP_READ, NULL}, + {"rm", cmd_rm, HELP_RM, NULL}, + {"mv", cmd_mv, HELP_MV, NULL}, + {"sync", cmd_sync, HELP_SYNC, NULL}, + {"mkdir", cmd_mkdir, HELP_MKDIR, NULL}, + {"touch", cmd_touch, HELP_TOUCH, NULL}, + {"write", cmd_write, HELP_WRITE, NULL}, +#endif }; void fs_cmds_init(void) diff --git a/extensions/net_cmds/socket_cmds.c b/extensions/net_cmds/socket_cmds.c index 16b4d64..1308aab 100644 --- a/extensions/net_cmds/socket_cmds.c +++ b/extensions/net_cmds/socket_cmds.c @@ -94,10 +94,14 @@ static int xcmd_udp_service(int argc, char** argv) return 0; } +XCMD_EXPORT_CMD(udp_client, xcmd_udp_client, "Usage: udp_client ip port msg") +XCMD_EXPORT_CMD(udp_service, xcmd_udp_service, "Usage: udp_service [ip] [port:default(8080)]") static xcmd_t cmds[] = { +#ifndef ENABLE_XCMD_EXPORT {"udp_client", xcmd_udp_client, "Usage: udp_client ip port msg", NULL}, {"udp_service", xcmd_udp_service, "Usage: udp_service [ip] [port:default(8080)]", NULL}, +#endif }; void socket_cmds_init(void) diff --git a/extensions/test/test.c b/extensions/test/test.c index 5df3e7e..06dc50c 100644 --- a/extensions/test/test.c +++ b/extensions/test/test.c @@ -169,18 +169,26 @@ static int cmd_print_color(int argc, char* argv[]) return 0; } +XCMD_EXPORT_CMD(history, cmd_history, "show history list") +XCMD_EXPORT_CMD(example, cmd_example, "example [-f|-i|-s] [val]") +XCMD_EXPORT_CMD(color, cmd_print_color, "printf color text") + static xcmd_t cmds[] = { +#ifndef ENABLE_XCMD_EXPORT {"history", cmd_history, "show history list", NULL}, {"example", cmd_example, "example [-f|-i|-s] [val]", NULL}, {"delcmd", cmd_delete_cmd, "delete cmd [val]", NULL}, {"delkey", cmd_delete_key, "delete key [val]", NULL}, {"color", cmd_print_color, "printf color text", NULL}, +#endif }; static xcmd_key_t keys[] = { +#ifndef ENABLE_XCMD_EXPORT {KEY_CTR_Q, cmd_ctr_q, "ctr+q", NULL}, +#endif }; void test_cmd_init(void) diff --git a/inc/xcmd.h b/inc/xcmd.h index 215610a..69d0708 100755 --- a/inc/xcmd.h +++ b/inc/xcmd.h @@ -9,6 +9,7 @@ #include #include #include "xcmd_define.h" +#include "xcmd_default_confg.h" #ifdef __cplusplus extern "C" { @@ -19,18 +20,22 @@ typedef int(*cmd_key_func_t)(void *); typedef struct __cmd { - char* name; + const char* name; cmd_func_t func; - char* help; + const char* help; +#ifndef ENABLE_XCMD_EXPORT struct __cmd *next; +#endif }xcmd_t; typedef struct __key { - char* key; + const char* key; cmd_key_func_t func; - char* help; + const char* help; +#ifndef ENABLE_XCMD_EXPORT struct __key *next; +#endif }xcmd_key_t; @@ -65,22 +70,6 @@ int xcmd_cmd_register(xcmd_t* cmds, uint16_t number); */ int xcmd_key_register(xcmd_key_t* keys, uint16_t number); -/** - * @description: 获取命令列表,可以通过next指针可以遍历所有指令 - * @param {*} - * @param {} - * @return {xcmd_t *}:指令链表表头 - */ -xcmd_t *xcmd_cmdlist_get(void); - -/** - * @description: 获取按键列表,可以通过next指针可以遍历所有按键 - * @param {*} - * @param {} - * @return {xcmd_key_t *}:快捷键链表表头 - */ -xcmd_key_t *xcmd_keylist_get(void); - /** * @description: 删除已经注册的cmd * @param {char*} cmd:cmd集 @@ -95,6 +84,70 @@ int xcmd_unregister_cmd(char *cmd); */ int xcmd_unregister_key(char *key); +#ifndef XCMD_SECTION + #if defined(__CC_ARM) || defined(__CLANG_ARM) + #define XCMD_SECTION(x) __attribute__((section(x))) + #elif defined (__IAR_SYSTEMS_ICC__) + #define XCMD_SECTION(x) @ x + #elif defined(__GNUC__) + #define XCMD_SECTION(x) __attribute__((section(x))) + #else + #define XCMD_SECTION(x) + #endif +#endif + +#ifndef XCMD_USED + #if defined(__CC_ARM) || defined(__CLANG_ARM) + #define XCMD_USED __attribute__((used)) + #elif defined (__IAR_SYSTEMS_ICC__) + #define XCMD_USED __root + #elif defined(__GNUC__) + #define XCMD_USED __attribute__((used)) + #else + #define XCMD_USED + #endif +#endif + +#ifdef ENABLE_XCMD_EXPORT +#define XCMD_EXPORT_CMD(_name, _func, _help) XCMD_USED const xcmd_t XCMD_SECTION("_xcmd_cmd_list") \ + xcmd_cmd_##_name={\ + .name=#_name, \ + .func=_func, \ + .help=_help\ + }; +#define XCMD_EXPORT_KEY(_key, _func, _help) XCMD_USED const xcmd_key_t XCMD_SECTION("_xcmd_key_list") \ + xcmd_key_##_key={\ + .key=_key, \ + .func=_func, \ + .help=_help\ + }; +extern xcmd_t _xcmd_cmd_list_start; +extern xcmd_t _xcmd_cmd_list_end; +extern xcmd_key_t _xcmd_key_list_start; +extern xcmd_key_t _xcmd_key_list_end; +#define XCMD_CMD_FOR_EACH(pos) for ((pos) = &_xcmd_cmd_list_start; (pos)<&_xcmd_cmd_list_end; ++(pos)) +#define XCMD_KEY_FOR_EACH(pos) for ((pos) = &_xcmd_key_list_start; (pos)<&_xcmd_key_list_end; ++(pos)) +#else +/** + * @description: 获取命令列表,可以通过next指针可以遍历所有指令 + * @param {*} + * @param {} + * @return {xcmd_t *}:指令链表表头 + */ +xcmd_t *xcmd_cmdlist_get(void); +/** + * @description: 获取按键列表,可以通过next指针可以遍历所有按键 + * @param {*} + * @param {} + * @return {xcmd_key_t *}:快捷键链表表头 + */ +xcmd_key_t *xcmd_keylist_get(void); +#define XCMD_EXPORT_CMD(name, func, help) +#define XCMD_EXPORT_KEY(key, func, help) +#define XCMD_CMD_FOR_EACH(pos) for ((pos) = xcmd_cmdlist_get(); (pos); (pos) = (pos)->next) +#define XCMD_KEY_FOR_EACH(pos) for ((pos) = xcmd_keylist_get(); (pos); (pos) = (pos)->next) +#endif + /** * @description: 手动执行命令 * @param {char* } str:命令 @@ -223,6 +276,10 @@ void xcmd_history_slider_reset(void); */ char* xcmd_end_of_input(void); + + + + #ifdef __cplusplus } #endif diff --git a/inc/xcmd_confg.h b/inc/xcmd_default_confg.h similarity index 71% rename from inc/xcmd_confg.h rename to inc/xcmd_default_confg.h index 4827797..b93535a 100755 --- a/inc/xcmd_confg.h +++ b/inc/xcmd_default_confg.h @@ -4,16 +4,18 @@ * @LastEditTime: 2021-10-11 21:40:01 * @LastEditors: Please set LastEditors * @Description: In User Settings Edit - * @FilePath: /xcmd/inc/xcmd_confg.h + * @FilePath: /xcmd/inc/xcmd_default_confg.h */ -#ifndef XCMD_CONFG_H -#define XCMD_CONFG_H +#ifndef XCMD_DEFAULT_CONFG_H +#define XCMD_DEFAULT_CONFG_H #ifdef __cplusplus extern "C" { #endif -#define VERSION "1.0.0" +#include "xcmd_confg.h" + +#define VERSION "1.1.0" #ifndef XCMD_LINE_MAX_LENGTH #define XCMD_LINE_MAX_LENGTH (64) /* 命令行支持的最大字符数 */ @@ -37,15 +39,19 @@ extern "C" { #endif #ifndef XCMD_DEFAULT_PROMPT -#define XCMD_DEFAULT_PROMPT ("->") +#define XCMD_DEFAULT_PROMPT "->" /*提示符*/ #endif #ifndef XCMD_DEFAULT_PROMPT_CLOLR -#define XCMD_DEFAULT_PROMPT_CLOLR TX_GREEN +#define XCMD_DEFAULT_PROMPT_CLOLR TX_GREEN /*提示符颜色*/ +#endif + +#ifndef ENABLE_XCMD_EXPORT +//#define ENABLE_XCMD_EXPORT /*使能XCMD_EXPORT_CMD和XCMD_EXPORT_KEY*/ #endif #ifdef __cplusplus } #endif -#endif /* XCMD_CONFG_H */ +#endif /* XCMD_DEFAULT_CONFG_H */ diff --git a/inc/xcmd_define.h b/inc/xcmd_define.h index 2de84e4..966f2c2 100644 --- a/inc/xcmd_define.h +++ b/inc/xcmd_define.h @@ -94,7 +94,7 @@ extern "C" { #define DCH(n) "\x1B[%dP",n /* 删除字符 删除当前光标位置的 个字符,这会从屏幕右边缘以空格字符移动。*/ #define ECH(n) "\x1B[%dX",n /* 擦除字符 擦除当前光标位置的 个字符,方法是使用空格字符覆盖它们。*/ #define IL(n) "\x1B[%dL",n /* 插入行 将 行插入光标位置的缓冲区。 光标所在的行及其下方的行将向下移动。*/ -#define DL(n) "\x1B[%dM",n /* 删除行 从缓冲区中删除 行,从光标所在的行开始。*/ +#define DL(n) "\x1B[%dM\r",n /* 删除行 从缓冲区中删除 行,从光标所在的行开始。*/ /* 打印字体颜色设置 */ #define TX_DEF "\x1b[0m" diff --git a/src/xcmd.c b/src/xcmd.c index 21a6c59..328fb5b 100755 --- a/src/xcmd.c +++ b/src/xcmd.c @@ -1,4 +1,3 @@ -#include "xcmd_confg.h" #include "xcmd.h" #include "xcmd_default_cmds.h" #include "xcmd_default_keys.h" @@ -28,12 +27,12 @@ struct struct { - xcmd_t *head; + xcmd_t head; }cmd_list; struct { - xcmd_key_t *head; + xcmd_key_t head; }key_list; struct @@ -162,10 +161,10 @@ static int xcmd_get_param(char* msg, char*delim, char* get[], int max_num) static int xcmd_cmd_match(int argc, char*argv[]) { - xcmd_t *p = g_xcmder.cmd_list.head; uint8_t flag = 0; int ret = -1; - while(p) + xcmd_t *p = NULL; + XCMD_CMD_FOR_EACH(p) { if(strcmp(p->name, argv[0]) == 0) { @@ -182,7 +181,6 @@ static int xcmd_cmd_match(int argc, char*argv[]) ret = p->func(argc, argv); break; } - p = p->next; } if(flag) { @@ -197,8 +195,8 @@ static int xcmd_cmd_match(int argc, char*argv[]) static void xcmd_key_match(char* key) { - xcmd_key_t *p = g_xcmder.key_list.head; - while(p) + xcmd_key_t *p = NULL; + XCMD_KEY_FOR_EACH(p) { if(strcmp(key, p->key) == 0) { @@ -207,7 +205,6 @@ static void xcmd_key_match(char* key) break; } } - p = p->next; } } @@ -546,48 +543,57 @@ int xcmd_exec(char* str) int xcmd_key_register(xcmd_key_t *keys, uint16_t number) { +#ifndef ENABLE_XCMD_EXPORT uint16_t i=0; xcmd_key_t * temp; while(iname) == 0) { @@ -595,16 +601,17 @@ int xcmd_unregister_cmd(char *cmd) return 0; } bk = p; - p = p->next; } +#endif return -1; } int xcmd_unregister_key(char *key) { - xcmd_key_t *p = g_xcmder.key_list.head; - xcmd_key_t *bk = p; - while(p) +#ifndef ENABLE_XCMD_EXPORT + xcmd_key_t *bk = &g_xcmder.key_list.head; + xcmd_key_t *p = NULL; + XCMD_KEY_FOR_EACH(p) { if(strcmp(key, p->key) == 0) { @@ -612,8 +619,8 @@ int xcmd_unregister_key(char *key) return 0; } bk = p; - p = p->next; } +#endif return -1; } @@ -646,7 +653,9 @@ void xcmd_init( int (*get_c)(uint8_t*), int (*put_c)(uint8_t)) g_xcmder.parser.byte_num = 0; g_xcmder.parser.cursor = 0; g_xcmder.parser.encode_case_stu = 0; - g_xcmder.cmd_list.head = NULL; +#ifndef ENABLE_XCMD_EXPORT + g_xcmder.cmd_list.head.next = NULL; +#endif if(g_xcmder._initOK == 0) { diff --git a/src/xcmd_default_cmds.c b/src/xcmd_default_cmds.c index 835cba7..08d7113 100755 --- a/src/xcmd_default_cmds.c +++ b/src/xcmd_default_cmds.c @@ -6,7 +6,7 @@ * @Description: In User Settings Edit * @FilePath: /xcmd/src/xcmd_default_cmds.c */ -#include "xcmd_confg.h" +#include "xcmd_default_confg.h" #include "xcmd_default_cmds.h" #include "xcmd.h" #include @@ -19,23 +19,21 @@ static int cmd_clear(int argc, char* argv[]) static int cmd_help(int argc, char* argv[]) { - xcmd_t *p = xcmd_cmdlist_get(); - while(p) + xcmd_t *p = NULL; + XCMD_CMD_FOR_EACH(p) { xcmd_print("%-20s %s\r\n",p->name, p->help); - p = p->next; } return 0; } static int cmd_keys(int argc, char* argv[]) { - xcmd_key_t *p = xcmd_keylist_get(); - while(p) + xcmd_key_t *p = NULL; + XCMD_KEY_FOR_EACH(p) { xcmd_print("0x%08X\t", p->key); xcmd_print("%s\r\n",p->help); - p = p->next; } return 0; } @@ -53,12 +51,19 @@ static int cmd_logo(int argc, char* argv[]) return 0; } +XCMD_EXPORT_CMD(clear, cmd_clear, "clear screen") +XCMD_EXPORT_CMD(help, cmd_help, "show this list") +XCMD_EXPORT_CMD(keys, cmd_keys, "show keys") +XCMD_EXPORT_CMD(logo, cmd_logo, "show logo") + static xcmd_t cmds[] = { +#ifndef ENABLE_XCMD_EXPORT {"clear", cmd_clear, "clear screen", NULL}, {"help", cmd_help, "show this list", NULL}, {"keys", cmd_keys, "show keys", NULL}, {"logo", cmd_logo, "show logo", NULL}, +#endif }; void default_cmds_init(void) diff --git a/src/xcmd_default_keys.c b/src/xcmd_default_keys.c index 671b16c..9e85f43 100755 --- a/src/xcmd_default_keys.c +++ b/src/xcmd_default_keys.c @@ -6,7 +6,7 @@ * @Description: In User Settings Edit * @FilePath: /xcmd/src/xcmd_default_keys.c */ -#include "xcmd_confg.h" +#include "xcmd_default_confg.h" #include "xcmd.h" #include "xcmd_default_keys.h" @@ -23,11 +23,14 @@ static int xcmd_str_match(const char* str1, const char* str2) return i; } + static int xcmd_del_char(void *pv) { xcmd_display_delete_char(); return 0; } +XCMD_EXPORT_KEY(KEY_CTR_H, xcmd_del_char, "backspace") +XCMD_EXPORT_KEY(KEY_BACKSPACE, xcmd_del_char, "delete") static int xcmd_enter(void *pv) { @@ -43,9 +46,10 @@ static int xcmd_enter(void *pv) #else xcmd_print(XCMD_DEFAULT_PROMPT_CLOLR "%s" TX_DEF, xcmd_get_prompt()); #endif - return 0; } +XCMD_EXPORT_KEY(KEY_CTR_M, xcmd_enter, "enter") +XCMD_EXPORT_KEY(KEY_CTR_J, xcmd_enter, "enter") static int xcmd_cursor_left(void *pv) { @@ -57,6 +61,7 @@ static int xcmd_cursor_left(void *pv) } return 0; } +XCMD_EXPORT_KEY(KEY_LEFT, xcmd_cursor_left, "left") static int xcmd_cursor_right(void *pv) { @@ -65,6 +70,7 @@ static int xcmd_cursor_right(void *pv) xcmd_display_cursor_set(pos); return 0; } +XCMD_EXPORT_KEY(KEY_RIGHT, xcmd_cursor_right, "right") #if XCMD_HISTORY_MAX_NUM static int xcmd_history_dw(void *pv) @@ -77,6 +83,7 @@ static int xcmd_history_dw(void *pv) } return 0; } +XCMD_EXPORT_KEY(KEY_DW, xcmd_history_dw, "down") static int xcmd_history_up(void *pv) { @@ -88,6 +95,7 @@ static int xcmd_history_up(void *pv) } return 0; } +XCMD_EXPORT_KEY(KEY_UP, xcmd_history_up, "up") #endif static int xcmd_auto_completion(void *pv) @@ -95,10 +103,10 @@ static int xcmd_auto_completion(void *pv) xcmd_t *match_cmd_first = NULL; uint16_t match_num = 0; uint16_t match_subscript_min = 0; - xcmd_t *p = xcmd_cmdlist_get(); char *display_line = xcmd_display_get(); uint16_t cursor_pos = xcmd_display_cursor_get(); - while(p) + xcmd_t *p = NULL; + XCMD_CMD_FOR_EACH(p) { if(strncmp(display_line, p->name, cursor_pos) == 0) { @@ -126,7 +134,6 @@ static int xcmd_auto_completion(void *pv) } match_num++; } - p = p->next; } if(match_num == 1) @@ -142,9 +149,11 @@ static int xcmd_auto_completion(void *pv) } return 0; } +XCMD_EXPORT_KEY(KEY_TAB, xcmd_auto_completion, "tab") static xcmd_key_t default_keys[] = { +#ifndef ENABLE_XCMD_EXPORT {KEY_CTR_M, xcmd_enter, "enter", NULL}, {KEY_CTR_J, xcmd_enter, "enter", NULL}, {KEY_CTR_H, xcmd_del_char, "backspace", NULL}, @@ -156,6 +165,7 @@ static xcmd_key_t default_keys[] = {KEY_DW, xcmd_history_dw, "down", NULL}, {KEY_UP, xcmd_history_up, "up", NULL}, #endif +#endif }; void default_keys_init(void)