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 AbstractPokitServicePrivate class. 7 : */ 8 : 9 : #ifndef QTPOKIT_ABSTRACTPOKITSERVICE_P_H 10 : #define QTPOKIT_ABSTRACTPOKITSERVICE_P_H 11 : 12 : #include <qtpokit/qtpokit_global.h> 13 : #include <qtpokit/pokitproducts.h> 14 : 15 : #include <QLoggingCategory> 16 : #include <QLowEnergyService> 17 : #include <QObject> 18 : 19 : #include <optional> 20 : 21 : class QLowEnergyController; 22 : 23 : QTPOKIT_BEGIN_NAMESPACE 24 : 25 : class AbstractPokitService; 26 : 27 : class QTPOKIT_EXPORT AbstractPokitServicePrivate : public QObject 28 : { 29 612 : Q_OBJECT 30 : 31 : public: 32 8619 : static Q_LOGGING_CATEGORY(lc, "pokit.ble.service", QtInfoMsg); ///< Logging category. 33 : 34 : bool autoDiscover { true }; ///< Whether autodiscovery is enabled or not. 35 : QLowEnergyController * controller { nullptr }; ///< BLE controller to fetch the service from. 36 : std::optional<PokitProduct> pokitProduct; ///< The Pokit product #controller is connected to. 37 : QLowEnergyService * service { nullptr }; ///< BLE service to read/write characteristics. 38 : QBluetoothUuid serviceUuid; ///< UUIDs for #service. 39 : 40 : AbstractPokitServicePrivate(const QBluetoothUuid &serviceUuid, 41 : QLowEnergyController * controller, AbstractPokitService * const q); 42 : 43 : bool createServiceObject(); 44 : QLowEnergyCharacteristic getCharacteristic(const QBluetoothUuid &uuid) const; 45 : bool readCharacteristic(const QBluetoothUuid &uuid); 46 : 47 : bool enableCharacteristicNotificatons(const QBluetoothUuid &uuid); 48 : bool disableCharacteristicNotificatons(const QBluetoothUuid &uuid); 49 : 50 : static bool checkSize(const QString &label, const QByteArray &data, const int minSize, 51 : const int maxSize=-1, const bool failOnMax=false); 52 : static QString toHexString(const QByteArray &data, const int maxSize=20); 53 : 54 : protected: 55 : AbstractPokitService * q_ptr; ///< Internal q-pointer. 56 : 57 : protected slots: 58 : void connected(); 59 : void discoveryFinished(); 60 : void errorOccurred(const QLowEnergyService::ServiceError newError); 61 : virtual void serviceDiscovered(const QBluetoothUuid &newService); 62 : void stateChanged(QLowEnergyService::ServiceState newState); 63 : 64 : virtual void characteristicRead(const QLowEnergyCharacteristic &characteristic, 65 : const QByteArray &value); 66 : virtual void characteristicWritten(const QLowEnergyCharacteristic &characteristic, 67 : const QByteArray &newValue); 68 : virtual void characteristicChanged(const QLowEnergyCharacteristic &characteristic, 69 : const QByteArray &newValue); 70 : 71 : private: 72 54 : Q_DECLARE_PUBLIC(AbstractPokitService) 73 : Q_DISABLE_COPY(AbstractPokitServicePrivate) 74 : friend class TestAbstractPokitService; 75 : }; 76 : 77 : QTPOKIT_END_NAMESPACE 78 : 79 : #endif // QTPOKIT_ABSTRACTPOKITSERVICE_P_H