Dokit
Native Qt library for Pokit devices
Loading...
Searching...
No Matches
statusservice.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 StatusService class.
7 */
8
9#ifndef QTPOKIT_STATUSSERVICE_H
10#define QTPOKIT_STATUSSERVICE_H
11
13
14#include <QBluetoothAddress>
15#include <QBluetoothUuid>
16#include <QVersionNumber>
17
18QTPOKIT_BEGIN_NAMESPACE
19
20class StatusServicePrivate;
21
22class QTPOKIT_EXPORT StatusService : public AbstractPokitService
23{
24 Q_OBJECT
25
26public:
27 struct QTPOKIT_EXPORT ServiceUuids {
30 };
31
32 struct QTPOKIT_EXPORT CharacteristicUuids {
34 static const QBluetoothUuid status;
35 static const QBluetoothUuid name;
37 };
38
40 QVersionNumber firmwareVersion; ///< Device's major and minor firmware version.
41 quint16 maximumVoltage; ///< Device's maximum input voltage.
42 quint16 maximumCurrent; ///< Device's maximum input current.
43 quint16 maximumResistance; ///< Device's maximum input resistance.
44 quint16 maximumSamplingRate; ///< Device's maximum sampling rate.
45 quint16 samplingBufferSize; ///< Device's sampling buffer size.
46 quint16 capabilityMask; ///< Reserved.
47 QBluetoothAddress macAddress; ///< Device's MAC address.
48 };
49
50 enum class DeviceStatus : quint8 {
51 Idle = 0, ///< Device is idle.
52 MultimeterDcVoltage = 1, ///< Multimeter is measuring DC voltage.
53 MultimeterAcVoltage = 2, ///< Multimeter is measuring AC voltage.
54 MultimeterDcCurrent = 3, ///< Multimeter is measuring DC current.
55 MultimeterAcCurrent = 4, ///< Multimeter is measuring AC current.
56 MultimeterResistance = 5, ///< Multimeter is measuring resistance.
57 MultimeterDiode = 6, ///< Multimeter is measuring diode.
58 MultimeterContinuity = 7, ///< Multimeter is measuring continuity.
59 MultimeterTemperature = 8,///< Multimeter is measuring temperature.
60 DsoModeSampling = 9, ///< DSO is sampling.
61 LoggerModeSampling = 10, ///< Data Logger is sampling.
62 };
63 static QString toString(const StatusService::DeviceStatus &status);
64
65 enum class BatteryStatus : quint8 {
66 Low = 0, ///< Low (replace battery).
67 Good = 1, ///< Good.
68 };
69 static QString toString(const StatusService::BatteryStatus &label);
70
71 struct Status {
72 DeviceStatus deviceStatus; ///< Current Pokit device status.
73 float batteryVoltage; ///< Current battery voltage level.
74 BatteryStatus batteryStatus; ///< Logical interpretation the battery voltage level.
75
76 };
77
78 StatusService(QLowEnergyController * const pokitDevice, QObject * parent = nullptr);
79 ~StatusService() override;
80
81 bool readCharacteristics() override;
82 bool readDeviceCharacteristics();
83 bool readStatusCharacteristic();
84 bool readNameCharacteristic();
85
86 // Device Characteristics characteristic (BLE read only).
87 DeviceCharacteristics deviceCharacteristics() const;
88
89 // Status characteristic (Read only).
90 Status status() const;
91
92 // Device Name characteristic (BLE read/write).
93 QString deviceName() const;
94 bool setDeviceName(const QString &name);
95
96 // Flash LED characteristic (BLE write only).
97 bool flashLed();
98
99signals:
101 void deviceNameRead(const QString &deviceName);
105
106protected:
107 /// \cond internal
108 StatusService(StatusServicePrivate * const d, QObject * const parent);
109 /// \endcond
110
111private:
112 Q_DECLARE_PRIVATE(StatusService)
114 friend class TestStatusService;
115};
116
117QTPOKIT_END_NAMESPACE
118
119#endif // QTPOKIT_STATUSSERVICE_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 StatusService class accesses the Pokit Status service of Pokit devices.
Definition: statusservice.h:23
BatteryStatus
Values supported by the Battery Status attribute of the Status characteristic.
Definition: statusservice.h:65
void deviceNameWritten()
This signal is emitted when the Device Name characteristic has been written successfully.
void deviceStatusRead(const StatusService::Status &status)
This signal is emitted when the Status characteristic has been read successfully.
DeviceStatus
Values supported by the Status attribute of the Status characteristic.
Definition: statusservice.h:50
void deviceLedFlashed()
This signal is emitted when device's LED has flashed in response to a write of the Flash LED characte...
void deviceCharacteristicsRead(const StatusService::DeviceCharacteristics &characteristics)
This signal is emitted when the Device Characteristics characteristic has been read successfully.
void deviceNameRead(const QString &deviceName)
This signal is emitted when the Device Name characteristic has been read successfully.
Q_DISABLE_COPY(Class)
Characteristics available via the Pokit Status service.
Definition: statusservice.h:32
static const QBluetoothUuid name
UUID of the Pokit Status service's Device Name characterstic.
Definition: statusservice.h:35
static const QBluetoothUuid deviceCharacteristics
UUID of the Pokit Status service's Device Characteristics characterstic.
Definition: statusservice.h:33
static const QBluetoothUuid flashLed
UUID of the Pokit Status service's Flash LED characterstic.
Definition: statusservice.h:36
static const QBluetoothUuid status
UUID of the Pokit Status service's Status characterstic.
Definition: statusservice.h:34
Attributes included in the Device Characteristics characterstic.
Definition: statusservice.h:39
quint16 maximumCurrent
Device's maximum input current.
Definition: statusservice.h:42
quint16 maximumSamplingRate
Device's maximum sampling rate.
Definition: statusservice.h:44
quint16 samplingBufferSize
Device's sampling buffer size.
Definition: statusservice.h:45
quint16 maximumVoltage
Device's maximum input voltage.
Definition: statusservice.h:41
quint16 capabilityMask
Reserved.
Definition: statusservice.h:46
QBluetoothAddress macAddress
Device's MAC address.
Definition: statusservice.h:47
quint16 maximumResistance
Device's maximum input resistance.
Definition: statusservice.h:43
QVersionNumber firmwareVersion
Device's major and minor firmware version.
Definition: statusservice.h:40
UUIDs of the "Pokit Status" service.
Definition: statusservice.h:27
static const QBluetoothUuid pokitPro
UUID of the Pokit Pro's Pokit Status service.
Definition: statusservice.h:29
static const QBluetoothUuid pokitMeter
UUID of the Pokit Meter's Pokit Status service.
Definition: statusservice.h:28
Attributes included in the Status characterstic.
Definition: statusservice.h:71
float batteryVoltage
Current battery voltage level.
Definition: statusservice.h:73
DeviceStatus deviceStatus
Current Pokit device status.
Definition: statusservice.h:72
BatteryStatus batteryStatus
Logical interpretation the battery voltage level.
Definition: statusservice.h:74