CuteHMI - Modbus (CuteHMI.Modbus.2)
QtServerBackend.hpp
1 #ifndef H_EXTENSIONS_CUTEHMI_MODBUS_2_INCLUDE_CUTEHMI_MODBUS_INTERNAL_QTSERVERBACKEND_HPP
2 #define H_EXTENSIONS_CUTEHMI_MODBUS_2_INCLUDE_CUTEHMI_MODBUS_INTERNAL_QTSERVERBACKEND_HPP
3 
4 #include "common.hpp"
5 #include "Config.hpp"
6 #include "AbstractServerBackend.hpp"
7 
8 #include <memory>
9 
10 #include <QModbusServer>
11 
12 namespace cutehmi {
13 namespace modbus {
14 namespace internal {
15 
16 class CUTEHMI_MODBUS_PRIVATE QtServerBackend:
18 {
19  Q_OBJECT
20 
21  public slots:
22  void ensureClosed();
23 
24  signals:
25  void opened();
26 
27  void closed();
28 
29  void coilsWritten(quint16 address, quint16 amount);
30 
31  void discreteInputsWritten(quint16 address, quint16 amount);
32 
33  void holdingRegistersWritten(quint16 address, quint16 amount);
34 
35  void inputRegistersWritten(quint16 address, quint16 amount);
36 
37  protected:
38  explicit QtServerBackend(std::unique_ptr<QModbusServer> qServer, QObject * parent = nullptr);
39 
40  virtual int slaveId() const = 0;
41 
42  virtual void configureConnection() = 0;
43 
44  QModbusServer * qServer() const;
45 
46  bool proceedRequest(QUuid requestId) override;
47 
48  void readCoils(QUuid requestId, quint16 startAddress, quint16 endAddress) override;
49 
50  void writeCoil(QUuid requestId, quint16 address, bool value) override;
51 
52  void writeMultipleCoils(QUuid requestId, quint16 startAddress, const QVector<quint16> & values) override;
53 
54  void readDiscreteInputs(QUuid requestId, quint16 startAddress, quint16 endAddress) override;
55 
56  void writeDiscreteInput(QUuid requestId, quint16 address, bool value) override;
57 
58  void writeMultipleDiscreteInputs(QUuid requestId, quint16 startAddress, const QVector<quint16> & values) override;
59 
60  void readHoldingRegisters(QUuid requestId, quint16 startAddress, quint16 endAddress) override;
61 
62  void writeHoldingRegister(QUuid requestId, quint16 address, quint16 value) override;
63 
64  void writeMultipleHoldingRegisters(QUuid requestId, quint16 startAddress, const QVector<quint16> & values) override;
65 
66  void readInputRegisters(QUuid requestId, quint16 startAddress, quint16 endAddress) override;
67 
68  void writeInputRegister(QUuid requestId, quint16 address, quint16 value) override;
69 
70  void writeMultipleInputRegisters(QUuid requestId, quint16 startAddress, const QVector<quint16> & values) override;
71 
72  protected slots:
73  void open() override;
74 
75  void close() override;
76 
77  void setBusy(bool busy) override;
78 
79  private:
80  void readDataUnitInt(QUuid requestId, QModbusDataUnit & unit);
81 
82  void readDataUnitBool(QUuid requestId, QModbusDataUnit & unit);
83 
84  private slots:
85  void onDataWritten(QModbusDataUnit::RegisterType table, int address, int size);
86 
87  void onStateChanged(QModbusDevice::State state);
88 
89  void onErrorOccurred(QModbusDevice::Error error);
90 
91  private:
92  struct Members
93  {
94  QModbusServer * qServer;
95  };
96 
97  MPtr<Members> m;
98 
99 };
100 
101 }
102 }
103 }
104 
105 #endif
106 
107 //(c)C: Copyright © 2019-2020, Michał Policht <michal@policht.pl>. All rights reserved.
108 //(c)C: This file is a part of CuteHMI.
109 //(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.
110 //(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.
111 //(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/>.
QModbusServer
QUuid
cutehmi::MPtr< Members >
QObject
cutehmi::modbus::internal::QtServerBackend
Definition: QtServerBackend.hpp:16
cutehmi
QModbusDataUnit
cutehmi::modbus::internal::AbstractServerBackend
Abstract server backend.
Definition: AbstractServerBackend.hpp:21
std::internal
T internal(T... args)
QVector
std::unique_ptr