1
0
mirror of https://github.com/NevermindZZT/letter-shell.git synced 2025-01-21 10:02:54 +08:00

Merge pull request #87 from NevermindZZT/master

merge master
This commit is contained in:
Letter 2021-05-31 22:45:45 +08:00 committed by GitHub
commit 3da93f4c03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 89 additions and 31 deletions

View File

@ -2,7 +2,7 @@
![version](https://img.shields.io/badge/version-3.1.0-brightgreen.svg)
![standard](https://img.shields.io/badge/standard-c99-brightgreen.svg)
![build](https://img.shields.io/badge/build-2021.05.09-brightgreen.svg)
![build](https://img.shields.io/badge/build-2021.05.24-brightgreen.svg)
![license](https://img.shields.io/badge/license-MIT-brightgreen.svg)
一个功能强大的嵌入式shell
@ -108,7 +108,7 @@
*
* @return unsigned short 实际写入的字符数量
*/
typedef unsigned short (*shellWrite)(const char *data, unsigned short len);
typedef unsigned short (*shellWrite)(char *data, unsigned short len);
```
3. 申请一片缓冲区

View File

@ -13,6 +13,8 @@
#define __SHELL_CFG_H__
#include "stm32f4xx_hal.h"
#include "FreeRTOS.h"
#include "portable.h"
/**
@ -33,12 +35,13 @@
* @brief 使shell伴生对象
* ()使
*/
#define SHELL_USING_COMPANION 0
#define SHELL_USING_COMPANION 1
/**
* @brief shell尾行模式
*/
#define SHELL_SUPPORT_END_LINE 0
#define SHELL_SUPPORT_END_LINE 1
/**
* @brief
@ -64,7 +67,7 @@
* @brief 使LF作为命令行回车触发
* SHELL_ENTER_CR同时开启
*/
#define SHELL_ENTER_LF 0
#define SHELL_ENTER_LF 1
/**
* @brief 使CR作为命令行回车触发
@ -113,6 +116,13 @@
*/
#define SHELL_PRINT_BUFFER 128
/**
* @brief shell格式化输入的缓冲大小
* 0使shell格式化输入
* @note shell格式化输入会阻塞shellTask, 使
*/
#define SHELL_SCAN_BUFFER 128
/**
* @brief (ms)
* Tick`HAL_GetTick()`
@ -120,17 +130,23 @@
*/
#define SHELL_GET_TICK() HAL_GetTick()
/**
* @brief 使
* @note 使shell锁时
*/
#define SHELL_USING_LOCK 1
/**
* @brief shell内存分配
* shell本身不需要此接口使shell伴生对象
*/
#define SHELL_MALLOC(size) 0
#define SHELL_MALLOC(size) pvPortMalloc(size)
/**
* @brief shell内存释放
* shell本身不需要此接口使shell伴生对象
*/
#define SHELL_FREE(obj) 0
#define SHELL_FREE(obj) vPortFree(obj)
/**
* @brief shell信息
@ -162,3 +178,4 @@
#define SHELL_LOCK_TIMEOUT 0 * 60 * 1000
#endif

View File

@ -9,23 +9,33 @@
*
*/
#include "FreeRTOS.h"
#include "task.h"
#include "shell.h"
#include "serial.h"
#include "stm32f4xx_hal.h"
#include "usart.h"
#include "cevent.h"
#include "log.h"
Shell shell;
char shellBuffer[512];
static SemaphoreHandle_t shellMutex;
/**
* @brief shell写
*
* @param data
* @param len
*
* @return short
*/
void userShellWrite(char data)
short userShellWrite(char *data, unsigned short len)
{
serialTransmit(&debugSerial, (uint8_t *)&data, 1, 0xFF);
serialTransmit(&debugSerial, (uint8_t *)data, len, 0x1FF);
return len;
}
@ -33,30 +43,58 @@ void userShellWrite(char data)
* @brief shell读
*
* @param data
* @return char
* @param len
*
* @return short
*/
signed char userShellRead(char *data)
short userShellRead(char *data, unsigned short len)
{
if (serialReceive(&debugSerial, (uint8_t *)data, 1, 0) == 1)
return serialReceive(&debugSerial, (uint8_t *)data, len, 0);
}
/**
* @brief shell上锁
*
* @param shell shell
*
* @return int 0
*/
int userShellLock(Shell *shell)
{
xSemaphoreTakeRecursive(shellMutex, portMAX_DELAY);
return 0;
}
else
/**
* @brief shell解锁
*
* @param shell shell
*
* @return int 0
*/
int userShellUnlock(Shell *shell)
{
return -1;
xSemaphoreGiveRecursive(shellMutex);
return 0;
}
}
/**
* @brief shell初始化
*
*/
void userShellInit(void)
{
shellMutex = xSemaphoreCreateMutex();
shell.write = userShellWrite;
shell.read = userShellRead;
shell.lock = userShellLock;
shell.unlock = userShellUnlock;
shellInit(&shell, shellBuffer, 512);
if (xTaskCreate(shellTask, "shell", 256, &shell, 5, NULL) != pdPASS)
{
logError("shell task creat failed");
}
}
CEVENT_EXPORT(EVENT_INIT_STAGE2, userShellInit);

View File

@ -152,3 +152,4 @@ typedef struct shell_command_cpp_key
#endif /**< __SHELL_CPP_H__ */

View File

@ -258,7 +258,7 @@ Shell* shellGetCurrent(void)
* @param shell shell对象
* @param data
*/
static void shellWriteByte(Shell *shell, const char data)
static void shellWriteByte(Shell *shell, char data)
{
shell->write(&data, 1);
}
@ -275,13 +275,13 @@ static void shellWriteByte(Shell *shell, const char data)
unsigned short shellWriteString(Shell *shell, const char *string)
{
unsigned short count = 0;
char *p = string;
const char *p = string;
SHELL_ASSERT(shell->write, return 0);
while(*p++)
{
count ++;
}
return shell->write(string, count);
return shell->write((char *)string, count);
}
@ -296,7 +296,7 @@ unsigned short shellWriteString(Shell *shell, const char *string)
static unsigned short shellWriteCommandDesc(Shell *shell, const char *string)
{
unsigned short count = 0;
char *p = string;
const char *p = string;
SHELL_ASSERT(shell->write, return 0);
while (*p && *p != '\r' && *p != '\n')
{
@ -306,12 +306,12 @@ static unsigned short shellWriteCommandDesc(Shell *shell, const char *string)
if (count > 36)
{
shell->write(string, 36);
shell->write((char *)string, 36);
shell->write("...", 3);
}
else
{
shell->write(string, count);
shell->write((char *)string, count);
}
return count > 36 ? 36 : 39;
}
@ -389,7 +389,7 @@ void shellScan(Shell *shell, char *fmt, ...)
do {
if (shell->read(&buffer[index], 1) == 1)
{
shell->write(buffer[index], 1);
shell->write(&buffer[index], 1);
index++;
}
} while (buffer[index -1] != '\r' && buffer[index -1] != '\n' && index < SHELL_SCAN_BUFFER);
@ -1757,7 +1757,7 @@ void shellWriteEndLine(Shell *shell, char *buffer, int len)
shellWriteString(shell, shell->parser.buffer);
for (short i = 0; i < shell->parser.length - shell->parser.cursor; i++)
{
shell->write('\b', 1);
shellWriteByte(shell, '\b');
}
}
}
@ -1927,3 +1927,4 @@ SHELL_EXPORT_CMD(
SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN)|SHELL_CMD_DISABLE_RETURN,
exec, shellExecute, execute function undefined);
#endif

View File

@ -360,7 +360,7 @@ typedef struct shell_def
unsigned char tabFlag : 1; /**< tab标志 */
} status;
signed short (*read)(char *, unsigned short); /**< shell读函数 */
signed short (*write)(const char *, unsigned short); /**< shell写函数 */
signed short (*write)(char *, unsigned short); /**< shell写函数 */
#if SHELL_USING_LOCK == 1
int (*lock)(struct shell_def *); /**< shell 加锁 */
int (*unlock)(struct shell_def *); /**< shell 解锁 */
@ -461,3 +461,4 @@ void *shellCompanionGet(Shell *shell, int id);
#endif