修改example

This commit is contained in:
hqm 2021-09-22 23:26:10 +08:00
parent 2e28faa27c
commit afb2d72182
15 changed files with 215 additions and 666 deletions

View File

@ -1,9 +1,16 @@
/*
* @Author: your name
* @Date: 2021-09-22 22:54:42
* @LastEditTime: 2021-09-22 22:54:42
* @LastEditors: your name
* @Description: In User Settings Edit
* @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"
extern void test_cmd_init(void);
#include "test.h"
int cmd_get_char(uint8_t *ch)
{
@ -24,33 +31,11 @@ int cmd_put_char(uint8_t ch)
return 1;
}
int cmd_ctr_a(void* pv)
{
xcmd_print("this is ctr+a\n");
}
int cmd_ctr_c(void* pv)
{
exit(0);
return 0;
}
static xcmd_key_t user_keys[] =
{
{CTR_A, cmd_ctr_a, NULL},
{CTR_C, cmd_ctr_c, NULL},
};
void user_keys_init(void)
{
xcmd_key_register(user_keys, sizeof(user_keys)/sizeof(xcmd_key_t));
}
void setup() {
Serial.begin(115200);
xcmd_init(cmd_get_char, cmd_put_char);
test_cmd_init();
user_keys_init();
test_keys_init();
}
void loop() {

230
example/linux/test_cmds.c → example/arduino/test.c Executable file → Normal file
View File

@ -1,102 +1,128 @@
/*
* @Author: your name
* @Date: 2021-09-14 23:58:24
* @LastEditTime: 2021-09-16 22:57:45
* @LastEditors: your name
* @Description: In User Settings Edit
* @FilePath: /xcmd/example/linux/test_cmds.c
*/
#include "xcmd.h"
#include <stdint.h>
#include <stdio.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 xcmd_t cmds[] =
{
{"echo", cmd_echo, "echo anything", NULL},
{"example", cmd_example, "example [-f|-i|-s] [val]", NULL},
};
void test_cmd_init(void)
{
xcmd_cmd_register(cmds, sizeof(cmds)/sizeof(xcmd_t));
}
/*
* @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));
}

28
example/arduino/test.h Normal file
View File

@ -0,0 +1,28 @@
/*
* @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 */

View File

@ -1,121 +0,0 @@
/*
* @Author: your name
* @Date: 2021-09-14 23:58:24
* @LastEditTime: 2021-09-16 22:57:45
* @LastEditors: your name
* @Description: In User Settings Edit
* @FilePath: /xcmd/example/linux/test_cmds.c
*/
#include "inc/xcmd.h"
#include <stdint.h>
#include <stdio.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_ls(int argc, char* argv[])
{
xcmd_t *p = xcmd_cmdlist_get();
uint8_t i = 0;
while(p)
{
xcmd_print("%-12s",p->name);
if(++i == 4)
{
xcmd_print("\r\n");
i = 0;
}
p = p->next;
}
xcmd_print("\r\n");
}
static void 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<argc; i++)
{
xcmd_print("%s\r\n", argv[i]);
}
}
if(strcmp(argv[1], "int") == 0)
{
for(i=2; i<argc; i++)
{
xcmd_print("%d\r\n", atoi(argv[i]));
}
}
if(strcmp(argv[1], "float") == 0)
{
for(i=2; i<argc; i++)
{
xcmd_print("%f\r\n", atof(argv[i]));
}
}
}
}
static xcmd_t cmds[] =
{
{"echo", cmd_echo, "echo anything", NULL},
{"ls", cmd_ls, "ls", NULL},
{"example", cmd_example, "example [str|int|float] [val]", NULL},
};
void test_cmd_init(void)
{
xcmd_cmd_register(cmds, sizeof(cmds)/sizeof(xcmd_t));
}

View File

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

View File

@ -1,7 +1,7 @@
/*
* @Author: your name
* @Date: 2021-09-14 23:58:24
* @LastEditTime: 2021-09-16 23:20:43
* @LastEditTime: 2021-09-22 22:50:56
* @LastEditors: Please set LastEditors
* @Description: In User Settings Edit
* @FilePath: /xcmd/example/linux/linux_main.c
@ -14,8 +14,7 @@
#include "xcmd_default_cmds.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
extern void test_cmd_init(void);
#include "test.h"
int cmd_get_char(unsigned char *ch)
{
@ -29,33 +28,11 @@ int cmd_put_char(unsigned char ch)
return 1;
}
int cmd_ctr_a(void* pv)
{
xcmd_print("this is ctr+a\n");
return 0;
}
int cmd_ctr_c(void* pv)
{
exit(0);
}
static xcmd_key_t user_keys[] =
{
{CTR_A, cmd_ctr_a, NULL},
{CTR_C, cmd_ctr_c, NULL},
};
void user_keys_init(void)
{
xcmd_key_register(user_keys, sizeof(user_keys)/sizeof(xcmd_key_t));
}
void app_main(void)
{
xcmd_init(cmd_get_char, cmd_put_char);
test_cmd_init();
user_keys_init();
test_keys_init();
while(1)
{

View File

@ -1,102 +0,0 @@
/*
* @Author: your name
* @Date: 2021-09-14 23:58:24
* @LastEditTime: 2021-09-16 22:57:45
* @LastEditors: your name
* @Description: In User Settings Edit
* @FilePath: /xcmd/example/linux/test_cmds.c
*/
#include "xcmd.h"
#include <stdint.h>
#include <stdio.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], "str") == 0)
{
for(i=2; i<argc; i++)
{
xcmd_print("%s\r\n", argv[i]);
}
}
if(strcmp(argv[1], "int") == 0)
{
for(i=2; i<argc; i++)
{
xcmd_print("%d\r\n", atoi(argv[i]));
}
}
if(strcmp(argv[1], "float") == 0)
{
for(i=2; i<argc; i++)
{
xcmd_print("%f\r\n", atof(argv[i]));
}
}
}
}
static xcmd_t cmds[] =
{
{"echo", cmd_echo, "echo anything", NULL},
{"example", cmd_example, "example [-f|-i|-s] [val]", NULL},
};
void test_cmd_init(void)
{
xcmd_cmd_register(cmds, sizeof(cmds)/sizeof(xcmd_t));
}

