CuteHMI - Modbus (CuteHMI.Modbus.2)
TCPServer.hpp
1 #ifndef H_EXTENSIONS_CUTEHMI_MODBUS_2_INCLUDE_CUTEHMI_MODBUS_TCPSERVER_HPP
2 #define H_EXTENSIONS_CUTEHMI_MODBUS_2_INCLUDE_CUTEHMI_MODBUS_TCPSERVER_HPP
3 
4 #include "AbstractServer.hpp"
5 #include "internal/RegisterTraits.hpp"
6 #include "internal/QtTCPServerBackend.hpp"
7 
8 #include <cutehmi/macros.hpp>
9 
10 #include <QThread>
11 #include <QStateMachine>
12 #include <QModbusTcpServer>
13 
14 namespace cutehmi {
15 namespace modbus {
16 
17 class CUTEHMI_MODBUS_API TCPServer:
18  public AbstractServer
19 {
20  Q_OBJECT
21 
22  public:
23  static constexpr int MIN_SLAVE_ADDRESS = internal::TCPServerConfig::MIN_SLAVE_ADDRESS;
24  static constexpr int MAX_SLAVE_ADDRESS = internal::TCPServerConfig::MAX_SLAVE_ADDRESS;
25  static const char * INITIAL_HOST;
26  static constexpr int INITIAL_PORT = internal::TCPServerConfig::INITIAL_PORT;
27  static constexpr int INITIAL_SLAVE_ADDRESS = internal::TCPServerConfig::INITIAL_SLAVE_ADDRESS;
28  static constexpr int INITIAL_COILS_ADDRESS_RANGE_MIN = internal::TCPServerConfig::INITIAL_COILS_ADDRESS_RANGE_MIN;
29  static constexpr int INITIAL_COILS_ADDRESS_RANGE_MAX = internal::TCPServerConfig::INITIAL_COILS_ADDRESS_RANGE_MAX;
30  static constexpr int INITIAL_DISCRETE_INPUTS_ADDRESS_RANGE_MIN = internal::TCPServerConfig::INITIAL_DISCRETE_INPUTS_ADDRESS_RANGE_MIN;
31  static constexpr int INITIAL_DISCRETE_INPUTS_ADDRESS_RANGE_MAX = internal::TCPServerConfig::INITIAL_DISCRETE_INPUTS_ADDRESS_RANGE_MAX;
32  static constexpr int INITIAL_HOLDING_REGISTERS_ADDRESS_RANGE_MIN = internal::TCPServerConfig::INITIAL_HOLDING_REGISTERS_ADDRESS_RANGE_MIN;
33  static constexpr int INITIAL_HOLDING_REGISTERS_ADDRESS_RANGE_MAX = internal::TCPServerConfig::INITIAL_HOLDING_REGISTERS_ADDRESS_RANGE_MAX;
34  static constexpr int INITIAL_INPUT_REGISTERS_ADDRESS_RANGE_MIN = internal::TCPServerConfig::INITIAL_INPUT_REGISTERS_ADDRESS_RANGE_MIN;
35  static constexpr int INITIAL_INPUT_REGISTERS_ADDRESS_RANGE_MAX = internal::TCPServerConfig::INITIAL_INPUT_REGISTERS_ADDRESS_RANGE_MAX;
36 
37  Q_PROPERTY(QString host READ host WRITE setHost NOTIFY hostChanged)
38  Q_PROPERTY(int port READ port WRITE setPort NOTIFY portChanged)
39  Q_PROPERTY(int slaveAddress READ slaveAddress WRITE setSlaveAddress NOTIFY slaveAddressChanged)
40 
41  TCPServer(QObject * parent = nullptr);
42 
43  ~TCPServer() override;
44 
45  QString host() const;
46 
47  void setHost(const QString & host);
48 
49  int port() const;
50 
51  void setPort(int port);
52 
53  int slaveAddress() const;
54 
55  void setSlaveAddress(int slaveAddress);
56 
57  void setBusy(bool busy) override;
58 
59  public slots:
60  void open() override;
61 
62  void close() override;
63 
64  signals:
65  void hostChanged();
66 
67  void portChanged();
68 
69  void slaveAddressChanged();
70 
71  private:
72  struct Members
73  {
76  QThread thread;
77 
82  backend(& config, coilData, discreteInputData, holdingRegisterData, inputRegisterData)
83  {
84  }
85  };
86 
87  MPtr<Members> m;
88 };
89 
90 }
91 }
92 
93 #endif
94 
95 //(c)C: Copyright © 2019, Michał Policht <michal@policht.pl>. All rights reserved.
96 //(c)C: This file is a part of CuteHMI.
97 //(c)C: CuteHMI is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
98 //(c)C: CuteHMI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
99 //(c)C: You should have received a copy of the GNU Lesser General Public License along with CuteHMI. If not, see <https://www.gnu.org/licenses/>.
cutehmi::modbus::internal::TCPServerConfig
Definition: TCPServerConfig.hpp:14
cutehmi::modbus::internal::TCPServerConfig::INITIAL_HOLDING_REGISTERS_ADDRESS_RANGE_MIN
static constexpr quint16 INITIAL_HOLDING_REGISTERS_ADDRESS_RANGE_MIN
Definition: TCPServerConfig.hpp:31
cutehmi::modbus::internal::TCPServerConfig::INITIAL_SLAVE_ADDRESS
static constexpr int INITIAL_SLAVE_ADDRESS
Definition: TCPServerConfig.hpp:26
QThread
cutehmi::modbus::internal::TCPServerConfig::INITIAL_COILS_ADDRESS_RANGE_MIN
static constexpr quint16 INITIAL_COILS_ADDRESS_RANGE_MIN
Definition: TCPServerConfig.hpp:27
cutehmi::modbus::internal::TCPServerConfig::INITIAL_INPUT_REGISTERS_ADDRESS_RANGE_MAX
static constexpr quint16 INITIAL_INPUT_REGISTERS_ADDRESS_RANGE_MAX
Definition: TCPServerConfig.hpp:34
cutehmi::modbus::TCPServer
Definition: TCPServer.hpp:17
cutehmi::modbus::internal::TCPServerConfig::MIN_SLAVE_ADDRESS
static constexpr int MIN_SLAVE_ADDRESS
Definition: TCPServerConfig.hpp:22
cutehmi::modbus::internal::TCPServerConfig::INITIAL_DISCRETE_INPUTS_ADDRESS_RANGE_MAX
static constexpr quint16 INITIAL_DISCRETE_INPUTS_ADDRESS_RANGE_MAX
Definition: TCPServerConfig.hpp:30
cutehmi::modbus::internal::QtTCPServer::HoldingRegisterDataContainer
RegisterTraits< HoldingRegister >::Container HoldingRegisterDataContainer
Definition: QtTCPServer.hpp:29
cutehmi::modbus::internal::QtTCPServerBackend
TCP server backend.
Definition: QtTCPServerBackend.hpp:15
cutehmi::MPtr< Members >
cutehmi::modbus::internal::QtTCPServer::CoilDataContainer
RegisterTraits< Coil >::Container CoilDataContainer
Definition: QtTCPServer.hpp:27
QObject
cutehmi::modbus::internal::TCPServerConfig::INITIAL_PORT
static constexpr int INITIAL_PORT
Definition: TCPServerConfig.hpp:25
cutehmi
QString
cutehmi::modbus::internal::TCPServerConfig::MAX_SLAVE_ADDRESS
static constexpr int MAX_SLAVE_ADDRESS
Definition: TCPServerConfig.hpp:23
cutehmi::modbus::internal::QtTCPServer::InputRegisterDataContainer
RegisterTraits< InputRegister >::Container InputRegisterDataContainer
Definition: QtTCPServer.hpp:30
cutehmi::modbus::internal::TCPServerConfig::INITIAL_INPUT_REGISTERS_ADDRESS_RANGE_MIN
static constexpr quint16 INITIAL_INPUT_REGISTERS_ADDRESS_RANGE_MIN
Definition: TCPServerConfig.hpp:33
cutehmi::modbus::internal::TCPServerConfig::INITIAL_DISCRETE_INPUTS_ADDRESS_RANGE_MIN
static constexpr quint16 INITIAL_DISCRETE_INPUTS_ADDRESS_RANGE_MIN
Definition: TCPServerConfig.hpp:29
cutehmi::modbus::internal::TCPServerConfig::INITIAL_HOLDING_REGISTERS_ADDRESS_RANGE_MAX
static constexpr quint16 INITIAL_HOLDING_REGISTERS_ADDRESS_RANGE_MAX
Definition: TCPServerConfig.hpp:32
cutehmi::modbus::TCPServer::INITIAL_HOST
static const char * INITIAL_HOST
Definition: TCPServer.hpp:25
cutehmi::modbus::AbstractServer
Abstract server.
Definition: AbstractServer.hpp:15
cutehmi::modbus::internal::TCPServerConfig::INITIAL_COILS_ADDRESS_RANGE_MAX
static constexpr quint16 INITIAL_COILS_ADDRESS_RANGE_MAX
Definition: TCPServerConfig.hpp:28
cutehmi::modbus::internal::QtTCPServer::DiscreteInputDataContainer
RegisterTraits< DiscreteInput >::Container DiscreteInputDataContainer
Definition: QtTCPServer.hpp:28