diff --git a/modules/SerialCommHub/main/serial_communication_hubImpl.cpp b/modules/SerialCommHub/main/serial_communication_hubImpl.cpp index 9848fc5ed..55b6022dc 100644 --- a/modules/SerialCommHub/main/serial_communication_hubImpl.cpp +++ b/modules/SerialCommHub/main/serial_communication_hubImpl.cpp @@ -39,8 +39,8 @@ void serial_communication_hubImpl::init() { rxtx_gpio_settings.inverted = config.rxtx_gpio_tx_high; if (!modbus.open_device(config.serial_port, config.baudrate, config.ignore_echo, rxtx_gpio_settings, - static_cast(config.parity), milliseconds(config.initial_timeout_ms), - milliseconds(config.within_message_timeout_ms))) { + static_cast(config.parity), config.rtscts, + milliseconds(config.initial_timeout_ms), milliseconds(config.within_message_timeout_ms))) { EVLOG_AND_THROW(Everest::EverestConfigError(fmt::format("Cannot open serial port {}.", config.serial_port))); } } diff --git a/modules/SerialCommHub/main/serial_communication_hubImpl.hpp b/modules/SerialCommHub/main/serial_communication_hubImpl.hpp index 02232bffc..2a3933f7b 100644 --- a/modules/SerialCommHub/main/serial_communication_hubImpl.hpp +++ b/modules/SerialCommHub/main/serial_communication_hubImpl.hpp @@ -28,6 +28,7 @@ struct Conf { std::string serial_port; int baudrate; int parity; + bool rtscts; bool ignore_echo; std::string rxtx_gpio_chip; int rxtx_gpio_line; diff --git a/modules/SerialCommHub/manifest.yaml b/modules/SerialCommHub/manifest.yaml index ab187548a..5a62bc7d3 100644 --- a/modules/SerialCommHub/manifest.yaml +++ b/modules/SerialCommHub/manifest.yaml @@ -20,6 +20,10 @@ provides: minimum: 0 maximum: 2 default: 0 + rtscts: + description: Use RTS/CTS hardware flow control + type: boolean + default: false ignore_echo: description: On some hardware every message that is sent is read back, this setting filters the sent message in the reply. type: boolean diff --git a/modules/SerialCommHub/tiny_modbus_rtu.cpp b/modules/SerialCommHub/tiny_modbus_rtu.cpp index fb5de291a..39cbb0c78 100644 --- a/modules/SerialCommHub/tiny_modbus_rtu.cpp +++ b/modules/SerialCommHub/tiny_modbus_rtu.cpp @@ -193,7 +193,7 @@ TinyModbusRTU::~TinyModbusRTU() { } bool TinyModbusRTU::open_device(const std::string& device, int _baud, bool _ignore_echo, - const Everest::GpioSettings& rxtx_gpio_settings, const Parity parity, + const Everest::GpioSettings& rxtx_gpio_settings, const Parity parity, bool rtscts, std::chrono::milliseconds _initial_timeout, std::chrono::milliseconds _within_message_timeout) { @@ -264,7 +264,12 @@ bool TinyModbusRTU::open_device(const std::string& device, int _baud, bool _igno tty.c_cflag &= ~(PARENB | PARODD); // shut off parity } tty.c_cflag &= ~CSTOPB; // 1 Stop bit - tty.c_cflag &= ~CRTSCTS; + + if (rtscts) { + tty.c_cflag |= CRTSCTS; + } else { + tty.c_cflag &= ~CRTSCTS; + } if (tcsetattr(fd, TCSANOW, &tty) != 0) { printf("Serial: error %d from tcsetattr\n", errno); diff --git a/modules/SerialCommHub/tiny_modbus_rtu.hpp b/modules/SerialCommHub/tiny_modbus_rtu.hpp index b80558e20..abcd76ff7 100644 --- a/modules/SerialCommHub/tiny_modbus_rtu.hpp +++ b/modules/SerialCommHub/tiny_modbus_rtu.hpp @@ -57,7 +57,7 @@ class TinyModbusRTU { ~TinyModbusRTU(); bool open_device(const std::string& device, int baud, bool ignore_echo, - const Everest::GpioSettings& rxtx_gpio_settings, const Parity parity, + const Everest::GpioSettings& rxtx_gpio_settings, const Parity parity, bool rtscts, std::chrono::milliseconds initial_timeout, std::chrono::milliseconds within_message_timeout); std::vector txrx(uint8_t device_address, FunctionCode function, uint16_t first_register_address,