Dokit
Internal development documentation
Loading...
Searching...
No Matches
dsoservice.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 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
20
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.
33 /// UUID of the `DSO` service's `Settings` characterstic.
34 static inline const QBluetoothUuid settings { QStringLiteral("a81af1b6-b8b3-4244-8859-3da368d2be39") };
35
36 /// UUID of the `DSO` service's `Metadata` characterstic.
37 static inline const QBluetoothUuid metadata { QStringLiteral("970f00ba-f46f-4825-96a8-153a5cd0cda9") };
38
39 /// UUID of the `DSO` service's `Reading` characterstic.
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
51 /// Values supported by the `Mode` attribute of the `Settings` and `Metadata` characteristics.
52 enum class Mode : quint8 {
53 Idle = 0, ///< Make device idle.
54 DcVoltage = 1, ///< Measure DC voltage.
55 AcVoltage = 2, ///< Measure AC voltage.
56 DcCurrent = 3, ///< Measure DC current.
57 AcCurrent = 4, ///< Measure AC current.
58 };
59 static QString toString(const Mode &mode);
60
61 static QString toString(const PokitProduct product, const quint8 range, const Mode mode);
62 QString toString(const quint8 range, const Mode mode) const;
63 static quint32 maxValue(const PokitProduct product, const quint8 range, const Mode mode);
64 quint32 maxValue(const quint8 range, const Mode mode) const;
65
66 /// Attributes included in the `Settings` characterstic.
67 struct Settings {
68 Command command; ///< Custom operation request.
69 float triggerLevel; ///< Trigger threshold level in Volts or Amps, depending on #mode.
70 Mode mode; ///< Desired operation mode.
71 quint8 range; ///< Desired range, eg settings.range = +PokitPro::CurrentRange::AutoRange;
72 quint32 samplingWindow; ///< Desired sampling window in microseconds.
73 quint16 numberOfSamples; ///< Desired number of samples to acquire.
74 };
75
76 /// Values supported by the `Status` attribute of the `Metadata` characteristic.
77 enum class DsoStatus : quint8 {
78 Done = 0, ///< Sampling has completed.
79 Sampling = 1, ///< Actively sampling.
80 Error = 255 ///< An error has occurred.
81 };
82
83 /// Attributes included in the `Metadata` characterstic.
84 struct Metadata {
85 DsoStatus status; ///< Current DSO status.
86 float scale; ///< Scale to apply to read samples.
87 Mode mode; ///< Operation mode used during last acquisition.
88 quint8 range; ///< Range used during last acquisition.
89 quint32 samplingWindow; ///< Sampling window (microseconds) used during last acquisition.
90 quint16 numberOfSamples; ///< Number of samples acquired (1 to 8192).
91 quint32 samplingRate; ///< Sampling rate used during last acquisition (1 to 1MHz).
92 };
93
95
96 DsoService(QLowEnergyController * const pokitDevice, QObject * parent = nullptr);
97 ~DsoService() = default;
98
99 bool readCharacteristics() override;
101
102 // Settings characteristic (BLE write only).
103 bool setSettings(const Settings &settings);
104 bool startDso(const Settings &settings);
105 bool fetchSamples();
106
107 // Metadata characteristic (BLE read/notify).
108 Metadata metadata() const;
111
112 // Reading characteristic (BLE notify only).
115
119 void samplesRead(const DsoService::Samples &samples);
120
121protected:
122 /// \cond internal
123 DsoService(DsoServicePrivate * const d, QObject * const parent);
124 /// \endcond
125
126private:
127 Q_DECLARE_PRIVATE(DsoService)
130};
131
133
134#endif // QTPOKIT_DSOSERVICE_H
Declares the AbstractPokitService class.
virtual bool readCharacteristics()=0
Read all characteristics.
The DsoServicePrivate class provides private implementation for DsoService.
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.
bool disableMetadataNotifications()
Disables client-side notifications of DSO metadata changes.
QVector< qint16 > Samples
Raw samples from the Reading characteristic.
Definition dsoservice.h:94
static const QBluetoothUuid serviceUuid
UUID of the "DSO" service.
Definition dsoservice.h:29
bool startDso(const Settings &settings)
Start the DSO with settings.
bool setSettings(const Settings &settings)
Configures the Pokit device's DSO mode.
void settingsWritten()
This signal is emitted when the Settings characteristic has been written successfully.
bool fetchSamples()
Fetch DSO samples.
bool enableMetadataNotifications()
Enables client-side notifications of DSO metadata changes.
DsoStatus
Values supported by the Status attribute of the Metadata characteristic.
Definition dsoservice.h:77
@ Sampling
Actively sampling.
Definition dsoservice.h:79
@ Error
An error has occurred.
Definition dsoservice.h:80
@ Done
Sampling has completed.
Definition dsoservice.h:78
bool enableReadingNotifications()
Enables client-side notifications of DSO readings.
bool readMetadataCharacteristic()
Reads the DSO service's Metadata characteristic.
Mode
Values supported by the Mode attribute of the Settings and Metadata characteristics.
Definition dsoservice.h:52
@ DcVoltage
Measure DC voltage.
Definition dsoservice.h:54
@ AcCurrent
Measure AC current.
Definition dsoservice.h:57
@ AcVoltage
Measure AC voltage.
Definition dsoservice.h:55
@ Idle
Make device idle.
Definition dsoservice.h:53
@ DcCurrent
Measure DC current.
Definition dsoservice.h:56
Command
Values supported by the Command attribute of the Settings characteristic.
Definition dsoservice.h:44
@ ResendData
Resend the last acquired data.
Definition dsoservice.h:48
@ FreeRunning
Run free, without waiting for edge triggers.
Definition dsoservice.h:45
@ RisingEdgeTrigger
Trigger on a rising edge.
Definition dsoservice.h:46
@ FallingEdgeTrigger
Trigger on a falling edge.
Definition dsoservice.h:47
bool disableReadingNotifications()
Disables client-side notifications of DSO readings.
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.
Declares the PokitProduct enumeration, and related helper functions.
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 DSO service.
Definition dsoservice.h:32
static const QBluetoothUuid metadata
UUID of the DSO service's Metadata characterstic.
Definition dsoservice.h:37
static const QBluetoothUuid reading
UUID of the DSO service's Reading characterstic.
Definition dsoservice.h:40
static const QBluetoothUuid settings
UUID of the DSO service's Settings characterstic.
Definition dsoservice.h:34
Attributes included in the Metadata characterstic.
Definition dsoservice.h:84
quint32 samplingRate
Sampling rate used during last acquisition (1 to 1MHz).
Definition dsoservice.h:91
DsoStatus status
Current DSO status.
Definition dsoservice.h:85
float scale
Scale to apply to read samples.
Definition dsoservice.h:86
quint16 numberOfSamples
Number of samples acquired (1 to 8192).
Definition dsoservice.h:90
quint8 range
Range used during last acquisition.
Definition dsoservice.h:88
Mode mode
Operation mode used during last acquisition.
Definition dsoservice.h:87
quint32 samplingWindow
Sampling window (microseconds) used during last acquisition.
Definition dsoservice.h:89
Attributes included in the Settings characterstic.
Definition dsoservice.h:67
Mode mode
Desired operation mode.
Definition dsoservice.h:70
quint8 range
Desired range, eg settings.range = +PokitPro::CurrentRange::AutoRange;.
Definition dsoservice.h:71
Command command
Custom operation request.
Definition dsoservice.h:68
quint32 samplingWindow
Desired sampling window in microseconds.
Definition dsoservice.h:72
float triggerLevel
Trigger threshold level in Volts or Amps, depending on mode.
Definition dsoservice.h:69
quint16 numberOfSamples
Desired number of samples to acquire.
Definition dsoservice.h:73