Commit 32017af3be074e9e763967ce7a43bb98bd509e80

Authored by Peter M. Groen
1 parent f45a5332

Setting up working version

CMakeLists.txt
... ... @@ -6,5 +6,15 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
6 6 aux_source_directory(3rdparty/libmodbus DIRSRCS)
7 7 include_directories(3rdparty/libmodbus include)
8 8  
9   -set(SOURCE_FILES tests/main.cpp)
10   -add_executable(main ${SOURCE_FILES} ${DIRSRCS})
  9 +set(SOURCE_FILES
  10 + tests/main.cpp
  11 + src/ConnectionConfig.h
  12 + src/IModbusAdapter.h
  13 + src/ModbusAdapter.h
  14 + src/ModbusAdapter.cpp
  15 +)
  16 +
  17 +add_executable(main
  18 + ${SOURCE_FILES}
  19 + ${DIRSRCS}
  20 +)
... ...
src/ConnectionConfig.h 0 → 100644
  1 +#pragma once
  2 +
  3 +#include <string>
  4 +
  5 +enum class ConnectionPort
  6 +{
  7 + CP_EXTERNAL,
  8 + CP_IOBUS,
  9 + CP_TCP
  10 +};
  11 +
  12 +enum class Parity
  13 +{
  14 + P_ODD,
  15 + P_EVEN,
  16 + P_NONE
  17 +};
  18 +
  19 +class ConnectionConfig
  20 +{
  21 +public:
  22 + ConnectionConfig( ConnectionPort port, int baud = 115200, Parity parity = Parity::P_NONE, int dataBits = 8, int stopBits = 1 )
  23 + {
  24 +
  25 + }
  26 +
  27 + ConnectionConfig( ConnectionPort port, const std::string &ip, int portnum, int timeOut = -1 )
  28 + {
  29 +
  30 + }
  31 +
  32 +private:
  33 +
  34 + /// Serial connections
  35 + ConnectionPort m_serPort;
  36 + int m_baudRate;
  37 + Parity m_parity;
  38 + int m_dataBits;
  39 + int m_stopBits;
  40 +
  41 + /// TCP connections
  42 +
  43 +};
... ...
src/IModbusAdapter.h 0 → 100644
  1 +/****************************************************************************
  2 + * Copyright (c) 2022 Priva b.v.
  3 + ****************************************************************************/
  4 +
  5 +#pragma once
  6 +
  7 +class IModbusAdapter
  8 +{
  9 + virtual ~IModbusAdapter() {}
  10 +};
... ...
src/ModbusAdapter.cpp 0 → 100644
src/ModbusAdapter.h 0 → 100644
  1 +/*****************************************************************************
  2 + * Copyright (c) 2022 Priva b.v.
  3 + *****************************************************************************/
  4 +
  5 +#pragma once
  6 +
  7 +#include "ConnectionConfig.h"
  8 +#include "IModbusAdapter.h"
  9 +
  10 +/// \brief This class represents a single modbus context. Each context will
  11 +/// result in an instance of this class. It is not intended to be
  12 +/// created directly but through a factory. The factory will create
  13 +/// the object and return the pointer to its interface.
  14 +
  15 +class ModbusAdapter : public IModbusAdapter
  16 +{
  17 +public:
  18 + ModbusAdapter();
  19 + virtual ~ModbusAdapter();
  20 +
  21 + void ModbusConnectRTU(const ConnectionConfig &conncfg);
  22 +};
... ...