View File

@ -1,14 +1,18 @@
OBJ += xcmd.o xcmd_default_keys.o xcmd_default_cmds.o test_cmds.o linux_main.o
OBJ += xcmd.o xcmd_default_keys.o xcmd_default_cmds.o linux_main.o test.o
BIN = xcmder
VPATH := ../../src
INC += ../../inc
VPATH := ../../src \
../../extensions/test/src
INC += -I../../inc \
-I../../extensions/test/inc
OBJ_WITH_BUILD_DIR:=$(addprefix build/,$(OBJ))
all: mkbuilddir $(OBJ_WITH_BUILD_DIR)
gcc $(OBJ_WITH_BUILD_DIR) -o $(BIN) -Wl,-Map,$(BIN).map
build/%.o:%.c
gcc -g -Wall -c -I$(INC) -o $@ $<
gcc -g -Wall -c $(INC) -o $@ $<
.PHONY:mkbuilddir
mkbuilddir:

View File

@ -1,7 +1,7 @@
/*
* @Author: your name
* @Date: 2021-09-14 23:58:24
* @LastEditTime: 2021-09-16 23:20:43
* @LastEditTime: 2021-09-22 23:13:05
* @LastEditors: Please set LastEditors
* @Description: In User Settings Edit
* @FilePath: /xcmd/example/linux/linux_main.c
@ -16,9 +16,7 @@
#include<sys/types.h>
#include<sys/socket.h>
#include <termio.h>
extern void test_cmd_init(void);
#include "test.h"
int getch(void)
{
@ -56,34 +54,27 @@ int cmd_put_char(uint8_t ch)
return 1;
}
int cmd_ctr_a(void* pv)
{
xcmd_print("this is ctr+a\n");
return 0;
}
int cmd_ctr_c(void* pv)
static int key_ctr_c(void* pv)
{
exit(0);
}
static xcmd_key_t user_keys[] =
static xcmd_key_t keys[] =
{
{CTR_A, cmd_ctr_a, NULL},
{CTR_C, cmd_ctr_c, NULL},
{CTR_C, key_ctr_c, NULL},
};
void user_keys_init(void)
{
xcmd_key_register(user_keys, sizeof(user_keys)/sizeof(xcmd_key_t));
xcmd_key_register(keys, sizeof(keys)/sizeof(xcmd_key_t));
}
int main(void)
{
xcmd_init(cmd_get_char, cmd_put_char);
test_cmd_init();
test_keys_init();
user_keys_init();
while(1)
{
xcmd_task();

View File

@ -312,10 +312,10 @@
</ArmAdsMisc>
<Cads>
<interw>1</interw>
<Optim>1</Optim>
<Optim>4</Optim>
<oTime>0</oTime>
<SplitLS>0</SplitLS>
<OneElfS>0</OneElfS>
<OneElfS>1</OneElfS>
<Strict>0</Strict>
<EnumInt>0</EnumInt>
<PlainCh>0</PlainCh>
@ -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</IncludePath>
<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>
</VariousControls>
</Cads>
<Aads>
@ -553,11 +553,6 @@
<FileType>1</FileType>
<FilePath>..\User\main.c</FilePath>
</File>
<File>
<FileName>test_cmds.c</FileName>
<FileType>1</FileType>
<FilePath>..\User\test_cmds.c</FilePath>
</File>
</Files>
</Group>
<Group>
@ -580,6 +575,16 @@
</File>
</Files>
</Group>
<Group>
<GroupName>extensions</GroupName>
<Files>
<File>
<FileName>test.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\..\extensions\test\src\test.c</FilePath>
</File>
</Files>
</Group>
</Groups>
</Target>
</Targets>

View File

@ -4,8 +4,7 @@
#include "uart.h"
#include <stdio.h>
#include "xcmd.h"
extern void test_cmd_init(void);
#include "test.h"
int cmd_get_char(uint8_t *ch)
{
@ -17,29 +16,6 @@ int cmd_put_char(uint8_t ch)
return uartWrChar(ch);
}
int cmd_ctr_a(void* pv)
{
xcmd_print("this is ctr+a\n");
return 0;
}
int cmd_ctr_c(void* pv)
{
return 0;
}
static xcmd_key_t user_keys[] =
{
{CTR_A, cmd_ctr_a, NULL},
{CTR_C, cmd_ctr_c, NULL},
};
void user_keys_init(void)
{
xcmd_key_register(user_keys, sizeof(user_keys)/sizeof(xcmd_key_t));
}
int main(void)
{
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
@ -48,7 +24,7 @@ int main(void)
xcmd_init(cmd_get_char, cmd_put_char);
test_cmd_init();
user_keys_init();
test_keys_init();
while(1)
{

View File

@ -1,102 +0,0 @@
/*
* @Author: your name
* @Date: 2021-09-14 23:58:24
* @LastEditTime: 2021-09-16 22:57:45
* @LastEditors: your name
* @Description: In User Settings Edit
* @FilePath: /xcmd/example/linux/test_cmds.c
*/
#include "xcmd.h"
#include <stdint.h>
#include <stdio.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], "str") == 0)
{
for(i=2; i<argc; i++)
{
xcmd_print("%s\r\n", argv[i]);
}
}
if(strcmp(argv[1], "int") == 0)
{
for(i=2; i<argc; i++)
{
xcmd_print("%d\r\n", atoi(argv[i]));
}
}
if(strcmp(argv[1], "float") == 0)
{
for(i=2; i<argc; i++)
{
xcmd_print("%f\r\n", atof(argv[i]));
}
}
}
}
static xcmd_t cmds[] =
{
{"echo", cmd_echo, "echo anything", NULL},
{"example", cmd_example, "example [-f|-i|-s] [val]", NULL},
};
void test_cmd_init(void)
{
xcmd_cmd_register(cmds, sizeof(cmds)/sizeof(xcmd_t));
}

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</IncludePath>
<IncludePath>..\FWLIB\CORE;..\FWLIB\inc;..\System\debug;..\System\delay;..\System\sys;..\System\debug;..\user;..\user\bsp\inc;..\user\bsp;..\..\..\..\..\inc;..\..\..\..\..\extensions\test\inc</IncludePath>
</VariousControls>
</Cads>
<Aads>
@ -642,11 +642,6 @@
<FileType>5</FileType>
<FilePath>..\user\config.h</FilePath>
</File>
<File>
<FileName>test_cmds.c</FileName>
<FileType>1</FileType>
<FilePath>..\user\test_cmds.c</FilePath>
</File>
</Files>
</Group>
<Group>
@ -669,6 +664,16 @@
</File>
</Files>
</Group>
<Group>
<GroupName>extensions</GroupName>
<Files>
<File>
<FileName>test.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\..\extensions\test\src\test.c</FilePath>
</File>
</Files>
</Group>
</Groups>
</Target>
</Targets>

