2020-07-11 14:44:09 +08:00

78 lines
2.5 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/******************************************************************************
* @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 */