Dokit
Native Qt library for Pokit devices
Loading...
Searching...
No Matches
dataloggerservice.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2022-2024 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:
27 /// UUID of the "DataLogger" service.
28 static inline const QBluetoothUuid serviceUuid { QStringLiteral("a5ff3566-1fd8-4e10-8362-590a578a4121") };
29
30 /// Characteristics available via the `DataLogger` service.
31 struct QTPOKIT_EXPORT CharacteristicUuids {
32 /// UUID of the `DataLogger` service's `Settings` characterstic.
33 static inline const QBluetoothUuid settings { QStringLiteral("5f97c62b-a83b-46c6-b9cd-cac59e130a78") };
34
35 /// UUID of the `DataLogger` service's `Metadata` characterstic.
36 static inline const QBluetoothUuid metadata { QStringLiteral("9acada2e-3936-430b-a8f7-da407d97ca6e") };
37
38 /// UUID of the `DataLogger` service's `Reading` characterstic.
39 static inline const QBluetoothUuid reading { QStringLiteral("3c669dab-fc86-411c-9498-4f9415049cc0") };
40 };
41
42 /// Values supported by the `Command` attribute of the `Settings` characteristic.
43 enum class Command : quint8 {
44 Start = 0, ///< Start the Data Logger.
45 Stop = 1, ///< Stop the Data Logger.
46 Refresh = 2, ///< Refresh the Data Logger.
47 };
48
49 /// Values supported by the `Mode` attribute of the `Settings` and `Metadata` characteristics.
50 enum class Mode : quint8 {
51 Idle = 0, ///< Make device idle.
52 DcVoltage = 1, ///< Measure DC voltage.
53 AcVoltage = 2, ///< Measure AC voltage.
54 DcCurrent = 3, ///< Measure DC current.
55 AcCurrent = 4, ///< Measure AC current.
56 Temperature = 5, ///< Measure temperature.
57 };
58 static QString toString(const Mode &mode);
59
60 static QString toString(const PokitProduct product, const quint8 range, const Mode mode);
61 QString toString(const quint8 range, const Mode mode) const;
62 static QVariant maxValue(const PokitProduct product, const quint8 range, const Mode mode);
63 QVariant maxValue(const quint8 range, const Mode mode) const;
64
65 /// Attributes included in the `Settings` characterstic.
66 struct Settings {
67 Command command; ///< Custom operation request.
68 quint16 arguments; ///< Reserved to used along with #command in future.
69 Mode mode; ///< Desired operation mode.
70 quint8 range; ///< Desired range.
71 quint32 updateInterval; ///< Desired update interval in milliseconds.
72 quint32 timestamp; ///< Custom timestamp for start time in retrieved metadata.
73 };
74
75 /// Values supported by the `Status` attribute of the `Metadata` characteristic.
76 enum class LoggerStatus : quint8 {
77 Done = 0, ///< Sampling has completed.
78 Sampling = 1, ///< Actively sampling.
79 BufferFull = 2, ///< Buffer is full.
80 Error = 255 ///< An error has occurred.
81 };
82
83 /// Attributes included in the `Metadata` characterstic.
84 struct Metadata {
85 LoggerStatus status; ///< Current data logger status.
86 float scale; ///< Scale to apply to read samples.
87 Mode mode; ///< Current operation mode.
88 quint8 range; ///< Current range.
89 quint32 updateInterval; ///< Current logging interval in milliseconds.
90 quint16 numberOfSamples; ///< Number of samples acquired (1 to 6192).
91 quint32 timestamp; ///< Timestamp stored at the beginning of the logging session.
92 };
93
95
96 DataLoggerService(QLowEnergyController * const pokitDevice, QObject * parent = nullptr);
97 ~DataLoggerService() = default;
98
99 bool readCharacteristics() override;
100 bool readMetadataCharacteristic();
101
102 // Settings characteristic (BLE write only).
103 bool setSettings(const Settings &settings);
104 bool startLogger(const Settings &settings);
105 bool stopLogger();
106 bool fetchSamples();
107
108 // Metadata characteristic (BLE read/notify).
109 Metadata metadata() const;
110 bool enableMetadataNotifications();
111 bool disableMetadataNotifications();
112
113 // Reading characteristic (BLE notify only).
114 bool enableReadingNotifications();
115 bool disableReadingNotifications();
116
121
122protected:
123 /// \cond internal
124 DataLoggerService(DataLoggerServicePrivate * const d, QObject * const parent);
125 /// \endcond
126
127private:
128 Q_DECLARE_PRIVATE(DataLoggerService)
130 friend class TestDataLoggerService;
131};
132
133QTPOKIT_END_NAMESPACE
134
135#endif // QTPOKIT_DATALOGGERSERVICE_H
Declares the AbstractPokitService class.
The AbstractPokitService class provides a common base for Pokit services classes.
Definition abstractpokitservice.h:27
virtual bool readCharacteristics()=0
Read all characteristics.
The DataLoggerService class accesses the Data Logger service of Pokit devices.
Definition dataloggerservice.h:23
LoggerStatus
Values supported by the Status attribute of the Metadata characteristic.
Definition dataloggerservice.h:76
QVector< qint16 > Samples
Raw samples from the Reading characteristic.
Definition dataloggerservice.h:94
void samplesRead(const DataLoggerService::Samples &samples)
This signal is emitted when the Reading characteristic has been notified.
void metadataRead(const DataLoggerService::Metadata &meta)
This signal is emitted when the Metadata characteristic has been read successfully.
Command
Values supported by the Command attribute of the Settings characteristic.
Definition dataloggerservice.h:43
Mode
Values supported by the Mode attribute of the Settings and Metadata characteristics.
Definition dataloggerservice.h:50
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)
Q_SIGNALSQ_SIGNALS
Characteristics available via the DataLogger service.
Definition dataloggerservice.h:31
Attributes included in the Metadata characterstic.
Definition dataloggerservice.h:84
quint8 range
Current range.
Definition dataloggerservice.h:88
quint16 numberOfSamples
Number of samples acquired (1 to 6192).
Definition dataloggerservice.h:90
quint32 timestamp
Timestamp stored at the beginning of the logging session.
Definition dataloggerservice.h:91
float scale
Scale to apply to read samples.
Definition dataloggerservice.h:86
LoggerStatus status
Current data logger status.
Definition dataloggerservice.h:85
quint32 updateInterval
Current logging interval in milliseconds.
Definition dataloggerservice.h:89
Mode mode
Current operation mode.
Definition dataloggerservice.h:87
Attributes included in the Settings characterstic.
Definition dataloggerservice.h:66
quint32 timestamp
Custom timestamp for start time in retrieved metadata.
Definition dataloggerservice.h:72
quint16 arguments
Reserved to used along with command in future.
Definition dataloggerservice.h:68
Command command
Custom operation request.
Definition dataloggerservice.h:67
quint8 range
Desired range.
Definition dataloggerservice.h:70
Mode mode
Desired operation mode.
Definition dataloggerservice.h:69
quint32 updateInterval
Desired update interval in milliseconds.
Definition dataloggerservice.h:71