Trident IoT SDK
 
Loading...
Searching...
No Matches
tr_cli.h File Reference

common CLI utility More...

#include <stdbool.h>
#include "tr_printf.h"
#include "tr_cli_command_parser.h"
#include "tr_cli_buffer.h"
+ Include dependency graph for tr_cli.h:

Go to the source code of this file.

Data Structures

struct  tr_cli
 

Macros

#define TR_CLI_MAX_LINE   120
 
#define TR_CLI_HISTORY_LEN   1000
 
#define TR_CLI_MAX_ARGC   16
 
#define TR_CLI_PROMPT   "trident> "
 
#define TR_CLI_MAX_PROMPT_LEN   10
 
#define TR_CLI_SERIAL_XLATE   1
 

Functions

void tr_cli_init (const char *prompt, void(*put_char)(char ch))
 
bool tr_cli_insert_char (char ch)
 
const char * tr_cli_get_line (void)
 
int tr_cli_argc (char ***argv)
 
void tr_cli_prompt (void)
 
const char * tr_cli_get_history (int history_pos)
 
void tr_cli_char_received (char data)
 
void tr_cli_common_printf (const char *pFormat,...)
 

Detailed Description

common CLI utility


SPDX-License-Identifier: LicenseRef-TridentMSLA SPDX-FileCopyrightText: 2025 Trident IoT, LLC https://www.tridentiot.com


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_MAX_ARGC

#define TR_CLI_MAX_ARGC   16

What is the 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/argc combo

Returns
number of values in argv (maximum of TR_CLI_MAX_ARGC)

◆ tr_cli_char_received()

void tr_cli_char_received ( char data)

Pass a received character to the cli

Parameters
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
pFormatprintf format string
...printf parameters

◆ tr_cli_get_history()

const char * tr_cli_get_history ( int history_pos)

Retrieve a history command line

Parameters
history_pos0 is the most recent command, 1 is the one before that etc...
Returns
NULL if the history buffer is exceeded

◆ tr_cli_get_line()

const char * tr_cli_get_line ( void )

Returns the nul terminated internal buffer. This will return NULL if the buffer is not yet complete

◆ tr_cli_init()

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

Start up the Embedded CLI subsystem. This should only be called once.

◆ tr_cli_insert_char()

bool tr_cli_insert_char ( char ch)

Adds a new character into 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