Line data Source code
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 : 12 : #include "abstractpokitservice.h" 13 : 14 : #include <QBluetoothAddress> 15 : #include <QBluetoothUuid> 16 : #include <QVersionNumber> 17 : 18 : QTPOKIT_BEGIN_NAMESPACE 19 : 20 : class StatusServicePrivate; 21 : 22 : class QTPOKIT_EXPORT StatusService : public AbstractPokitService 23 : { 24 18 : Q_OBJECT 25 : 26 : public: 27 : struct QTPOKIT_EXPORT ServiceUuids { 28 : static const QBluetoothUuid pokitMeter; 29 : static const QBluetoothUuid pokitPro; 30 : }; 31 : 32 : struct QTPOKIT_EXPORT CharacteristicUuids { 33 : static const QBluetoothUuid deviceCharacteristics; 34 : static const QBluetoothUuid status; 35 : static const QBluetoothUuid name; 36 : static const QBluetoothUuid flashLed; 37 : }; 38 : 39 1262 : struct DeviceCharacteristics { 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 : 99 : signals: 100 : void deviceCharacteristicsRead(const StatusService::DeviceCharacteristics &characteristics); 101 : void deviceNameRead(const QString &deviceName); 102 : void deviceNameWritten(); 103 : void deviceStatusRead(const StatusService::Status &status); 104 : void deviceLedFlashed(); 105 : 106 : protected: 107 : /// \cond internal 108 : StatusService(StatusServicePrivate * const d, QObject * const parent); 109 : /// \endcond 110 : 111 : private: 112 690 : Q_DECLARE_PRIVATE(StatusService) 113 : Q_DISABLE_COPY(StatusService) 114 : friend class TestStatusService; 115 : }; 116 : 117 : QTPOKIT_END_NAMESPACE 118 : 119 : #endif // QTPOKIT_STATUSSERVICE_H