HF-TMC51x0 Driver (TMC5130 & TMC5160) 0.1.0-dev
Hardware Agnostic C++ Driver for the TMC51x0 (TMC5130 & TMC5160)
Loading...
Searching...
No Matches
UartCommandParser Class Reference

Redesigned UART command parser with word-based commands. More...

Public Member Functions

 UartCommandParser (uart_port_t uart_port)
 Construct a UART command parser bound to a specific UART port.
 
bool ProcessCommand (const char *line, FatigueTest::FatigueTestMotion &motion) noexcept
 Parse and execute a single command line.
 
void ProcessUartCommands (FatigueTest::FatigueTestMotion &motion) noexcept
 Poll the UART for input and process complete lines.
 

Private Member Functions

std::vector< std::string > Tokenize (const char *line) noexcept
 Split a command line into tokens.
 
CommandType ParseCommandType (const std::string &token) noexcept
 Map a verb token (first token) to a CommandType.
 
bool ParseCommand (const std::vector< std::string > &tokens, ParsedCommand &cmd) noexcept
 Convert tokens into a structured ParsedCommand.
 

Private Attributes

uart_port_t uart_port_
 
char rx_buffer_ [256]
 
char line_buffer_ [256]
 
size_t line_buffer_pos_
 

Static Private Attributes

static constexpr size_t RX_BUF_SIZE = 256
 

Detailed Description

Redesigned UART command parser with word-based commands.

Constructor & Destructor Documentation

◆ UartCommandParser()

UartCommandParser::UartCommandParser ( uart_port_t uart_port)
inline

Construct a UART command parser bound to a specific UART port.

Configures the UART driver for non-blocking reads and line-based parsing. On ESP32-C6, UART0 is often already configured by the console; this constructor tolerates that case.

Parameters
uart_portUART port to use (e.g. UART_NUM_0).

Member Function Documentation

◆ ParseCommand()

bool UartCommandParser::ParseCommand ( const std::vector< std::string > & tokens,
ParsedCommand & cmd )
inlineprivatenoexcept

Convert tokens into a structured ParsedCommand.

Parameters
tokensToken vector as returned by Tokenize().
cmdOutput structured command.
Returns
true if parsing succeeded; false otherwise.
Here is the call graph for this function:

◆ ParseCommandType()

CommandType UartCommandParser::ParseCommandType ( const std::string & token)
inlineprivatenoexcept

Map a verb token (first token) to a CommandType.

Parameters
tokenLowercase verb token (e.g. "set", "start").
Returns
Parsed command type. Unknown verbs map to HELP.

◆ ProcessCommand()

bool UartCommandParser::ProcessCommand ( const char * line,
FatigueTest::FatigueTestMotion & motion )
inlinenoexcept

Parse and execute a single command line.

Parameters
lineNull-terminated command line.
motionMotion controller to operate on.
Returns
true if the command executed successfully; false otherwise.
Note
This function routes to the Handle* command handlers.
Here is the call graph for this function:

◆ ProcessUartCommands()

void UartCommandParser::ProcessUartCommands ( FatigueTest::FatigueTestMotion & motion)
inlinenoexcept

Poll the UART for input and process complete lines.

Reads any currently buffered bytes (non-blocking) and accumulates them into a line buffer. When a newline is received, the line is executed via ProcessCommand().

Parameters
motionMotion controller to operate on.
Warning
This runs in a polling task. Keep per-call work bounded.
Here is the caller graph for this function:

◆ Tokenize()

std::vector< std::string > UartCommandParser::Tokenize ( const char * line)
inlineprivatenoexcept

Split a command line into tokens.

  • Splits on whitespace
  • Preserves quoted substrings (double quotes)
Parameters
lineNull-terminated command line string.
Returns
Token vector (may be empty).

Member Data Documentation

◆ line_buffer_

char UartCommandParser::line_buffer_[256]
private

◆ line_buffer_pos_

size_t UartCommandParser::line_buffer_pos_
private

◆ RX_BUF_SIZE

constexpr size_t UartCommandParser::RX_BUF_SIZE = 256
staticconstexprprivate

◆ rx_buffer_

char UartCommandParser::rx_buffer_[256]
private

◆ uart_port_

uart_port_t UartCommandParser::uart_port_
private

The documentation for this class was generated from the following file: