CuteHMI - Modbus (CuteHMI.Modbus.2)
QtClientBackend.hpp
1 #ifndef H_EXTENSIONS_CUTEHMI_MODBUS_2_INCLUDE_CUTEHMI_MODBUS_INTERNAL_QTCLIENTBACKEND_HPP
2 #define H_EXTENSIONS_CUTEHMI_MODBUS_2_INCLUDE_CUTEHMI_MODBUS_INTERNAL_QTCLIENTBACKEND_HPP
3 
4 #include "common.hpp"
5 #include "Config.hpp"
6 #include "AbstractClientBackend.hpp"
7 
8 #include <memory>
9 
10 #include <QModbusClient>
11 
12 namespace cutehmi {
13 namespace modbus {
14 namespace internal {
15 
16 class CUTEHMI_MODBUS_PRIVATE QtClientBackend:
18 {
19  Q_OBJECT
20 
21  public slots:
22  void ensureClosed();
23 
24  signals:
25  void opened();
26 
27  void closed();
28 
29  protected:
30  explicit QtClientBackend(std::unique_ptr<QModbusClient> qClient, QObject * parent = nullptr);
31 
32  virtual int slaveAddress() const = 0;
33 
34  virtual void configureConnection() = 0;
35 
36  QModbusClient * qClient() const;
37 
38  bool proceedRequest(QUuid requestId) override;
39 
40  void readCoils(QUuid requestId, quint16 startAddress, quint16 endAddress) override;
41 
42  void writeCoil(QUuid requestId, quint16 address, bool value) override;
43 
44  void writeMultipleCoils(QUuid requestId, quint16 startAddress, const QVector<quint16> & values) override;
45 
46  void readDiscreteInputs(QUuid requestId, quint16 startAddress, quint16 endAddress) override;
47 
48  void readHoldingRegisters(QUuid requestId, quint16 startAddress, quint16 endAddress) override;
49 
50  void writeHoldingRegister(QUuid requestId, quint16 address, quint16 value) override;
51 
52  void writeMultipleHoldingRegisters(QUuid requestId, quint16 startAddress, const QVector<quint16> & values) override;
53 
54  void readInputRegisters(QUuid requestId, quint16 startAddress, quint16 endAddress) override;
55 
56  void readExceptionStatus(QUuid requestId) override;
57 
58  void diagnostics(QUuid requestId, AbstractDevice::DiagnosticsSubfunction subfunction, quint16 data) override;
59 
60  void fetchCommEventCounter(QUuid requestId) override;
61 
62  void fetchCommEventLog(QUuid requestId) override;
63 
64  void reportSlaveId(QUuid requestId) override;
65 
66  void readFileRecord(QUuid requestId, quint8 byteCount, QJsonArray subrequests) override;
67 
68  void writeFileRecord(QUuid requestId, quint8 byteCount, QJsonArray subrequests) override;
69 
70  void maskWriteHoldingRegister(QUuid requestId, quint16 address, quint16 andMask, quint16 orMask) override;
71 
72  void readWriteMultipleHoldingRegisters(QUuid requestId, quint16 readStartAddress, quint16 readEndAddress, quint16 writeAddress, const QVector<quint16> & values) override;
73 
74  void readFIFOQueue(QUuid requestId, quint16 address) override;
75 
76  protected slots:
77  void open() override;
78 
79  void close() override;
80 
81  private slots:
82  void onStateChanged(QModbusDevice::State state);
83 
84  void onErrorOccurred(QModbusDevice::Error error);
85 
86  private:
87  void writeDataUnit(QUuid requestId, const QModbusDataUnit & unit);
88 
89  void readDataUnitInt(QUuid requestId, const QModbusDataUnit & unit);
90 
91  void readDataUnitBool(QUuid requestId, const QModbusDataUnit & unit);
92 
93  void prepareErrorReply(const QModbusReply & modbusReply, QJsonObject & reply);
94 
100  void pushByte(uchar byte, uchar *& destination);
101 
107  void pushWord(uint word, uchar *& destination);
108 
114  uchar pullByte(const uchar *& source);
115 
121  uint pullWord(const uchar *& source);
122 
123  struct Members
124  {
125  QModbusClient * qClient;
126  };
127 
128  MPtr<Members> m;
129 };
130 
131 }
132 }
133 }
134 
135 #endif
136 
137 //(c)C: Copyright © 2019-2020, Michał Policht <michal@policht.pl>. All rights reserved.
138 //(c)C: This file is a part of CuteHMI.
139 //(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.
140 //(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.
141 //(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::AbstractClientBackend
Abstract client backend.
Definition: AbstractClientBackend.hpp:23
QUuid
QModbusClient
cutehmi::MPtr< Members >
QModbusReply
cutehmi::modbus::internal::QtClientBackend
Definition: QtClientBackend.hpp:16
QObject
cutehmi
QJsonArray
QModbusDataUnit
QJsonObject
std::internal
T internal(T... args)
cutehmi::modbus::AbstractDevice::DiagnosticsSubfunction
DiagnosticsSubfunction
Definition: AbstractDevice.hpp:82
QVector
std::unique_ptr