CuteHMI - Modbus (CuteHMI.Modbus.4)
AbstractDeviceBackend.hpp
1#ifndef H_EXTENSIONS_CUTEHMI_MODBUS_4_INCLUDE_CUTEHMI_MODBUS_INTERNAL_ABSTRACTDEVICEBACKEND_HPP
2#define H_EXTENSIONS_CUTEHMI_MODBUS_4_INCLUDE_CUTEHMI_MODBUS_INTERNAL_ABSTRACTDEVICEBACKEND_HPP
3
4#include "common.hpp"
5#include "RegisterTraits.hpp"
6#include "../AbstractClient.hpp"
7
8#include <cutehmi/InplaceError.hpp>
9
10#include <QObject>
11#include <QJsonObject>
12#include <QJsonArray>
13#include <QUuid>
14
15namespace cutehmi {
16namespace modbus {
17namespace internal {
18
23class 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
35
37
39
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 © 2022-2023, Michał Policht <michal@policht.pl>. All rights reserved.
109//(c)C: SPDX-License-Identifier: LGPL-3.0-or-later OR MIT
110//(c)C: This file is a part of CuteHMI.
111//(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.
112//(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.
113//(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/>.
114//(c)C: Additionally, this file is licensed under terms of MIT license as expressed below.
115//(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:
116//(c)C: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
117//(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.
DiagnosticsSubfunction
Definition: AbstractDevice.hpp:86
Function
Definition: AbstractDevice.hpp:56
State
Definition: AbstractDevice.hpp:48
Abstract device backend.
Definition: AbstractDeviceBackend.hpp:25
virtual bool proceedRequest(QUuid requestId)=0
void stateChanged(cutehmi::modbus::AbstractDevice::State state)
void errored(cutehmi::InplaceError error)
void replied(QUuid requestId, QJsonObject reply)
T internal(T... args)