整理代码

This commit is contained in:
hqm 2021-09-28 10:48:16 +08:00
parent 9f5b784343
commit 0af1034660
26 changed files with 47 additions and 193 deletions

View File

@ -7,9 +7,7 @@
* @FilePath: /xcmd/example/arduino/arduino.ino
*/
#include <Arduino.h>
#include "inc/xcmd.h"
#include "inc/xcmd_default_keys.h"
#include "inc/xcmd_default_cmds.h"
#include "xcmd.h"
#include "test.h"
int cmd_get_char(uint8_t *ch)

View File

@ -1 +0,0 @@
../../inc/

View File

@ -1 +0,0 @@
需要把根目录的inc和src拷贝到当前目录才能编译通过

View File

@ -1 +0,0 @@
../../src/

View File

@ -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));
}

1
example/arduino/test.c Symbolic link
View File

@ -0,0 +1 @@
../../extensions/test/test.c

View File

@ -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 */

1
example/arduino/test.h Symbolic link
View File

@ -0,0 +1 @@
../../extensions/test/test.h

1
example/arduino/xcmd.c Symbolic link
View File

@ -0,0 +1 @@
../../src/xcmd.c

1
example/arduino/xcmd.h Symbolic link
View File

@ -0,0 +1 @@
../../inc/xcmd.h

View File

@ -0,0 +1 @@
../../inc/xcmd_confg.h

View File

@ -0,0 +1 @@
../../src/xcmd_default_cmds.c

View File

@ -0,0 +1 @@
../../inc/xcmd_default_cmds.h

View File

@ -0,0 +1 @@
../../src/xcmd_default_keys.c

View File

@ -0,0 +1 @@
../../inc/xcmd_default_keys.h

View File

@ -0,0 +1 @@
../../inc/xcmd_define.h

View File

@ -1,8 +1,8 @@
idf_component_register(SRCS "esp_idf.c"
"../../../extensions/test//src/test.c"
"../../../extensions/test/test.c"
"../../../src/xcmd.c"
"../../../src/xcmd_default_keys.c"
"../../../src/xcmd_default_cmds.c"
INCLUDE_DIRS "."
"../../../inc/"
"../../../extensions/test/inc/")
"../../../extensions/test/")

View File

@ -10,8 +10,6 @@
#include <stdint.h>
#include <stdlib.h>
#include "xcmd.h"
#include "xcmd_default_keys.h"
#include "xcmd_default_cmds.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "test.h"

View File

@ -1,10 +1,10 @@
OBJ += xcmd.o xcmd_default_keys.o xcmd_default_cmds.o linux_main.o test.o
BIN = xcmder
VPATH := ../../src \
../../extensions/test/src
../../extensions/test
INC += -I../../inc \
-I../../extensions/test/inc
-I../../extensions/test
OBJ_WITH_BUILD_DIR:=$(addprefix build/,$(OBJ))

View File

@ -9,13 +9,10 @@
#include <stdio.h>
#include <stdint.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/socket.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <termio.h>
#include "xcmd.h"
#include "test.h"
int getch(void)

View File

@ -338,7 +338,7 @@
<MiscControls></MiscControls>
<Define>USE_STDPERIPH_DRIVER,STM32F10X_MD</Define>
<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>
</Cads>
<Aads>
@ -581,7 +581,7 @@
<File>
<FileName>test.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\..\extensions\test\src\test.c</FilePath>
<FilePath>..\..\..\..\..\extensions\test\test.c</FilePath>
</File>
</Files>
</Group>

View File

@ -338,7 +338,7 @@
<MiscControls></MiscControls>
<Define>STM32F427_437xx,USE_STDPERIPH_DRIVER</Define>
<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>
</Cads>
<Aads>
@ -670,7 +670,7 @@
<File>
<FileName>test.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\..\extensions\test\src\test.c</FilePath>
<FilePath>..\..\..\..\..\extensions\test\test.c</FilePath>
</File>
</Files>
</Group>

View File

@ -6,9 +6,10 @@
* @Description: In User Settings Edit
* @FilePath: /xcmd/extensions/test/test.c
*/
#include "test.h"
#include <string.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")

View File

@ -10,8 +10,6 @@
#ifndef TEST_H
#define TEST_H
#include "xcmd.h"
#ifdef __cplusplus
extern "C" {
#endif

View File

@ -15,10 +15,21 @@ extern "C" {
#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缓存 */
#endif
#ifndef XCMD_HISTORY_MAX_NUM
#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)
#undef XCMD_PRINT_BUF_MAX_LENGTH

View File

@ -1,7 +1,7 @@
#include "../inc/xcmd.h"
#include "../inc/xcmd_confg.h"
#include "../inc/xcmd_default_cmds.h"
#include "../inc/xcmd_default_keys.h"
#include "xcmd_confg.h"
#include "xcmd.h"
#include "xcmd_default_cmds.h"
#include "xcmd_default_keys.h"
#include <stdlib.h>
#include <stdio.h>

View File

@ -6,9 +6,9 @@
* @Description: In User Settings Edit
* @FilePath: /xcmd/src/xcmd_default_cmds.c
*/
#include "../inc/xcmd_default_cmds.h"
#include "../inc/xcmd.h"
#include "../inc/xcmd_confg.h"
#include "xcmd_confg.h"
#include "xcmd_default_cmds.h"
#include "xcmd.h"
#include <stdlib.h>
static void cmd_clear(int argc, char* argv[])

View File

@ -6,9 +6,9 @@
* @Description: In User Settings Edit
* @FilePath: /xcmd/src/xcmd_default_keys.c
*/
#include "../inc/xcmd_default_keys.h"
#include "../inc/xcmd_confg.h"
#include "../inc/xcmd.h"
#include "xcmd_confg.h"
#include "xcmd.h"
#include "xcmd_default_keys.h"
static int xcmd_del_char(void *pv)
{