ether2ser 0.1.0
Ethernet <-> synchronous V.24 bridge firmware for RP2040 + W5500
Loading...
Searching...
No Matches
cli_parser.c File Reference
#include "cli_parser.h"
#include <errno.h>
#include <limits.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "drivers/v24_config.h"
#include "platform/pinmap.h"
#include "system/common.h"
#include "system/error.h"
Include dependency graph for cli_parser.c:

Go to the source code of this file.

Macros

#define NUM_PINS   ARRAY_LEN(pin_table)
 
#define DECIMAL_BASE   10U
 

Functions

size_t get_num_pins (void)
 Return number of entries in the CLI pin table.
 
static bool prefix_to_mask (uint8_t prefix, uint8_t netmask[4])
 
static bool parse_u32_strict (const char *input_str, uint32_t *output_value)
 
static bool parse_i32_strict (const char *input_str, int32_t *output_value)
 
static bool parse_ipv4_strict (const char *input_str, uint8_t ip_addr[4])
 
static e2s_error_t parse_ipv4_with_optional_prefix (const char *args, const char *prefix, uint8_t ip_addr[4])
 
static e2s_error_t parse_u16_with_optional_prefix (const char *args, const char *prefix, uint16_t *value)
 
e2s_error_t parse_set_ip_args (const char *args, uint8_t ip_addr[4], uint8_t netmask[4])
 Parse ip_addr and optional netmask values.
 
e2s_error_t parse_set_gpio_args (const char *args, char *pin_name, int *value, const pin_info_t **pin)
 Parse GPIO set command arguments.
 
e2s_error_t parse_set_net_ip_args (const char *args, uint8_t ip_addr[4], uint8_t netmask[4])
 Parse network local ip_addr/subnet arguments.
 
e2s_error_t parse_set_ip_remote_args (const char *args, uint8_t ip_addr[4])
 Parse remote ip_addr argument.
 
e2s_error_t parse_set_gateway_args (const char *args, uint8_t ip_addr[4])
 Parse gateway ip_addr argument.
 
e2s_error_t parse_set_udp_port_local_args (const char *args, uint16_t *port)
 Parse local UDP port argument.
 
e2s_error_t parse_set_udp_port_remote_args (const char *args, uint16_t *port)
 Parse remote UDP port argument.
 
e2s_error_t parse_set_v24_polarities (const char *args, V24_POLARITIES_T *polarities)
 Parse V.24 polarities argument list.
 
e2s_error_t parse_set_v24_baudrate (const char *args, V24_BAUDRATE_T *baudrate)
 Parse V.24 baudrate argument.
 
e2s_error_t parse_set_v24_clockmode (const char *args, bool *clockmode)
 Parse V.24 tx clock mode argument.
 
const pin_info_tget_pin_table (void)
 Return pointer to static pin metadata table.
 
const pin_info_tfind_pin (const char *name)
 Lookup pin metadata by name.
 
e2s_error_t parse_get_args (const char *args, char *pin_name, const pin_info_t **pin)
 Parse get command arguments and resolve pin metadata.
 
e2s_error_t cli_parse (const char *line, char *cmd, size_t cmd_cap, char *args, size_t args_cap)
 Split one CLI line into command and argument string.
 

Variables

static const pin_info_t pin_table []
 

Macro Definition Documentation

◆ DECIMAL_BASE

#define DECIMAL_BASE   10U

Definition at line 42 of file cli_parser.c.

◆ NUM_PINS

#define NUM_PINS   ARRAY_LEN(pin_table)

Definition at line 41 of file cli_parser.c.

Function Documentation

◆ cli_parse()

e2s_error_t cli_parse ( const char *  line,
char *  cmd,
size_t  cmd_cap,
char *  args,
size_t  args_cap 
)

Split one CLI line into command and argument string.

Parameters
lineInput command line.
cmdOutput command token buffer.
cmd_capCommand token buffer capacity.
argsOutput argument string buffer.
args_capArgs token buffer capacity.
Returns
Parse status.

Definition at line 531 of file cli_parser.c.

References E2S_ERR_CLI_EMPTY_LINE, E2S_ERR_CLI_LINE_FORMAT, E2S_ERR_CLI_LINE_TRUNCATED, E2S_ERR_CLI_USAGE_SET, and E2S_OK.

Referenced by handle_cli_line().

Here is the caller graph for this function:

◆ find_pin()

const pin_info_t * find_pin ( const char *  name)

Lookup pin metadata by name.

Parameters
namePin name.
Returns
Pointer to pin metadata or NULL.

Definition at line 503 of file cli_parser.c.

References NUM_PINS, and pin_table.

Referenced by cmd_pininfo(), parse_get_args(), parse_set_gpio_args(), and parse_set_v24_polarities().

Here is the caller graph for this function:

◆ get_num_pins()

size_t get_num_pins ( void  )

Return number of entries in the CLI pin table.

Definition at line 44 of file cli_parser.c.

References NUM_PINS.

◆ get_pin_table()

