Dokit
Native Qt library for Pokit devices
Loading...
Searching...
No Matches
dataloggerservice.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2022-2023 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, ///< Start the Data Logger.
37 Stop = 1, ///< Stop the Data Logger.
38 Refresh = 2, ///< Refresh the Data Logger.
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 Temperature = 5, ///< Measure temperature.
48 };
49 static QString toString(const Mode &mode);
50
51 static QString toString(const PokitProduct product, const quint8 range, const Mode mode);
52 QString toString(const quint8 range, const Mode mode) const;
53 static QVariant maxValue(const PokitProduct product, const quint8 range, const Mode mode);
54 QVariant maxValue(const quint8 range, const Mode mode) const;
55
56 struct Settings {
57 Command command; ///< Custom operation request.
58 quint16 arguments; ///< Reserved to used along with #command in future.
59 Mode mode; ///< Desired operation mode.
60 quint8 range; ///< Desired range.
61 quint32 updateInterval; ///< Desired update interval in milliseconds.
62 quint32 timestamp; ///< Custom timestamp for start time in retrieved metadata.
63 };
64
65 enum class LoggerStatus : quint8 {
66 Done = 0, ///< Sampling has completed.
67 Sampling = 1, ///< Actively sampling.
68 BufferFull = 2, ///< Buffer is full.
69 Error = 255 ///< An error has occurred.
70 };
71
72 struct Metadata {
73 LoggerStatus status; ///< Current data logger status.
74 float scale; ///< Scale to apply to read samples.
75 Mode mode; ///< Current operation mode.
76 quint8 range; ///< Current range.
77 quint32 updateInterval; ///< Current logging interval in milliseconds.
78 quint16 numberOfSamples; ///< Number of samples acquired (1 to 6192).
79 quint32 timestamp; ///< Timestamp stored at the beginning of the logging session.
80 };
81
83
84 DataLoggerService(QLowEnergyController * const pokitDevice, QObject * parent = nullptr);
85 ~DataLoggerService() override;
86
87 bool readCharacteristics() override;
88 bool readMetadataCharacteristic();
89
90 // Settings characteristic (BLE write only).
91 bool setSettings(const Settings &settings);
92 bool startLogger(const Settings &settings);
93 bool stopLogger();
94 bool fetchSamples();
95
96 // Metadata characteristic (BLE read/notify).
97 Metadata metadata() const;
98 bool enableMetadataNotifications();
99 bool disableMetadataNotifications();
100
101 // Reading characteristic (BLE notify only).
102 bool enableReadingNotifications();
103 bool disableReadingNotifications();
104
105signals:
109
110protected:
111 /// \cond internal
112 DataLoggerService(DataLoggerServicePrivate * const d, QObject * const parent);
113 /// \endcond
114
115private:
116 Q_DECLARE_PRIVATE(DataLoggerService)
118 friend class TestDataLoggerService;
119};
120
121QTPOKIT_END_NAMESPACE
122
123#endif // QTPOKIT_DATALOGGERSERVICE_H
Declares the AbstractPokitService class.
The AbstractPokitService class provides a common base for Pokit services classes.
Definition abstractpokitservice.h:25
virtual bool readCharacteristics()=0
Read all characteristics.
The DataLoggerService class accesses the Data Logger service of Pokit devices.
Definition dataloggerservice.h:23
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:65
QVector< qint16 > Samples
Raw samples from the Reading characteristic.
Definition dataloggerservice.h:82
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
void settingsWritten()
This signal is emitted when the Settings characteristic has been written successfully.
PokitProduct
Pokit products known to, and supported by, the QtPokit library.
Definition pokitproducts.h:21
QTPOKIT_EXPORT QString toString(const PokitProduct product)
Returns product as user-friendly string.
Definition pokitproducts.cpp:26
Q_DISABLE_COPY(Class)
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:72
quint8 range
Current range.
Definition dataloggerservice.h:76
quint16 numberOfSamples
Number of samples acquired (1 to 6192).
Definition dataloggerservice.h:78
quint32 timestamp
Timestamp stored at the beginning of the logging session.
Definition dataloggerservice.h:79
float scale
Scale to apply to read samples.
Definition dataloggerservice.h:74
LoggerStatus status
Current data logger status.
Definition dataloggerservice.h:73
quint32 updateInterval
Current logging interval in milliseconds.
Definition dataloggerservice.h:77
Mode mode
Current operation mode.
Definition dataloggerservice.h:75
Attributes included in the Settings characterstic.
Definition dataloggerservice.h:56
quint32 timestamp
Custom timestamp for start time in retrieved metadata.
Definition dataloggerservice.h:62
quint16 arguments
Reserved to used along with command in future.
Definition dataloggerservice.h:58
Command command
Custom operation request.
Definition dataloggerservice.h:57
quint8 range
Desired range.
Definition dataloggerservice.h:60
Mode mode
Desired operation mode.
Definition dataloggerservice.h:59
quint32 updateInterval
Desired update interval in milliseconds.
Definition dataloggerservice.h:61