Commit 481027bb66d6a30f0dfb6d31aa201d0c6998cbe3
1 parent
d87350fb
Minor fixes
Showing
4 changed files
with
20 additions
and
26 deletions
src/modbusbase.h
| ... | ... | @@ -212,10 +212,10 @@ private: // Members (Giggity!) |
| 212 | 212 | bool m_connected{}; |
| 213 | 213 | uint32_t m_msg_id{}; |
| 214 | 214 | int m_slaveId{}; |
| 215 | - bool m_error{}; | |
| 216 | - int m_error_number{}; | |
| 217 | - std::string m_error_message; | |
| 218 | - unsigned int m_max_message_length; | |
| 215 | + bool m_error{false}; | |
| 216 | + int m_error_number{0}; | |
| 217 | + std::string m_error_message = ""; | |
| 218 | + unsigned int m_max_message_length = 254; | |
| 219 | 219 | |
| 220 | 220 | }; |
| 221 | 221 | ... | ... |
src/modbusrtu.cpp
| ... | ... | @@ -17,15 +17,15 @@ |
| 17 | 17 | |
| 18 | 18 | using namespace osdev::components::modbus; |
| 19 | 19 | |
| 20 | -ModbusRtu::ModbusRtu( const ConnectionConfig &conf ) | |
| 21 | - : m_conConfig( conf ) | |
| 20 | +ModbusRtu::ModbusRtu(const ConnectionConfig &conf) | |
| 21 | + : m_conConfig(conf) | |
| 22 | 22 | , m_socket( -1 ) |
| 23 | 23 | { |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | bool ModbusRtu::Connect() |
| 27 | 27 | { |
| 28 | - m_socket = open( m_conConfig.getPortName().c_str(), O_RDWR); | |
| 28 | + m_socket = open(m_conConfig.getPortName().c_str(), O_RDWR); | |
| 29 | 29 | if(m_socket == -1) |
| 30 | 30 | { |
| 31 | 31 | return false; |
| ... | ... | @@ -36,16 +36,16 @@ bool ModbusRtu::Connect() |
| 36 | 36 | // Read in existing settings, and handle any error |
| 37 | 37 | if( tcgetattr(m_socket, &l_tty) != 0 ) |
| 38 | 38 | { |
| 39 | - // Replace later on with a logger line. | |
| 39 | + //TODO: Replace later on with a logger line. | |
| 40 | 40 | return false; |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /* Control modes */ |
| 44 | - l_tty.c_cflag &= ~PARENB; // Clear parity bit, disabling parity (most common) | |
| 45 | - l_tty.c_cflag &= ~CSTOPB; // Clear stop field, only one stop bit used in communication (most common) | |
| 44 | + l_tty.c_cflag &= ~PARENB; // Clear parity bit, disabling parity | |
| 45 | + l_tty.c_cflag &= ~CSTOPB; // Clear stop field, only one stop bit used in communication | |
| 46 | 46 | l_tty.c_cflag &= ~CSIZE; // Clear all bits that set the data field |
| 47 | - l_tty.c_cflag |= CS8; // 8 bits per byte (most common) | |
| 48 | - l_tty.c_cflag &= ~CRTSCTS; // Disable RTS / CTS hardware flow control (most common) | |
| 47 | + l_tty.c_cflag |= CS8; // 8 bits per byte | |
| 48 | + l_tty.c_cflag &= ~CRTSCTS; // Disable RTS / CTS hardware flow control | |
| 49 | 49 | l_tty.c_cflag |= CREAD | CLOCAL; // Turn on READ & ignore ctrl lines (CLOCAL = 1) |
| 50 | 50 | |
| 51 | 51 | /* local modes */ | ... | ... |
src/modbusrtu.h
| ... | ... | @@ -18,22 +18,10 @@ public: |
| 18 | 18 | explicit ModbusRtu( const ConnectionConfig &conf ); |
| 19 | 19 | virtual ~ModbusRtu() {} |
| 20 | 20 | |
| 21 | + /*! Implementation of ModbusBase */ | |
| 21 | 22 | virtual bool Connect() override; |
| 22 | 23 | virtual bool Close() override; |
| 23 | - | |
| 24 | - /*! | |
| 25 | - * \brief modbusSend | |
| 26 | - * \param to_send | |
| 27 | - * \param length | |
| 28 | - * \return | |
| 29 | - */ | |
| 30 | 24 | virtual int modbusSend(uint8_t *to_send, size_t length) override; |
| 31 | - | |
| 32 | - /*! | |
| 33 | - * \brief modbusReceive | |
| 34 | - * \param buffer | |
| 35 | - * \return | |
| 36 | - */ | |
| 37 | 25 | virtual int modbusReceive(uint8_t *buffer) override; |
| 38 | 26 | |
| 39 | 27 | private: | ... | ... |
tests/connectionconfigtest.cpp
| ... | ... | @@ -23,5 +23,11 @@ TEST(ConnectionConfigTest, SerialPortConfig) |
| 23 | 23 | oConfig.setPortName( "/dev/ttyUSB0" ); |
| 24 | 24 | |
| 25 | 25 | // Test all parameters |
| 26 | - | |
| 26 | + EXPECT_EQ(oConfig.getBaudRate(), B9600); | |
| 27 | + EXPECT_EQ(oConfig.getConnectionType(), ConnectionConfig::E_CONNECTIONTYPE::SERIAL); | |
| 28 | + EXPECT_EQ(oConfig.getDataBits(), 8); | |
| 29 | + EXPECT_EQ(oConfig.getStopBits(), 1); | |
| 30 | + EXPECT_EQ(oConfig.getFrameTimeout(), 10); | |
| 31 | + EXPECT_EQ(oConfig.getParity(), ConnectionConfig::E_PARITY::NONE); | |
| 32 | + EXPECT_EQ(oConfig.getPortName(), "/dev/ttyUSB0"); | |
| 27 | 33 | } | ... | ... |