File syn_cli.c¶
Go to the source code of this file
Command-line interpreter implementation.
#include "../port/syn_port_serial.h"#include "../util/syn_assert.h"#include "../util/syn_fmt.h"#include "syn_cli.h"#include <string.h>#include <stdarg.h>#include <stdio.h>#include "../port/syn_port_system.h"#include "../sched/syn_sched.h"#include "../system/syn_errlog.h"#include "../system/syn_version.h"
Public Static Attributes¶
| Type | Name |
|---|---|
| struct SYN_ErrLog * | s_cli_errlog = NULLGlobal error log singleton reference for CLI diagnostics. |
| struct SYN_Sched * | s_cli_sched = NULLGlobal scheduler singleton reference for CLI task listing. |
Public Functions¶
| Type | Name |
|---|---|
| void | syn_cli_init (SYN_CLI * cli, const SYN_CLI_Command * commands, size_t cmd_count, const char * prompt) Initialize a CLI instance. |
| void | syn_cli_print_prompt (SYN_CLI * cli) |
| void | syn_cli_printf (SYN_CLI * cli, const char * fmt, ...) Print formatted output through the CLI's output function. |
| void | syn_cli_process_char (SYN_CLI * cli, char ch) Process a single received character. |
| void | syn_cli_process_line (SYN_CLI * cli, const char * line) Process a complete null-terminated line. |
| void | syn_cli_refresh_prompt (SYN_CLI * cli) Refresh / redraw the prompt and active draft line. |
| void | syn_cli_set_echo (SYN_CLI * cli, bool echo) Enable or disable local echo. |
| void | syn_cli_set_errlog (struct SYN_ErrLog * errlog) Set errlog instance for the errors built-in command. |
| void | syn_cli_set_scheduler (struct SYN_Sched * sched) Set scheduler instance for the tasks built-in command. |
Public Static Functions¶
| Type | Name |
|---|---|
| void | cli_builtin_errors (const SYN_CLI * cli) Built-in 'errors' command handler. |
| void | cli_builtin_tasks (const SYN_CLI * cli) Built-in 'tasks' command handler. |
| void | cli_builtin_uptime (const SYN_CLI * cli) Built-in 'uptime' command handler. |
| void | cli_builtin_version (const SYN_CLI * cli) Built-in 'version' command handler. |
| void | cli_dispatch (SYN_CLI * cli, char * line) Look up and execute a command. |
| void | cli_putchar (const SYN_CLI * cli, char ch) Emit a single character via the console serial port. |
| void | cli_puts (const SYN_CLI * cli, const char * str) Emit a null-terminated string via the console serial port. |
| int | cli_tokenize (char * line, char * argv, int max_args) Tokenize a line buffer in-place into argv[]. |
Public Static Attributes Documentation¶
variable s_cli_errlog¶
Global error log singleton reference for CLI diagnostics.
variable s_cli_sched¶
Global scheduler singleton reference for CLI task listing.
Public Functions Documentation¶
function syn_cli_init¶
Initialize a CLI instance.
void syn_cli_init (
SYN_CLI * cli,
const SYN_CLI_Command * commands,
size_t cmd_count,
const char * prompt
)
Output goes directly to syn_port_serial_write — no callback needed.
Parameters:
cliCLI instance to initialize.commandsArray of command descriptors.cmd_countNumber of commands.promptPrompt string (e.g., "> " or "syntropic> "). Stored by pointer, not copied.
function syn_cli_print_prompt¶
function syn_cli_printf¶
Print formatted output through the CLI's output function.
Automatically manages prompt restoration during asynchronous logging.
Parameters:
cliCLI instance.fmtFormat string....Arguments.
function syn_cli_process_char¶
Process a single received character.
Call this for each byte received from the input stream (UART RX ISR, polled read, etc.). The CLI handles line editing (backspace) and dispatches the command when a newline is received.
Parameters:
cliCLI instance.chReceived character.
function syn_cli_process_line¶
Process a complete null-terminated line.
Alternative to process_char when you already have a full line (e.g., from a buffered read). Does not echo or handle editing.
Parameters:
cliCLI instance.lineNull-terminated command line.
function syn_cli_refresh_prompt¶
Refresh / redraw the prompt and active draft line.
Useful after external serial output to restore prompt visual state.
Parameters:
cliCLI instance.
function syn_cli_set_echo¶
Enable or disable local echo.
When enabled (default), the CLI echoes each received character back to the terminal. Disable if the terminal handles its own echo.
Parameters:
cliCLI instance.echotrue to enable echo, false to disable.
function syn_cli_set_errlog¶
Set errlog instance for the errors built-in command.
Parameters:
errlogError log instance (or NULL to detach).
function syn_cli_set_scheduler¶
Set scheduler instance for the tasks built-in command.
Parameters:
schedScheduler instance (or NULL to detach).
Public Static Functions Documentation¶
function cli_builtin_errors¶
Built-in 'errors' command handler.
Parameters:
cliCLI instance.
function cli_builtin_tasks¶
Built-in 'tasks' command handler.
Parameters:
cliCLI instance.
function cli_builtin_uptime¶
Built-in 'uptime' command handler.
Parameters:
cliCLI instance.
function cli_builtin_version¶
Built-in 'version' command handler.
Parameters:
cliCLI instance.
function cli_dispatch¶
Look up and execute a command.
Parameters:
cliCLI instance.lineInput line (modified in-place during tokenization).
function cli_putchar¶
Emit a single character via the console serial port.
Parameters:
cliCLI instance (unused, kept for internal API consistency).chCharacter to emit.
function cli_puts¶
Emit a null-terminated string via the console serial port.
Parameters:
cliCLI instance (unused, kept for internal API consistency).strString to print.
function cli_tokenize¶
Tokenize a line buffer in-place into argv[].
Handles double-quoted strings (quotes are stripped).
Parameters:
lineInput line (modified in-place).argv[out] Array of token pointers.max_argsMaximum number of tokens.
Returns:
Token count (argc).
The documentation for this class was generated from the following file src/syntropic/cli/syn_cli.c