QtPokit
Native Qt library for Pokit devices
Loading...
Searching...
No Matches
dataloggerservice.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2022 Paul Colby <git@colby.id.au>
2// SPDX-License-Identifier: LGPL-3.0-or-later
3
4/*!
5 * \file
6 * Declares the DataLoggerService class.
7 */
8
9#ifndef QTPOKIT_DATALOGGERSERVICE_H
10#define QTPOKIT_DATALOGGERSERVICE_H
11
13
14#include <QBluetoothAddress>
15#include <QBluetoothUuid>
16#include <QVersionNumber>
17
18QTPOKIT_BEGIN_NAMESPACE
19
20class DataLoggerServicePrivate;
21
22class QTPOKIT_EXPORT DataLoggerService : public AbstractPokitService
23{
24 Q_OBJECT
25
26public:
28
29 struct QTPOKIT_EXPORT CharacteristicUuids {
32 static const QBluetoothUuid reading;
33 };
34
35 enum class Command : quint8 {
36 Start = 0,
37 Stop = 1,
38 Refresh = 2,
39 };
40
41 enum class Mode : quint8 {
42 Idle = 0, ///< Make device idle.
43 DcVoltage = 1, ///< Measure DC voltage.
44 AcVoltage = 2, ///< Measure AC voltage.
45 DcCurrent = 3, ///< Measure DC current.
46 AcCurrent = 4, ///< Measure AC current.
47 /// \todo Pokit Pro supports temperature in logger mode too.
48 };
49 static QString toString(const Mode &mode);
50
51 enum class VoltageRange : quint8 {
52 _0_to_300mV = 0, ///< 0 to 300mV.
53 _300mV_to_2V = 1, ///< 300mV to 2V.
54 _2V_to_6V = 2, ///< 2V to 6V.
55 _6V_to_12V = 3, ///< 6V to 12V.
56 _12V_to_30V = 4, ///< 12V to 30V.
57 _30V_to_60V = 5, ///< 30V to 60V.
58 /// \todo Pokit Pro supports up to 600V, which are enum 6 and 7 via Android app.
59 };
60 static QString toString(const VoltageRange &range);
61 static QVariant minValue(const VoltageRange &range);
62 static QVariant maxValue(const VoltageRange &range);
63
64 enum class CurrentRange : quint8 {
65 _0_to_10mA = 0, ///< 0 to 10mA.
66 _10mA_to_30mA = 1, ///< 10mA to 30mA.
67 _30mA_to_150mA = 2, ///< 30mA to 150mA.
68 _150mA_to_300mA = 3, ///< 150mA to 300mA.
69 _300mA_to_3A = 4, ///< 300mA to 3A.
70 /// \todo Pokit Pro supports up to 10A.
71 };
72 static QString toString(const CurrentRange &range);
73 static QVariant minValue(const CurrentRange &range);
74 static QVariant maxValue(const CurrentRange &range);
75
76 union QTPOKIT_EXPORT Range {
77 VoltageRange voltageRange; ///< Range when in AC/DC voltage mode.
78 CurrentRange currentRange; ///< Range when in AC/DC current mode.
79 Range();
80 Range(const VoltageRange range);
81 Range(const CurrentRange range);
82 };
83 static QString toString(const Range &range, const Mode &mode);
84
85 struct Settings {
86 Command command; ///< Custom operation request.
87 quint16 arguments; ///< Reserved to used along with #command in future.
88 Mode mode; ///< Desired operation mode.
89 Range range; ///< Desired range.
90 quint32 updateInterval; ///< Desired update interval in milliseconds.
91 quint32 timestamp; ///< Custom timestamp for start time in retrieved metadata.
92 };
93
94 enum class LoggerStatus : quint8 {
95 Done = 0,
96 Sampling = 1,
97 BufferFull = 2,
98 Error = 255
99 };
100
101 struct Metadata {
102 LoggerStatus status; ///< Current data logger status.
103 float scale; ///< Scale to apply to read samples.
104 Mode mode; ///< Current operation mode.
105 Range range; ///< Current range.
106 quint32 updateInterval; ///< Current logging interval in milliseconds.
107 quint16 numberOfSamples; ///< Number of samples acquired (1 to 6192).
108 quint32 timestamp; ///< Timestamp stored at the beginning of the logging session.
109 };
110
112
113 DataLoggerService(QLowEnergyController * const pokitDevice, QObject * parent = nullptr);
114 ~DataLoggerService() override;
115
116 bool readCharacteristics() override;
117 bool readMetadataCharacteristic();
118
119 // Settings characteristic (BLE write only).
120 bool setSettings(const Settings &settings);
121 bool startLogger(const Settings &settings);
122 bool stopLogger();
123 bool fetchSamples();
124
125 // Metadata characteristic (BLE read/notify).
126 Metadata metadata() const;
127 bool enableMetadataNotifications();
128 bool disableMetadataNotifications();
129
130 // Reading characteristic (BLE notify only).
131 bool enableReadingNotifications();
132 bool disableReadingNotifications();
133
134signals:
138
139protected:
140 /// \cond internal
141 DataLoggerService(DataLoggerServicePrivate * const d, QObject * const parent);
142 /// \endcond
143
144private:
145 Q_DECLARE_PRIVATE(DataLoggerService)
146 Q_DISABLE_COPY(DataLoggerService)
147 friend class TestDataLoggerService;
148};
149
150QTPOKIT_EXPORT bool operator==(const DataLoggerService::Range &lhs, const DataLoggerService::Range &rhs);
151QTPOKIT_EXPORT bool operator!=(const DataLoggerService::Range &lhs, const DataLoggerService::Range &rhs);
152QTPOKIT_EXPORT bool operator< (const DataLoggerService::Range &lhs, const DataLoggerService::Range &rhs);
153QTPOKIT_EXPORT bool operator> (const DataLoggerService::Range &lhs, const DataLoggerService::Range &rhs);
154QTPOKIT_EXPORT bool operator<=(const DataLoggerService::Range &lhs, const DataLoggerService::Range &rhs);
155QTPOKIT_EXPORT bool operator>=(const DataLoggerService::Range &lhs, const DataLoggerService::Range &rhs);
156
157QTPOKIT_END_NAMESPACE
158
159#endif // QTPOKIT_DATALOGGERSERVICE_H
Declares the AbstractPokitService class.
The AbstractPokitService class provides a common base for Pokit services classes.
Definition: abstractpokitservice.h:24
virtual bool readCharacteristics()=0
Read all characteristics.
The DataLoggerService class accesses the Pokit Status service of Pokit devices.
Definition: dataloggerservice.h:23
CurrentRange
Values supported by the Range attribute of the Settings and Metadata characteristics,...
Definition: dataloggerservice.h:64
static const QBluetoothUuid serviceUuid
UUID of the "DataLogger" service.
Definition: dataloggerservice.h:27
LoggerStatus
Values supported by the Status attribute of the Metadata characteristic.
Definition: dataloggerservice.h:94
QVector< qint16 > Samples
Raw samples from the Reading characteristic.
Definition: dataloggerservice.h:111
void metadataRead(const DataLoggerService::Metadata &meta)
This signal is emitted when the Metadata characteristic has been read successfully.
void samplesRead(const DataLoggerService::Samples &samples)
This signal is emitted when the Reading characteristic has been notified.
Command
Values supported by the Command attribute of the Settings characteristic.
Definition: dataloggerservice.h:35
Mode
Values supported by the Mode attribute of the Settings and Metadata characteristics.
Definition: dataloggerservice.h:41
VoltageRange
Values supported by the Range attribute of the Settings and Metadata characteristics,...
Definition: dataloggerservice.h:51
void settingsWritten()
This signal is emitted when the Settings characteristic has been written successfully.
QTPOKIT_EXPORT bool operator<=(const DataLoggerService::Range &lhs, const DataLoggerService::Range &rhs)
Returns true if lhs is numerically less than or equal to rhs, false otherwise.
Definition: dataloggerservice.cpp:243
QTPOKIT_EXPORT bool operator>=(const DataLoggerService::Range &lhs, const DataLoggerService::Range &rhs)
Returns true if lhs is numerically greater than or equal to rhs, false otherwise.
Definition: dataloggerservice.cpp:250
QTPOKIT_EXPORT bool operator<(const DataLoggerService::Range &lhs, const DataLoggerService::Range &rhs)
Returns true if lhs is numerically less than rhs, false otherwise.
Definition: dataloggerservice.cpp:229
QTPOKIT_EXPORT bool operator>(const DataLoggerService::Range &lhs, const DataLoggerService::Range &rhs)
Returns true if lhs is numerically greater than rhs, false otherwise.
Definition: dataloggerservice.cpp:236
QTPOKIT_EXPORT bool operator!=(const DataLoggerService::Range &lhs, const DataLoggerService::Range &rhs)
Returns true if lhs is numerically not-equal to rhs, false otherwise.
Definition: dataloggerservice.cpp:222
QTPOKIT_EXPORT bool operator==(const DataLoggerService::Range &lhs, const DataLoggerService::Range &rhs)
Returns true if lhs is numerically equal to rhs, false otherwise.
Definition: dataloggerservice.cpp:215
Characteristics available via the DataLogger service.
Definition: dataloggerservice.h:29
static const QBluetoothUuid metadata
UUID of the DataLogger service's Metadata characterstic.
Definition: dataloggerservice.h:31
static const QBluetoothUuid settings
UUID of the DataLogger service's Settings characterstic.
Definition: dataloggerservice.h:30
static const QBluetoothUuid reading
UUID of the DataLogger service's Reading characterstic.
Definition: dataloggerservice.h:32
Attributes included in the Metadata characterstic.
Definition: dataloggerservice.h:101
Range range
Current range.
Definition: dataloggerservice.h:105
quint16 numberOfSamples
Number of samples acquired (1 to 6192).
Definition: dataloggerservice.h:107
quint32 timestamp
Timestamp stored at the beginning of the logging session.
Definition: dataloggerservice.h:108
float scale
Scale to apply to read samples.
Definition: dataloggerservice.h:103
LoggerStatus status
Current data logger status.
Definition: dataloggerservice.h:102
quint32 updateInterval
Current logging interval in milliseconds.
Definition: dataloggerservice.h:106
Mode mode
Current operation mode.
Definition: dataloggerservice.h:104
Attributes included in the Settings characterstic.
Definition: dataloggerservice.h:85
quint32 timestamp
Custom timestamp for start time in retrieved metadata.
Definition: dataloggerservice.h:91
quint16 arguments
Reserved to used along with command in future.
Definition: dataloggerservice.h:87
Command command
Custom operation request.
Definition: dataloggerservice.h:86
Mode mode
Desired operation mode.
Definition: dataloggerservice.h:88
Range range
Desired range.
Definition: dataloggerservice.h:89
quint32 updateInterval
Desired update interval in milliseconds.
Definition: dataloggerservice.h:90
Values supported by the Range attribute of the Settings and Metadata characteristics.
Definition: dataloggerservice.h:76
CurrentRange currentRange
Range when in AC/DC current mode.
Definition: dataloggerservice.h:78
VoltageRange voltageRange
Range when in AC/DC voltage mode.
Definition: dataloggerservice.h:77