Dokit
Internal development documentation
Loading...
Searching...
No Matches
multimeterservice.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 MultimeterService class.
7 */
8
9#ifndef QTPOKIT_MULTIMETERSERVICE_H
10#define QTPOKIT_MULTIMETERSERVICE_H
11
13
14#include <QBluetoothAddress>
15#include <QBluetoothUuid>
16#include <QVersionNumber>
17
19
21
22class QTPOKIT_EXPORT MultimeterService : public AbstractPokitService
23{
25
26public:
27 /// UUID of the `Multimeter` service.
28 static inline const QBluetoothUuid serviceUuid { QStringLiteral("e7481d2f-5781-442e-bb9a-fd4e3441dadc") };
29
30 /// Characteristics available via the `Multimeter` service.
32 /// UUID of the `Multimeter` service's `Settings` characterstic.
33 static inline const QBluetoothUuid settings { QStringLiteral("53dc9a7a-bc19-4280-b76b-002d0e23b078") };
34
35 /// UUID of the `Multimeter` service's `Reading` characterstic.
36 static inline const QBluetoothUuid reading { QStringLiteral("047d3559-8bee-423a-b229-4417fa603b90") };
37 };
38
39 /// Values supported by the `Mode` attribute of the `Settings` and `Reading` characteristics.
40 enum class Mode : quint8 {
41 Idle = 0, ///< Make device idle.
42 DcVoltage = 1, ///< Measure DC voltage.
43 AcVoltage = 2, ///< Measure AC voltage.
44 DcCurrent = 3, ///< Measure DC current.
45 AcCurrent = 4, ///< Measure AC current.
46 Resistance = 5, ///< Measure resistance.
47 Diode = 6, ///< Measure diode.
48 Continuity = 7, ///< Measure continuity.
49 Temperature = 8, ///< Measure temperature.
50 Capacitance = 9, ///< Measure capacitance.
51 ExternalTemperature = 10, ///< Measure temperature via an external temperature probe.
52 };
53 static QString toString(const Mode &mode);
54
55 static QString toString(const PokitProduct product, const quint8 range, const Mode mode);
56 QString toString(const quint8 range, const Mode mode) const;
57 static quint32 maxValue(const PokitProduct product, const quint8 range, const Mode mode);
58 quint32 maxValue(const quint8 range, const Mode mode) const;
59
60 /// Attributes included in the `Settings` characterstic.
61 struct Settings {
62 Mode mode; ///< Desired operation mode.
63 quint8 range; ///< Desired range.
64 quint32 updateInterval; ///< Desired update interval in milliseconds.
65 };
66
67 /// Values supported by the `Status` attribute of the `Settings` characteristic.
68 enum class MeterStatus : quint8 {
69 AutoRangeOff = 0, ///< Auto-range is disabled (voltage, current and resistance modes only).
70 AutoRangeOn = 1, ///< Auto-range is enabled (voltage, current and resistance modes only).
71 NoContinuity = 0, ///< No continuity (continuity mode only).
72 Continuity = 1, ///< Continuity (continuity mode only).
73 Ok = 0, ///< Ok (temperature and diode modes only).
74 Error = 255 ///< Error (all modes).
75 };
76
77 /// Attributes included in the `Reading` characterstic.
78 struct Reading {
79 MeterStatus status; ///< Current multimeter status.
80 float value; ///< Last acquired value.
81 Mode mode; ///< Current operation mode.
82 quint8 range; ///< Current range.
83 };
84
85 MultimeterService(QLowEnergyController * const pokitDevice, QObject * parent = nullptr);
86 ~MultimeterService() = default;
87
88 bool readCharacteristics() override;
90
91 // Settings characteristic (BLE write only).
92 bool setSettings(const Settings &settings);
93
94 // Reading characteristic (BLE read/notify).
95 Reading reading() const;
98
102
103protected:
104 /// \cond internal
106 /// \endcond
107
108private:
109 Q_DECLARE_PRIVATE(MultimeterService)
112};
113
115
116#endif // QTPOKIT_MULTIMETERSERVICE_H
Declares the AbstractPokitService class.
virtual bool readCharacteristics()=0
Read all characteristics.
The MultimeterServicePrivate class provides private implementation for MultimeterService.
void settingsWritten()
This signal is emitted when the Settings characteristic has been written successfully.
bool enableReadingNotifications()
Enables client-side notifications of meter readings.
MeterStatus
Values supported by the Status attribute of the Settings characteristic.
@ AutoRangeOn
Auto-range is enabled (voltage, current and resistance modes only).
@ AutoRangeOff
Auto-range is disabled (voltage, current and resistance modes only).
@ NoContinuity
No continuity (continuity mode only).
@ Ok
Ok (temperature and diode modes only).
Mode
Values supported by the Mode attribute of the Settings and Reading characteristics.
@ DcVoltage
Measure DC voltage.
@ Capacitance
Measure capacitance.
@ AcCurrent
Measure AC current.
@ ExternalTemperature
Measure temperature via an external temperature probe.
@ Resistance
Measure resistance.
@ AcVoltage
Measure AC voltage.
@ Idle
Make device idle.
@ Temperature
Measure temperature.
@ DcCurrent
Measure DC current.
@ Continuity
Measure continuity.
static const QBluetoothUuid serviceUuid
UUID of the Multimeter service.
void readingRead(const MultimeterService::Reading &reading)
This signal is emitted when the Reading characteristic has been read successfully.
MultimeterService(QLowEnergyController *const pokitDevice, QObject *parent=nullptr)
Constructs a new Pokit service with parent.
bool readReadingCharacteristic()
Read the Multimeter service's Reading characteristic.
bool setSettings(const Settings &settings)
Configures the Pokit device's multimeter mode.
Reading reading() const
Returns the most recent value of the Multimeter service's Reading characteristic.
bool disableReadingNotifications()
Disables client-side notifications of meter readings.
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 Multimeter service.
static const QBluetoothUuid reading
UUID of the Multimeter service's Reading characterstic.
static const QBluetoothUuid settings
UUID of the Multimeter service's Settings characterstic.
Attributes included in the Reading characterstic.
MeterStatus status
Current multimeter status.
Mode mode
Current operation mode.
float value
Last acquired value.
quint8 range
Current range.
Attributes included in the Settings characterstic.
quint32 updateInterval
Desired update interval in milliseconds.
Mode mode
Desired operation mode.