整理代码
This commit is contained in:
parent
9f5b784343
commit
0af1034660
|
@ -7,9 +7,7 @@
|
||||||
* @FilePath: /xcmd/example/arduino/arduino.ino
|
* @FilePath: /xcmd/example/arduino/arduino.ino
|
||||||
*/
|
*/
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include "inc/xcmd.h"
|
#include "xcmd.h"
|
||||||
#include "inc/xcmd_default_keys.h"
|
|
||||||
#include "inc/xcmd_default_cmds.h"
|
|
||||||
#include "test.h"
|
#include "test.h"
|
||||||
|
|
||||||
int cmd_get_char(uint8_t *ch)
|
int cmd_get_char(uint8_t *ch)
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
../../inc/
|
|
|
@ -1 +0,0 @@
|
||||||
需要把根目录的inc和src拷贝到当前目录才能编译通过
|
|
|
@ -1 +0,0 @@
|
||||||
../../src/
|
|
|
@ -1,128 +0,0 @@
|
||||||
/*
|
|
||||||
* @Author: your name
|
|
||||||
* @Date: 2021-09-22 22:33:17
|
|
||||||
* @LastEditTime: 2021-09-22 23:17:02
|
|
||||||
* @LastEditors: Please set LastEditors
|
|
||||||
* @Description: In User Settings Edit
|
|
||||||
* @FilePath: /xcmd/extensions/test/test.c
|
|
||||||
*/
|
|
||||||
#include "test.h"
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#define EXIT_MESSAGE() xcmd_print(g_cmder, "press \"q\" or \"Q\" to exit!\r\n")
|
|
||||||
|
|
||||||
#define EXIT_CHECK() \
|
|
||||||
do \
|
|
||||||
(toupper(GET_CHAR()) == 'Q') \
|
|
||||||
{ \
|
|
||||||
uint8_t c; \
|
|
||||||
if (GET_CHAR(&c)) \
|
|
||||||
{ \
|
|
||||||
switch (c) \
|
|
||||||
case 'q': \
|
|
||||||
case 'Q': \
|
|
||||||
case 0x1B: \
|
|
||||||
return; \
|
|
||||||
} \
|
|
||||||
} \
|
|
||||||
while (0);
|
|
||||||
|
|
||||||
static uint8_t param_check(int need, int argc, char*argv[])
|
|
||||||
{
|
|
||||||
uint8_t i,ret = 0;
|
|
||||||
if(need<(argc))
|
|
||||||
{
|
|
||||||
ret = 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
xcmd_print("err need %d but input %d:\r\n", need, argc-1);
|
|
||||||
xcmd_print("input= ");
|
|
||||||
for(i=0; i<argc; i++)
|
|
||||||
{
|
|
||||||
if(argv[i] != NULL)
|
|
||||||
{
|
|
||||||
xcmd_print("%s ", argv[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
xcmd_print("\r\n");
|
|
||||||
ret = 0;
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void cmd_echo(int argc, char* argv[])
|
|
||||||
{
|
|
||||||
if(param_check(1, argc, argv))
|
|
||||||
{
|
|
||||||
xcmd_print("%s\r\n", argv[1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void cmd_example(int argc, char* argv[])
|
|
||||||
{
|
|
||||||
uint8_t i;
|
|
||||||
if(param_check(1, argc, argv))
|
|
||||||
{
|
|
||||||
if(strcmp(argv[1], "-s") == 0)
|
|
||||||
{
|
|
||||||
for(i=2; i<argc; i++)
|
|
||||||
{
|
|
||||||
xcmd_print("%s\r\n", argv[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(strcmp(argv[1], "-i") == 0)
|
|
||||||
{
|
|
||||||
for(i=2; i<argc; i++)
|
|
||||||
{
|
|
||||||
xcmd_print("%d\r\n", atoi(argv[i]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(strcmp(argv[1], "-f") == 0)
|
|
||||||
{
|
|
||||||
for(i=2; i<argc; i++)
|
|
||||||
{
|
|
||||||
xcmd_print("%f\r\n", atof(argv[i]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void cmd_history(int argc, char* argv[])
|
|
||||||
{
|
|
||||||
uint16_t len = xcmd_history_len();
|
|
||||||
xcmd_history_reset();
|
|
||||||
do
|
|
||||||
{
|
|
||||||
xcmd_print("%s\r\n", xcmd_history_next());
|
|
||||||
}while(len--);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int cmd_ctr_a(void* pv)
|
|
||||||
{
|
|
||||||
xcmd_print("this is ctr+a\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static xcmd_t cmds[] =
|
|
||||||
{
|
|
||||||
{"echo", cmd_echo, "echo anything", NULL},
|
|
||||||
{"history", cmd_history, "show history list", NULL},
|
|
||||||
{"example", cmd_example, "example [-f|-i|-s] [val]", NULL},
|
|
||||||
};
|
|
||||||
|
|
||||||
static xcmd_key_t keys[] =
|
|
||||||
{
|
|
||||||
{CTR_A, cmd_ctr_a, NULL},
|
|
||||||
};
|
|
||||||
|
|
||||||
void test_cmd_init(void)
|
|
||||||
{
|
|
||||||
xcmd_cmd_register(cmds, sizeof(cmds)/sizeof(xcmd_t));
|
|
||||||
}
|
|
||||||
|
|
||||||
void test_keys_init(void)
|
|
||||||
{
|
|
||||||
xcmd_key_register(keys, sizeof(keys)/sizeof(xcmd_key_t));
|
|
||||||
}
|
|
|
@ -0,0 +1 @@
|
||||||
|
../../extensions/test/test.c
|
|
@ -1,28 +0,0 @@
|
||||||
/*
|
|
||||||
* @Author: your name
|
|
||||||
* @Date: 2021-09-22 22:33:24
|
|
||||||
* @LastEditTime: 2021-09-22 22:52:45
|
|
||||||
* @LastEditors: Please set LastEditors
|
|
||||||
* @Description: In User Settings Edit
|
|
||||||
* @FilePath: /xcmd/extensions/test/test.h
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef TEST_H
|
|
||||||
#define TEST_H
|
|
||||||
|
|
||||||
#include "inc/xcmd.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
void test_cmd_init(void);
|
|
||||||
void test_keys_init(void);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* TEST_H */
|
|
|
@ -0,0 +1 @@
|
||||||
|
../../extensions/test/test.h
|
|
@ -0,0 +1 @@
|
||||||
|
../../src/xcmd.c
|
|
@ -0,0 +1 @@
|
||||||
|
../../inc/xcmd.h
|
|
@ -0,0 +1 @@
|
||||||
|
../../inc/xcmd_confg.h
|
|
@ -0,0 +1 @@
|
||||||
|
../../src/xcmd_default_cmds.c
|
|
@ -0,0 +1 @@
|
||||||
|
../../inc/xcmd_default_cmds.h
|
|
@ -0,0 +1 @@
|
||||||
|
../../src/xcmd_default_keys.c
|
|
@ -0,0 +1 @@
|
||||||
|
../../inc/xcmd_default_keys.h
|
|
@ -0,0 +1 @@
|
||||||
|
../../inc/xcmd_define.h
|
|
@ -1,8 +1,8 @@
|
||||||
idf_component_register(SRCS "esp_idf.c"
|
idf_component_register(SRCS "esp_idf.c"
|
||||||
"../../../extensions/test//src/test.c"
|
"../../../extensions/test/test.c"
|
||||||
"../../../src/xcmd.c"
|
"../../../src/xcmd.c"
|
||||||
"../../../src/xcmd_default_keys.c"
|
"../../../src/xcmd_default_keys.c"
|
||||||
"../../../src/xcmd_default_cmds.c"
|
"../../../src/xcmd_default_cmds.c"
|
||||||
INCLUDE_DIRS "."
|
INCLUDE_DIRS "."
|
||||||
"../../../inc/"
|
"../../../inc/"
|
||||||
"../../../extensions/test/inc/")
|
"../../../extensions/test/")
|
||||||
|
|
|
@ -10,8 +10,6 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "xcmd.h"
|
#include "xcmd.h"
|
||||||
#include "xcmd_default_keys.h"
|
|
||||||
#include "xcmd_default_cmds.h"
|
|
||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "freertos/task.h"
|
#include "freertos/task.h"
|
||||||
#include "test.h"
|
#include "test.h"
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
OBJ += xcmd.o xcmd_default_keys.o xcmd_default_cmds.o linux_main.o test.o
|
OBJ += xcmd.o xcmd_default_keys.o xcmd_default_cmds.o linux_main.o test.o
|
||||||
BIN = xcmder
|
BIN = xcmder
|
||||||
VPATH := ../../src \
|
VPATH := ../../src \
|
||||||
../../extensions/test/src
|
../../extensions/test
|
||||||
|
|
||||||
INC += -I../../inc \
|
INC += -I../../inc \
|
||||||
-I../../extensions/test/inc
|
-I../../extensions/test
|
||||||
|
|
||||||
OBJ_WITH_BUILD_DIR:=$(addprefix build/,$(OBJ))
|
OBJ_WITH_BUILD_DIR:=$(addprefix build/,$(OBJ))
|
||||||
|
|
||||||
|
|
|
@ -9,13 +9,10 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "xcmd.h"
|
|
||||||
#include "xcmd_default_keys.h"
|
|
||||||
#include "xcmd_default_cmds.h"
|
|
||||||
#include<errno.h>
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <termio.h>
|
#include <termio.h>
|
||||||
|
#include "xcmd.h"
|
||||||
#include "test.h"
|
#include "test.h"
|
||||||
|
|
||||||
int getch(void)
|
int getch(void)
|
||||||
|
|
|
@ -338,7 +338,7 @@
|
||||||
<MiscControls></MiscControls>
|
<MiscControls></MiscControls>
|
||||||
<Define>USE_STDPERIPH_DRIVER,STM32F10X_MD</Define>
|
<Define>USE_STDPERIPH_DRIVER,STM32F10X_MD</Define>
|
||||||
<Undefine></Undefine>
|
<Undefine></Undefine>
|
||||||
<IncludePath>..\Libraries\CMSIS\Device\ST\STM32F10x\Include;..\Libraries\STM32F10x_StdPeriph_Driver\inc;..\Libraries\CMSIS\Include;..\User;..\User\port;..\..\..\..\..\inc;..\lib\inc;..\..\..\..\..\extensions\test\inc</IncludePath>
|
<IncludePath>..\Libraries\CMSIS\Device\ST\STM32F10x\Include;..\Libraries\STM32F10x_StdPeriph_Driver\inc;..\Libraries\CMSIS\Include;..\User;..\User\port;..\..\..\..\..\inc;..\lib\inc;..\..\..\..\..\extensions\test</IncludePath>
|
||||||
</VariousControls>
|
</VariousControls>
|
||||||
</Cads>
|
</Cads>
|
||||||
<Aads>
|
<Aads>
|
||||||
|
@ -581,7 +581,7 @@
|
||||||
<File>
|
<File>
|
||||||
<FileName>test.c</FileName>
|
<FileName>test.c</FileName>
|
||||||
<FileType>1</FileType>
|
<FileType>1</FileType>
|
||||||
<FilePath>..\..\..\..\..\extensions\test\src\test.c</FilePath>
|
<FilePath>..\..\..\..\..\extensions\test\test.c</FilePath>
|
||||||
</File>
|
</File>
|
||||||
</Files>
|
</Files>
|
||||||
</Group>
|
</Group>
|
||||||
|
|
|
@ -338,7 +338,7 @@
|
||||||
<MiscControls></MiscControls>
|
<MiscControls></MiscControls>
|
||||||
<Define>STM32F427_437xx,USE_STDPERIPH_DRIVER</Define>
|
<Define>STM32F427_437xx,USE_STDPERIPH_DRIVER</Define>
|
||||||
<Undefine></Undefine>
|
<Undefine></Undefine>
|
||||||
<IncludePath>..\FWLIB\CORE;..\FWLIB\inc;..\System\debug;..\System\delay;..\System\sys;..\System\debug;..\user;..\user\bsp\inc;..\user\bsp;..\..\..\..\..\inc;..\..\..\..\..\extensions\test\inc</IncludePath>
|
<IncludePath>..\FWLIB\CORE;..\FWLIB\inc;..\System\debug;..\System\delay;..\System\sys;..\System\debug;..\user;..\user\bsp\inc;..\user\bsp;..\..\..\..\..\inc;..\..\..\..\..\extensions\test</IncludePath>
|
||||||
</VariousControls>
|
</VariousControls>
|
||||||
</Cads>
|
</Cads>
|
||||||
<Aads>
|
<Aads>
|
||||||
|
@ -670,7 +670,7 @@
|
||||||
<File>
|
<File>
|
||||||
<FileName>test.c</FileName>
|
<FileName>test.c</FileName>
|
||||||
<FileType>1</FileType>
|
<FileType>1</FileType>
|
||||||
<FilePath>..\..\..\..\..\extensions\test\src\test.c</FilePath>
|
<FilePath>..\..\..\..\..\extensions\test\test.c</FilePath>
|
||||||
</File>
|
</File>
|
||||||
</Files>
|
</Files>
|
||||||
</Group>
|
</Group>
|
||||||
|
|
|
@ -6,9 +6,10 @@
|
||||||
* @Description: In User Settings Edit
|
* @Description: In User Settings Edit
|
||||||
* @FilePath: /xcmd/extensions/test/test.c
|
* @FilePath: /xcmd/extensions/test/test.c
|
||||||
*/
|
*/
|
||||||
#include "test.h"
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include "xcmd.h"
|
||||||
|
#include "test.h"
|
||||||
|
|
||||||
#define EXIT_MESSAGE() xcmd_print(g_cmder, "press \"q\" or \"Q\" to exit!\r\n")
|
#define EXIT_MESSAGE() xcmd_print(g_cmder, "press \"q\" or \"Q\" to exit!\r\n")
|
||||||
|
|
|
@ -10,8 +10,6 @@
|
||||||
#ifndef TEST_H
|
#ifndef TEST_H
|
||||||
#define TEST_H
|
#define TEST_H
|
||||||
|
|
||||||
#include "xcmd.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
|
@ -15,10 +15,21 @@ extern "C" {
|
||||||
|
|
||||||
#define VERSION "1.0.0"
|
#define VERSION "1.0.0"
|
||||||
|
|
||||||
#define XCMD_LINE_MAX_LENGTH (256) /* 命令行支持的最大字符数 */
|
#ifndef XCMD_LINE_MAX_LENGTH
|
||||||
|
#define XCMD_LINE_MAX_LENGTH (64) /* 命令行支持的最大字符数 */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef XCMD_PRINT_BUF_MAX_LENGTH
|
||||||
#define XCMD_PRINT_BUF_MAX_LENGTH (128) /* xcmd_print缓存 */
|
#define XCMD_PRINT_BUF_MAX_LENGTH (128) /* xcmd_print缓存 */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef XCMD_HISTORY_MAX_NUM
|
||||||
#define XCMD_HISTORY_MAX_NUM (8) /* 支持的历史记录个数,0为不支持 */
|
#define XCMD_HISTORY_MAX_NUM (8) /* 支持的历史记录个数,0为不支持 */
|
||||||
#define XCMD_PARAM_MAX_NUM (16) /* 支持输入的参数个数 */
|
#endif
|
||||||
|
|
||||||
|
#ifndef XCMD_PARAM_MAX_NUM
|
||||||
|
#define XCMD_PARAM_MAX_NUM (8) /* 支持输入的参数个数 */
|
||||||
|
#endif
|
||||||
|
|
||||||
#if XCMD_PRINT_BUF_MAX_LENGTH < (XCMD_LINE_MAX_LENGTH+32)
|
#if XCMD_PRINT_BUF_MAX_LENGTH < (XCMD_LINE_MAX_LENGTH+32)
|
||||||
#undef XCMD_PRINT_BUF_MAX_LENGTH
|
#undef XCMD_PRINT_BUF_MAX_LENGTH
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include "../inc/xcmd.h"
|
#include "xcmd_confg.h"
|
||||||
#include "../inc/xcmd_confg.h"
|
#include "xcmd.h"
|
||||||
#include "../inc/xcmd_default_cmds.h"
|
#include "xcmd_default_cmds.h"
|
||||||
#include "../inc/xcmd_default_keys.h"
|
#include "xcmd_default_keys.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
|
|
@ -6,9 +6,9 @@
|
||||||
* @Description: In User Settings Edit
|
* @Description: In User Settings Edit
|
||||||
* @FilePath: /xcmd/src/xcmd_default_cmds.c
|
* @FilePath: /xcmd/src/xcmd_default_cmds.c
|
||||||
*/
|
*/
|
||||||
#include "../inc/xcmd_default_cmds.h"
|
#include "xcmd_confg.h"
|
||||||
#include "../inc/xcmd.h"
|
#include "xcmd_default_cmds.h"
|
||||||
#include "../inc/xcmd_confg.h"
|
#include "xcmd.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
static void cmd_clear(int argc, char* argv[])
|
static void cmd_clear(int argc, char* argv[])
|
||||||
|
|
|
@ -6,9 +6,9 @@
|
||||||
* @Description: In User Settings Edit
|
* @Description: In User Settings Edit
|
||||||
* @FilePath: /xcmd/src/xcmd_default_keys.c
|
* @FilePath: /xcmd/src/xcmd_default_keys.c
|
||||||
*/
|
*/
|
||||||
#include "../inc/xcmd_default_keys.h"
|
#include "xcmd_confg.h"
|
||||||
#include "../inc/xcmd_confg.h"
|
#include "xcmd.h"
|
||||||
#include "../inc/xcmd.h"
|
#include "xcmd_default_keys.h"
|
||||||
|
|
||||||
static int xcmd_del_char(void *pv)
|
static int xcmd_del_char(void *pv)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue