CuteHMI - Modbus (CuteHMI.Modbus.2)
AbstractServer.hpp
1 #ifndef H_EXTENSIONS_CUTEHMI_MODBUS_2_INCLUDE_CUTEHMI_MODBUS_ABSTRACTSERVER_HPP
2 #define H_EXTENSIONS_CUTEHMI_MODBUS_2_INCLUDE_CUTEHMI_MODBUS_ABSTRACTSERVER_HPP
3 
4 #include "AbstractDevice.hpp"
5 
6 namespace cutehmi {
7 namespace modbus {
8 
15 class CUTEHMI_MODBUS_API AbstractServer:
16  public AbstractDevice
17 {
18  Q_OBJECT
19 
20  public:
21  static constexpr bool INITIAL_BUSY = false;
22 
23  Q_PROPERTY(bool busy READ busy WRITE setBusy NOTIFY busyChanged)
24 
25  bool busy() const;
26 
27  virtual void setBusy(bool busy) = 0;
28 
29  std::unique_ptr<ServiceStatuses> configureStarting(QState * starting) override;
30 
31  std::unique_ptr<ServiceStatuses> configureStarted(QState * active, const QState * idling, const QState * yielding) override;
32 
33  std::unique_ptr<ServiceStatuses> configureStopping(QState * stopping) override;
34 
35  std::unique_ptr<ServiceStatuses> configureBroken(QState * broken) override;
36 
37  std::unique_ptr<ServiceStatuses> configureRepairing(QState * repairing) override;
38 
39  std::unique_ptr<ServiceStatuses> configureEvacuating(QState * evacuating) override;
40 
41  std::unique_ptr<QAbstractTransition> transitionToStarted() const override;
42 
43  std::unique_ptr<QAbstractTransition> transitionToStopped() const override;
44 
45  std::unique_ptr<QAbstractTransition> transitionToBroken() const override;
46 
47  std::unique_ptr<QAbstractTransition> transitionToYielding() const override;
48 
49  std::unique_ptr<QAbstractTransition> transitionToIdling() const override;
50 
51  signals:
52  void busyChanged();
53 
54  protected:
55  AbstractServer(QObject * parent = nullptr);
56 
57  void handleRequest(const QJsonObject & request) override;
58 
59  protected slots:
60  virtual void handleCoilsWritten(quint16 address, quint16 amount);
61 
62  virtual void handleDiscreteInputsWritten(quint16 address, quint16 amount);
63 
64  virtual void handleHoldingRegistersWritten(quint16 address, quint16 amount);
65 
66  virtual void handleInputRegistersWritten(quint16 address, quint16 amount);
67 
68  void updateBusy(bool busy);
69 
70  CUTEHMI_PROTECTED_SIGNALS:
71  void requestReceived(QJsonObject request);
72 
73  void broke();
74 
75  void stopped();
76 
77  void started();
78 
79  private:
80  struct Members {
81  bool busy = INITIAL_BUSY;
82  };
83 
84  MPtr<Members> m;
85 };
86 
87 }
88 }
89 
90 #endif
91 
92 //(c)C: Copyright © 2019, Michał Policht <michal@policht.pl>. All rights reserved.
93 //(c)C: This file is a part of CuteHMI.
94 //(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.
95 //(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.
96 //(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/>.
QState
cutehmi::modbus::AbstractDevice
Abstract Modbus device.
Definition: AbstractDevice.hpp:32
cutehmi::MPtr< Members >
QObject
cutehmi
QJsonObject
cutehmi::modbus::AbstractServer
Abstract server.
Definition: AbstractServer.hpp:15
std::unique_ptr