Trident IoT SDK
Loading...
Searching...
No Matches
tr_cli.h
Go to the documentation of this file.
1
10#ifndef TR_CLI_H
11#define TR_CLI_H
12
13#include <stdbool.h>
14#include "tr_printf.h"
16#include "tr_cli_buffer.h"
17
32
33#ifndef TR_CLI_MAX_LINE
37#define TR_CLI_MAX_LINE 120
38#endif
39
40#ifndef TR_CLI_HISTORY_LEN
46#define TR_CLI_HISTORY_LEN 1000
47#endif
48
49#ifndef TR_CLI_MAX_ARGC
53#define TR_CLI_MAX_ARGC 16
54#endif
55
56#ifndef TR_CLI_PROMPT
60#define TR_CLI_PROMPT "trident> "
61#endif
62
63#ifndef TR_CLI_MAX_PROMPT_LEN
67#define TR_CLI_MAX_PROMPT_LEN 10
68#endif
69
70#ifndef TR_CLI_SERIAL_XLATE
76#define TR_CLI_SERIAL_XLATE 1
77#endif
78
79#ifndef TR_CLI_LOCAL_ECHO
83#define TR_CLI_LOCAL_ECHO 1
84#endif
85
94struct tr_cli
95{
101
102#if TR_CLI_HISTORY_LEN
106 char history[TR_CLI_HISTORY_LEN];
107
111 bool searching;
112
116 int history_pos;
117#endif
118
122 int len;
123
128
132 bool done;
133
137 void (*put_char)(char ch);
138
142 void *cb_data;
143
148
153
158
163
168};
169
179void tr_cli_init(const char *prompt,
180 void (*put_char)(char ch));
181
192bool tr_cli_insert_char(char ch);
193
200const char *tr_cli_get_line(void);
201
210int tr_cli_argc(char ***argv);
211
219void tr_cli_prompt(void);
220
229const char *tr_cli_get_history(int history_pos);
230
237void tr_cli_char_received(char data);
238
249void tr_cli_common_printf(const char *pFormat,
250 ...);
251
257
258#endif // TR_CLI_H
bool tr_cli_insert_char(char ch)
Adds a new character into the buffer.
#define TR_CLI_MAX_PROMPT_LEN
Maximum number of bytes in the prompt.
Definition tr_cli.h:67
void tr_cli_init(const char *prompt, void(*put_char)(char ch))
Starts up the Embedded CLI subsystem.
int tr_cli_argc(char ***argv)
Parses the internal buffer and returns it as an argc/argv combo.
#define TR_CLI_HISTORY_LEN
Maximum number of bytes to retain of history data.
Definition tr_cli.h:46
void tr_cli_common_printf(const char *pFormat,...)
Printf function used for printing to terminal.
const char * tr_cli_get_history(int history_pos)
Retrieves a history command line.
const char * tr_cli_get_line(void)
Returns the null terminated internal buffer.
#define TR_CLI_MAX_LINE
Maximum number of bytes to accept in a single line.
Definition tr_cli.h:37
void tr_cli_prompt(void)
Outputs the CLI prompt.
#define TR_CLI_MAX_ARGC
Maximum number of arguments we reserve space for.
Definition tr_cli.h:53
void tr_cli_char_received(char data)
Passes a received character to the CLI.
Structure which defines the current state of the CLI.
Definition tr_cli.h:95
int len
Number of characters in buffer at the moment.
Definition tr_cli.h:122
bool have_csi
Flag indicating if we have a CSI sequence.
Definition tr_cli.h:152
char * argv[TR_CLI_MAX_ARGC]
Array of argument strings.
Definition tr_cli.h:162
void * cb_data
Data to provide to the put_char callback.
Definition tr_cli.h:142
bool have_escape
Flag indicating if we have an escape sequence.
Definition tr_cli.h:147
char buffer[TR_CLI_MAX_LINE]
Internal buffer. This should not be accessed directly, use the access functions below.
Definition tr_cli.h:100
void(* put_char)(char ch)
Callback function to output a single character to the user.
Definition tr_cli.h:137
bool done
Have we just parsed a full line?
Definition tr_cli.h:132
char prompt[TR_CLI_MAX_PROMPT_LEN]
CLI prompt string.
Definition tr_cli.h:167
int cursor
Position of the cursor.
Definition tr_cli.h:127
int counter
Counter of the value for the CSI code.
Definition tr_cli.h:157
code for buffering bytes to be sent to the CLI utility
common CLI utility for parsing incoming commands
A simple printf utility for debug prints and cli support. Required for remote CLI to function properl...