Dokit 0.5.3-pre
Internal development documentation
Loading...
Searching...
No Matches
abstractpokitservice_p.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2022-2024 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
19#include <optional>
20
22
24
26
28{
29 Q_OBJECT
30
31public:
32 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
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
54protected:
55 AbstractPokitService * q_ptr; ///< Internal q-pointer.
56
57protected Q_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
71private:
72 Q_DECLARE_PUBLIC(AbstractPokitService)
74 friend class TestAbstractPokitService;
75};
76
78
79#endif // QTPOKIT_ABSTRACTPOKITSERVICE_P_H
The AbstractPokitServicePrivate class provides private implementation for AbstractPokitService.
static Q_LOGGING_CATEGORY(lc, "pokit.ble.service", QtInfoMsg)
Logging category.
QBluetoothUuid serviceUuid
UUIDs for service.
AbstractPokitService * q_ptr
Internal q-pointer.
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.
Q_DISABLE_COPY(Class)
Q_SLOTSQ_SLOTS
Global QtPokit library macros.
#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).