FreeRTOS_CLIRegisterCommand()
FreeRTOS_CLI.h
BaseType_t FreeRTOS_CLIRegisterCommand( CLI_Command_Definition_t *pxCommandToRegister )
FreeRTOS-Plus-CLI 是一个可扩展的框架,
应用程序编写者可以通过该框架定义并注册自己的命令行输入命令。 实现用户定义命令的行为的函数必须使用特定接口
,
如另一页面的描述所示。
此页面介绍了 FreeRTOS_CLIRegisterCommand () ,
它是用于向 FreeRTOS-Plus-CLI 注册命令的 API 函数。 命令通过将
实现命令行为的函数与文本字符串相关联
并告知 FreeRTOS-Plus-CLI 该关联的方式注册。
然后,FreeRTOS-Plus-CLI 将在每次输入命令文本字符串时自动运行该函数
。 阅读此页面后即可了解。
注意: 出现在代码中的 FreeRTOS_CLIRegisterCommand() 原型采用
指向 CLI_Command_Definition_t 类型的常量结构体的常量指针。 此处删除了常量限定符,
以使原型更易于阅读。
参数:
pxCommandToRegister
|
正在注册的命令,
由 CLI_Command_Definition_t 类型的结构体定义。 该结构体
在该表格下方描述。
|
返回:
如果命令成功注册,则返回 pdPASS。
如果由于没有足够的
FreeRTOS 堆
可用于创建新列表项,导致命令无法注册,则返回 pdFAIL。
CLI_Command_Definition_t
命令由 CLI_Command_Definition_t 类型的结构体定义,
结构体如下所示。 代码中的注释描述了
结构体成员。
typedef struct xCLI_COMMAND_DEFINITION
{
const char * const pcCommand;
const char * const pcHelpString;
const pdCOMMAND_LINE_CALLBACK pxCommandInterpreter;
char cExpectedNumberOfParameters;
} CLI_Command_Definition_t;
The CLI_Command_Definition_t structure
示例
一种 FreeRTOS-Plus-CLI 特色演示实现了文件系统
"del" 命令。 命令定义如下。
static const CLI_Command_Definition_t xDelCommand =
{
"del",
"del <filename>: Deletes <filename> from the diskrn",
prvDelCommand,
1
};
The definition of the file system del command
注册此命令后:
-
每次用户键入 “del” 时都会执行 prvDelCommand()。
-
输出 "del <filename>: Deletes <filename> from the diskrn"
来描述用户键入 “help” 时的 del 命令。
-
del 命令需要一个参数(被删除文件的名称
)。 如果输入参数的数量不是 1,FreeRTOS-Plus-CLI 将输出错误字符串,而不是执行
prvDelCommand()。
然后使用以下函数调用向 FreeRTOS-Plus-CLI 注册 del 命令:
FreeRTOS_CLIRegisterCommand( &xDelCommand );
Registering the xDelCommand structure with FreeRTOS-Plus-CLI
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.