Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ CLIRet_t CLIInit(CLIInst_t *cli, CLIConfig_t cnf)
cli->config = cnf;
cli->bufp = cli->config.buf;
commandClr(*cli, cli->config.buf);
cli->config.tx((CLI_BUF_VALUE_T *) CLI_DELETE_LINE, sizeof(CLI_DELETE_LINE));
cli->config.tx((CLI_BUF_VALUE_T *) CLI_LINE_BEGINNING, sizeof(CLI_LINE_BEGINNING));
cli->config.tx(cli->config.port, (CLI_BUF_VALUE_T *) CLI_DELETE_LINE, sizeof(CLI_DELETE_LINE));
cli->config.tx(cli->config.port, (CLI_BUF_VALUE_T *) CLI_LINE_BEGINNING, sizeof(CLI_LINE_BEGINNING));
}

return ret;
Expand All @@ -55,6 +55,7 @@ CLIRet_t CLIDeinit(CLIInst_t *cli)

if (cli)
{
cli->config.port = CLIPORT_NONE;
cli->config.buf = NULL;
cli->config.bufc = 0;
cli->config.commands = NULL;
Expand Down Expand Up @@ -95,10 +96,10 @@ CLIRet_t CLIInsert(CLIInst_t *cli, CLI_BUF_VALUE_T value)
cli->ready = FLAG_READY;
cli->bufp = cli->config.buf;
value = CLI_NEW_LINE_VALUE;
cli->config.tx(&value, SPECIAL_VALUE_LENGTH);
cli->config.tx(cli->config.port, &value, SPECIAL_VALUE_LENGTH);
#if CLI_INCLUDE_CARRIAGE_RETURN
value = CLI_CARRIAGE_RETURN_VALUE;
cli->config.tx(&value, SPECIAL_VALUE_LENGTH);
cli->config.tx(cli->config.port, &value, SPECIAL_VALUE_LENGTH);
#endif // CLI_INCLUDE_CARRIAGE_RETURN
}
break;
Expand All @@ -111,7 +112,7 @@ CLIRet_t CLIInsert(CLIInst_t *cli, CLI_BUF_VALUE_T value)
if (cli->bufp > cli->config.buf)
{
#if CLI_DELETE_IN_INSERT
cli->config.tx((CLI_BUF_VALUE_T *) CLI_DELETE_CHAR, sizeof(CLI_DELETE_CHAR));
cli->config.tx(cli->config.port, (CLI_BUF_VALUE_T *) CLI_DELETE_CHAR, sizeof(CLI_DELETE_CHAR));
#else
cli->delete = FLAG_READY;
#endif //CLI_DELETE_IN_INSERT
Expand All @@ -133,7 +134,7 @@ CLIRet_t CLIInsert(CLIInst_t *cli, CLI_BUF_VALUE_T value)
cli->bufd = cli->bufp;
}
*cli->bufp = value;
cli->config.tx((CLI_BUF_VALUE_T *) cli->bufp, 1U);
cli->config.tx(cli->config.port, (CLI_BUF_VALUE_T *) cli->bufp, 1U);
cli->bufp++;
}
else
Expand Down Expand Up @@ -255,7 +256,7 @@ static inline CLIRet_t flagHandler(CLIInst_t *cli)
if (cli->delete)
{
#if !CLI_DELETE_IN_INSERT
cli->config.tx((CLI_BUF_VALUE_T *) CLI_DELETE_CHAR, sizeof(CLI_DELETE_CHAR));
cli->config.tx(cli->config.port, (CLI_BUF_VALUE_T *) CLI_DELETE_CHAR, sizeof(CLI_DELETE_CHAR));
ret = CLI_OK;
#endif //CLI_DELETE_IN_INSERT
}
Expand Down Expand Up @@ -297,10 +298,10 @@ static inline CLIRet_t flagHandler(CLIInst_t *cli)

ret = cli->config.commands[commandIdx].callback(args, argc);

cli->config.tx(&endl, SPECIAL_VALUE_LENGTH);
cli->config.tx(cli->config.port, &endl, SPECIAL_VALUE_LENGTH);
#if CLI_INCLUDE_CARRIAGE_RETURN
endl = CLI_CARRIAGE_RETURN_VALUE;
cli->config.tx(&endl, SPECIAL_VALUE_LENGTH);
cli->config.tx(cli->config.port, &endl, SPECIAL_VALUE_LENGTH);
#endif // CLI_INCLUDE_CARRIAGE_RETURN
break;
}
Expand All @@ -327,17 +328,17 @@ static inline CLIRet_t flagHandler(CLIInst_t *cli)
{
commandClr(*cli, cli->config.buf);
cli->cdone = FLAG_NOT_READY;
cli->config.tx((CLI_BUF_VALUE_T *) CLI_LINE_BEGINNING, sizeof(CLI_LINE_BEGINNING));
cli->config.tx(cli->config.port, (CLI_BUF_VALUE_T *) CLI_LINE_BEGINNING, sizeof(CLI_LINE_BEGINNING));
}
#if CLI_TAB_COMPLETE_ENABLE
else if (cli->tab && tab.found)
{
nbuf = commandLen(cli, (CLI_BUF_VALUE_T *) cli->config.commands[tab.cIdx].command);
commandCopy((unsigned char *) cli->config.buf, (unsigned char *) cli->config.commands[tab.cIdx].command, nbuf);
cli->bufp = cli->config.buf + nbuf;
cli->config.tx((CLI_BUF_VALUE_T *) CLI_DELETE_LINE, sizeof(CLI_DELETE_LINE));
cli->config.tx((CLI_BUF_VALUE_T *) CLI_LINE_BEGINNING, sizeof(CLI_LINE_BEGINNING));
cli->config.tx(cli->config.buf, nbuf);
cli->config.tx(cli->config.port, (CLI_BUF_VALUE_T *) CLI_DELETE_LINE, sizeof(CLI_DELETE_LINE));
cli->config.tx(cli->config.port, (CLI_BUF_VALUE_T *) CLI_LINE_BEGINNING, sizeof(CLI_LINE_BEGINNING));
cli->config.tx(cli->config.port, cli->config.buf, nbuf);
}
#endif // CLI_TAB_COMPLETE_ENABLE
}
Expand Down
3 changes: 2 additions & 1 deletion cli.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ typedef enum
} CLIRet_t;

typedef CLIRet_t (*CLICommandCallback_t)(void **args, CLI_ARG_COUNT_VALUE_T argc);
typedef void (*CLITXCallback_t)(CLI_BUF_VALUE_T *buf, CLI_TX_BUF_COUNT_VALUE_T bufc);
typedef void (*CLITXCallback_t)(PORT_ENUM_T port, CLI_BUF_VALUE_T *buf, CLI_TX_BUF_COUNT_VALUE_T bufc);

typedef struct
{
Expand All @@ -36,6 +36,7 @@ typedef struct
CLITXCallback_t tx;
CLI_BUF_VALUE_T *buf;
CLI_BUF_COUNT_VALUE_T bufc;
PORT_ENUM_T port;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this defined at? In the config file? Can you add that to the example config if so.
Also, prepend this with CLI so we have CLI_PORT_ENUM_T please.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The README should also be updated to reflect the changes in the function pointer.

} CLIConfig_t;

typedef struct
Expand Down