View File

@ -4,6 +4,7 @@
#include "delay.h"
#include <stdio.h>
#include "xcmd.h"
#include "test.h"
extern void test_cmd_init(void);
@ -23,36 +24,13 @@ int cmd_put_char(uint8_t ch)
return uartWrChar(DENUG_UART, ch);
}
int cmd_ctr_a(void* pv)
{
xcmd_print("this is ctr+a\n");
return 0;
}
int cmd_ctr_c(void* pv)
{
return 0;
}
static xcmd_key_t user_keys[] =
{
{CTR_A, cmd_ctr_a, NULL},
{CTR_C, cmd_ctr_c, NULL},
};
void user_keys_init(void)
{
xcmd_key_register(user_keys, sizeof(user_keys)/sizeof(xcmd_key_t));
}
int main(void)
{
sysInit();
xcmd_init(cmd_get_char, cmd_put_char);
test_cmd_init();
user_keys_init();
test_keys_init();
while(1)
{

View File

@ -1,102 +0,0 @@
/*
* @Author: your name
* @Date: 2021-09-14 23:58:24
* @LastEditTime: 2021-09-16 22:57:45
* @LastEditors: your name
* @Description: In User Settings Edit
* @FilePath: /xcmd/example/linux/test_cmds.c
*/
#include "xcmd.h"
#include <stdint.h>
#include <stdio.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], "str") == 0)
{
for(i=2; i<argc; i++)
{
xcmd_print("%s\r\n", argv[i]);
}
}
if(strcmp(argv[1], "int") == 0)
{
for(i=2; i<argc; i++)
{
xcmd_print("%d\r\n", atoi(argv[i]));
}
}
if(strcmp(argv[1], "float") == 0)
{
for(i=2; i<argc; i++)
{
xcmd_print("%f\r\n", atof(argv[i]));
}
}
}
}
static xcmd_t cmds[] =
{
{"echo", cmd_echo, "echo anything", NULL},
{"example", cmd_example, "example [-f|-i|-s] [val]", NULL},
};
void test_cmd_init(void)
{
xcmd_cmd_register(cmds, sizeof(cmds)/sizeof(xcmd_t));
}