From 83133b1bcae2eae59383dad7d1b6070657e9d279 Mon Sep 17 00:00:00 2001 From: David Riseborough Date: Fri, 2 Feb 2018 19:59:03 +1100 Subject: [PATCH] This commit fixes the way baud rate is generated from the program argument in the FTPS client and agent. A table has been added to the FTPS client and agent code that correlates the baud rate value with the encoding. A function has been added to the FTPS client and agent to take the program argument for baud rate and use it to look up the table and return the entry containing both the value and the encoding. The value is displayed for the user and the encoding is sent to the uart node constructor. Signed-off-by: David Riseborough --- .../urtps/microRTPS_agent.cpp.template | 37 ++++++++++++++++--- .../micrortps_client/microRTPS_client.h | 10 ++++- .../microRTPS_client_main.cpp | 30 +++++++++++++-- 3 files changed, 67 insertions(+), 10 deletions(-) diff --git a/msg/templates/urtps/microRTPS_agent.cpp.template b/msg/templates/urtps/microRTPS_agent.cpp.template index af3fd609f3..9c6e5162e9 100644 --- a/msg/templates/urtps/microRTPS_agent.cpp.template +++ b/msg/templates/urtps/microRTPS_agent.cpp.template @@ -58,6 +58,7 @@ recv_topics = [s.short_name for idx, s in enumerate(spec) if scope[idx] == MsgSc #include #include #include +#include #include #include @@ -73,7 +74,8 @@ recv_topics = [s.short_name for idx, s in enumerate(spec) if scope[idx] == MsgSc // Default values #define DEVICE "/dev/ttyACM0" #define SLEEP_US 1 -#define BAUDRATE 460800 +#define BAUDRATE B460800 +#define BAUDRATE_VAL 460800 #define POLL_MS 0 #define WAIT_CNST 2 #define DEFAULT_RECV_PORT 2020 @@ -87,6 +89,22 @@ Transport_node *transport_node = nullptr; RtpsTopics topics; uint32_t total_sent = 0, sent = 0; +struct baudtype { + speed_t code; + uint32_t val; +}; + +const baudtype baudlist[] = { + [0] = {.code = B0, .val = 0}, + [1] = {.code = B9600, .val = 9600}, + [2] = {.code = B19200, .val = 19200}, + [3] = {.code = B38400, .val = 38400}, + [4] = {.code = B57600, .val = 57600}, + [5] = {.code = B115200, .val = 115200}, + [6] = {.code = B230400, .val = 230400}, + [7] = {.code = B460800, .val = 460800}, +}; + struct options { enum class eTransports { @@ -96,7 +114,7 @@ struct options { eTransports transport = options::eTransports::UART; char device[64] = DEVICE; int sleep_us = SLEEP_US; - uint32_t baudrate = BAUDRATE; + baudtype baudrate = {.code=BAUDRATE,.val=BAUDRATE_VAL}; int poll_ms = POLL_MS; uint16_t recv_port = DEFAULT_RECV_PORT; uint16_t send_port = DEFAULT_SEND_PORT; @@ -115,6 +133,15 @@ static void usage(const char *name) name); } +baudtype getbaudrate(char *valstr) +{ + uint32_t baudval = strtoul(valstr, nullptr, 10); + for (unsigned int i=1; i