QtPokit
Native Qt library for Pokit devices
Loading...
Searching...
No Matches
dsoservice.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2022 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
14#include <QBluetoothAddress>
15#include <QBluetoothUuid>
16#include <QVersionNumber>
17
18QTPOKIT_BEGIN_NAMESPACE
19
20class DsoServicePrivate;
21
22class QTPOKIT_EXPORT DsoService : public AbstractPokitService
23{
24 Q_OBJECT
25
26public:
28
29 struct QTPOKIT_EXPORT CharacteristicUuids {
32 static const QBluetoothUuid reading;
33 };
34
35 enum class Command : quint8 {
36 FreeRunning = 0,
37 RisingEdgeTrigger = 1,
38 FallingEdgeTrigger = 2,
39 ResendData = 3
40 };
41
42 enum class Mode : quint8 {
43 Idle = 0, ///< Make device idle.
44 DcVoltage = 1, ///< Measure DC voltage.
45 AcVoltage = 2, ///< Measure AC voltage.
46 DcCurrent = 3, ///< Measure DC current.
47 AcCurrent = 4, ///< Measure AC current.
48 };
49 static QString toString(const Mode &mode);
50
51 enum class VoltageRange : quint8 {
52 _0_to_300mV = 0, ///< 0 to 300mV.
53 _300mV_to_2V = 1, ///< 300mV to 2V.
54 _2V_to_6V = 2, ///< 2V to 6V.
55 _6V_to_12V = 3, ///< 6V to 12V.
56 _12V_to_30V = 4, ///< 12V to 30V.
57 _30V_to_60V = 5, ///< 30V to 60V.
58 /// \todo Pokit Pro supports up to 600V.
59 };
60 static QString toString(const VoltageRange &range);
61 static QVariant minValue(const VoltageRange &range);
62 static QVariant maxValue(const VoltageRange &range);
63
64 enum class CurrentRange : quint8 {
65 _0_to_10mA = 0, ///< 0 to 10mA.
66 _10mA_to_30mA = 1, ///< 10mA to 30mA.
67 _30mA_to_150mA = 2, ///< 30mA to 150mA.
68 _150mA_to_300mA = 3, ///< 150mA to 300mA.
69 _300mA_to_3A = 4, ///< 300mA to 3A.
70 /// \todo Pokit Pro supports up to 10A.
71 };
72 static QString toString(const CurrentRange &range);
73 static QVariant minValue(const CurrentRange &range);
74 static QVariant maxValue(const CurrentRange &range);
75
76 union QTPOKIT_EXPORT Range {
77 VoltageRange voltageRange; ///< Range when in AC/DC voltage mode.
78 CurrentRange currentRange; ///< Range when in AC/DC current mode.
79 Range();
80 Range(const VoltageRange range);
81 Range(const CurrentRange range);
82 };
83 static QString toString(const Range &range, const Mode &mode);
84
85 struct Settings {
86 Command command; ///< Custom operation request.
87 float triggerLevel; ///< Trigger threshold level in Volts or Amps, depending on #mode.
88 Mode mode; ///< Desired operation mode.
89 Range range; ///< Desired range.
90 quint32 samplingWindow; ///< Desired sampling window in microseconds.
91 quint16 numberOfSamples; ///< Desired number of samples to acquire.
92 };
93
94 enum class DsoStatus : quint8 {
95 Done = 0,
96 Sampling = 1,
97 Error = 255
98 };
99
100 struct Metadata {
101 DsoStatus status; ///< Current DSO status.
102 float scale; ///< Scale to apply to read samples.
103 Mode mode; ///< Operation mode used during last acquisition.
104 Range range; ///< Range used during last acquisition.
105 quint32 samplingWindow; ///< Sampling window (microseconds) used during last acquisition.
106 quint16 numberOfSamples; ///< Number of samples acquired (1 to 8192).
107 quint32 samplingRate; ///< Sampling rate used during last acquisition (1 to 1MHz).
108 };
109
111
112 DsoService(QLowEnergyController * const pokitDevice, QObject * parent = nullptr);
113 ~DsoService() override;
114
115 bool readCharacteristics() override;
116 bool readMetadataCharacteristic();
117
118 // Settings characteristic (BLE write only).
119 bool setSettings(const Settings &settings);
120 bool startDso(const Settings &settings);
121 bool fetchSamples();
122
123 // Metadata characteristic (BLE read/notify).
124 Metadata metadata() const;
125 bool enableMetadataNotifications();
126 bool disableMetadataNotifications();
127
128 // Reading characteristic (BLE notify only).
129 bool enableReadingNotifications();
130 bool disableReadingNotifications();
131
132signals:
135 void samplesRead(const DsoService::Samples &samples);
136
137protected:
138 /// \cond internal
139 DsoService(DsoServicePrivate * const d, QObject * const parent);
140 /// \endcond
141
142private:
143 Q_DECLARE_PRIVATE(DsoService)
144 Q_DISABLE_COPY(DsoService)
145 friend class TestDsoService;
146};
147
148QTPOKIT_EXPORT bool operator==(const DsoService::Range &lhs, const DsoService::Range &rhs);
149QTPOKIT_EXPORT bool operator!=(const DsoService::Range &lhs, const DsoService::Range &rhs);
150QTPOKIT_EXPORT bool operator< (const DsoService::Range &lhs, const DsoService::Range &rhs);
151QTPOKIT_EXPORT bool operator> (const DsoService::Range &lhs, const DsoService::Range &rhs);
152QTPOKIT_EXPORT bool operator<=(const DsoService::Range &lhs, const DsoService::Range &rhs);
153QTPOKIT_EXPORT bool operator>=(const DsoService::Range &lhs, const DsoService::Range &rhs);
154
155QTPOKIT_END_NAMESPACE
156
157#endif // QTPOKIT_DSOSERVICE_H
Declares the AbstractPokitService class.
The AbstractPokitService class provides a common base for Pokit services classes.
Definition: abstractpokitservice.h:24
virtual bool readCharacteristics()=0
Read all characteristics.
The DsoService class accesses the Pokit Status service of Pokit devices.
Definition: dsoservice.h:23
static const QBluetoothUuid serviceUuid
UUID of the "DSO" service.
Definition: dsoservice.h:27
VoltageRange
Values supported by the Range attribute of the Settings and Metadata characteristics,...
Definition: dsoservice.h:51
QVector< qint16 > Samples
Raw samples from the Reading characteristic.
Definition: dsoservice.h:110
void metadataRead(const DsoService::Metadata &meta)
This signal is emitted when the Metadata characteristic has been read successfully.
void samplesRead(const DsoService::Samples &samples)
This signal is emitted when the Reading characteristic has been notified.
DsoStatus
Values supported by the Status attribute of the Metadata characteristic.
Definition: dsoservice.h:94
Mode
Values supported by the Mode attribute of the Settings and Metadata characteristics.
Definition: dsoservice.h:42
void settingsWritten()
This signal is emitted when the Settings characteristic has been written successfully.
Command
Values supported by the Command attribute of the Settings characteristic.
Definition: dsoservice.h:35
CurrentRange
Values supported by the Range attribute of the Settings and Metadata characteristics,...
Definition: dsoservice.h:64
QTPOKIT_EXPORT bool operator>=(const DsoService::Range &lhs, const DsoService::Range &rhs)
Returns true if lhs is numerically greater than or equal to rhs, false otherwise.
Definition: dsoservice.cpp:247
QTPOKIT_EXPORT bool operator<=(const DsoService::Range &lhs, const DsoService::Range &rhs)
Returns true if lhs is numerically less than or equal to rhs, false otherwise.
Definition: dsoservice.cpp:240
QTPOKIT_EXPORT bool operator<(const DsoService::Range &lhs, const DsoService::Range &rhs)
Returns true if lhs is numerically less than rhs, false otherwise.
Definition: dsoservice.cpp:226
QTPOKIT_EXPORT bool operator!=(const DsoService::Range &lhs, const DsoService::Range &rhs)
Returns true if lhs is numerically not-equal to rhs, false otherwise.
Definition: dsoservice.cpp:219
QTPOKIT_EXPORT bool operator>(const DsoService::Range &lhs, const DsoService::Range &rhs)
Returns true if lhs is numerically greater than rhs, false otherwise.
Definition: dsoservice.cpp:233
QTPOKIT_EXPORT bool operator==(const DsoService::Range &lhs, const DsoService::Range &rhs)
Returns true if lhs is numerically equal to rhs, false otherwise.
Definition: dsoservice.cpp:212
Characteristics available via the DSO service.
Definition: dsoservice.h:29
static const QBluetoothUuid metadata
UUID of the DSO service's Metadata characterstic.
Definition: dsoservice.h:31
static const QBluetoothUuid reading
UUID of the DSO service's Reading characterstic.
Definition: dsoservice.h:32
static const QBluetoothUuid settings
UUID of the DSO service's Settings characterstic.
Definition: dsoservice.h:30
Attributes included in the Metadata characterstic.
Definition: dsoservice.h:100
quint32 samplingRate
Sampling rate used during last acquisition (1 to 1MHz).
Definition: dsoservice.h:107
DsoStatus status
Current DSO status.
Definition: dsoservice.h:101
float scale
Scale to apply to read samples.
Definition: dsoservice.h:102
quint16 numberOfSamples
Number of samples acquired (1 to 8192).
Definition: dsoservice.h:106
Mode mode
Operation mode used during last acquisition.
Definition: dsoservice.h:103
quint32 samplingWindow
Sampling window (microseconds) used during last acquisition.
Definition: dsoservice.h:105
Range range
Range used during last acquisition.
Definition: dsoservice.h:104
Attributes included in the Settings characterstic.
Definition: dsoservice.h:85
Mode mode
Desired operation mode.
Definition: dsoservice.h:88
Range range
Desired range.
Definition: dsoservice.h:89
Command command
Custom operation request.
Definition: dsoservice.h:86
quint32 samplingWindow
Desired sampling window in microseconds.
Definition: dsoservice.h:90
float triggerLevel
Trigger threshold level in Volts or Amps, depending on mode.
Definition: dsoservice.h:87
quint16 numberOfSamples
Desired number of samples to acquire.
Definition: dsoservice.h:91
Values supported by the Range attribute of the Settings and Metadata characteristics.
Definition: dsoservice.h:76
VoltageRange voltageRange
Range when in AC/DC voltage mode.
Definition: dsoservice.h:77
CurrentRange currentRange
Range when in AC/DC current mode.
Definition: dsoservice.h:78