const pin_info_t * get_pin_table ( void  )

Return pointer to static pin metadata table.

Definition at line 497 of file cli_parser.c.

References pin_table.

Referenced by cmd_help().

Here is the caller graph for this function:

◆ parse_get_args()

e2s_error_t parse_get_args ( const char *  args,
char *  pin_name,
const pin_info_t **  pin 
)

Parse get command arguments and resolve pin metadata.

Parameters
argsArgument string.
pin_nameOutput pin name.
pinResolved pin metadata entry.
Returns
Parse status.

Definition at line 515 of file cli_parser.c.

References E2S_ERR_CLI_UNKNOWN_PIN, E2S_ERR_CLI_USAGE_GET, E2S_OK, and find_pin().

Referenced by cat_gpio_get().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_i32_strict()

static bool parse_i32_strict ( const char *  input_str,
int32_t *  output_value 
)
static

Definition at line 83 of file cli_parser.c.

References DECIMAL_BASE.

Referenced by parse_set_gpio_args().

Here is the caller graph for this function:

◆ parse_ipv4_strict()

static bool parse_ipv4_strict ( const char *  input_str,
uint8_t  ip_addr[4] 
)
static

Definition at line 103 of file cli_parser.c.

References DECIMAL_BASE.

Referenced by parse_ipv4_with_optional_prefix(), and parse_set_ip_args().

Here is the caller graph for this function:

◆ parse_ipv4_with_optional_prefix()

static e2s_error_t parse_ipv4_with_optional_prefix ( const char *  args,
const char *  prefix,
uint8_t  ip_addr[4] 
)
static

Definition at line 145 of file cli_parser.c.

References E2S_ERR_CLI_USAGE_SET, E2S_OK, and parse_ipv4_strict().

Referenced by parse_set_gateway_args(), and parse_set_ip_remote_args().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_set_gateway_args()

e2s_error_t parse_set_gateway_args ( const char *  args,
uint8_t  ip_addr[4] 
)

Parse gateway ip_addr argument.

Parameters
argsArgument string.
ip_addrOutput ip_addrv4 address.
Returns
Parse status.

Definition at line 297 of file cli_parser.c.

References parse_ipv4_with_optional_prefix().

Here is the call graph for this function:

◆ parse_set_gpio_args()

e2s_error_t parse_set_gpio_args ( const char *  args,
char *  pin_name,
int *  value,
const pin_info_t **  pin 
)

Parse GPIO set command arguments.

Parameters
argsArgument string.
pin_nameOutput pin name.
valueOutput pin value.
pinResolved pin metadata entry.
Returns
Parse status.

Definition at line 231 of file cli_parser.c.

References E2S_ERR_CLI_PIN_INPUT_ONLY, E2S_ERR_CLI_UNKNOWN_PIN, E2S_ERR_CLI_USAGE_SET, E2S_OK, find_pin(), and parse_i32_strict().

Referenced by cat_gpio_set().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_set_ip_args()

e2s_error_t parse_set_ip_args ( const char *  args,
uint8_t  ip_addr[4],
uint8_t  netmask[4] 
)

Parse ip_addr and optional netmask values.

Parameters
argsArgument string.
ip_addrOutput ip_addrv4 address.
netmaskOutput subnet netmas.
Returns
Parse status.

Definition at line 187 of file cli_parser.c.

References E2S_ERR_CLI_USAGE_SET, E2S_OK, parse_ipv4_strict(), parse_u32_strict(), and prefix_to_mask().

Referenced by parse_set_net_ip_args(), and subcmd_set_ip_local().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_set_ip_remote_args()

e2s_error_t parse_set_ip_remote_args ( const char *  args,
uint8_t  ip_addr[4] 
)

Parse remote ip_addr argument.

Parameters
argsArgument string.
ip_addrOutput ip_addrv4 address.
Returns
Parse status.

Definition at line 292 of file cli_parser.c.

References parse_ipv4_with_optional_prefix().

Referenced by subcmd_set_ip_gateway(), and subcmd_set_ip_remote().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_set_net_ip_args()

e2s_error_t parse_set_net_ip_args ( const char *  args,
uint8_t  ip_addr[4],
uint8_t  netmask[4] 
)

Parse network local ip_addr/subnet arguments.

Parameters
argsArgument string.
ip_addrOutput ip_addrv4 address.
netmaskOutput subnet netmask.
Returns
Parse status.

Definition at line 283 of file cli_parser.c.

References E2S_ERR_CLI_USAGE_SET, and parse_set_ip_args().

Here is the call graph for this function:

◆ parse_set_udp_port_local_args()

e2s_error_t parse_set_udp_port_local_args ( const char *  args,
uint16_t *  port 
)

Parse local UDP port argument.

Parameters
argsArgument string.
portOutput UDP port.
Returns
Parse status.

Definition at line 302 of file cli_parser.c.

References parse_u16_with_optional_prefix().

Referenced by subcmd_set_udp_port_local().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_set_udp_port_remote_args()

