1
0
mirror of https://github.com/NevermindZZT/letter-shell.git synced 2025-01-01 09:58:41 +08:00

新增 shell格式化输入

This commit is contained in:
Letter 2020-12-15 20:43:14 +08:00
parent 38b8c7795f
commit cf3f6d7f1f
5 changed files with 63 additions and 0 deletions

View File

@ -112,6 +112,13 @@
*/
#define SHELL_PRINT_BUFFER 128
/**
* @brief shell格式化输入的缓冲大小
* 0使shell格式化输入
* @note shell格式化输入会阻塞shellTask, 使
*/
#define SHELL_SCAN_BUFFER 128
/**
* @brief (ms)
* Tick`HAL_GetTick()`

View File

@ -150,3 +150,15 @@ void shellKeyTest(void)
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC),
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);

View File

@ -366,6 +366,42 @@ void shellPrint(Shell *shell, char *fmt, ...)
#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
*

View File

@ -410,6 +410,7 @@ typedef struct
void shellInit(Shell *shell, char *buffer, unsigned short size);
unsigned short shellWriteString(Shell *shell, const char *string);
void shellPrint(Shell *shell, char *fmt, ...);
void shellScan(Shell *shell, char *fmt, ...);
Shell* shellGetCurrent(void);
void shellHandler(Shell *shell, char data);
void shellWriteEndLine(Shell *shell, char *buffer, int len);

View File

@ -111,6 +111,13 @@
*/
#define SHELL_PRINT_BUFFER 128
/**
* @brief shell格式化输入的缓冲大小
* 0使shell格式化输入
* @note shell格式化输入会阻塞shellTask, 使
*/
#define SHELL_SCAN_BUFFER 0
/**
* @brief (ms)
* Tick`HAL_GetTick()`