Trident IoT SDK
Loading...
Searching...
No Matches

Common CLI functionality including main structure and core functions. More...

Collaboration diagram for common:

Data Structures

struct  tr_cli
 Structure which defines the current state of the CLI. More...

Macros

#define TR_CLI_MAX_LINE   120
 Maximum number of bytes to accept in a single line.
#define TR_CLI_HISTORY_LEN   1000
 Maximum number of bytes to retain of history data.
#define TR_CLI_MAX_ARGC   16
 Maximum number of arguments we reserve space for.
#define TR_CLI_PROMPT   "trident> "
 CLI prompt to display after pressing enter.
#define TR_CLI_MAX_PROMPT_LEN   10
 Maximum number of bytes in the prompt.
#define TR_CLI_SERIAL_XLATE   1
 Translate CR -> NL on input and output CR NL on output.
#define TR_CLI_LOCAL_ECHO   1
 Enable or disable local echo.

Functions

void tr_cli_init (const char *prompt, void(*put_char)(char ch))
 Starts up the Embedded CLI subsystem.
bool tr_cli_insert_char (char ch)
 Adds a new character into the buffer.
const char * tr_cli_get_line (void)
 Returns the null terminated internal buffer.
int tr_cli_argc (char ***argv)
 Parses the internal buffer and returns it as an argc/argv combo.
void tr_cli_prompt (void)
 Outputs the CLI prompt.
const char * tr_cli_get_history (int history_pos)
 Retrieves a history command line.
void tr_cli_char_received (char data)
 Passes a received character to the CLI.
void tr_cli_common_printf (const char *pFormat,...)
 Printf function used for printing to terminal.

Detailed Description

Common CLI functionality including main structure and core functions.

Macro Definition Documentation

◆ TR_CLI_HISTORY_LEN

#define TR_CLI_HISTORY_LEN   1000

Maximum number of bytes to retain of history data.

Define this to 0 to remove history support.

◆ TR_CLI_LOCAL_ECHO

#define TR_CLI_LOCAL_ECHO   1

Enable or disable local echo.

◆ TR_CLI_MAX_ARGC

#define TR_CLI_MAX_ARGC   16

Maximum number of arguments we reserve space for.

◆ TR_CLI_MAX_LINE

#define TR_CLI_MAX_LINE   120

Maximum number of bytes to accept in a single line.

◆ TR_CLI_MAX_PROMPT_LEN

#define TR_CLI_MAX_PROMPT_LEN   10

Maximum number of bytes in the prompt.

◆ TR_CLI_PROMPT

#define TR_CLI_PROMPT   "trident> "

CLI prompt to display after pressing enter.

◆ TR_CLI_SERIAL_XLATE

#define TR_CLI_SERIAL_XLATE   1

Translate CR -> NL on input and output CR NL on output.

This allows "natural" processing when using a serial terminal.

Function Documentation

◆ tr_cli_argc()

int tr_cli_argc ( char *** argv)

Parses the internal buffer and returns it as an argc/argv combo.

Parameters
[out]argvPointer to store the argument vector.
Returns
Number of values in argv (maximum of TR_CLI_MAX_ARGC).

◆ tr_cli_char_received()

void tr_cli_char_received ( char data)

Passes a received character to the CLI.

Parameters
[in]dataCharacter received on the terminal.

◆ tr_cli_common_printf()

void tr_cli_common_printf ( const char * pFormat,
... )

Printf function used for printing to terminal.

This function can be re-defined by the application using the CLI to add additional formatting behavior if desired.

Parameters
[in]pFormatPrintf format string.
[in]...Printf parameters.

◆ tr_cli_get_history()

const char * tr_cli_get_history ( int history_pos)

Retrieves a history command line.

Parameters
[in]history_pos0 is the most recent command, 1 is the one before that, etc.
Returns
Pointer to the history command line, or NULL if the history buffer is exceeded.

◆ tr_cli_get_line()

const char * tr_cli_get_line ( void )

Returns the null terminated internal buffer.

Returns
Pointer to the internal buffer, or NULL if the buffer is not yet complete.

◆ tr_cli_init()

void tr_cli_init ( const char * prompt,
void(* put_char )(char ch) )

Starts up the Embedded CLI subsystem.

This should only be called once during system initialization.

Parameters
[in]promptThe prompt string to display.
[in]put_charFunction pointer for character output.

◆ tr_cli_insert_char()

bool tr_cli_insert_char ( char ch)

Adds a new character into the buffer.

Parameters
[in]chThe character to add to the buffer.
Returns
true if the buffer should now be processed.
Note
This function should not be called from an interrupt handler.

◆ tr_cli_prompt()

void tr_cli_prompt ( void )

Outputs the CLI prompt.

This should be called after tr_cli_argc or tr_cli_get_line has been called and the command fully processed.