Dokit
Internal development documentation
Loading...
Searching...
No Matches
dsoservice.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 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
24{
25 Q_OBJECT
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 QVariant maxValue(const PokitProduct product, const quint8 range, const Mode mode);
64 QVariant 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;
100 bool readMetadataCharacteristic();
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;
109 bool enableMetadataNotifications();
110 bool disableMetadataNotifications();
111
112 // Reading characteristic (BLE notify only).
113 bool enableReadingNotifications();
114 bool disableReadingNotifications();
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)
129 friend class TestDsoService;
130};
131
133
134#endif // QTPOKIT_DSOSERVICE_H
Declares the AbstractPokitService class.
The AbstractPokitService class provides a common base for Pokit services classes.
virtual bool readCharacteristics()=0
Read all characteristics.
The DsoServicePrivate class provides private implementation for DsoService.
The DsoService class accesses the DSO (Digital Storage Oscilloscope) service of Pokit devices.
Definition dsoservice.h:24
void metadataRead(const DsoService::Metadata &meta)
This signal is emitted when the Metadata characteristic has been read successfully.
QVector< qint16 > Samples
Raw samples from the Reading characteristic.
Definition dsoservice.h:94
void settingsWritten()
This signal is emitted when the Settings characteristic has been written successfully.
DsoStatus
Values supported by the Status attribute of the Metadata characteristic.
Definition dsoservice.h:77
Mode
Values supported by the Mode attribute of the Settings and Metadata characteristics.
Definition dsoservice.h:52
Command
Values supported by the Command attribute of the Settings characteristic.
Definition dsoservice.h:44
void samplesRead(const DsoService::Samples &samples)
This signal is emitted when the Reading characteristic has been notified.
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.
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 DSO service.
Definition dsoservice.h:32
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