Dokit 0.5.3-pre
Internal development documentation
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
19
21
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.
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() override;
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
134
135#endif // QTPOKIT_DATALOGGERSERVICE_H
Declares the AbstractPokitService class.
The AbstractPokitService class provides a common base for Pokit services classes.
virtual bool readCharacteristics()=0
Read all characteristics.
The DataLoggerServicePrivate class provides private implementation for DataLoggerService.
The DataLoggerService class accesses the Data Logger service of Pokit devices.
LoggerStatus
Values supported by the Status attribute of the Metadata characteristic.
QVector< qint16 > Samples
Raw samples from the Reading characteristic.
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.
Mode
Values supported by the Mode attribute of the Settings and Metadata characteristics.
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.
Q_DISABLE_COPY(Class)
Q_SIGNALSQ_SIGNALS
#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.
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.