123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- #ifndef _CLI_H__
- #define _CLI_H__
- #include "SEGGER_RTT.h"
- #include "string.h"
- #include "stdlib.h"
- #include "cli_vt100.h" //¿ÉÖ±½Ó¸´ÖÆÎļþ
- typedef enum
- {
- NRF_CLI_VT100_COLOR_BLACK = 0,
- NRF_CLI_VT100_COLOR_RED,
- NRF_CLI_VT100_COLOR_GREEN,
- NRF_CLI_VT100_COLOR_YELLOW,
- NRF_CLI_VT100_COLOR_BLUE,
- NRF_CLI_VT100_COLOR_MAGENTA,
- NRF_CLI_VT100_COLOR_CYAN,
- NRF_CLI_VT100_COLOR_WHITE,
- } nrf_cli_vt100_color_t;
- typedef struct
- {
- nrf_cli_vt100_color_t col; // text color
- nrf_cli_vt100_color_t bgcol; // background color
- } nrf_cli_vt100_colors_t;
- typedef void (*cli_char_put_t)(unsigned char);
- typedef unsigned char (*cli_char_get_t)(void);
- typedef char (*cli_char_ok_t)(void);
- typedef struct
- {
- const char *_p_cmd_str;
- const char *_p_cmd_help_str;
- const void *_p_cmd_hander;
- } cli_section_cmd_t;
- typedef struct
- {
- char const *const p_name;
- cli_char_put_t char_put;
- cli_char_get_t char_get;
- cli_char_ok_t char_ok;
- unsigned char cmdbuf[256];
- unsigned char cmdwp;
- unsigned char cmdrp;
- unsigned char historyrp;
- char tempbuf[256];
- unsigned chartemplen;
- unsigned char tab_sta;
- nrf_cli_vt100_colors_t col;
- } cli_t;
- /**
- * @brief CLI command handler prototype.
- */
- typedef void (*cli_cmd_t)(cli_t const *p_cli, unsigned short argc, char **argv);
- #define CLI_CMD_REGISTER(_p_cmd, _p_help, _p_handler) \
- __attribute__((section("cli_cmd"))) cli_section_cmd_t const cli_cmd_##_p_cmd##_row = \
- { \
- ._p_cmd_str = (const char *)STRINGIFY(_p_cmd), \
- ._p_cmd_help_str = (const char *)_p_help, \
- ._p_cmd_hander = (const void *)_p_handler}
- #define cli_fprintf(p_cli, color, ...) \
- { \
- nrf_cli_vt100_colors_t col; \
- vt100_colors_store(p_cli, &col); \
- vt100_color_set(p_cli, color); \
- cli_printf(p_cli, __VA_ARGS__); \
- vt100_colors_restore(p_cli, &col); \
- }
- #define cli_printf(p_cli, ...) \
- { \
- p_cli->chartemplen = sprintf(p_cli->tempbuf, __VA_ARGS__); \
- for (int i = 0; i < p_cli->chartemplen; i++) \
- p_cli->char_put(p_cli->tempbuf[i]); \
- }
- #define NRF_CLI_VT100_CMD(_p_cli_, _cmd_) \
- { \
- static char const cmd[] = _cmd_; \
- cli_printf(_p_cli_, "%s", cmd); \
- }
- #define CLI_DEFINE(name, cli_prefix, p_char_ok, p_char_get, p_char_put) \
- cli_t name = { \
- .p_name = cli_prefix, \
- .char_ok = p_char_ok, \
- .char_get = p_char_get, \
- .char_put = p_char_put, \
- .cmdbuf[255] = '*', \
- .col.col = NRF_CLI_VT100_COLOR_WHITE}
- void cli_process(cli_t *p_cli);
- void cli_exe_cmd(cli_t *p_cli,char *cmd);
-
- extern cli_t clirtt;
- #endif
|