下载 FreeRTOS
 

出色的 RTOS & 嵌入式软件

最新资讯
简化任何设备的身份验证云连接。
利用 CoAP 设计节能型云连接 IoT 解决方案。
11.0.0 版 FreeRTOS 内核简介:
FreeRTOS 路线图和代码贡献流程。
使用 FreeRTOS 实现 OPC-UA over TSN。

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
{
/* The command line input string. This is the string that the user enters
to run the command. For example, the FreeRTOS-Plus-CLI help function uses the
string "help". If a user types "help" the help command executes. */

const char * const pcCommand;

/* A string that describes the command, and its expected parameters. This
is the string that is output when the help command is executed. The string
must start with the command itself, and end with "rn". For example, the
help string for the help command itself is:
"help: Returns a list of all the commandsrn" */

const char * const pcHelpString;

/* A pointer to the function that implements the command behaviour
(effectively the function name). */

const pdCOMMAND_LINE_CALLBACK pxCommandInterpreter;

/* The number of parameters required by the command. FreeRTOS-Plus-CLI will only
execute the command if the number of parameters entered on the command line
matches this number. */

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.