e2s_error_t parse_set_udp_port_remote_args ( const char *  args,
uint16_t *  port 
)

Parse remote UDP port argument.

Parameters
argsArgument string.
portOutput UDP port.
Returns
Parse status.

Definition at line 307 of file cli_parser.c.

References parse_u16_with_optional_prefix().

Referenced by subcmd_set_udp_port_remote().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_set_v24_baudrate()

e2s_error_t parse_set_v24_baudrate ( const char *  args,
V24_BAUDRATE_T baudrate 
)

Parse V.24 baudrate argument.

Parameters
argsArgument string.
baudrateOutput baudrate value.
Returns
Parse status.

Definition at line 417 of file cli_parser.c.

References E2S_ERR_CLI_USAGE_SET, E2S_OK, parse_u32_strict(), V24_BAUD_115200, V24_BAUD_1200, V24_BAUD_16000, V24_BAUD_19200, V24_BAUD_2400, V24_BAUD_38400, V24_BAUD_4800, V24_BAUD_57600, and V24_BAUD_9600.

Referenced by subcmd_set_v24_baudrate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_set_v24_clockmode()

e2s_error_t parse_set_v24_clockmode ( const char *  args,
bool *  clockmode 
)

Parse V.24 tx clock mode argument.

Parameters
argsArgument string.
clockmodeOutput clock mode (0 internal, 1 external).
Returns
Parse status.

Definition at line 462 of file cli_parser.c.

References E2S_ERR_CLI_USAGE_SET, E2S_OK, and parse_u32_strict().

Referenced by subcmd_set_v24_clockmode().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_set_v24_polarities()

e2s_error_t parse_set_v24_polarities ( const char *  args,
V24_POLARITIES_T polarities 
)

Parse V.24 polarities argument list.

Parameters
argsArgument string.
polaritiesOutput polarity configuration.
Returns
Parse status.

Definition at line 312 of file cli_parser.c.

References V24_TX_POLARITIES_T::cts_inverted, V24_RX_POLARITIES_T::dcd_inverted, V24_TX_POLARITIES_T::dtr_inverted, E2S_ERR_CLI_USAGE_SET, E2S_OK, find_pin(), V24_TX_POLARITIES_T::rts_inverted, V24_POLARITIES_T::rx_polarities, V24_RX_POLARITIES_T::rxc_inverted, V24_RX_POLARITIES_T::rxd_inverted, V24_POLARITIES_T::tx_polarities, V24_TX_POLARITIES_T::txc_inverted, and V24_TX_POLARITIES_T::txd_inverted.

Referenced by subcmd_set_v24_inverted().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_u16_with_optional_prefix()

static e2s_error_t parse_u16_with_optional_prefix ( const char *  args,
const char *  prefix,
uint16_t *  value 
)
static

Definition at line 165 of file cli_parser.c.

References E2S_ERR_CLI_USAGE_SET, E2S_OK, and parse_u32_strict().

Referenced by parse_set_udp_port_local_args(), and parse_set_udp_port_remote_args().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_u32_strict()

static bool parse_u32_strict ( const char *  input_str,
uint32_t *  output_value 
)
static

Definition at line 64 of file cli_parser.c.

References DECIMAL_BASE.

Referenced by parse_set_ip_args(), parse_set_v24_baudrate(), parse_set_v24_clockmode(), and parse_u16_with_optional_prefix().

Here is the caller graph for this function:

◆ prefix_to_mask()

static bool prefix_to_mask ( uint8_t  prefix,
uint8_t  netmask[4] 
)
static

Definition at line 50 of file cli_parser.c.

References UINT32_ALL_ONES.

Referenced by parse_set_ip_args().

Here is the caller graph for this function:

Variable Documentation

◆ pin_table

const pin_info_t pin_table[]
static
Initial value:
= {
{"txd", V24_TXD, true}, {"rxd", V24_RXD, false},
{"rts", V24_RTS, true}, {"cts", V24_CTS, false},
{"dtr", V24_DTR, true}, {"dsr", V24_DSR, false},
{"dcd", V24_DCD, false}, {"tx_active", V24_TX_ACTIVE, true},
{"tck", V24_TXC_DTE, true}, {"rck", V24_RXC, false},
{"led", V24_STATUS_LED, true}}
#define V24_RXC
Definition pinmap.h:28
#define V24_DCD
Definition pinmap.h:30
#define V24_DTR
Definition pinmap.h:37
#define V24_TXD
Definition pinmap.h:35
#define V24_RTS
Definition pinmap.h:34
#define V24_TXC_DTE
Definition pinmap.h:29
#define V24_STATUS_LED
Definition pinmap.h:39
#define V24_RXD
Definition pinmap.h:33
#define V24_DSR
Definition pinmap.h:31
#define V24_CTS
Definition pinmap.h:32
#define V24_TX_ACTIVE
Definition pinmap.h:38

Definition at line 33 of file cli_parser.c.

Referenced by cmd_help(), find_pin(), and get_pin_table().