From fae1627d9294deb414df021b4e0d28ff989df34b Mon Sep 17 00:00:00 2001 From: TSC21 Date: Fri, 23 Jul 2021 11:22:03 +0200 Subject: [PATCH] microRTPS: client: cleanup and make arguments consistent --- msg/templates/urtps/microRTPS_transport.cpp | 12 +++---- .../micrortps_client/microRTPS_client.h | 6 ++-- .../microRTPS_client_main.cpp | 33 ++++++++++++------- 3 files changed, 32 insertions(+), 19 deletions(-) diff --git a/msg/templates/urtps/microRTPS_transport.cpp b/msg/templates/urtps/microRTPS_transport.cpp index 60b04a9ba3..6e3382b768 100644 --- a/msg/templates/urtps/microRTPS_transport.cpp +++ b/msg/templates/urtps/microRTPS_transport.cpp @@ -157,11 +157,11 @@ ssize_t Transport_node::read(uint8_t *topic_id, char out_buffer[], size_t buffer if (msg_start_pos > (_rx_buff_pos - header_size)) { #ifndef PX4_DEBUG - if (debug) { printf("\033[1;33m[ micrortps_transport ]\t (↓↓ %" PRIu32 ")\033[0m\n", msg_start_pos); } + if (_debug) { printf("\033[1;33m[ micrortps_transport ]\t (↓↓ %" PRIu32 ")\033[0m\n", msg_start_pos); } #else - if (debug) { PX4_DEBUG(" (↓↓ %" PRIu32 ")", msg_start_pos); } + if (_debug) { PX4_DEBUG(" (↓↓ %" PRIu32 ")", msg_start_pos); } #endif /* PX4_DEBUG */ @@ -200,11 +200,11 @@ ssize_t Transport_node::read(uint8_t *topic_id, char out_buffer[], size_t buffer if (msg_start_pos > 0) { #ifndef PX4_DEBUG - if (debug) { printf("\033[1;33m[ micrortps_transport ]\t (↓ %" PRIu32 ")\033[0m\n", msg_start_pos); } + if (_debug) { printf("\033[1;33m[ micrortps_transport ]\t (↓ %" PRIu32 ")\033[0m\n", msg_start_pos); } #else - if (debug) { PX4_DEBUG(" (↓ %" PRIu32 ")", msg_start_pos); } + if (_debug) { PX4_DEBUG(" (↓ %" PRIu32 ")", msg_start_pos); } #endif /* PX4_DEBUG */ memmove(_rx_buffer, _rx_buffer + msg_start_pos, _rx_buff_pos - msg_start_pos); @@ -220,7 +220,7 @@ ssize_t Transport_node::read(uint8_t *topic_id, char out_buffer[], size_t buffer if (read_crc != calc_crc) { #ifndef PX4_DEBUG - if (debug) { printf("\033[0;31m[ micrortps_transport ]\tBad CRC %" PRIu16 " != %" PRIu16 "\t\t(↓ %lu)\033[0m\n", read_crc, calc_crc, (unsigned long)(header_size + payload_len)); } + if (_debug) { printf("\033[0;31m[ micrortps_transport ]\tBad CRC %" PRIu16 " != %" PRIu16 "\t\t(↓ %lu)\033[0m\n", read_crc, calc_crc, (unsigned long)(header_size + payload_len)); } #else @@ -375,7 +375,7 @@ int UART_node::init() _uart_name, _baudrate); #else PX4_ERR("UART transport: ERR SET BAUD %s: Unsupported baudrate: %" PRIu32 "\n\tsupported examples:\n\t9600, 19200, 38400, 57600, 115200, 230400, 460800, 500000, 921600, 1000000\n", - uart_name, baudrate); + _uart_name, _baudrate); #endif /* PX4_ERR */ close(); return -EINVAL; diff --git a/src/modules/micrortps_bridge/micrortps_client/microRTPS_client.h b/src/modules/micrortps_bridge/micrortps_client/microRTPS_client.h index 381b9a1603..029bb2331d 100644 --- a/src/modules/micrortps_bridge/micrortps_client/microRTPS_client.h +++ b/src/modules/micrortps_bridge/micrortps_client/microRTPS_client.h @@ -51,11 +51,13 @@ #define LOOPS -1 #define SLEEP_US 1000 +#define MAX_SLEEP_US 1000000 #define BAUDRATE 460800 #define MAX_DATA_RATE 10000000 #define DEVICE "/dev/ttyACM0" #define POLL_MS 1 -#define IP "127.0.0.1" +#define MAX_POLL_MS 1000 +#define DEFAULT_IP "127.0.0.1" #define DEFAULT_RECV_PORT 2019 #define DEFAULT_SEND_PORT 2020 #define MIN_TX_INTERVAL_US 1000.f @@ -79,7 +81,7 @@ struct options { }; eTransports transport = options::eTransports::UART; char device[64] = DEVICE; - char ip[16] = IP; + char ip[16] = DEFAULT_IP; uint16_t recv_port = DEFAULT_RECV_PORT; uint16_t send_port = DEFAULT_SEND_PORT; uint32_t sleep_us = SLEEP_US; diff --git a/src/modules/micrortps_bridge/micrortps_client/microRTPS_client_main.cpp b/src/modules/micrortps_bridge/micrortps_client/microRTPS_client_main.cpp index 947dd1f7d5..228e750c5f 100644 --- a/src/modules/micrortps_bridge/micrortps_client/microRTPS_client_main.cpp +++ b/src/modules/micrortps_bridge/micrortps_client/microRTPS_client_main.cpp @@ -75,11 +75,12 @@ static void usage(const char *name) PRINT_MODULE_USAGE_PARAM_STRING('t', "UART", "UART|UDP", "Transport protocol", true); PRINT_MODULE_USAGE_PARAM_STRING('d', "/dev/ttyACM0", "", "Select Serial Device", true); PRINT_MODULE_USAGE_PARAM_INT('b', 460800, 9600, 3000000, "Baudrate (can also be p:)", true); - PRINT_MODULE_USAGE_PARAM_INT('m', 0, 10, 10000000, "Maximum sending data rate in B/s", true); - PRINT_MODULE_USAGE_PARAM_INT('p', -1, 1, 1000, "Poll timeout for UART in ms", true); - PRINT_MODULE_USAGE_PARAM_INT('l', 10000, -1, 100000, "Limit number of iterations until the program exits (-1=infinite)", + PRINT_MODULE_USAGE_PARAM_INT('m', 0, 0, MAX_DATA_RATE, "Maximum sending data rate in B/s (0=not limited)", true); + PRINT_MODULE_USAGE_PARAM_INT('p', 1, 1, MAX_POLL_MS, "Poll timeout for UART in milliseconds", true); + PRINT_MODULE_USAGE_PARAM_INT('l', -1, -1, INT32_MAX, "Limit number of iterations until the program exits (-1=infinite)", true); - PRINT_MODULE_USAGE_PARAM_INT('w', 1, 1, 1000000, "Time in us for which each read from the link iteration sleeps", true); + PRINT_MODULE_USAGE_PARAM_INT('w', 1000, 0, MAX_SLEEP_US, + "Iteration time for data publishing to the uORB side, in microseconds", true); PRINT_MODULE_USAGE_PARAM_INT('r', 2019, 0, 65536, "Select UDP Network Port for receiving (local)", true); PRINT_MODULE_USAGE_PARAM_INT('s', 2020, 0, 65536, "Select UDP Network Port for sending (remote)", true); PRINT_MODULE_USAGE_PARAM_STRING('i', "127.0.0.1", "", "Select IP address (remote)", true); @@ -145,11 +146,21 @@ static int parse_options(int argc, char *argv[]) if (_options.datarate > MAX_DATA_RATE) { _options.datarate = MAX_DATA_RATE; - PX4_WARN("Invalid data rate. Using max datarate of %ul B/s", MAX_DATA_RATE); + PX4_WARN("Data rate too high. Using max datarate of %d B/s instead", MAX_DATA_RATE); } - if (_options.poll_ms < 1) { - PX4_WARN("Poll timeout too low, using %ul ms", POLL_MS); + if (_options.poll_ms < POLL_MS) { + _options.poll_ms = POLL_MS; + PX4_WARN("Poll timeout too low. Using %d ms instead", POLL_MS); + + } else if (_options.poll_ms > MAX_POLL_MS) { + _options.poll_ms = MAX_POLL_MS; + PX4_WARN("Poll timeout too high. Using %d ms instead", MAX_POLL_MS); + } + + if (_options.sleep_us > MAX_SLEEP_US) { + _options.sleep_us = MAX_SLEEP_US; + PX4_WARN("Publishing iteration cycle too slow. Using %d us instead", MAX_SLEEP_US); } if (_options.hw_flow_control && _options.sw_flow_control) { @@ -176,8 +187,8 @@ static int micrortps_start(int argc, char *argv[]) transport_node = new UART_node(_options.device, _options.baudrate, _options.poll_ms, _options.sw_flow_control, _options.hw_flow_control, sys_id, _options.verbose_debug); - PX4_INFO("UART transport: device: %s; baudrate: %" PRIu32 "; sleep: %" PRIu32 "ms; flow_control: %s", - _options.device, _options.baudrate, _options.sleep_us, _options.poll_ms, + PX4_INFO("UART transport: device: %s; baudrate: %" PRIu32 "; poll: %" PRIu32 "ms; flow_control: %s", + _options.device, _options.baudrate, _options.poll_ms, _options.sw_flow_control ? "SW enabled" : (_options.hw_flow_control ? "HW enabled" : "No")); } break; @@ -185,8 +196,8 @@ static int micrortps_start(int argc, char *argv[]) case options::eTransports::UDP: { transport_node = new UDP_node(_options.ip, _options.recv_port, _options.send_port, sys_id, _options.verbose_debug); - PX4_INFO("UDP transport: ip address: %s; recv port: %" PRIu16 "; send port: %" PRIu16 "; sleep: %" PRIu32 "us", - _options.ip, _options.recv_port, _options.send_port, _options.sleep_us); + PX4_INFO("UDP transport: ip address: %s; recv port: %" PRIu16 "; send port: %" PRIu16, + _options.ip, _options.recv_port, _options.send_port); } break;