CuteHMI - Data Acquisition (CuteHMI.DataAcquisition.1)
HistoryWriter.hpp
1#ifndef H_EXTENSIONS_CUTEHMI_DATAACQUISITION_1_INCLUDE_CUTEHMI_DATAACQUISITION_HISTORYWRITER_HPP
2#define H_EXTENSIONS_CUTEHMI_DATAACQUISITION_1_INCLUDE_CUTEHMI_DATAACQUISITION_HISTORYWRITER_HPP
3
4#include "internal/HistoryCollective.hpp"
5#include "internal/DbServiceableMixin.hpp"
6#include "AbstractWriter.hpp"
7
8#include <cutehmi/services/Serviceable.hpp>
9
10#include <QTimer>
11
12namespace cutehmi {
13namespace dataacquisition {
14
15class CUTEHMI_DATAACQUISITION_API HistoryWriter:
17 private internal::DbServiceableMixin<HistoryWriter>
18{
19 Q_OBJECT
20 QML_NAMED_ELEMENT(HistoryWriter)
21
23
24 public:
25 static constexpr int INITIAL_INTERVAL = 100;
26 static constexpr int INITIAL_SAMPLES = 100;
27
34 Q_PROPERTY(int interval READ interval WRITE setInterval NOTIFY intervalChanged)
35
36
42 Q_PROPERTY(int samples READ samples WRITE setSamples NOTIFY samplesChanged)
43
44 HistoryWriter(QObject * parent = nullptr);
45
46 int interval() const;
47
48 void setInterval(int interval);
49
50 int samples() const;
51
52 void setSamples(int samples);
53
54 void configureStarting(QState * starting, AssignStatusFunction assignStatus) override;
55
56 void configureStarted(QState * active, const QState * idling, const QState * yielding, AssignStatusFunction assignStatus) override;
57
58 void configureStopping(QState * stopping, AssignStatusFunction assignStatus) override;
59
60 void configureBroken(QState * broken, AssignStatusFunction assignStatus) override;
61
62 void configureRepairing(QState * repairing, AssignStatusFunction assignStatus) override;
63
64 void configureEvacuating(QState * evacuating, AssignStatusFunction assignStatus) override;
65
66 std::unique_ptr<QAbstractTransition> transitionToStarted() const override;
67
68 std::unique_ptr<QAbstractTransition> transitionToStopped() const override;
69
70 std::unique_ptr<QAbstractTransition> transitionToBroken() const override;
71
72 std::unique_ptr<QAbstractTransition> transitionToYielding() const override;
73
74 std::unique_ptr<QAbstractTransition> transitionToIdling() const override;
75
76 signals:
78
80
81 protected slots:
82 void sampleValues();
83
84 void insertValues();
85
86 protected:
87 Q_SIGNAL void initialized();
88
89 Q_SIGNAL void samplingTimerStarted();
90
91 Q_SIGNAL void samplingTimerStopped();
92
93 Q_SIGNAL void schemaValidatedTrue();
94
95 Q_SIGNAL void schemaValidatedFalse();
96
97 Q_SIGNAL void insertValuesBegan();
98
99 Q_SIGNAL void collectiveFinished();
100
101 void onValueAppend(TagValue * tagValue) override;
102
103 void onValueRemove(TagValue * tagValue) override;
104
105 private slots:
106 void onSchemaChanged();
107
108 void initialize();
109
110 void adjustSamplingTimer();
111
112 void startSamplingTimer();
113
114 void stopSamplingTimer();
115
116 void confirmCollectiveFinished();
117
118 private:
119 void configureStartingOrRepairing(QState * parent, AssignStatusFunction assignStatus);
120
121 void clearData();
122
123 template <typename T>
124 void addSample(T value, internal::HistoryCollective::Tuple & tuple);
125
126 struct Members
127 {
129 internal::HistoryCollective dbCollective;
130 QTimer samplingTimer;
131 int interval;
132 int samples;
133 int sampleCounter;
134
135 Members():
136 interval(INITIAL_INTERVAL),
137 samples(INITIAL_SAMPLES),
138 sampleCounter(0)
139 {
140 }
141 };
142
144};
145
146}
147}
148
149#endif
150
151//(c)C: Copyright © 2022, Michał Policht <michal@policht.pl>. All rights reserved.
152//(c)C: SPDX-License-Identifier: LGPL-3.0-or-later OR MIT
153//(c)C: This file is a part of CuteHMI.
154//(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.
155//(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.
156//(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/>.
157//(c)C: Additionally, this file is licensed under terms of MIT license as expressed below.
158//(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:
159//(c)C: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
160//(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 database writer.
Definition: AbstractWriter.hpp:28
Definition: HistoryWriter.hpp:18
Tag value.
Definition: TagValue.hpp:19
Definition: DbServiceableMixin.hpp:17
Definition: HistoryCollective.hpp:16