|
ether2ser 0.1.0
Ethernet <-> synchronous V.24 bridge firmware for RP2040 + W5500
|
#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"
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_t * | get_pin_table (void) |
| Return pointer to static pin metadata table. | |
| const pin_info_t * | find_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 [] |
| #define DECIMAL_BASE 10U |
Definition at line 42 of file cli_parser.c.
Definition at line 41 of file cli_parser.c.
| 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.
| line | Input command line. |
| cmd | Output command token buffer. |
| cmd_cap | Command token buffer capacity. |
| args | Output argument string buffer. |
| args_cap | Args token buffer capacity. |
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().

| const pin_info_t * find_pin | ( | const char * | name | ) |
Lookup pin metadata by name.
| name | Pin name. |
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().

| 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.
| 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().

| 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.
| args | Argument string. |
| pin_name | Output pin name. |
| pin | Resolved pin metadata entry. |
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().


|
static |
Definition at line 83 of file cli_parser.c.
References DECIMAL_BASE.
Referenced by parse_set_gpio_args().

|
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().

|
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().


| e2s_error_t parse_set_gateway_args | ( | const char * | args, |
| uint8_t | ip_addr[4] | ||
| ) |
Parse gateway ip_addr argument.
| args | Argument string. |
| ip_addr | Output ip_addrv4 address. |
Definition at line 297 of file cli_parser.c.
References parse_ipv4_with_optional_prefix().

| 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.
| args | Argument string. |
| pin_name | Output pin name. |
| value | Output pin value. |
| pin | Resolved pin metadata entry. |
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().


| 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.
| args | Argument string. |
| ip_addr | Output ip_addrv4 address. |
| netmask | Output subnet netmas. |
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().


| e2s_error_t parse_set_ip_remote_args | ( | const char * | args, |
| uint8_t | ip_addr[4] | ||
| ) |
Parse remote ip_addr argument.
| args | Argument string. |
| ip_addr | Output ip_addrv4 address. |
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().


| 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.
| args | Argument string. |
| ip_addr | Output ip_addrv4 address. |
| netmask | Output subnet netmask. |
Definition at line 283 of file cli_parser.c.
References E2S_ERR_CLI_USAGE_SET, and parse_set_ip_args().

| e2s_error_t parse_set_udp_port_local_args | ( | const char * | args, |
| uint16_t * | port | ||
| ) |
Parse local UDP port argument.
| args | Argument string. |
| port | Output UDP port. |
Definition at line 302 of file cli_parser.c.
References parse_u16_with_optional_prefix().
Referenced by subcmd_set_udp_port_local().


| e2s_error_t parse_set_udp_port_remote_args | ( | const char * | args, |
| uint16_t * | port | ||
| ) |
Parse remote UDP port argument.
| args | Argument string. |
| port | Output UDP port. |
Definition at line 307 of file cli_parser.c.
References parse_u16_with_optional_prefix().
Referenced by subcmd_set_udp_port_remote().


| e2s_error_t parse_set_v24_baudrate | ( | const char * | args, |
| V24_BAUDRATE_T * | baudrate | ||
| ) |
Parse V.24 baudrate argument.
| args | Argument string. |
| baudrate | Output baudrate value. |
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().


| e2s_error_t parse_set_v24_clockmode | ( | const char * | args, |
| bool * | clockmode | ||
| ) |
Parse V.24 tx clock mode argument.
| args | Argument string. |
| clockmode | Output clock mode (0 internal, 1 external). |
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().


| e2s_error_t parse_set_v24_polarities | ( | const char * | args, |
| V24_POLARITIES_T * | polarities | ||
| ) |
Parse V.24 polarities argument list.
| args | Argument string. |
| polarities | Output polarity configuration. |
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().


|
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().


|
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().

|
static |
Definition at line 50 of file cli_parser.c.
References UINT32_ALL_ONES.
Referenced by parse_set_ip_args().

|
static |
Definition at line 33 of file cli_parser.c.
Referenced by cmd_help(), find_pin(), and get_pin_table().