CuteHMI - Modbus (CuteHMI.Modbus.2)
AbstractDeviceBackend.hpp
1 #ifndef H_EXTENSIONS_CUTEHMI_MODBUS_2_INCLUDE_CUTEHMI_MODBUS_INTERNAL_ABSTRACTDEVICEBACKEND_HPP
2 #define H_EXTENSIONS_CUTEHMI_MODBUS_2_INCLUDE_CUTEHMI_MODBUS_INTERNAL_ABSTRACTDEVICEBACKEND_HPP
3 
4 #include "common.hpp"
5 #include "RegisterTraits.hpp"
6 
7 #include <cutehmi/InplaceError.hpp>
8 #include <cutehmi/modbus/AbstractClient.hpp>
9 
10 #include <QObject>
11 #include <QJsonObject>
12 #include <QJsonArray>
13 #include <QUuid>
14 
15 namespace cutehmi {
16 namespace modbus {
17 namespace internal {
18 
23 class CUTEHMI_MODBUS_PRIVATE AbstractDeviceBackend:
24  public QObject
25 {
26  Q_OBJECT
27 
28  public slots:
29  virtual void processRequest(QJsonObject request);
30 
31  signals:
32  void replied(QUuid requestId, QJsonObject reply);
33 
34  void errored(cutehmi::InplaceError error);
35 
36  void stateChanged(cutehmi::modbus::AbstractDevice::State state);
37 
38  void openRequested();
39 
40  void closeRequested();
41 
42  protected:
43  explicit AbstractDeviceBackend(QObject * parent = nullptr);
44 
45  virtual bool proceedRequest(QUuid requestId) = 0;
46 
47  virtual void readCoils(QUuid requestId, quint16 startAddress, quint16 endAddress);
48 
49  virtual void writeCoil(QUuid requestId, quint16 address, bool value);
50 
51  virtual void writeMultipleCoils(QUuid requestId, quint16 startAddress, const QVector<quint16> & values);
52 
53  virtual void readDiscreteInputs(QUuid requestId, quint16 startAddress, quint16 endAddress);
54 
55  virtual void writeDiscreteInput(QUuid requestId, quint16 address, bool value);
56 
57  virtual void writeMultipleDiscreteInputs(QUuid requestId, quint16 startAddress, const QVector<quint16> & values);
58 
59  virtual void readHoldingRegisters(QUuid requestId, quint16 startAddress, quint16 endAddress);
60 
61  virtual void writeHoldingRegister(QUuid requestId, quint16 address, quint16 value);
62 
63  virtual void writeMultipleHoldingRegisters(QUuid requestId, quint16 startAddress, const QVector<quint16> & values);
64 
65  virtual void readInputRegisters(QUuid requestId, quint16 startAddress, quint16 endAddress);
66 
67  virtual void writeInputRegister(QUuid requestId, quint16 address, quint16 value);
68 
69  virtual void writeMultipleInputRegisters(QUuid requestId, quint16 startAddress, const QVector<quint16> & values);
70 
71  virtual void readExceptionStatus(QUuid requestId);
72 
73  virtual void diagnostics(QUuid requestId, AbstractDevice::DiagnosticsSubfunction subfunction, quint16 data);
74 
75  virtual void fetchCommEventCounter(QUuid requestId);
76 
77  virtual void fetchCommEventLog(QUuid requestId);
78 
79  virtual void reportSlaveId(QUuid requestId);
80 
81  virtual void readFileRecord(QUuid requestId, quint8 byteCount, QJsonArray subrequests);
82 
83  virtual void writeFileRecord(QUuid requestId, quint8 byteCount, QJsonArray subrequests);
84 
85  virtual void maskWriteHoldingRegister(QUuid requestId, quint16 address, quint16 andMask, quint16 orMask);
86 
87  virtual void readWriteMultipleHoldingRegisters(QUuid requestId, quint16 readStartAddress, quint16 readEndAddress, quint16 writeAddress, const QVector<quint16> & values);
88 
89  virtual void readFIFOQueue(QUuid requestId, quint16 address);
90 
91  protected slots:
92  virtual void open() = 0;
93 
94  virtual void close() = 0;
95 
96  private:
97  void replyIllegalFunction(QUuid requestId);
98 
99  const char * humanFunctionName(AbstractDevice::Function) const;
100 };
101 
102 }
103 }
104 }
105 
106 #endif
107 
108 //(c)C: Copyright © 2019, Michał Policht <michal@policht.pl>. All rights reserved.
109 //(c)C: This file is a part of CuteHMI.
110 //(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.
111 //(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.
112 //(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/>.
QUuid
cutehmi::InplaceError
QObject
cutehmi
QJsonArray
cutehmi::modbus::AbstractDevice::State
State
Definition: AbstractDevice.hpp:43
QJsonObject
std::internal
T internal(T... args)
cutehmi::modbus::AbstractDevice::Function
Function
Definition: AbstractDevice.hpp:51
cutehmi::modbus::AbstractDevice::DiagnosticsSubfunction
DiagnosticsSubfunction
Definition: AbstractDevice.hpp:81
QVector
cutehmi::modbus::internal::AbstractDeviceBackend
Abstract device backend.
Definition: AbstractDeviceBackend.hpp:23