Skip to content

Commit

Permalink
Fix CI issues with the build
Browse files Browse the repository at this point in the history
Signed-off-by: Mateusz Mazur <mateusz.mazur@e.email>
  • Loading branch information
Mazurel committed Oct 20, 2024
1 parent 393a439 commit 21f4b22
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ project(protocolConverter)

set(CMAKE_CXX_STANDARD 17)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -pedantic")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -pedantic -Werror=unused-result")

option(MODBUS_EXAMPLE "Build example program" OFF)
option(MODBUS_TESTS "Build tests" OFF)
Expand Down
12 changes: 10 additions & 2 deletions include/MB/modbusRequest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class ModbusRequest {
}

/**
* Simple constructor, that allows to create "dummy" ModbusResponse
* Simple constructor, that allows to create "dummy" ModbusRequest
* object. May be useful in some cases.
*/
explicit ModbusRequest(
Expand All @@ -80,7 +80,15 @@ class ModbusRequest {
uint16_t address = 0, uint16_t registersNumber = 0,
std::vector<ModbusCell> values = {}) noexcept;

ModbusRequest(const ModbusRequest &) = default;
/**
* Copy constructor for the response.
*/
ModbusRequest(const ModbusRequest&);

/**
* Equal operator for the response.
*/
ModbusRequest& operator=(const ModbusRequest &);

//! Returns string representation of object
[[nodiscard]] std::string toString() const noexcept;
Expand Down
10 changes: 9 additions & 1 deletion include/MB/modbusResponse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,15 @@ class ModbusResponse {
uint16_t address = 0, uint16_t registersNumber = 0,
std::vector<ModbusCell> values = {});

ModbusResponse(const ModbusResponse &) = default;
/**
* Copy constructor for the response.
*/
ModbusResponse(const ModbusResponse&);

/**
* Equal operator for the response.
*/
ModbusResponse& operator=(const ModbusResponse &);

//! Converts object to it's string representation
[[nodiscard]] std::string toString() const;
Expand Down
4 changes: 4 additions & 0 deletions include/MB/modbusUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,4 +233,8 @@ inline void pushUint16(std::vector<uint8_t> &buffer, const uint16_t val) {
buffer.push_back(low);
}

//! Ignore some value explicitly
template<typename T>
inline void ignore_result(T&& v) { (void)v; }

} // namespace MB::utils
3 changes: 2 additions & 1 deletion src/Serial/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Licensed under: MIT License <http://opensource.org/licenses/MIT>

#include "Serial/connection.hpp"
#include "modbusUtils.hpp"
#include <sys/poll.h>

using namespace MB::Serial;
Expand Down Expand Up @@ -139,7 +140,7 @@ std::vector<uint8_t> Connection::send(std::vector<uint8_t> data) {
// most cases)
tcflush(_fd, TCOFLUSH);
// Write
write(_fd, data.begin().base(), data.size());
utils::ignore_result(write(_fd, data.begin().base(), data.size()));
// It may be a good idea to use tcdrain, although it has tendency to not
// work as expected tcdrain(_fd);

Expand Down
17 changes: 17 additions & 0 deletions src/modbusRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,23 @@ ModbusRequest::ModbusRequest(uint8_t slaveId, utils::MBFunctionCode functionCode
}
}

ModbusRequest::ModbusRequest(const ModbusRequest& reference) :
_slaveID(reference.slaveID()),
_functionCode(reference.functionCode()),
_address(reference.registerAddress()),
_registersNumber(reference.numberOfRegisters()),
_values(reference.registerValues()){ }


ModbusRequest& ModbusRequest::operator=(const ModbusRequest &reference) {
this->_slaveID = reference.slaveID();
this->_functionCode = reference.functionCode();
this->_address = reference.registerAddress();
this->_registersNumber = reference.numberOfRegisters();
this->_values = reference.registerValues();
return *this;
}

ModbusRequest::ModbusRequest(const std::vector<uint8_t> &inputData, bool CRC) {
try {
if (inputData.size() < 3)
Expand Down
17 changes: 17 additions & 0 deletions src/modbusResponse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,23 @@ ModbusResponse::ModbusResponse(uint8_t slaveId, utils::MBFunctionCode functionCo
}
}

ModbusResponse::ModbusResponse(const ModbusResponse& reference) :
_slaveID(reference.slaveID()),
_functionCode(reference.functionCode()),
_address(reference.registerAddress()),
_registersNumber(reference.numberOfRegisters()),
_values(reference.registerValues()){ }


ModbusResponse& ModbusResponse::operator=(const ModbusResponse &reference) {
this->_slaveID = reference.slaveID();
this->_functionCode = reference.functionCode();
this->_address = reference.registerAddress();
this->_registersNumber = reference.numberOfRegisters();
this->_values = reference.registerValues();
return *this;
}

ModbusResponse::ModbusResponse(std::vector<uint8_t> inputData, bool CRC) {
try {
if (inputData.size() < 3)
Expand Down

0 comments on commit 21f4b22

Please sign in to comment.