Skip to content

File syn_cli.c

FileList > cli > 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 = NULL
Global error log singleton reference for CLI diagnostics.
struct SYN_Sched * s_cli_sched = NULL
Global 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.

struct SYN_ErrLog* s_cli_errlog;


variable s_cli_sched

Global scheduler singleton reference for CLI task listing.

struct SYN_Sched* s_cli_sched;


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:

  • cli CLI instance to initialize.
  • commands Array of command descriptors.
  • cmd_count Number of commands.
  • prompt Prompt string (e.g., "> " or "syntropic> "). Stored by pointer, not copied.

function syn_cli_print_prompt

void syn_cli_print_prompt (
    SYN_CLI * cli
) 

function syn_cli_printf

Print formatted output through the CLI's output function.

void syn_cli_printf (
    SYN_CLI * cli,
    const char * fmt,
    ...
) 

Automatically manages prompt restoration during asynchronous logging.

Parameters:

  • cli CLI instance.
  • fmt Format string.
  • ... Arguments.

function syn_cli_process_char

Process a single received character.

void syn_cli_process_char (
    SYN_CLI * cli,
    char ch
) 

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:

  • cli CLI instance.
  • ch Received character.

function syn_cli_process_line

Process a complete null-terminated line.

void syn_cli_process_line (
    SYN_CLI * cli,
    const char * 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:

  • cli CLI instance.
  • line Null-terminated command line.

function syn_cli_refresh_prompt

Refresh / redraw the prompt and active draft line.

void syn_cli_refresh_prompt (
    SYN_CLI * cli
) 

Useful after external serial output to restore prompt visual state.

Parameters:

  • cli CLI instance.

function syn_cli_set_echo

Enable or disable local echo.

void syn_cli_set_echo (
    SYN_CLI * cli,
    bool echo
) 

When enabled (default), the CLI echoes each received character back to the terminal. Disable if the terminal handles its own echo.

Parameters:

  • cli CLI instance.
  • echo true to enable echo, false to disable.

function syn_cli_set_errlog

Set errlog instance for the errors built-in command.

void syn_cli_set_errlog (
    struct SYN_ErrLog * errlog
) 

Parameters:

  • errlog Error log instance (or NULL to detach).

function syn_cli_set_scheduler

Set scheduler instance for the tasks built-in command.

void syn_cli_set_scheduler (
    struct SYN_Sched * sched
) 

Parameters:

  • sched Scheduler instance (or NULL to detach).

Public Static Functions Documentation

function cli_builtin_errors

Built-in 'errors' command handler.

static void cli_builtin_errors (
    const SYN_CLI * cli
) 

Parameters:

  • cli CLI instance.

function cli_builtin_tasks

Built-in 'tasks' command handler.

static void cli_builtin_tasks (
    const SYN_CLI * cli
) 

Parameters:

  • cli CLI instance.

function cli_builtin_uptime

Built-in 'uptime' command handler.

static void cli_builtin_uptime (
    const SYN_CLI * cli
) 

Parameters:

  • cli CLI instance.

function cli_builtin_version

Built-in 'version' command handler.

static void cli_builtin_version (
    const SYN_CLI * cli
) 

Parameters:

  • cli CLI instance.

function cli_dispatch

Look up and execute a command.

static void cli_dispatch (
    SYN_CLI * cli,
    char * line
) 

Parameters:

  • cli CLI instance.
  • line Input line (modified in-place during tokenization).

function cli_putchar

Emit a single character via the console serial port.

static void cli_putchar (
    const SYN_CLI * cli,
    char ch
) 

Parameters:

  • cli CLI instance (unused, kept for internal API consistency).
  • ch Character to emit.

function cli_puts

Emit a null-terminated string via the console serial port.

static void cli_puts (
    const SYN_CLI * cli,
    const char * str
) 

Parameters:

  • cli CLI instance (unused, kept for internal API consistency).
  • str String to print.

function cli_tokenize

Tokenize a line buffer in-place into argv[].

static int cli_tokenize (
    char * line,
    char * argv,
    int max_args
) 

Handles double-quoted strings (quotes are stripped).

Parameters:

  • line Input line (modified in-place).
  • argv [out] Array of token pointers.
  • max_args Maximum number of tokens.

Returns:

Token count (argc).



The documentation for this class was generated from the following file src/syntropic/cli/syn_cli.c