Dokit
Internal development documentation
Loading...
Searching...
No Matches
dataloggerservice.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2022-2025 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
19
21
22class QTPOKIT_EXPORT DataLoggerService : public AbstractPokitService
23{
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.
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 quint32 maxValue(const PokitProduct product, const quint8 range, const Mode mode);
63 quint32 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;
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;
112
113 // Reading characteristic (BLE notify only).
116
121
122protected:
123 /// \cond internal
125 /// \endcond
126
127private:
128 Q_DECLARE_PRIVATE(DataLoggerService)
131};
132
134
135#endif // QTPOKIT_DATALOGGERSERVICE_H
Declares the AbstractPokitService class.
virtual bool readCharacteristics()=0
Read all characteristics.
The DataLoggerServicePrivate class provides private implementation for DataLoggerService.
bool readMetadataCharacteristic()
Reads the DataLogger service's Metadata characteristic.
bool enableMetadataNotifications()
Enables client-side notifications of Data Logger metadata changes.
static const QBluetoothUuid serviceUuid
UUID of the "DataLogger" service.
LoggerStatus
Values supported by the Status attribute of the Metadata characteristic.
@ Error
An error has occurred.
@ Done
Sampling has completed.
DataLoggerService(QLowEnergyController *const pokitDevice, QObject *parent=nullptr)
Constructs a new Pokit service with parent.
bool disableMetadataNotifications()
Disables client-side notifications of Data Logger metadata changes.
bool enableReadingNotifications()
Enables client-side notifications of Data Logger readings.
bool setSettings(const Settings &settings)
Configures the Pokit device's data logger mode.
bool startLogger(const Settings &settings)
Start the data logger with settings.
QVector< qint16 > Samples
Raw samples from the Reading characteristic.
bool fetchSamples()
Start the data logger.
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.
@ Stop
Stop the Data Logger.
@ Refresh
Refresh the Data Logger.
@ Start
Start the Data Logger.
bool disableReadingNotifications()
Disables client-side notifications of Data Logger readings.
bool stopLogger()
Stop the data logger.
Metadata metadata() const
Returns the most recent value of the DataLogger service's Metadata characteristic.
Mode
Values supported by the Mode attribute of the Settings and Metadata characteristics.
@ DcVoltage
Measure DC voltage.
@ AcCurrent
Measure AC current.
@ AcVoltage
Measure AC voltage.
@ Idle
Make device idle.
@ Temperature
Measure temperature.
@ DcCurrent
Measure DC current.
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.
QTPOKIT_EXPORT QString toString(const PokitProduct product)
Returns product as user-friendly string.
QObject(QObject *parent)
Q_DISABLE_COPY(Class)
Q_OBJECTQ_OBJECT
Q_SIGNALSQ_SIGNALS
QObject * parent() const const
#define QTPOKIT_BEFRIEND_TEST(Class)
Macro for befriending a related unit test class, but only when QT_TESTLIB_LIB is defined.
#define QTPOKIT_BEGIN_NAMESPACE
Macro for starting the QtPokit library's top-most namespace (if one is defined).
#define QTPOKIT_EXPORT
QtPokit library export/import macro.
#define QTPOKIT_END_NAMESPACE
Macro for ending the QtPokit library's top-most namespace (if one is defined).
Characteristics available via the DataLogger service.
static const QBluetoothUuid metadata
UUID of the DataLogger service's Metadata characterstic.
static const QBluetoothUuid settings
UUID of the DataLogger service's Settings characterstic.
static const QBluetoothUuid reading
UUID of the DataLogger service's Reading characterstic.
Attributes included in the Metadata characterstic.
quint16 numberOfSamples
Number of samples acquired (1 to 6192).
quint32 timestamp
Timestamp stored at the beginning of the logging session.
float scale
Scale to apply to read samples.
LoggerStatus status
Current data logger status.
quint32 updateInterval
Current logging interval in milliseconds.
Mode mode
Current operation mode.
Attributes included in the Settings characterstic.
quint32 timestamp
Custom timestamp for start time in retrieved metadata.
quint16 arguments
Reserved to used along with command in future.
Command command
Custom operation request.
Mode mode
Desired operation mode.
quint32 updateInterval
Desired update interval in milliseconds.