This library provides a simple configurable command line interface for serial communication. It allows registering commands and processing input from a serial interface like UART.
- Register commands with callback functions.
- Backspace handling.
- Autogenerated help command.
- Configurable maximum number of commands and arguments per command.
- Configurable input/output buffer sizes.
- SerialCLI: The main structure representing the CLI instance.
- SerialCLI_Write: Callback function type for writing serial output.
- SerialCLI_Read: Function for reading serial input.
- SerialCLI_CommandEntry: Structure representing a command entry.
To initialize the CLI, use the SerialCLI_Init function:
SerialCLI cli;
SerialCLI_Init(&cli, writeFunctionCallback);Register a command using the SerialCLI_RegisterCommand function:
static SerialCLI_CommandEntry commandEntry;
static void exampleCommand(SerialCLI *cli, int argc, const char **argv) {
SerialCLI_WriteString(cli, "%d arguments provided.\r\n", argc);
}
int main() {
SerialCLI_Init(&cli, serialWrite);
commandEntry.command = exampleCommand;
commandEntry.commandName = "example";
commandEntry.commandDescription = "Example command.";
SerialCLI_RegisterCommand(&cli, &commandEntry);
// ...
}Process CLI input in a task or main loop using the SerialCLI_Process function:
static void serialRead(const char *data, size_t len) {
// Read characters from serial and pass them to the CLI
SerialCLI_Read(&cli, data, len);
}
static void serialWrite(const char *data, size_t len) {
// Callback function to write output to serial
}
int main() {
// ...
while (1) {
SerialCLI_Process(&cli);
}
}You can find a more detailed example in the examples directory.