CuteHMI - Modbus (CuteHMI.Modbus.4)
AbstractClient.hpp
1#ifndef H_EXTENSIONS_CUTEHMI_MODBUS_4_INCLUDE_CUTEHMI_MODBUS_ABSTRACTCLIENT_HPP
2#define H_EXTENSIONS_CUTEHMI_MODBUS_4_INCLUDE_CUTEHMI_MODBUS_ABSTRACTCLIENT_HPP
3
4#include "AbstractDevice.hpp"
5
6#include "internal/PollingIterator.hpp"
7
8#include <QQmlEngine>
9#include <QQueue>
10#include <QTimer>
11
12namespace cutehmi {
13namespace modbus {
14
30class CUTEHMI_MODBUS_API AbstractClient:
32{
33 Q_OBJECT
34 QML_NAMED_ELEMENT(AbstractClient)
35 QML_UNCREATABLE("AbstractClient is an abstract class")
36
37 public:
38 static constexpr int INITIAL_POLLING_INTERVAL = 250;
39
40 static constexpr int INITIAL_POLLING_TASK_INTERVAL = 10;
41
42 static constexpr int INITIAL_REQUEST_INTERVAL = 5;
43
47 Q_PROPERTY(int pollingInterval READ pollingInterval WRITE setPollingInterval NOTIFY pollingIntervalChanged)
48
49
53 Q_PROPERTY(int pollingTaskInterval READ pollingTaskInterval WRITE setPollingTaskInterval NOTIFY pollingTaskIntervalChanged)
54
55
66 Q_PROPERTY(int requestInterval READ requestInterval WRITE setRequestInterval NOTIFY requestIntervalChanged)
67
68
71 Q_PROPERTY(int timeout READ timeout WRITE setTimeout NOTIFY timeoutChanged STORED false)
72
73 int pollingInterval() const;
74
75 void setPollingInterval(int interval);
76
77 int pollingTaskInterval() const;
78
79 void setPollingTaskInterval(int interval);
80
81 int requestInterval() const;
82
83 void setRequestInterval(int interval);
84
85 virtual int timeout() const = 0;
86
87 virtual void setTimeout(int timeout) = 0;
88
89 void configureStarting(QState * starting, AssignStatusFunction assignStatus) override;
90
91 void configureStarted(QState * active, const QState * idling, const QState * yielding, AssignStatusFunction assignStatus) override;
92
93 void configureStopping(QState * stopping, AssignStatusFunction assignStatus) override;
94
95 void configureBroken(QState * broken, AssignStatusFunction assignStatus) override;
96
97 void configureRepairing(QState * repairing, AssignStatusFunction assignStatus) override;
98
99 void configureEvacuating(QState * evacuating, AssignStatusFunction assignStatus) override;
100
101 std::unique_ptr<QAbstractTransition> transitionToStarted() const override;
102
103 std::unique_ptr<QAbstractTransition> transitionToStopped() const override;
104
105 std::unique_ptr<QAbstractTransition> transitionToBroken() const override;
106
107 std::unique_ptr<QAbstractTransition> transitionToYielding() const override;
108
109 std::unique_ptr<QAbstractTransition> transitionToIdling() const override;
110
111 signals:
113
115
117
119
120 protected:
121 AbstractClient(QObject * parent = nullptr);
122
123 void handleRequest(const QJsonObject & request) override;
124
125 void handleReply(QUuid requestId, QJsonObject reply) override;
126
127 protected slots:
128 virtual void onStateChanged();
129
130 void poll();
131
132 void pollingTask();
133
134 protected:
135 Q_SIGNAL void requestAccepted(QJsonObject request);
136
137 Q_SIGNAL void pollingRequested();
138
139 Q_SIGNAL void pollingFinished();
140
141 Q_SIGNAL void pollingTaskRequested();
142
143 Q_SIGNAL void pollingTaskFinished();
144
145 private slots:
146 void dequeueRequest();
147
148 private:
150
151 struct Members {
152 internal::PollingIterator pollingIterator;
153 int pollingInterval;
154 int pollingTaskInterval;
155 int requestInterval;
156 qint64 lastProcessRequestTimestamp;
157 QTimer requestDequeueTimer;
158 RequestQueueContainer requestQueue;
159
160 Members(AbstractDevice * device):
161 pollingIterator(device),
162 pollingInterval(INITIAL_POLLING_INTERVAL),
163 pollingTaskInterval(INITIAL_POLLING_TASK_INTERVAL),
164 requestInterval(INITIAL_REQUEST_INTERVAL),
165 lastProcessRequestTimestamp(0)
166 {
167 }
168 };
169
171};
172
173}
174}
175
176#endif
177
178//(c)C: Copyright © 2022, Michał Policht <michal@policht.pl>. All rights reserved.
179//(c)C: SPDX-License-Identifier: LGPL-3.0-or-later OR MIT
180//(c)C: This file is a part of CuteHMI.
181//(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.
182//(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.
183//(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/>.
184//(c)C: Additionally, this file is licensed under terms of MIT license as expressed below.
185//(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:
186//(c)C: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
187//(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 client.
Definition: AbstractClient.hpp:32
virtual int timeout() const =0
Q_SIGNAL void requestAccepted(QJsonObject request)
virtual void setTimeout(int timeout)=0
Q_SIGNAL void pollingTaskFinished()
Q_SIGNAL void pollingTaskRequested()
Abstract Modbus device.
Definition: AbstractDevice.hpp:38
Definition: PollingIterator.hpp:18