You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
140 lines
5.7 KiB
Plaintext
140 lines
5.7 KiB
Plaintext
![]()
2 years ago
|
/******************************************************************************
|
||
|
* file include/cli.h
|
||
|
* author LandPower
|
||
|
* version 1.0.0
|
||
|
* date 10-Sep-2021
|
||
|
* brief This file provides all the headers of the cli functions.
|
||
|
|
||
|
******************************************************************************
|
||
|
* Attention
|
||
|
*
|
||
|
* <h2><center>© COPYRIGHT(c) 2021 LandPower</center></h2>
|
||
|
*
|
||
|
* Redistribution and use in source and binary forms, with or without modification,
|
||
|
* are permitted provided that the following conditions are met:
|
||
|
* 1. Redistributions of source code must retain the above copyright notice,
|
||
|
* this list of conditions and the following disclaimer.
|
||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||
|
* this list of conditions and the following disclaimer in the documentation
|
||
|
* and/or other materials provided with the distribution.
|
||
|
* 3. Neither the name of LandPower nor the names of its contributors may be used to
|
||
|
* endorse or promote products derived from this software without specific
|
||
|
* prior written permission.
|
||
|
*
|
||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||
|
*
|
||
|
******************************************************************************/
|
||
|
|
||
|
#ifndef _CLI_H_
|
||
|
#define _CLI_H_
|
||
|
|
||
|
/* Includes ------------------------------------------------------------------*/
|
||
|
#include "list.h"
|
||
|
|
||
|
/* Define --------------------------------------------------------------------*/
|
||
|
#define CLI_NODE_MAME_LEN 32
|
||
|
#define CLI_USERNAME_LEN 64
|
||
|
#define CLI_PARAM_LEN 32
|
||
|
|
||
|
#define CLI_USERNAME_DEFAULT "ld"
|
||
|
#define CLI_PASSWORD_DEFAULT "1"
|
||
|
|
||
|
/* Exported types ------------------------------------------------------------*/
|
||
|
/* The prototype to which callback functions used to process command line
|
||
|
commands must comply. buf is a buffer into which the output from
|
||
|
executing the command can be written, xWriteBufferLen is the length, in bytes of
|
||
|
the buf buffer, and pcCommandString is the entire string as input by
|
||
|
the user (from which parameters can be extracted). */
|
||
|
typedef int32_t (*CLI_COMMAND_CALLBACK)(const char *cmd_str);
|
||
|
|
||
|
/* 节点类型. */
|
||
|
typedef enum
|
||
|
{
|
||
|
CLI_NODE_COMMON = 0,
|
||
|
CLI_NODE_PASSWORD,
|
||
|
CLI_NODE_CONFIG,
|
||
|
CLI_NODE_COUNT,
|
||
|
} CLI_NODE_E;
|
||
|
|
||
|
/* The structure that defines command line commands. A command line command
|
||
|
should be defined by declaring a const structure of this type. */
|
||
|
typedef struct _cli_command_t
|
||
|
{
|
||
|
const char * const cmd_str; /* The command that causes pxCommandInterpreter to be executed. For example "help". Must be all lower case. */
|
||
|
const char * const help_str; /* 帮助字符串,解释命令的用途. */
|
||
|
const CLI_COMMAND_CALLBACK function; /* A pointer to the callback function that will return the output generated by the command. */
|
||
|
int8_t param_num; /* Commands expect a fixed number of parameters, which may be zero. */
|
||
|
} cli_command_t;
|
||
|
|
||
|
/* 命令保存链表结构体. */
|
||
|
typedef struct _cli_list_item_t
|
||
|
{
|
||
|
const cli_command_t *cmd;
|
||
|
struct list_head list;
|
||
|
} cli_list_item_t;
|
||
|
|
||
|
/* 命令行节点结构体. */
|
||
|
typedef struct _cli_node_t
|
||
|
{
|
||
|
char name[CLI_NODE_MAME_LEN];
|
||
|
uint16_t index;
|
||
|
uint16_t upper_node;
|
||
|
struct list_head list;
|
||
|
} cli_node_t;
|
||
|
|
||
|
/* 命令行节点结构体. */
|
||
|
typedef struct _cli_user_t
|
||
|
{
|
||
|
char username[CLI_USERNAME_LEN];
|
||
|
char password[CLI_USERNAME_LEN];
|
||
|
struct list_head list;
|
||
|
} cli_user_t;
|
||
|
|
||
|
/* Exported macro ------------------------------------------------------------*/
|
||
|
|
||
|
/* Extern global variables ---------------------------------------------------*/
|
||
|
|
||
|
/* Extern functions ----------------------------------------------------------*/
|
||
|
/* Register the command passed in using the pxCommandToRegister parameter.
|
||
|
Registering a command adds the command to the list of commands that are
|
||
|
handled by the command interpreter. Once a command has been registered it
|
||
|
can be executed from the command line. */
|
||
|
int32_t cli_register_command(const cli_command_t* const cmd, CLI_NODE_E node);
|
||
|
|
||
|
/* Runs the command interpreter for the command string "pcCommandInput". Any
|
||
|
output generated by running the command will be placed into buf.
|
||
|
xWriteBufferLen must indicate the size, in bytes, of the buffer pointed to
|
||
|
by buf.
|
||
|
|
||
|
FreeRTOS_CLIProcessCommand should be called repeatedly until it returns pdFALSE.
|
||
|
|
||
|
pcCmdIntProcessCommand is not reentrant. It must not be called from more
|
||
|
than one task - or at least - by more than one task at a time. */
|
||
|
int32_t cli_process_command(const char * const cmd_str);
|
||
|
|
||
|
/* Return a pointer to the xParameterNumber'th word in pcCommandString. */
|
||
|
const char *cli_parameter_get(const char *cmd_str, int32_t param_index, int32_t *param_len);
|
||
|
|
||
|
/* 进入命令行节点. */
|
||
|
int32_t cli_entry_node(CLI_NODE_E node, int16_t index);
|
||
|
|
||
|
/* 退出命令行当前节点 */
|
||
|
void cli_quit_node(void);
|
||
|
|
||
|
/* 从shell终端读取一行命. */
|
||
|
char *cli_shell_gets(void);
|
||
|
|
||
|
int32_t cli_init(void);
|
||
|
|
||
|
#endif
|
||
|
/************************ (C) COPYRIGHT LandPower ***** END OF FILE ****************/
|