Dokit
Internal development documentation
Loading...
Searching...
No Matches
abstractpokitservice_p.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 AbstractPokitServicePrivate class.
7 */
8
9#ifndef QTPOKIT_ABSTRACTPOKITSERVICE_P_H
10#define QTPOKIT_ABSTRACTPOKITSERVICE_P_H
11
14
15#include <QLoggingCategory>
16#include <QLowEnergyService>
17#include <QObject>
18
20
22
24
26{
28
29public:
30 static Q_LOGGING_CATEGORY(lc, "pokit.ble.service", QtInfoMsg); ///< Logging category.
31
32 bool autoDiscover { true }; ///< Whether autodiscovery is enabled or not.
33 QLowEnergyController * controller { nullptr }; ///< BLE controller to fetch the service from.
34 std::optional<PokitProduct> pokitProduct; ///< The Pokit product #controller is connected to.
35 QLowEnergyService * service { nullptr }; ///< BLE service to read/write characteristics.
36 QBluetoothUuid serviceUuid; ///< UUIDs for #service.
37
40
41 virtual ~AbstractPokitServicePrivate() = default;
42
45 bool readCharacteristic(const QBluetoothUuid &uuid);
46
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
54protected:
55 AbstractPokitService * q_ptr; ///< Internal q-pointer.
56
57protected Q_SLOTS:
58 void connected();
59 void discoveryFinished();
61 virtual void serviceDiscovered(const QBluetoothUuid &newService);
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
71private:
72 Q_DECLARE_PUBLIC(AbstractPokitService)
75};
76
78
79#endif // QTPOKIT_ABSTRACTPOKITSERVICE_P_H
bool autoDiscover
Whether autodiscovery is enabled or not.
bool disableCharacteristicNotificatons(const QBluetoothUuid &uuid)
Disables client (Pokit device) side notification for characteristic uuid.
bool createServiceObject()
Creates an internal service object from the internal controller.
void discoveryFinished()
Handles QLowEnergyController::discoveryFinished events.
static Q_LOGGING_CATEGORY(lc, "pokit.ble.service", QtInfoMsg)
Logging category.
QBluetoothUuid serviceUuid
UUIDs for service.
virtual void characteristicChanged(const QLowEnergyCharacteristic &characteristic, const QByteArray &newValue)
Handles QLowEnergyService::characteristicChanged events.
virtual void serviceDiscovered(const QBluetoothUuid &newService)
Handles QLowEnergyController::serviceDiscovered events.
AbstractPokitService * q_ptr
Internal q-pointer.
AbstractPokitServicePrivate(const QBluetoothUuid &serviceUuid, QLowEnergyController *controller, AbstractPokitService *const q)
bool enableCharacteristicNotificatons(const QBluetoothUuid &uuid)
Enables client (Pokit device) side notification for characteristic uuid.
virtual void characteristicRead(const QLowEnergyCharacteristic &characteristic, const QByteArray &value)
Handles QLowEnergyService::characteristicRead events.
void connected()
Handles QLowEnergyController::connected events.
QLowEnergyCharacteristic getCharacteristic(const QBluetoothUuid &uuid) const
Get uuid characteristc from the underlying service.
virtual void characteristicWritten(const QLowEnergyCharacteristic &characteristic, const QByteArray &newValue)
Handles QLowEnergyService::characteristicWritten events.
void errorOccurred(const QLowEnergyService::ServiceError newError)
Handles QLowEnergyController::errorOccurred events.
void stateChanged(QLowEnergyService::ServiceState newState)
Handles QLowEnergyController::stateChanged events.
bool readCharacteristic(const QBluetoothUuid &uuid)
Read the uuid characteristic.
QLowEnergyService * service
BLE service to read/write characteristics.
QLowEnergyController * controller
BLE controller to fetch the service from.
static QString toHexString(const QByteArray &data, const int maxSize=20)
Returns up to maxSize bytes of data as a human readable hexadecimal string.
static bool checkSize(const QString &label, const QByteArray &data, const int minSize, const int maxSize=-1, const bool failOnMax=false)
Returns false if data is smaller than minSize, otherwise returns failOnMax if data is bigger than max...
std::optional< PokitProduct > pokitProduct
The Pokit product controller is connected to.
The AbstractPokitService class provides a common base for Pokit services classes.
Declares the PokitProduct enumeration, and related helper functions.
QObject(QObject *parent)
Q_DISABLE_COPY(Class)
Q_OBJECTQ_OBJECT
Q_SLOTSQ_SLOTS
Global QtPokit library macros.
#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).