diff --git a/CMakeLists.txt b/CMakeLists.txt index 443cfde..00445ca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,5 +6,15 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17") aux_source_directory(3rdparty/libmodbus DIRSRCS) include_directories(3rdparty/libmodbus include) -set(SOURCE_FILES tests/main.cpp) -add_executable(main ${SOURCE_FILES} ${DIRSRCS}) +set(SOURCE_FILES + tests/main.cpp + src/ConnectionConfig.h + src/IModbusAdapter.h + src/ModbusAdapter.h + src/ModbusAdapter.cpp +) + +add_executable(main + ${SOURCE_FILES} + ${DIRSRCS} +) diff --git a/src/ConnectionConfig.h b/src/ConnectionConfig.h new file mode 100644 index 0000000..09bd306 --- /dev/null +++ b/src/ConnectionConfig.h @@ -0,0 +1,43 @@ +#pragma once + +#include + +enum class ConnectionPort +{ + CP_EXTERNAL, + CP_IOBUS, + CP_TCP +}; + +enum class Parity +{ + P_ODD, + P_EVEN, + P_NONE +}; + +class ConnectionConfig +{ +public: + ConnectionConfig( ConnectionPort port, int baud = 115200, Parity parity = Parity::P_NONE, int dataBits = 8, int stopBits = 1 ) + { + + } + + ConnectionConfig( ConnectionPort port, const std::string &ip, int portnum, int timeOut = -1 ) + { + + } + +private: + + /// Serial connections + ConnectionPort m_serPort; + int m_baudRate; + Parity m_parity; + int m_dataBits; + int m_stopBits; + + /// TCP connections + +}; diff --git a/src/IModbusAdapter.h b/src/IModbusAdapter.h new file mode 100644 index 0000000..c83af9b --- /dev/null +++ b/src/IModbusAdapter.h @@ -0,0 +1,10 @@ +/**************************************************************************** + * Copyright (c) 2022 Priva b.v. + ****************************************************************************/ + +#pragma once + +class IModbusAdapter +{ + virtual ~IModbusAdapter() {} +}; diff --git a/src/ModbusAdapter.cpp b/src/ModbusAdapter.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/ModbusAdapter.cpp diff --git a/src/ModbusAdapter.h b/src/ModbusAdapter.h new file mode 100644 index 0000000..9a6a8ce --- /dev/null +++ b/src/ModbusAdapter.h @@ -0,0 +1,22 @@ +/***************************************************************************** + * Copyright (c) 2022 Priva b.v. + *****************************************************************************/ + +#pragma once + +#include "ConnectionConfig.h" +#include "IModbusAdapter.h" + +/// \brief This class represents a single modbus context. Each context will +/// result in an instance of this class. It is not intended to be +/// created directly but through a factory. The factory will create +/// the object and return the pointer to its interface. + +class ModbusAdapter : public IModbusAdapter +{ +public: + ModbusAdapter(); + virtual ~ModbusAdapter(); + + void ModbusConnectRTU(const ConnectionConfig &conncfg); +};