mirror of
https://github.com/NevermindZZT/letter-shell.git
synced 2025-01-21 10:02:54 +08:00
新增 shell格式化输入
This commit is contained in:
parent
38b8c7795f
commit
cf3f6d7f1f
@ -112,6 +112,13 @@
|
|||||||
*/
|
*/
|
||||||
#define SHELL_PRINT_BUFFER 128
|
#define SHELL_PRINT_BUFFER 128
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief shell格式化输入的缓冲大小
|
||||||
|
* 为0时不使用shell格式化输入
|
||||||
|
* @note shell格式化输入会阻塞shellTask, 仅适用于在有操作系统的情况下使用
|
||||||
|
*/
|
||||||
|
#define SHELL_SCAN_BUFFER 128
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 获取系统时间(ms)
|
* @brief 获取系统时间(ms)
|
||||||
* 定义此宏为获取系统Tick,如`HAL_GetTick()`
|
* 定义此宏为获取系统Tick,如`HAL_GetTick()`
|
||||||
|
@ -150,3 +150,15 @@ void shellKeyTest(void)
|
|||||||
}
|
}
|
||||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC),
|
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC),
|
||||||
keyTest, shellKeyTest, key test);
|
keyTest, shellKeyTest, key test);
|
||||||
|
|
||||||
|
void shellScanTest(void)
|
||||||
|
{
|
||||||
|
int a;
|
||||||
|
char b[12];
|
||||||
|
shellScan(shellGetCurrent(), "%x %s\n", &a, b);
|
||||||
|
shellPrint(shellGetCurrent(), "result: a = %x, b = %s\r\n", a, b);
|
||||||
|
}
|
||||||
|
SHELL_EXPORT_CMD(
|
||||||
|
SHELL_CMD_PERMISSION(0x00)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_DISABLE_RETURN,
|
||||||
|
scanTest, shellScanTest, test scan);
|
||||||
|
|
||||||
|
36
src/shell.c
36
src/shell.c
@ -366,6 +366,42 @@ void shellPrint(Shell *shell, char *fmt, ...)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if SHELL_SCAN_BUFFER > 0
|
||||||
|
/**
|
||||||
|
* @brief shell格式化输入
|
||||||
|
*
|
||||||
|
* @param shell shell对象
|
||||||
|
* @param fmt 格式化字符串
|
||||||
|
* @param ... 参数
|
||||||
|
*/
|
||||||
|
void shellScan(Shell *shell, char *fmt, ...)
|
||||||
|
{
|
||||||
|
char buffer[SHELL_SCAN_BUFFER];
|
||||||
|
va_list vargs;
|
||||||
|
short index = 0;
|
||||||
|
|
||||||
|
SHELL_ASSERT(shell, return);
|
||||||
|
|
||||||
|
if (shell->read)
|
||||||
|
{
|
||||||
|
do {
|
||||||
|
if (shell->read(&buffer[index]) == 0)
|
||||||
|
{
|
||||||
|
shell->write(buffer[index]);
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
} while (buffer[index -1] != '\r' && buffer[index -1] != '\n' && index < SHELL_SCAN_BUFFER);
|
||||||
|
shellWriteString(shell, "\r\n");
|
||||||
|
buffer[index] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
va_start(vargs, fmt);
|
||||||
|
vsscanf(buffer, fmt, vargs);
|
||||||
|
va_end(vargs);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief shell 检查命令权限
|
* @brief shell 检查命令权限
|
||||||
*
|
*
|
||||||
|
@ -410,6 +410,7 @@ typedef struct
|
|||||||
void shellInit(Shell *shell, char *buffer, unsigned short size);
|
void shellInit(Shell *shell, char *buffer, unsigned short size);
|
||||||
unsigned short shellWriteString(Shell *shell, const char *string);
|
unsigned short shellWriteString(Shell *shell, const char *string);
|
||||||
void shellPrint(Shell *shell, char *fmt, ...);
|
void shellPrint(Shell *shell, char *fmt, ...);
|
||||||
|
void shellScan(Shell *shell, char *fmt, ...);
|
||||||
Shell* shellGetCurrent(void);
|
Shell* shellGetCurrent(void);
|
||||||
void shellHandler(Shell *shell, char data);
|
void shellHandler(Shell *shell, char data);
|
||||||
void shellWriteEndLine(Shell *shell, char *buffer, int len);
|
void shellWriteEndLine(Shell *shell, char *buffer, int len);
|
||||||
|
@ -111,6 +111,13 @@
|
|||||||
*/
|
*/
|
||||||
#define SHELL_PRINT_BUFFER 128
|
#define SHELL_PRINT_BUFFER 128
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief shell格式化输入的缓冲大小
|
||||||
|
* 为0时不使用shell格式化输入
|
||||||
|
* @note shell格式化输入会阻塞shellTask, 仅适用于在有操作系统的情况下使用
|
||||||
|
*/
|
||||||
|
#define SHELL_SCAN_BUFFER 0
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 获取系统时间(ms)
|
* @brief 获取系统时间(ms)
|
||||||
* 定义此宏为获取系统Tick,如`HAL_GetTick()`
|
* 定义此宏为获取系统Tick,如`HAL_GetTick()`
|
||||||
|
Loading…
x
Reference in New Issue
Block a user