mirror of
https://gitee.com/moluo-tech/CodeBrick.git
synced 2025-01-30 04:42:53 +08:00
78 lines
2.5 KiB
C
78 lines
2.5 KiB
C
/******************************************************************************
|
||
* @brief <20><><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD>
|
||
*
|
||
* Copyright (c) 2015-2020, <master_roger@sina.com>
|
||
*
|
||
* SPDX-License-Identifier: Apache-2.0
|
||
*
|
||
* Change Logs:
|
||
* Date Author Notes
|
||
* 2015-06-09 Morro <20><><EFBFBD><EFBFBD>
|
||
*
|
||
* 2017-07-04 Morro <20>Ż<EFBFBD><C5BB>ֶηָ<D6B8><EEB4A6>
|
||
*
|
||
* 2020-07-05 Morro ʹ<><CAB9>cli_obj_t<5F><74><EFBFBD><EFBFBD>, ֧<>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD>
|
||
******************************************************************************/
|
||
#ifndef _CMDLINE_H_
|
||
#define _CMDLINE_H_
|
||
|
||
#include "comdef.h"
|
||
|
||
#define CLI_MAX_CMD_LEN 64 /*<2A><><EFBFBD><EFBFBD><EFBFBD>г<EFBFBD><D0B3><EFBFBD>*/
|
||
#define CLI_MAX_ARGS 16 /*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
||
#define CLI_MAX_CMDS 32 /*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
||
|
||
struct cli_obj;
|
||
|
||
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EEB6A8>*/
|
||
typedef struct {
|
||
char *name; /*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
||
/*<2A><><EFBFBD><EFBFBD><EEB4A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
||
int (*handler)(struct cli_obj *o, int argc, char *argv[]);
|
||
const char *brief; /*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
||
}cmd_item_t;
|
||
|
||
#define __cmd_register(name,handler,brief)\
|
||
USED ANONY_TYPE(const cmd_item_t,__cli_cmd_##handler)\
|
||
SECTION("cli.cmd.1") = {name, handler, brief}
|
||
|
||
/*******************************************************************************
|
||
* @brief <20><><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>
|
||
* @params name - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
* @params handler - <20><><EFBFBD><EFBFBD><EEB4A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
* <20><><EFBFBD><EFBFBD>:int (*handler)(struct cli_obj *s, int argc, char *argv[]);
|
||
* @params brief - ʹ<><CAB9>˵<EFBFBD><CBB5>
|
||
*/
|
||
#define cmd_register(name,handler,brief)\
|
||
__cmd_register(name,handler,brief)
|
||
|
||
/*cli <20>ӿڶ<D3BF><DAB6><EFBFBD> -------------------------------------------------------------*/
|
||
typedef struct {
|
||
unsigned int (*write)(const void *buf, unsigned int len);
|
||
unsigned int (*read) (void *buf, unsigned int len);
|
||
}cli_port_t;
|
||
|
||
/*<2A><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6><EFBFBD>*/
|
||
typedef struct cli_obj {
|
||
unsigned int (*write)(const void *buf, unsigned int len);
|
||
unsigned int (*read) (void *buf, unsigned int len);
|
||
void (*print)(struct cli_obj *this, const char *fmt, ...);
|
||
char recvbuf[CLI_MAX_CMD_LEN + 1]; /*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD><EFBFBD><EFBFBD>*/
|
||
unsigned short recvcnt; /*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ճ<EFBFBD><D5B3><EFBFBD>*/
|
||
unsigned enable : 1;
|
||
}cli_obj_t;
|
||
|
||
void cli_init(cli_obj_t *obj, const cli_port_t *p);
|
||
|
||
void cli_enable(cli_obj_t *obj);
|
||
|
||
void cli_disable (cli_obj_t *obj);
|
||
|
||
void cli_exec_cmd(cli_obj_t *obj, const char *cmd);
|
||
|
||
void cli_process(cli_obj_t *obj);
|
||
|
||
|
||
|
||
#endif /* __CMDLINE_H */
|