Dokit
Native Qt library for Pokit devices
Loading...
Searching...
No Matches
dsoservice.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2022-2026 Paul Colby <git@colby.id.au>
2// SPDX-License-Identifier: LGPL-3.0-or-later
3
4/*!
5 * \file
6 * Declares the DsoService class.
7 */
8
9#ifndef QTPOKIT_DSOSERVICE_H
10#define QTPOKIT_DSOSERVICE_H
11
13#include "pokitproducts.h"
14
15#include <QBluetoothAddress>
16#include <QBluetoothUuid>
17#include <QVersionNumber>
18
19QTPOKIT_BEGIN_NAMESPACE
20
21class DsoServicePrivate;
22
23class QTPOKIT_EXPORT DsoService : public AbstractPokitService
24{
26
27public:
28 /// UUID of the "DSO" service.
29 static inline const QBluetoothUuid serviceUuid { QStringLiteral("1569801e-1425-4a7a-b617-a4f4ed719de6") };
30
31 /// Characteristics available via the `DSO` service.
32 struct QTPOKIT_EXPORT CharacteristicUuids {
33 /// UUID of the `DSO` service's `Settings` characteristic.
34 static inline const QBluetoothUuid settings { QStringLiteral("a81af1b6-b8b3-4244-8859-3da368d2be39") };
35
36 /// UUID of the `DSO` service's `Metadata` characteristic.
37 static inline const QBluetoothUuid metadata { QStringLiteral("970f00ba-f46f-4825-96a8-153a5cd0cda9") };
38
39 /// UUID of the `DSO` service's `Reading` characteristic.
40 static inline const QBluetoothUuid reading { QStringLiteral("98e14f8e-536e-4f24-b4f4-1debfed0a99e") };
41 };
42
43 /// Values supported by the `Command` attribute of the `Settings` characteristic.
44 enum class Command : quint8 {
45 FreeRunning = 0, ///< Run free, without waiting for edge triggers.
46 RisingEdgeTrigger = 1, ///< Trigger on a rising edge.
47 FallingEdgeTrigger = 2, ///< Trigger on a falling edge.
48 ResendData = 3 ///< Resend the last acquired data.
49 };
50 static QString toString(const Command &command);
51
52 /// Values supported by the `Mode` attribute of the `Settings` and `Metadata` characteristics.
53 enum class Mode : quint8 {
54 Idle = 0, ///< Make device idle.
55 DcVoltage = 1, ///< Measure DC voltage.
56 AcVoltage = 2, ///< Measure AC voltage.
57 DcCurrent = 3, ///< Measure DC current.
58 AcCurrent = 4, ///< Measure AC current.
59 };
60 static QString toString(const Mode &mode);
61
62 static QString toString(const PokitProduct product, const quint8 range, const Mode mode);
63 QString toString(const quint8 range, const Mode mode) const;
64 static quint32 maxValue(const PokitProduct product, const quint8 range, const Mode mode);
65 quint32 maxValue(const quint8 range, const Mode mode) const;
66
67 /// Attributes included in the `Settings` characteristic.
68 struct Settings {
69 Command command; ///< Custom operation request.
70 float triggerLevel; ///< Trigger threshold level in Volts or Amps, depending on #mode.
71 Mode mode; ///< Desired operation mode.
72 quint8 range; ///< Desired range, eg settings.range = +PokitPro::CurrentRange::AutoRange;
73 quint32 samplingWindow; ///< Desired sampling window in microseconds.
74 quint16 numberOfSamples; ///< Desired number of samples to acquire.
75 };
76
77 /// Values supported by the `Status` attribute of the `Metadata` characteristic.
78 enum class DsoStatus : quint8 {
79 Done = 0, ///< Sampling has completed.
80 Sampling = 1, ///< Actively sampling.
81 Error = 255 ///< An error has occurred.
82 };
83
84 /// Attributes included in the `Metadata` characteristic.
85 struct Metadata {
86 DsoStatus status; ///< Current DSO status.
87 float scale; ///< Scale to apply to read samples.
88 Mode mode; ///< Operation mode used during last acquisition.
89 quint8 range; ///< Range used during last acquisition.
90 quint32 samplingWindow; ///< Sampling window (microseconds) used during last acquisition.
91 quint16 numberOfSamples; ///< Number of samples acquired (1 to 8192).
92 quint32 samplingRate; ///< Sampling rate used during last acquisition (1 to 1MHz).
93 };
94
96
97 DsoService(QLowEnergyController * const pokitDevice, QObject * parent = nullptr);
98 ~DsoService() = default;
99
100 bool readCharacteristics() override;
102
103 // Settings characteristic (BLE write only).
104 bool setSettings(const Settings &settings);
105 bool startDso(const Settings &settings);
106 bool fetchSamples();
107
108 // Metadata characteristic (BLE read/notify).
109 Metadata metadata() const;
112
113 // Reading characteristic (BLE notify only).
116
120 void samplesRead(const DsoService::Samples &samples);
121
122protected:
123 /// \cond internal
124 DsoService(DsoServicePrivate * const d, QObject * const parent);
125 /// \endcond
126
127private:
128 Q_DECLARE_PRIVATE(DsoService)
130 QTPOKIT_BEFRIEND_TEST(DsoService)
131};
132
133QTPOKIT_END_NAMESPACE
134
135#endif // QTPOKIT_DSOSERVICE_H
Declares the AbstractPokitService class.
virtual bool readCharacteristics()=0
Read all characteristics.
void metadataRead(const DsoService::Metadata &meta)
This signal is emitted when the Metadata characteristic has been read successfully.
DsoService(QLowEnergyController *const pokitDevice, QObject *parent=nullptr)
Constructs a new Pokit service with parent.
Definition dsoservice.cpp:117
bool disableMetadataNotifications()
Disables client-side notifications of DSO metadata changes.
Definition dsoservice.cpp:260
QVector< qint16 > Samples
Raw samples from the Reading characteristic.
Definition dsoservice.h:95
static const QBluetoothUuid serviceUuid
UUID of the "DSO" service.
Definition dsoservice.h:29
bool startDso(const Settings &settings)
Start the DSO with settings.
Definition dsoservice.cpp:186
bool setSettings(const Settings &settings)
Configures the Pokit device's DSO mode.
Definition dsoservice.cpp:162
void settingsWritten()
This signal is emitted when the Settings characteristic has been written successfully.
bool fetchSamples()
Fetch DSO samples.
Definition dsoservice.cpp:207
bool enableMetadataNotifications()
Enables client-side notifications of DSO metadata changes.
Definition dsoservice.cpp:247
DsoStatus
Values supported by the Status attribute of the Metadata characteristic.
Definition dsoservice.h:78
bool enableReadingNotifications()
Enables client-side notifications of DSO readings.
Definition dsoservice.cpp:273
bool readMetadataCharacteristic()
Reads the DSO service's Metadata characteristic.
Definition dsoservice.cpp:149
Mode
Values supported by the Mode attribute of the Settings and Metadata characteristics.
Definition dsoservice.h:53
Command
Values supported by the Command attribute of the Settings characteristic.
Definition dsoservice.h:44
bool disableReadingNotifications()
Disables client-side notifications of DSO readings.
Definition dsoservice.cpp:284
void samplesRead(const DsoService::Samples &samples)
This signal is emitted when the Reading characteristic has been notified.
Metadata metadata() const
Returns the most recent value of the DSO service's Metadata characteristic.
Definition dsoservice.cpp:229
Declares the PokitProduct enumeration, and related helper functions.
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:35
QObject(QObject *parent)
Q_DISABLE_COPY(Class)
Q_OBJECTQ_OBJECT
Q_SIGNALSQ_SIGNALS
QObject * parent() const const
Characteristics available via the DSO service.
Definition dsoservice.h:32
static const QBluetoothUuid metadata
UUID of the DSO service's Metadata characteristic.
Definition dsoservice.h:37
static const QBluetoothUuid reading
UUID of the DSO service's Reading characteristic.
Definition dsoservice.h:40
static const QBluetoothUuid settings
UUID of the DSO service's Settings characteristic.
Definition dsoservice.h:34
Attributes included in the Metadata characteristic.
Definition dsoservice.h:85
quint32 samplingRate
Sampling rate used during last acquisition (1 to 1MHz).
Definition dsoservice.h:92
DsoStatus status
Current DSO status.
Definition dsoservice.h:86
float scale
Scale to apply to read samples.
Definition dsoservice.h:87
quint16 numberOfSamples
Number of samples acquired (1 to 8192).
Definition dsoservice.h:91
quint8 range
Range used during last acquisition.
Definition dsoservice.h:89
Mode mode
Operation mode used during last acquisition.
Definition dsoservice.h:88
quint32 samplingWindow
Sampling window (microseconds) used during last acquisition.
Definition dsoservice.h:90
Attributes included in the Settings characteristic.
Definition dsoservice.h:68
Mode mode
Desired operation mode.
Definition dsoservice.h:71
quint8 range
Desired range, eg settings.range = +PokitPro::CurrentRange::AutoRange;.
Definition dsoservice.h:72
Command command
Custom operation request.
Definition dsoservice.h:69
quint32 samplingWindow
Desired sampling window in microseconds.
Definition dsoservice.h:73
float triggerLevel
Trigger threshold level in Volts or Amps, depending on mode.
Definition dsoservice.h:70
quint16 numberOfSamples
Desired number of samples to acquire.
Definition dsoservice.h:74