Dokit
Native Qt library for Pokit devices
Loading...
Searching...
No Matches
dsoservice.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2022-2023 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{
25 Q_OBJECT
26
27public:
29
30 struct QTPOKIT_EXPORT CharacteristicUuids {
33 static const QBluetoothUuid reading;
34 };
35
36 enum class Command : quint8 {
37 FreeRunning = 0, ///< Run free, without waiting for edge triggers.
38 RisingEdgeTrigger = 1, ///< Trigger on a rising edge.
39 FallingEdgeTrigger = 2, ///< Trigger on a falling edge.
40 ResendData = 3 ///< Resend the last acquired data.
41 };
42
43 enum class Mode : quint8 {
44 Idle = 0, ///< Make device idle.
45 DcVoltage = 1, ///< Measure DC voltage.
46 AcVoltage = 2, ///< Measure AC voltage.
47 DcCurrent = 3, ///< Measure DC current.
48 AcCurrent = 4, ///< Measure AC current.
49 };
50 static QString toString(const Mode &mode);
51
52 static QString toString(const PokitProduct product, const quint8 range, const Mode mode);
53 QString toString(const quint8 range, const Mode mode) const;
54 static QVariant maxValue(const PokitProduct product, const quint8 range, const Mode mode);
55 QVariant maxValue(const quint8 range, const Mode mode) const;
56
57 struct Settings {
58 Command command; ///< Custom operation request.
59 float triggerLevel; ///< Trigger threshold level in Volts or Amps, depending on #mode.
60 Mode mode; ///< Desired operation mode.
61 quint8 range; ///< Desired range, eg settings.range = +PokitPro::CurrentRange::AutoRange;
62 quint32 samplingWindow; ///< Desired sampling window in microseconds.
63 quint16 numberOfSamples; ///< Desired number of samples to acquire.
64 };
65
66 enum class DsoStatus : quint8 {
67 Done = 0, ///< Sampling has completed.
68 Sampling = 1, ///< Actively sampling.
69 Error = 255 ///< An error has occurred.
70 };
71
72 struct Metadata {
73 DsoStatus status; ///< Current DSO status.
74 float scale; ///< Scale to apply to read samples.
75 Mode mode; ///< Operation mode used during last acquisition.
76 quint8 range; ///< Range used during last acquisition.
77 quint32 samplingWindow; ///< Sampling window (microseconds) used during last acquisition.
78 quint16 numberOfSamples; ///< Number of samples acquired (1 to 8192).
79 quint32 samplingRate; ///< Sampling rate used during last acquisition (1 to 1MHz).
80 };
81
83
84 DsoService(QLowEnergyController * const pokitDevice, QObject * parent = nullptr);
85 ~DsoService() override;
86
87 bool readCharacteristics() override;
88 bool readMetadataCharacteristic();
89
90 // Settings characteristic (BLE write only).
91 bool setSettings(const Settings &settings);
92 bool startDso(const Settings &settings);
93 bool fetchSamples();
94
95 // Metadata characteristic (BLE read/notify).
96 Metadata metadata() const;
97 bool enableMetadataNotifications();
98 bool disableMetadataNotifications();
99
100 // Reading characteristic (BLE notify only).
101 bool enableReadingNotifications();
102 bool disableReadingNotifications();
103
104signals:
107 void samplesRead(const DsoService::Samples &samples);
108
109protected:
110 /// \cond internal
111 DsoService(DsoServicePrivate * const d, QObject * const parent);
112 /// \endcond
113
114private:
115 Q_DECLARE_PRIVATE(DsoService)
117 friend class TestDsoService;
118};
119
120QTPOKIT_END_NAMESPACE
121
122#endif // QTPOKIT_DSOSERVICE_H
Declares the AbstractPokitService class.
The AbstractPokitService class provides a common base for Pokit services classes.
Definition abstractpokitservice.h:25
virtual bool readCharacteristics()=0
Read all characteristics.
The DsoService class accesses the DSO (Digital Storage Oscilloscope) service of Pokit devices.
Definition dsoservice.h:24
static const QBluetoothUuid serviceUuid
UUID of the "DSO" service.
Definition dsoservice.h:28
QVector< qint16 > Samples
Raw samples from the Reading characteristic.
Definition dsoservice.h:82
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:66
Mode
Values supported by the Mode attribute of the Settings and Metadata characteristics.
Definition dsoservice.h:43
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:36
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:26
Q_DISABLE_COPY(Class)
Characteristics available via the DSO service.
Definition dsoservice.h:30
static const QBluetoothUuid metadata
UUID of the DSO service's Metadata characterstic.
Definition dsoservice.h:32
static const QBluetoothUuid reading
UUID of the DSO service's Reading characterstic.
Definition dsoservice.h:33
static const QBluetoothUuid settings
UUID of the DSO service's Settings characterstic.
Definition dsoservice.h:31
Attributes included in the Metadata characterstic.
Definition dsoservice.h:72
quint32 samplingRate
Sampling rate used during last acquisition (1 to 1MHz).
Definition dsoservice.h:79
DsoStatus status
Current DSO status.
Definition dsoservice.h:73
float scale
Scale to apply to read samples.
Definition dsoservice.h:74
quint16 numberOfSamples
Number of samples acquired (1 to 8192).
Definition dsoservice.h:78
quint8 range
Range used during last acquisition.
Definition dsoservice.h:76
Mode mode
Operation mode used during last acquisition.
Definition dsoservice.h:75
quint32 samplingWindow
Sampling window (microseconds) used during last acquisition.
Definition dsoservice.h:77
Attributes included in the Settings characterstic.
Definition dsoservice.h:57
Mode mode
Desired operation mode.
Definition dsoservice.h:60
quint8 range
Desired range, eg settings.range = +PokitPro::CurrentRange::AutoRange;.
Definition dsoservice.h:61
Command command
Custom operation request.
Definition dsoservice.h:58
quint32 samplingWindow
Desired sampling window in microseconds.
Definition dsoservice.h:62
float triggerLevel
Trigger threshold level in Volts or Amps, depending on mode.
Definition dsoservice.h:59
quint16 numberOfSamples
Desired number of samples to acquire.
Definition dsoservice.h:63