CuteHMI - Data Acquisition (CuteHMI.DataAcquisition.0)
HistoryWriter.hpp
1 #ifndef H_EXTENSIONS_CUTEHMI_DATAACQUISITION_0_INCLUDE_CUTEHMI_DATAACQUISITION_HISTORYWRITER_HPP
2 #define H_EXTENSIONS_CUTEHMI_DATAACQUISITION_0_INCLUDE_CUTEHMI_DATAACQUISITION_HISTORYWRITER_HPP
3 
4 #include "internal/common.hpp"
5 #include "internal/HistoryCollective.hpp"
6 #include "AbstractWriter.hpp"
7 
8 #include <cutehmi/services/Serviceable.hpp>
9 
10 #include <QTimer>
11 
12 namespace cutehmi {
13 namespace dataacquisition {
14 
15 class CUTEHMI_DATAACQUISITION_API HistoryWriter:
16  public AbstractWriter
17 
18 {
19  Q_OBJECT
20 
21  public:
22  static constexpr int INITIAL_INTERVAL = 100;
23  static constexpr int INITIAL_SAMPLES = 100;
24 
31  Q_PROPERTY(int interval READ interval WRITE setInterval NOTIFY intervalChanged)
32 
33 
39  Q_PROPERTY(int samples READ samples WRITE setSamples NOTIFY samplesChanged)
40 
41  HistoryWriter(QObject * parent = nullptr);
42 
43  int interval() const;
44 
45  void setInterval(int interval);
46 
47  int samples() const;
48 
49  void setSamples(int samples);
50 
51  virtual std::unique_ptr<ServiceStatuses> configureStarting(QState * starting) override;
52 
53  virtual std::unique_ptr<ServiceStatuses> configureStarted(QState * active, const QState * idling, const QState * yielding) override;
54 
55  virtual std::unique_ptr<ServiceStatuses> configureStopping(QState * stopping) override;
56 
57  virtual std::unique_ptr<ServiceStatuses> configureBroken(QState * broken) override;
58 
59  virtual std::unique_ptr<ServiceStatuses> configureRepairing(QState * repairing) override;
60 
61  virtual std::unique_ptr<ServiceStatuses> configureEvacuating(QState * evacuating) override;
62 
63  virtual std::unique_ptr<QAbstractTransition> transitionToStarted() const override;
64 
65  virtual std::unique_ptr<QAbstractTransition> transitionToStopped() const override;
66 
67  virtual std::unique_ptr<QAbstractTransition> transitionToBroken() const override;
68 
69  virtual std::unique_ptr<QAbstractTransition> transitionToYielding() const override;
70 
71  virtual std::unique_ptr<QAbstractTransition> transitionToIdling() const override;
72 
73  signals:
74  void intervalChanged();
75 
76  void samplesChanged();
77 
78  protected slots:
79  void sampleValues();
80 
81  void insertValues();
82 
83  CUTEHMI_PROTECTED_SIGNALS:
84  void initialized();
85 
86  void samplingTimerStarted();
87 
88  void samplingTimerStopped();
89 
90  void schemaValidatedTrue();
91 
92  void schemaValidatedFalse();
93 
94  void insertValuesBegan();
95 
96  private slots:
97  void onSchemaChanged();
98 
99  void initialize();
100 
101  void adjustSamplingTimer();
102 
103  void startSamplingTimer();
104 
105  void stopSamplingTimer();
106 
107  private:
108  std::unique_ptr<ServiceStatuses> configureStartingOrRepairing(QState * parent);
109 
110  void addIntSample(const QString & tagName, int value);
111 
112  void addBoolSample(const QString & tagName, bool value);
113 
114  void addRealSample(const QString & tagName, double value);
115 
116  void clearData();
117 
118  template <typename T>
119  void addSample(T value, typename internal::HistoryTable<T>::Tuple & tuple);
120 
121  struct Members
122  {
126  internal::HistoryCollective dbCollective;
127  QTimer samplingTimer;
128  int interval;
129  int samples;
130  int sampleCounter;
131 
132  Members():
133  interval(INITIAL_INTERVAL),
134  samples(INITIAL_SAMPLES),
135  sampleCounter(0)
136  {
137  }
138  };
139 
140  MPtr<Members> m;
141 };
142 
143 }
144 }
145 
146 #endif
147 
148 //(c)C: Copyright © 2020, Michał Policht <michal@policht.pl>. All rights reserved.
149 //(c)C: This file is a part of CuteHMI.
150 //(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.
151 //(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.
152 //(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/>.
QTimer
QState
cutehmi::dataacquisition::internal::HistoryCollective
Definition: HistoryCollective.hpp:13
cutehmi::MPtr< Members >
QObject
cutehmi
QString
QAbstractTransition
cutehmi::dataacquisition::AbstractWriter
Abstract database writer.
Definition: AbstractWriter.hpp:19
std
QHash
cutehmi::dataacquisition::HistoryWriter
Definition: HistoryWriter.hpp:15