microRTPS: agent: cleanup and make arguments consistent

This commit is contained in:
TSC21
2021-08-12 08:44:53 +02:00
committed by Nuno Marques
parent e83a3a6cf7
commit 109b031156
+44 -29
View File
@@ -80,14 +80,16 @@ recv_topics = [(alias[idx] if alias[idx] else s.short_name) for idx, s in enumer
@[end if]@
// Default values
#define DEVICE "/dev/ttyACM0"
#define SLEEP_US 1
#define BAUDRATE 460800
#define POLL_MS 1
#define WAIT_CNST 2
#define SLEEP_US 1
#define MAX_SLEEP_US 1000000
#define BAUDRATE 460800
#define MAX_DATA_RATE 10000000
#define DEVICE "/dev/ttyACM0"
#define POLL_MS 1
#define MAX_POLL_MS 1000
#define DEFAULT_RECV_PORT 2020
#define DEFAULT_SEND_PORT 2019
#define DEFAULT_IP "127.0.0.1"
#define DEFAULT_IP "127.0.0.1"
using namespace eprosima;
using namespace eprosima::fastrtps;
@@ -119,18 +121,22 @@ struct options {
static void usage(const char *name)
{
printf("usage: %s [options]\n\n"
" -b <baudrate> UART device baudrate. Default 460800\n"
" -d <device> UART device. Default /dev/ttyACM0\n"
" -f <sw flow control> Activates UART link SW flow control\n"
" -h <hw flow control> Activates UART link HW flow control\n"
" -i <ip_address> Target IP for UDP. Default 127.0.0.1\n"
" -n <namespace> ROS 2 topics namespace. Identifies the vehicle in a multi-agent network\n"
" -p <poll_ms> Time in ms to poll over UART. Default 1ms\n"
" -r <reception port> UDP port for receiving. Default 2020\n"
" -s <sending port> UDP port for sending. Default 2019\n"
" -t <transport> [UART|UDP] Default UART\n"
" -v <debug verbosity> Add more verbosity\n"
" -w <sleep_time_us> Time in us for which each iteration sleep. Default 1ms\n",
" -b <baudrate> UART device baudrate. Defaults to 460800\n"
" -d <device> UART device. Defaults to /dev/ttyACM0\n"
" -f <sw-flow-control> Activates UART link SW flow control\n"
" -h <hw-flow-control> Activates UART link HW flow control\n"
" -i <ip-address> Target remote IP address for UDP. Defaults to 127.0.0.1\n"
" -n <namespace> Topics namespace. Identifies the vehicle in a multi-agent network\n"
" -o <poll-ms> UART polling timeout in milliseconds. Defaults to 1ms\n"
" -r <reception-port> UDP port for receiving (local). Defaults to 2020\n"
" -s <sending-port> UDP port for sending (remote). Defaults to 2019\n"
" -t <transport> [UART|UDP] Defaults to UART\n"
" -v <increase-verbosity> Add more verbosity\n"
" -w <sleep-time-us> Iteration time for data publishing to the DDS world, in microseconds.\n"
" Defaults to 1us\n"
" <ros-args> (ROS2 only) Allows to pass arguments to the timesync ROS2 node.\n"
" Currently used for setting the usage of simulation time by the node using\n"
" '--ros-args -p use_sim_time:=true'\n",
name);
}
@@ -143,7 +149,7 @@ static int parse_options(int argc, char **argv)
{"hw-flow-control", no_argument, NULL, 'g'},
{"ip-address", required_argument, NULL, 'i'},
{"namespace", required_argument, NULL, 'n'},
{"poll-ms", required_argument, NULL, 'p'},
{"poll-ms", required_argument, NULL, 'o'},
{"reception-port", required_argument, NULL, 'r'},
{"sending-port", required_argument, NULL, 's'},
{"transport", required_argument, NULL, 't'},
@@ -163,7 +169,7 @@ static int parse_options(int argc, char **argv)
case 'd': if (nullptr != optarg) strcpy(_options.device, optarg); break;
case 'w': _options.sleep_us = strtol(optarg, nullptr, 10); break;
case 'w': _options.sleep_us = strtoul(optarg, nullptr, 10); break;
case 'b': _options.baudrate = strtoul(optarg, nullptr, 10); break;
@@ -195,13 +201,21 @@ static int parse_options(int argc, char **argv)
}
}
if (_options.poll_ms < 1) {
_options.poll_ms = 1;
printf("\033[1;33m[ micrortps_agent ]\tPoll timeout too low, using 1 ms\033[0m");
if (_options.poll_ms < POLL_MS) {
_options.poll_ms = POLL_MS;
printf("\033[1;33m[ micrortps_agent ]\tPoll timeout too low. Using %d ms instead\033[0m\n", POLL_MS);
} else if (_options.poll_ms > MAX_POLL_MS) {
_options.poll_ms = MAX_POLL_MS;
printf("\033[1;33m[ micrortps_agent ]\tPoll timeout too high. Using %d ms instead\033[0m\n", MAX_POLL_MS);
}
if (_options.sleep_us > MAX_SLEEP_US) {
_options.sleep_us = MAX_SLEEP_US;
printf("\033[1;33m[ micrortps_agent ]\tPublishing iteration cycle too slow. Using %d us instead\033[0m\n", MAX_SLEEP_US);
}
if (_options.hw_flow_control && _options.sw_flow_control) {
printf("\033[0;31m[ micrortps_agent ]\tHW and SW flow control set. Please set only one or another\033[0m");
printf("\033[0;31m[ micrortps_agent ]\tHW and SW flow control set. Please set only one or another\033[0m\n");
return -1;
}
@@ -259,6 +273,8 @@ void signal_handler(int signum)
int main(int argc, char **argv)
{
printf("\033[0;37m--- MicroRTPS Agent ---\033[0m\n");
if (-1 == parse_options(argc, argv)) {
printf("\033[1;33m[ micrortps_agent ]\tEXITING...\033[0m\n");
return -1;
@@ -274,7 +290,6 @@ int main(int argc, char **argv)
// register signal SIGINT and signal handler
signal(SIGINT, signal_handler);
printf("\033[0;37m--- MicroRTPS Agent ---\033[0m\n");
printf("[ micrortps_agent ]\tStarting link...\n");
const char* localhost_only = std::getenv("ROS_LOCALHOST_ONLY");
@@ -296,8 +311,8 @@ int main(int argc, char **argv)
case options::eTransports::UART: {
transport_node = std::make_unique<UART_node>(_options.device, _options.baudrate, _options.poll_ms,
_options.sw_flow_control, _options.hw_flow_control, sys_id, _options.verbose_debug);
printf("[ micrortps_agent ]\tUART transport: device: %s; baudrate: %d; sleep: %dus; poll: %dms; flow_control: %s\n",
_options.device, _options.baudrate, _options.sleep_us, _options.poll_ms,
printf("[ micrortps_agent ]\tUART transport: device: %s; baudrate: %d; poll: %dms; flow_control: %s\n",
_options.device, _options.baudrate, _options.poll_ms,
_options.sw_flow_control ? "SW enabled" : (_options.hw_flow_control ? "HW enabled" : "No"));
}
break;
@@ -305,8 +320,8 @@ int main(int argc, char **argv)
case options::eTransports::UDP: {
transport_node = std::make_unique<UDP_node>(_options.ip, _options.recv_port, _options.send_port,
sys_id, _options.verbose_debug);
printf("[ micrortps_agent ]\tUDP transport: ip address: %s; recv port: %u; send port: %u; sleep: %dus\n",
_options.ip, _options.recv_port, _options.send_port, _options.sleep_us);
printf("[ micrortps_agent ]\tUDP transport: ip address: %s; recv port: %u; send port: %u\n",
_options.ip, _options.recv_port, _options.send_port);
}
break;