ether2ser 0.1.0
Ethernet <-> synchronous V.24 bridge firmware for RP2040 + W5500
Loading...
Searching...
No Matches
cli_parser.h File Reference
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "drivers/gpio_driver.h"
#include "drivers/v24_config.h"
#include "system/error.h"
Include dependency graph for cli_parser.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  pin_info_t
 Pin metadata entry used by CLI lookup and validation. More...
 

Functions

size_t get_num_pins (void)
 Return number of entries in the CLI pin table.
 
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.
 
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.
 
const pin_info_tfind_pin (const char *name)
 Lookup pin metadata by name.
 
const pin_info_tget_pin_table (void)
 Return pointer to static pin metadata table.
 
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.
 

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_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: