CuteHMI - Modbus (CuteHMI.Modbus.2)
Register1Controller.hpp
1 #ifndef H_EXTENSIONS_CUTEHMI_MODBUS_2_INCLUDE_CUTEHMI_MODBUS_REGISTER1CONTROLLER_HPP
2 #define H_EXTENSIONS_CUTEHMI_MODBUS_2_INCLUDE_CUTEHMI_MODBUS_REGISTER1CONTROLLER_HPP
3 
4 #include "internal/common.hpp"
5 #include "internal/RegisterControllerMixin.hpp"
6 #include "AbstractDevice.hpp"
7 #include "Register1.hpp"
8 #include "AbstractRegisterController.hpp"
9 
10 #include <QObject>
11 #include <QBasicTimer>
12 
13 namespace cutehmi {
14 namespace modbus {
15 
19 class CUTEHMI_MODBUS_API Register1Controller:
21  protected internal::RegisterControllerMixin<Register1Controller>
22 {
23  Q_OBJECT
24 
27 
28  public:
29  static constexpr bool INITIAL_VALUE = false;
30 
31  Q_PROPERTY(bool value READ value WRITE setValue NOTIFY valueChanged)
32 
33  Register1Controller(QObject * parent = nullptr);
34 
35  ~Register1Controller() override;
36 
37  bool value() const;
38 
39  void setValue(bool value);
40 
41  public slots:
42  void writeValue();
43 
44  signals:
45  void valueChanged();
46 
47  void valueUpdated();
48 
49  void valueWritten();
50 
51  void valueFailed();
52 
53  void valueMismatch();
54 
55  protected:
56  virtual Register1 * registerAt(quint16 address) const = 0;
57 
58  virtual AbstractDevice::Function readRegistersFunction() const = 0;
59 
60  virtual AbstractDevice::Function writeRegisterFunction() const = 0;
61 
62  virtual void requestWriteRegister(quint16 address, bool value, QUuid * requestId) const = 0;
63 
64  void timerEvent(QTimerEvent * event) override;
65 
66  quint16 bytes() const override;
67 
68  void onDeviceDestroyed() override;
69 
70  protected slots:
71  void onRequestCompleted(QJsonObject request, QJsonObject reply) override;
72 
73  void resetRegister();
74 
75  private:
76  void updateValue();
77 
78  void updateValue(bool value);
79 
80  void updateValue(const QJsonValue & value);
81 
82  void requestWrite(bool value);
83 
84  bool verifyRegisterValue() const;
85 
86  private:
87  struct Members {
88  bool value;
89  bool postponedWritePending;
90  bool adjustingValue;
91  bool requestedValue;
92  Register1 * register1;
93  QUuid requestId;
94  QBasicTimer writeTimer;
95 
96  Members():
97  value(INITIAL_VALUE),
98  postponedWritePending(false),
99  adjustingValue(false),
100  requestedValue(0.0),
101  register1(nullptr)
102  {
103  }
104  };
105 
106  MPtr<Members> m;
107 };
108 
109 }
110 }
111 
112 #endif
113 
114 //(c)C: Copyright © 2019, Michał Policht <michal@policht.pl>. All rights reserved.
115 //(c)C: This file is a part of CuteHMI.
116 //(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.
117 //(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.
118 //(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/>.
QTimerEvent
cutehmi::modbus::Register1Controller
Register controller for 1 bit registers.
Definition: Register1Controller.hpp:19
cutehmi::modbus::internal::RegisterControllerMixin
Definition: RegisterControllerMixin.hpp:17
QUuid
QBasicTimer
cutehmi::modbus::Register1
Cached properties of 1 bit register.
Definition: Register1.hpp:14
cutehmi::MPtr< Members >
QJsonValue
QObject
cutehmi
cutehmi::modbus::AbstractRegisterController
Abstract register controller.
Definition: AbstractRegisterController.hpp:16
QJsonObject
cutehmi::modbus::AbstractDevice::Function
Function
Definition: AbstractDevice.hpp:51