Skip to content

Commit

Permalink
优化 最大历史记录设置为0s时移除相关代码
Browse files Browse the repository at this point in the history
  • Loading branch information
NevermindZZT committed Jun 27, 2021
1 parent 6b79f9a commit a34f08a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# letter shell 3.x

![version](https://img.shields.io/badge/version-3.1.0-brightgreen.svg)
![version](https://img.shields.io/badge/version-3.1.1-brightgreen.svg)
![standard](https://img.shields.io/badge/standard-c99-brightgreen.svg)
![build](https://img.shields.io/badge/build-2021.05.24-brightgreen.svg)
![build](https://img.shields.io/badge/build-2021.06.27-brightgreen.svg)
![license](https://img.shields.io/badge/license-MIT-brightgreen.svg)

一个功能强大的嵌入式shell
Expand Down Expand Up @@ -284,7 +284,7 @@ letter shell采取一个静态数组对定义的多个shell进行管理,shell
### 执行未导出函数
letter shell支持通过函数地址直接执行函数,可以方便执行那些没有导出,但是有临时需要使用的函数,使用命令`exec [addr] [args]`执行,使用此功能需要开启`SHELL_EXEC_UNDEF_FUNC`宏,注意,由于直接操作函数地址执行,如果给进的地址有误,可能引起程序崩溃
letter shell支持通过函数地址直接执行函数,可以方便执行那些没有导出,但是又临时需要使用的函数,使用命令`exec [addr] [args]`执行,使用此功能需要开启`SHELL_EXEC_UNDEF_FUNC`宏,注意,由于直接操作函数地址执行,如果给进的地址有误,可能引起程序崩溃
函数的地址可以通过编译生成的文件查找,比如说对于keil,可以在`.map`文件中查找到每个函数的地址,对于keil,`.map`文件中的地址需要偏移一个字节,才可以成功执行,比如说`shellClear`函数地址为`0x08028620`,则通过`exec`执行应为`exec 0x08028621`
Expand All @@ -298,7 +298,7 @@ letter shell 3.x将可执行的函数命令定义,用户定义,按键定义
letter shell 支持使用命令导出方式和命令表方式进行命令的添加,定义,通过宏```SHELL_USING_CMD_EXPORT```控制
命令导出方式支持keil,IAR(未测试)以及GCC
命令导出方式支持keil,IAR以及GCC
1. 命令导出方式
Expand Down
15 changes: 12 additions & 3 deletions src/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,18 +169,21 @@ void shellInit(Shell *shell, char *buffer, unsigned short size)
{
shell->parser.length = 0;
shell->parser.cursor = 0;
shell->history.offset = 0;
shell->history.number = 0;
shell->history.record = 0;
shell->info.user = NULL;
shell->status.isChecked = 1;

shell->parser.buffer = buffer;
shell->parser.bufferSize = size / (SHELL_HISTORY_MAX_NUMBER + 1);

#if SHELL_HISTORY_MAX_NUMBER > 0
shell->history.offset = 0;
shell->history.number = 0;
shell->history.record = 0;
for (short i = 0; i < SHELL_HISTORY_MAX_NUMBER; i++)
{
shell->history.item[i] = buffer + shell->parser.bufferSize * (i + 1);
}
#endif /** SHELL_HISTORY_MAX_NUMBER > 0 */

#if SHELL_USING_CMD_EXPORT == 1
#if defined(__CC_ARM) || (defined(__ARMCC_VERSION) && __ARMCC_VERSION >= 6000000)
Expand Down Expand Up @@ -1272,6 +1275,7 @@ static void shellWriteReturnValue(Shell *shell, int value)
}


#if SHELL_HISTORY_MAX_NUMBER > 0
/**
* @brief shell历史记录添加
*
Expand Down Expand Up @@ -1351,6 +1355,7 @@ static void shellHistory(Shell *shell, signed char dir)
}

}
#endif /** SHELL_HISTORY_MAX_NUMBER > 0 */


/**
Expand Down Expand Up @@ -1383,7 +1388,9 @@ void shellExec(Shell *shell)

if (shell->status.isChecked)
{
#if SHELL_HISTORY_MAX_NUMBER > 0
shellHistoryAdd(shell);
#endif /** SHELL_HISTORY_MAX_NUMBER > 0 */
shellParserParam(shell);
shell->parser.length = shell->parser.cursor = 0;
if (shell->parser.paramCount == 0)
Expand Down Expand Up @@ -1412,6 +1419,7 @@ void shellExec(Shell *shell)
}


#if SHELL_HISTORY_MAX_NUMBER > 0
/**
* @brief shell上方向键输入
*
Expand All @@ -1434,6 +1442,7 @@ void shellDown(Shell *shell)
shellHistory(shell, -1);
}
SHELL_EXPORT_KEY(SHELL_CMD_PERMISSION(0), 0x1B5B4200, shellDown, down);
#endif /** SHELL_HISTORY_MAX_NUMBER > 0 */


/**
Expand Down
4 changes: 3 additions & 1 deletion src/shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#include "shell_cfg.h"

#define SHELL_VERSION "3.1.0" /**< 版本号 */
#define SHELL_VERSION "3.1.1" /**< 版本号 */


/**
Expand Down Expand Up @@ -341,13 +341,15 @@ typedef struct shell_def
unsigned short paramCount; /**< 参数数量 */
int keyValue; /**< 输入按键键值 */
} parser;
#if SHELL_HISTORY_MAX_NUMBER > 0
struct
{
char *item[SHELL_HISTORY_MAX_NUMBER]; /**< 历史记录 */
unsigned short number; /**< 历史记录数 */
unsigned short record; /**< 当前记录位置 */
signed short offset; /**< 当前历史记录偏移 */
} history;
#endif /** SHELL_HISTORY_MAX_NUMBER > 0 */
struct
{
void *base; /**< 命令表基址 */
Expand Down

0 comments on commit a34f08a

Please sign in to comment.