CuteHMI - Modbus (CuteHMI.Modbus.4)
TCPServer.hpp
1#ifndef H_EXTENSIONS_CUTEHMI_MODBUS_4_INCLUDE_CUTEHMI_MODBUS_TCPSERVER_HPP
2#define H_EXTENSIONS_CUTEHMI_MODBUS_4_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#include <QQmlEngine>
14
15namespace cutehmi {
16namespace modbus {
17
18class CUTEHMI_MODBUS_API TCPServer:
20{
21 Q_OBJECT
22 QML_NAMED_ELEMENT(TCPServer)
23
24 public:
25 static constexpr int MIN_SLAVE_ADDRESS = internal::TCPServerConfig::MIN_SLAVE_ADDRESS;
26 static constexpr int MAX_SLAVE_ADDRESS = internal::TCPServerConfig::MAX_SLAVE_ADDRESS;
27 static const char * INITIAL_HOST;
28 static constexpr int INITIAL_PORT = internal::TCPServerConfig::INITIAL_PORT;
29 static constexpr int INITIAL_SLAVE_ADDRESS = internal::TCPServerConfig::INITIAL_SLAVE_ADDRESS;
30 static constexpr int INITIAL_COILS_ADDRESS_RANGE_MIN = internal::TCPServerConfig::INITIAL_COILS_ADDRESS_RANGE_MIN;
31 static constexpr int INITIAL_COILS_ADDRESS_RANGE_MAX = internal::TCPServerConfig::INITIAL_COILS_ADDRESS_RANGE_MAX;
32 static constexpr int INITIAL_DISCRETE_INPUTS_ADDRESS_RANGE_MIN = internal::TCPServerConfig::INITIAL_DISCRETE_INPUTS_ADDRESS_RANGE_MIN;
33 static constexpr int INITIAL_DISCRETE_INPUTS_ADDRESS_RANGE_MAX = internal::TCPServerConfig::INITIAL_DISCRETE_INPUTS_ADDRESS_RANGE_MAX;
34 static constexpr int INITIAL_HOLDING_REGISTERS_ADDRESS_RANGE_MIN = internal::TCPServerConfig::INITIAL_HOLDING_REGISTERS_ADDRESS_RANGE_MIN;
35 static constexpr int INITIAL_HOLDING_REGISTERS_ADDRESS_RANGE_MAX = internal::TCPServerConfig::INITIAL_HOLDING_REGISTERS_ADDRESS_RANGE_MAX;
36 static constexpr int INITIAL_INPUT_REGISTERS_ADDRESS_RANGE_MIN = internal::TCPServerConfig::INITIAL_INPUT_REGISTERS_ADDRESS_RANGE_MIN;
37 static constexpr int INITIAL_INPUT_REGISTERS_ADDRESS_RANGE_MAX = internal::TCPServerConfig::INITIAL_INPUT_REGISTERS_ADDRESS_RANGE_MAX;
38
39 Q_PROPERTY(QString host READ host WRITE setHost NOTIFY hostChanged)
40 Q_PROPERTY(int port READ port WRITE setPort NOTIFY portChanged)
41 Q_PROPERTY(int slaveAddress READ slaveAddress WRITE setSlaveAddress NOTIFY slaveAddressChanged)
42
43 TCPServer(QObject * parent = nullptr);
44
45 ~TCPServer() override;
46
47 QString host() const;
48
49 void setHost(const QString & host);
50
51 int port() const;
52
53 void setPort(int port);
54
55 int slaveAddress() const;
56
57 void setSlaveAddress(int slaveAddress);
58
59 void setBusy(bool busy) override;
60
61 public slots:
62 void open() override;
63
64 void close() override;
65
66 signals:
68
70
72
73 private:
74 struct Members
75 {
78 QThread thread;
79
84 backend(& config, coilData, discreteInputData, holdingRegisterData, inputRegisterData)
85 {
86 }
87 };
88
90};
91
92}
93}
94
95#endif
96
97//(c)C: Copyright © 2022, Michał Policht <michal@policht.pl>. All rights reserved.
98//(c)C: SPDX-License-Identifier: LGPL-3.0-or-later OR MIT
99//(c)C: This file is a part of CuteHMI.
100//(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.
101//(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.
102//(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/>.
103//(c)C: Additionally, this file is licensed under terms of MIT license as expressed below.
104//(c)C: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
105//(c)C: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
106//(c)C: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Abstract server.
Definition: AbstractServer.hpp:19
Definition: TCPServer.hpp:20
static const char * INITIAL_HOST
Definition: TCPServer.hpp:27
TCP server backend.
Definition: QtTCPServerBackend.hpp:17
RegisterTraits< HoldingRegister >::Container HoldingRegisterDataContainer
Definition: QtTCPServer.hpp:29
RegisterTraits< Coil >::Container CoilDataContainer
Definition: QtTCPServer.hpp:27
RegisterTraits< InputRegister >::Container InputRegisterDataContainer
Definition: QtTCPServer.hpp:30
RegisterTraits< DiscreteInput >::Container DiscreteInputDataContainer
Definition: QtTCPServer.hpp:28
Definition: TCPServerConfig.hpp:16
static constexpr int MIN_SLAVE_ADDRESS
Definition: TCPServerConfig.hpp:22
static constexpr int INITIAL_PORT
Definition: TCPServerConfig.hpp:25
static constexpr int INITIAL_SLAVE_ADDRESS
Definition: TCPServerConfig.hpp:26
static constexpr quint16 INITIAL_DISCRETE_INPUTS_ADDRESS_RANGE_MIN
Definition: TCPServerConfig.hpp:29
static constexpr quint16 INITIAL_HOLDING_REGISTERS_ADDRESS_RANGE_MAX
Definition: TCPServerConfig.hpp:32
static constexpr quint16 INITIAL_COILS_ADDRESS_RANGE_MAX
Definition: TCPServerConfig.hpp:28
static constexpr quint16 INITIAL_INPUT_REGISTERS_ADDRESS_RANGE_MIN
Definition: TCPServerConfig.hpp:33
static constexpr quint16 INITIAL_DISCRETE_INPUTS_ADDRESS_RANGE_MAX
Definition: TCPServerConfig.hpp:30
static constexpr quint16 INITIAL_INPUT_REGISTERS_ADDRESS_RANGE_MAX
Definition: TCPServerConfig.hpp:34
static constexpr quint16 INITIAL_HOLDING_REGISTERS_ADDRESS_RANGE_MIN
Definition: TCPServerConfig.hpp:31
static constexpr int MAX_SLAVE_ADDRESS
Definition: TCPServerConfig.hpp:23
static constexpr quint16 INITIAL_COILS_ADDRESS_RANGE_MIN
Definition: TCPServerConfig.hpp:27