Dokit
Internal development documentation
Loading...
Searching...
No Matches
AbstractPokitServicePrivate Class Reference

The AbstractPokitServicePrivate class provides private implementation for AbstractPokitService. More...

Inheritance diagram for AbstractPokitServicePrivate:
[legend]
Collaboration diagram for AbstractPokitServicePrivate:
[legend]

Public Member Functions

 AbstractPokitServicePrivate (const QBluetoothUuid &serviceUuid, QLowEnergyController *controller, AbstractPokitService *const q)
 
bool createServiceObject ()
 Creates an internal service object from the internal controller.
 
QLowEnergyCharacteristic getCharacteristic (const QBluetoothUuid &uuid) const
 Get uuid characteristc from the underlying service.
 
bool readCharacteristic (const QBluetoothUuid &uuid)
 Read the uuid characteristic.
 
bool enableCharacteristicNotificatons (const QBluetoothUuid &uuid)
 Enables client (Pokit device) side notification for characteristic uuid.
 
bool disableCharacteristicNotificatons (const QBluetoothUuid &uuid)
 Disables client (Pokit device) side notification for characteristic uuid.
 
- Public Member Functions inherited from QObject
virtual const QMetaObjectmetaObject () const const
 
 QObject (QObject *parent)
 
virtual bool event (QEvent *e)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
QString objectName () const const
 
void setObjectName (const QString &name)
 
bool isWidgetType () const const
 
bool isWindowType () const const
 
bool signalsBlocked () const const
 
bool blockSignals (bool block)
 
QThreadthread () const const
 
void moveToThread (QThread *targetThread)
 
int startTimer (int interval, Qt::TimerType timerType)
 
int startTimer (std::chrono::milliseconds time, Qt::TimerType timerType)
 
void killTimer (int id)
 
findChild (const QString &name, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QString &name, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegExp &regExp, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const
 
const QObjectListchildren () const const
 
void setParent (QObject *parent)
 
void installEventFilter (QObject *filterObj)
 
void removeEventFilter (QObject *obj)
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const const
 
bool disconnect (const char *signal, const QObject *receiver, const char *method) const const
 
bool disconnect (const QObject *receiver, const char *method) const const
 
void dumpObjectTree ()
 
void dumpObjectInfo ()
 
void dumpObjectTree () const const
 
void dumpObjectInfo () const const
 
bool setProperty (const char *name, const QVariant &value)
 
QVariant property (const char *name) const const
 
QList< QByteArraydynamicPropertyNames () const const
 
void destroyed (QObject *obj)
 
void objectNameChanged (const QString &objectName)
 
QObjectparent () const const
 
bool inherits (const char *className) const const
 
void deleteLater ()
 
 Q_DISABLE_COPY (Class)
 
 Q_DISABLE_MOVE (Class)
 
 Q_DISABLE_COPY_MOVE (Class)
 
qobject_cast (QObject *object)
 
qobject_cast (const QObject *object)
 
qFindChild (const QObject *obj, const QString &name)
 
QList< T > qFindChildren (const QObject *obj, const QString &name)
 
QList< T > qFindChildren (const QObject *obj, const QRegExp &regExp)
 
 Q_CLASSINFO (Name, Value)
 
 Q_INTERFACES (...)
 
 Q_PROPERTY (...)
 
 Q_ENUMS (...)
 
 Q_FLAGS (...)
 
 Q_ENUM (...)
 
 Q_FLAG (...)
 
 Q_ENUM_NS (...)
 
 Q_FLAG_NS (...)
 
 Q_OBJECT Q_OBJECT
 
 Q_GADGET Q_GADGET
 
 Q_NAMESPACE Q_NAMESPACE
 
 Q_NAMESPACE_EXPORT (EXPORT_MACRO)
 
 Q_SIGNALS Q_SIGNALS
 
 Q_SIGNAL Q_SIGNAL
 
 Q_SLOTS Q_SLOTS
 
 Q_SLOT Q_SLOT
 
 Q_EMIT Q_EMIT
 
 Q_INVOKABLE Q_INVOKABLE
 
 Q_REVISION Q_REVISION
 
 Q_SET_OBJECT_NAME (Object)
 
 QT_NO_NARROWING_CONVERSIONS_IN_CONNECT QT_NO_NARROWING_CONVERSIONS_IN_CONNECT
 

Static Public Member Functions

static Q_LOGGING_CATEGORY (lc, "pokit.ble.service", QtInfoMsg)
 Logging category.
 
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 maxSize, otherwise returns true.
 
static QString toHexString (const QByteArray &data, const int maxSize=20)
 Returns up to maxSize bytes of data as a human readable hexadecimal string.
 
- Static Public Member Functions inherited from QObject
QString tr (const char *sourceText, const char *disambiguation, int n)
 
QString trUtf8 (const char *sourceText, const char *disambiguation, int n)
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, Functor functor)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type)
 
bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)
 
bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method)
 
bool disconnect (const QMetaObject::Connection &connection)
 
bool disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method)
 

Public Attributes

bool autoDiscover { true }
 Whether autodiscovery is enabled or not.
 
QLowEnergyControllercontroller { nullptr }
 BLE controller to fetch the service from.
 
std::optional< PokitProductpokitProduct
 The Pokit product controller is connected to.
 
QLowEnergyServiceservice { nullptr }
 BLE service to read/write characteristics.
 
QBluetoothUuid serviceUuid
 UUIDs for service.
 
- Public Attributes inherited from QObject
typedef QObjectList
 

Protected Slots

void connected ()
 Handles QLowEnergyController::connected events.
 
void discoveryFinished ()
 Handles QLowEnergyController::discoveryFinished events.
 
void errorOccurred (const QLowEnergyService::ServiceError newError)
 Handles QLowEnergyController::errorOccurred events.
 
virtual void serviceDiscovered (const QBluetoothUuid &newService)
 Handles QLowEnergyController::serviceDiscovered events.
 
void stateChanged (QLowEnergyService::ServiceState newState)
 Handles QLowEnergyController::stateChanged events.
 
virtual void characteristicRead (const QLowEnergyCharacteristic &characteristic, const QByteArray &value)
 Handles QLowEnergyService::characteristicRead events.
 
virtual void characteristicWritten (const QLowEnergyCharacteristic &characteristic, const QByteArray &newValue)
 Handles QLowEnergyService::characteristicWritten events.
 
virtual void characteristicChanged (const QLowEnergyCharacteristic &characteristic, const QByteArray &newValue)
 Handles QLowEnergyService::characteristicChanged events.
 

Protected Attributes

AbstractPokitServiceq_ptr
 Internal q-pointer.
 

Friends

class TestAbstractPokitService
 

Additional Inherited Members

- Protected Member Functions inherited from QObject
QObjectsender () const const
 
int senderSignalIndex () const const
 
int receivers (const char *signal) const const
 
bool isSignalConnected (const QMetaMethod &signal) const const
 
virtual void timerEvent (QTimerEvent *event)
 
virtual void childEvent (QChildEvent *event)
 
virtual void customEvent (QEvent *event)
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 
- Properties inherited from QObject
 objectName
 

Detailed Description

The AbstractPokitServicePrivate class provides private implementation for AbstractPokitService.

Definition at line 27 of file abstractpokitservice_p.h.

Constructor & Destructor Documentation

◆ AbstractPokitServicePrivate()

AbstractPokitServicePrivate::AbstractPokitServicePrivate ( const QBluetoothUuid & serviceUuid,
QLowEnergyController * controller,
AbstractPokitService *const q )

Constructs a new AbstractPokitServicePrivate object with public implementation q.

Note, typically the serviceUuid should be set validly, however, in the rare case that a service's UUID can vary (ie the Status Service), serviceUuid may be set to a null QBluetoothUuid here, and updated when the correct service UUID is known.

See also
StatusService::ServiceUuids
StatusServicePrivate::serviceDiscovered

Definition at line 168 of file abstractpokitservice.cpp.

171{
172 if (controller) {
175
178
181
183 }
184}
bool createServiceObject()
Creates an internal service object from the internal controller.
void discoveryFinished()
Handles QLowEnergyController::discoveryFinished events.
QBluetoothUuid serviceUuid
UUIDs for service.
virtual void serviceDiscovered(const QBluetoothUuid &newService)
Handles QLowEnergyController::serviceDiscovered events.
AbstractPokitService * q_ptr
Internal q-pointer.
void connected()
Handles QLowEnergyController::connected events.
QLowEnergyController * controller
BLE controller to fetch the service from.
void serviceDiscovered(const QBluetoothUuid &newService)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)

References QObject::connect(), connected(), QLowEnergyController::connected(), controller, createServiceObject(), discoveryFinished(), QLowEnergyController::discoveryFinished(), serviceDiscovered(), and QLowEnergyController::serviceDiscovered().

Here is the call graph for this function:

Member Function Documentation

◆ characteristicChanged

void AbstractPokitServicePrivate::characteristicChanged ( const QLowEnergyCharacteristic & characteristic,
const QByteArray & newValue )
protectedvirtualslot

Handles QLowEnergyService::characteristicChanged events.

This base implementation simply debug logs the event.

If derived classes support characteristics with client-side notification (ie Notify, as opposed to Read or Write operations), they should implement this function to handle the successful reads of characteristic, typically by parsing value, then emitting a speciailised signal.

Reimplemented in DataLoggerServicePrivate, DsoServicePrivate, and MultimeterServicePrivate.

Definition at line 590 of file abstractpokitservice.cpp.

592{
593 qCDebug(lc).noquote() << tr(R"(Characteristic %1 "%2" changed to %Ln byte/s: %3)", nullptr, newValue.size())
594 .arg(characteristic.uuid().toString(), PokitDevice::charcteristicToString(characteristic.uuid()), toHexString(newValue));
595}
static QString toHexString(const QByteArray &data, const int maxSize=20)
Returns up to maxSize bytes of data as a human readable hexadecimal string.
static QString charcteristicToString(const QBluetoothUuid &uuid)
Returns a human-readable name for the uuid characteristic, or a null QString if unknown.
int size() const const
QBluetoothUuid uuid() const const
QString tr(const char *sourceText, const char *disambiguation, int n)
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
QString toString() const const

References QString::arg(), PokitDevice::charcteristicToString(), QByteArray::size(), toHexString(), QUuid::toString(), QObject::tr(), and QLowEnergyCharacteristic::uuid().

Referenced by DataLoggerServicePrivate::characteristicChanged(), DsoServicePrivate::characteristicChanged(), MultimeterServicePrivate::characteristicChanged(), and createServiceObject().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ characteristicRead

void AbstractPokitServicePrivate::characteristicRead ( const QLowEnergyCharacteristic & characteristic,
const QByteArray & value )
protectedvirtualslot

Handles QLowEnergyService::characteristicRead events.

This base implementation simply debug logs the event.

Derived classes should implement this function to handle the successful reads of characteristic, typically by parsing value, then emitting a speciailised signal.

Reimplemented in DataLoggerServicePrivate, DeviceInfoServicePrivate, DsoServicePrivate, MultimeterServicePrivate, and StatusServicePrivate.

Definition at line 561 of file abstractpokitservice.cpp.

563{
564 qCDebug(lc).noquote() << tr(R"(Characteristic %1 "%2" read %n byte/s: %3)", nullptr, value.size()).arg(
565 characteristic.uuid().toString(), PokitDevice::charcteristicToString(characteristic.uuid()), toHexString(value));
566}

References QString::arg(), PokitDevice::charcteristicToString(), QByteArray::size(), toHexString(), QUuid::toString(), QObject::tr(), and QLowEnergyCharacteristic::uuid().

Referenced by DataLoggerServicePrivate::characteristicRead(), DeviceInfoServicePrivate::characteristicRead(), DsoServicePrivate::characteristicRead(), MultimeterServicePrivate::characteristicRead(), StatusServicePrivate::characteristicRead(), and createServiceObject().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ characteristicWritten

void AbstractPokitServicePrivate::characteristicWritten ( const QLowEnergyCharacteristic & characteristic,
const QByteArray & newValue )
protectedvirtualslot

Handles QLowEnergyService::characteristicWritten events.

This base implementation simply debug logs the event.

Derived classes should implement this function to handle the successful writes of characteristic, typically by parsing newValue, then emitting a speciailised signal.

Reimplemented in CalibrationServicePrivate, DataLoggerServicePrivate, DsoServicePrivate, MultimeterServicePrivate, and StatusServicePrivate.

Definition at line 575 of file abstractpokitservice.cpp.

577{
578 qCDebug(lc).noquote() << tr(R"(Characteristic %1 "%2" written with %Ln byte/s: %3)", nullptr, newValue.size())
579 .arg(characteristic.uuid().toString(), PokitDevice::charcteristicToString(characteristic.uuid()), toHexString(newValue));
580}

References QString::arg(), PokitDevice::charcteristicToString(), QByteArray::size(), toHexString(), QUuid::toString(), QObject::tr(), and QLowEnergyCharacteristic::uuid().

Referenced by CalibrationServicePrivate::characteristicWritten(), DataLoggerServicePrivate::characteristicWritten(), DsoServicePrivate::characteristicWritten(), MultimeterServicePrivate::characteristicWritten(), StatusServicePrivate::characteristicWritten(), and createServiceObject().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ checkSize()

bool AbstractPokitServicePrivate::checkSize ( const QString & label,
const QByteArray & data,
const int minSize,
const int maxSize = -1,
const bool failOnMax = false )
static

Returns false if data is smaller than minSize, otherwise returns failOnMax if data is bigger than maxSize, otherwise returns true.

A warning is logged if either minSize or maxSize is violated, regardless of the returned value; ie this funcion can be used to simply warn if data is too big, or it can be used to failed (return false) in that case.

Definition at line 399 of file abstractpokitservice.cpp.

402{
403 if (data.size() < minSize) {
404 qCWarning(lc).noquote() << tr("%1 requires %n byte/s, but only %2 present: %3", nullptr, minSize)
405 .arg(label).arg(data.size()).arg(toHexString(data));
406 return false;
407 }
408 if ((maxSize >= 0) && (data.size() > maxSize)) {
409 qCWarning(lc).noquote() << tr("%1 has %n extraneous byte/s: %2", nullptr, data.size()-maxSize)
410 .arg(label, toHexString(data.mid(maxSize)));
411 return (!failOnMax);
412 }
413 return true;
414}
QByteArray mid(int pos, int len) const const

References QString::arg(), QByteArray::mid(), QByteArray::size(), toHexString(), and QObject::tr().

Referenced by StatusServicePrivate::characteristicRead(), StatusServicePrivate::parseButtonPress(), StatusServicePrivate::parseDeviceCharacteristics(), DataLoggerServicePrivate::parseMetadata(), DsoServicePrivate::parseMetadata(), MultimeterServicePrivate::parseReading(), StatusServicePrivate::parseStatus(), and StatusServicePrivate::parseTorchStatus().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ connected

void AbstractPokitServicePrivate::connected ( )
protectedslot

Handles QLowEnergyController::connected events.

If autoDiscover is enabled, this will begin service discovery on the newly connected contoller.

See also
AbstractPokitService::autoDiscover()

Definition at line 440 of file abstractpokitservice.cpp.

441{
442 if (!controller) {
443 qCWarning(lc).noquote() << tr("Connected with no controller set") << sender();
444 return;
445 }
446
447 qCDebug(lc).noquote() << tr(R"(Connected to "%1" (%2) at %3.)").arg(
450 if (autoDiscover) {
452 }
453}
bool autoDiscover
Whether autodiscovery is enabled or not.
QString toString() const const
QBluetoothAddress remoteAddress() const const
QBluetoothUuid remoteDeviceUuid() const const
QString remoteName() const const
QObject * sender() const const

References QString::arg(), autoDiscover, controller, QLowEnergyController::discoverServices(), QLowEnergyController::remoteAddress(), QLowEnergyController::remoteDeviceUuid(), QLowEnergyController::remoteName(), QObject::sender(), QBluetoothAddress::toString(), QUuid::toString(), and QObject::tr().

Referenced by AbstractPokitServicePrivate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ createServiceObject()

bool AbstractPokitServicePrivate::createServiceObject ( )

Creates an internal service object from the internal controller.

Any existing service object will not be replaced.

Returns true if a service was created successfully, either now, or sometime previously.

Definition at line 193 of file abstractpokitservice.cpp.

194{
195 if (!controller) {
196 return false;
197 }
198
199 if (service) {
200 qCDebug(lc).noquote() << tr("Already have service object:") << service;
201 return true;
202 }
203
204 if (serviceUuid.isNull()) {
205 qCDebug(lc).noquote() << tr("Service UUID not assigned yet.");
206 return false;
207 }
208
210 if (!service) {
211 return false;
212 }
213 qCDebug(lc).noquote() << tr("Service object created for %1 device:").arg(toString(*this->pokitProduct)) << service;
214
223
225 [](const QLowEnergyDescriptor &descriptor, const QByteArray &value){
226 qCDebug(lc).noquote() << tr(R"(Descriptor "%1" (%2) read.)")
227 .arg(descriptor.name(), descriptor.uuid().toString());
228 Q_UNUSED(value)
229 });
230
232 [](const QLowEnergyDescriptor &descriptor, const QByteArray &newValue){
233 qCDebug(lc).noquote() << tr(R"(Descriptor "%1" (%2) written.)")
234 .arg(descriptor.name(), descriptor.uuid().toString());
235 Q_UNUSED(newValue)
236 });
237
239 #if (QT_VERSION < QT_VERSION_CHECK(6, 2, 0))
240 QOverload<QLowEnergyService::ServiceError>::of(&QLowEnergyService::error),
241 #else
242 &QLowEnergyService::errorOccurred,
243 #endif
245
246 if (autoDiscover) {
248 }
249 return true;
250}
virtual void characteristicChanged(const QLowEnergyCharacteristic &characteristic, const QByteArray &newValue)
Handles QLowEnergyService::characteristicChanged events.
virtual void characteristicRead(const QLowEnergyCharacteristic &characteristic, const QByteArray &value)
Handles QLowEnergyService::characteristicRead events.
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.
QLowEnergyService * service
BLE service to read/write characteristics.
std::optional< PokitProduct > pokitProduct
The Pokit product controller is connected to.
QTPOKIT_EXPORT QString toString(const PokitProduct product)
Returns product as user-friendly string.
QLowEnergyService * createServiceObject(const QBluetoothUuid &serviceUuid, QObject *parent)
QString name() const const
QBluetoothUuid uuid() const const
void characteristicChanged(const QLowEnergyCharacteristic &characteristic, const QByteArray &newValue)
void characteristicRead(const QLowEnergyCharacteristic &characteristic, const QByteArray &value)
void characteristicWritten(const QLowEnergyCharacteristic &characteristic, const QByteArray &newValue)
void descriptorRead(const QLowEnergyDescriptor &descriptor, const QByteArray &value)
void descriptorWritten(const QLowEnergyDescriptor &descriptor, const QByteArray &newValue)
QLowEnergyService::ServiceError error() const const
void stateChanged(QLowEnergyService::ServiceState newState)
bool isNull() const const

References QString::arg(), autoDiscover, characteristicChanged(), QLowEnergyService::characteristicChanged(), characteristicRead(), QLowEnergyService::characteristicRead(), characteristicWritten(), QLowEnergyService::characteristicWritten(), QObject::connect(), controller, QLowEnergyController::createServiceObject(), QLowEnergyService::descriptorRead(), QLowEnergyService::descriptorWritten(), QLowEnergyService::discoverDetails(), QLowEnergyService::error(), errorOccurred(), QUuid::isNull(), QLowEnergyDescriptor::name(), pokitProduct, service, serviceUuid, stateChanged(), QLowEnergyService::stateChanged(), QUuid::toString(), toString(), QObject::tr(), and QLowEnergyDescriptor::uuid().

Referenced by AbstractPokitServicePrivate(), discoveryFinished(), and serviceDiscovered().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ disableCharacteristicNotificatons()

bool AbstractPokitServicePrivate::disableCharacteristicNotificatons ( const QBluetoothUuid & uuid)

Disables client (Pokit device) side notification for characteristic uuid.

Returns true if the notication disable request was successfully queued, false otherwise.

See also
AbstractPokitServicePrivate::characteristicChanged
AbstractPokitServicePrivate::enableCharacteristicNotificatons

Definition at line 364 of file abstractpokitservice.cpp.

365{
366 qCDebug(lc).noquote() << tr(R"(Disabling CCCD for characteristic %1 "%2".)")
368 QLowEnergyCharacteristic characteristic = getCharacteristic(uuid);
369 if (!characteristic.isValid()) {
370 return false;
371 }
372
373 QLowEnergyDescriptor descriptor = characteristic.descriptor(
374 QBluetoothUuid::DescriptorType::ClientCharacteristicConfiguration); // 0x2902
375 if (!descriptor.isValid()) {
376 qCWarning(lc).noquote() << tr(R"(Characteristic %1 "%2" has no client configuration descriptor.)")
378 return false;
379 }
380
381 service->writeDescriptor(descriptor,
382 #if (QT_VERSION >= QT_VERSION_CHECK(6, 2, 0))
383 QLowEnergyCharacteristic::CCCDDisable
384 #else
385 QByteArray::fromHex("0000") // See Qt6's QLowEnergyCharacteristic::CCCDDisable.
386 #endif
387 );
388 return true;
389}
QLowEnergyCharacteristic getCharacteristic(const QBluetoothUuid &uuid) const
Get uuid characteristc from the underlying service.
QByteArray fromHex(const QByteArray &hexEncoded)
QLowEnergyDescriptor descriptor(const QBluetoothUuid &uuid) const const
bool isValid() const const
bool isValid() const const
void writeDescriptor(const QLowEnergyDescriptor &descriptor, const QByteArray &newValue)

References QString::arg(), PokitDevice::charcteristicToString(), QLowEnergyCharacteristic::descriptor(), QByteArray::fromHex(), getCharacteristic(), QLowEnergyCharacteristic::isValid(), QLowEnergyDescriptor::isValid(), service, QUuid::toString(), QObject::tr(), and QLowEnergyService::writeDescriptor().

Here is the call graph for this function:

◆ discoveryFinished

void AbstractPokitServicePrivate::discoveryFinished ( )
protectedslot

Handles QLowEnergyController::discoveryFinished events.

As this event indicates that the conroller has finished discovering services, this function will invoke createServiceObject() to create the internal service object (if not already created).

Definition at line 461 of file abstractpokitservice.cpp.

462{
463 if (!controller) {
464 qCWarning(lc).noquote() << tr("Discovery finished with no controller set") << sender();
465 return;
466 }
467
468 qCDebug(lc).noquote() << tr(R"(Discovery finished for "%1" (%2) at %3.)").arg(
471
472 if (!createServiceObject()) {
473 qCWarning(lc).noquote() << tr("Discovery finished, but service not found.");
475 Q_EMIT q->serviceErrorOccurred(QLowEnergyService::ServiceError::UnknownError);
476 }
477}
The AbstractPokitService class provides a common base for Pokit services classes.
Q_EMITQ_EMIT

References QString::arg(), controller, createServiceObject(), QObject::Q_EMIT(), QLowEnergyController::remoteAddress(), QLowEnergyController::remoteDeviceUuid(), QLowEnergyController::remoteName(), QObject::sender(), QBluetoothAddress::toString(), QUuid::toString(), and QObject::tr().

Referenced by AbstractPokitServicePrivate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ enableCharacteristicNotificatons()

bool AbstractPokitServicePrivate::enableCharacteristicNotificatons ( const QBluetoothUuid & uuid)

Enables client (Pokit device) side notification for characteristic uuid.

Returns true if the notication enable request was successfully queued, false otherwise.

See also
AbstractPokitServicePrivate::characteristicChanged
AbstractPokitServicePrivate::disableCharacteristicNotificatons

Definition at line 329 of file abstractpokitservice.cpp.

330{
331 qCDebug(lc).noquote() << tr(R"(Enabling CCCD for characteristic %1 "%2".)")
333 QLowEnergyCharacteristic characteristic = getCharacteristic(uuid);
334 if (!characteristic.isValid()) {
335 return false;
336 }
337
338 QLowEnergyDescriptor descriptor = characteristic.descriptor(
339 QBluetoothUuid::DescriptorType::ClientCharacteristicConfiguration); // 0x2902
340 if (!descriptor.isValid()) {
341 qCWarning(lc).noquote() << tr(R"(Characteristic %1 "%2" has no client configuration descriptor.)")
343 return false;
344 }
345
346 service->writeDescriptor(descriptor,
347 #if (QT_VERSION >= QT_VERSION_CHECK(6, 2, 0))
348 QLowEnergyCharacteristic::CCCDEnableNotification
349 #else
350 QByteArray::fromHex("0100") // See Qt6's QLowEnergyCharacteristic::CCCDEnableNotification.
351 #endif
352 );
353 return true;
354}

References QString::arg(), PokitDevice::charcteristicToString(), QLowEnergyCharacteristic::descriptor(), QByteArray::fromHex(), getCharacteristic(), QLowEnergyCharacteristic::isValid(), QLowEnergyDescriptor::isValid(), service, QUuid::toString(), QObject::tr(), and QLowEnergyService::writeDescriptor().

Here is the call graph for this function:

◆ errorOccurred

void AbstractPokitServicePrivate::errorOccurred ( const QLowEnergyService::ServiceError newError)
protectedslot

Handles QLowEnergyController::errorOccurred events.

This function simply re-emits newError as AbstractPokitService::serviceErrorOccurred.

Definition at line 484 of file abstractpokitservice.cpp.

485{
487 qCDebug(lc).noquote() << tr("Service error") << newError;
488 Q_EMIT q->serviceErrorOccurred(newError);
489}

References QObject::Q_EMIT(), and QObject::tr().

Referenced by createServiceObject().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getCharacteristic()

QLowEnergyCharacteristic AbstractPokitServicePrivate::getCharacteristic ( const QBluetoothUuid & uuid) const

Get uuid characteristc from the underlying service.

This helper function is equivalent to

return service->characteristic(uuid);
QLowEnergyCharacteristic characteristic(const QBluetoothUuid &uuid) const const

except that it performs some sanity checks, such as checking the service object pointer has been assigned first, and also logs failures in a consistent manner.

Parameters
uuid
Returns

Definition at line 265 of file abstractpokitservice.cpp.

266{
267 if (!service) {
268 qCDebug(lc).noquote() << tr(R"(Characteristic %1 "%2" requested before service assigned.)")
271 }
272
273 if (const QLowEnergyCharacteristic characteristic = service->characteristic(uuid); characteristic.isValid()) {
274 return characteristic;
275 }
276
278 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
279 ServiceDiscovered
280 #else
281 RemoteServiceDiscovered
282 #endif
283 ) {
284 qCWarning(lc).noquote() << tr(R"(Characteristic %1 "%2" requested before service %3 "%4" discovered.)")
287 qCInfo(lc).noquote() << tr("Current service state:") << service->state();
289 }
290
291 qCWarning(lc).noquote() << tr(R"(Characteristic %1 "%2" not found in service %3 "%4".)")
295}
static QString serviceToString(const QBluetoothUuid &uuid)
Returns a human-readable name for the uuid service, or a null QString if unknonw.
QBluetoothUuid serviceUuid() const const
QLowEnergyService::ServiceState state() const const

References QString::arg(), QLowEnergyService::characteristic(), PokitDevice::charcteristicToString(), service, PokitDevice::serviceToString(), QLowEnergyService::serviceUuid(), QLowEnergyService::state(), QUuid::toString(), and QObject::tr().

Referenced by disableCharacteristicNotificatons(), enableCharacteristicNotificatons(), and readCharacteristic().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ readCharacteristic()

bool AbstractPokitServicePrivate::readCharacteristic ( const QBluetoothUuid & uuid)

Read the uuid characteristic.

If succesful, the QLowEnergyService::characteristicRead signal will be emitted by the internal service object. For convenience, derived classes should implement the characteristicRead() virtual function to handle the read value.

Returns true if the characteristic read request was successfully queued, false otherwise.

See also
AbstractPokitService::readCharacteristics()
AbstractPokitServicePrivate::characteristicRead()

Definition at line 309 of file abstractpokitservice.cpp.

310{
311 const QLowEnergyCharacteristic characteristic = getCharacteristic(uuid);
312 if (!characteristic.isValid()) {
313 return false;
314 }
315 qCDebug(lc).noquote() << tr(R"(Reading characteristic %1 "%2".)")
317 service->readCharacteristic(characteristic);
318 return true;
319}
void readCharacteristic(const QLowEnergyCharacteristic &characteristic)

References QString::arg(), PokitDevice::charcteristicToString(), getCharacteristic(), QLowEnergyCharacteristic::isValid(), QLowEnergyService::readCharacteristic(), service, QUuid::toString(), and QObject::tr().

Here is the call graph for this function:

◆ serviceDiscovered

void AbstractPokitServicePrivate::serviceDiscovered ( const QBluetoothUuid & newService)
protectedvirtualslot

Handles QLowEnergyController::serviceDiscovered events.

If the discovered service is the one this (or rather the derived) class wraps, then createServiceObject() will be invoked immediately (otherwise it will be invoked after full service discovery has completed, ie in discoveryFinished()).

Reimplemented in StatusServicePrivate.

Definition at line 498 of file abstractpokitservice.cpp.

499{
500 if ((!service) && (newService == serviceUuid)) {
501 qCDebug(lc).noquote() << tr("Service discovered") << newService;
503 }
504}

References createServiceObject(), service, serviceUuid, and QObject::tr().

Referenced by AbstractPokitServicePrivate(), and StatusServicePrivate::serviceDiscovered().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stateChanged

void AbstractPokitServicePrivate::stateChanged ( QLowEnergyService::ServiceState newState)
protectedslot

Handles QLowEnergyController::stateChanged events.

If newState indicates that service details have now been discovered, then AbstractPokitService::serviceDetailsDiscovered will be emitted.

See also
AbstractPokitService::autoDiscover()

Definition at line 514 of file abstractpokitservice.cpp.

515{
516 qCDebug(lc).noquote() << tr("State changed to") << newState;
517
518 if (lc().isDebugEnabled()) {
519 for (const auto &characteristic: service->characteristics()) {
520 QStringList properties;
521 /// \cond no-doxygen
522 #define QTPOKIT_INTERNAL_TEST_AND_APPEND(property) \
523 if (characteristic.properties().testFlag(QLowEnergyCharacteristic::property)) { \
524 properties.append(QStringLiteral(#property).toLower());\
525 }
526 /// \endcond
527 QTPOKIT_INTERNAL_TEST_AND_APPEND(Broadcasting)
528 QTPOKIT_INTERNAL_TEST_AND_APPEND(Read)
529 QTPOKIT_INTERNAL_TEST_AND_APPEND(WriteNoResponse)
530 QTPOKIT_INTERNAL_TEST_AND_APPEND(Write)
531 QTPOKIT_INTERNAL_TEST_AND_APPEND(Notify)
532 QTPOKIT_INTERNAL_TEST_AND_APPEND(Indicate)
533 QTPOKIT_INTERNAL_TEST_AND_APPEND(WriteSigned)
534 QTPOKIT_INTERNAL_TEST_AND_APPEND(ExtendedProperty)
535 #undef QTPOKIT_INTERNAL_TEST_AND_APPEND
536 qCDebug(lc).noquote() << tr(R"(Characteristic %1 "%2" supports %3.)").arg(characteristic.uuid().toString(),
537 PokitDevice::charcteristicToString(characteristic.uuid()), properties.join(QStringLiteral(", ")));
538 }
539 }
540
541 if (newState == QLowEnergyService::
542 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
543 ServiceDiscovered
544 #else
545 RemoteServiceDiscovered
546 #endif
547 ) {
549 qCDebug(lc).noquote() << tr("Service details discovered.");
550 Q_EMIT q->serviceDetailsDiscovered();
551 }
552}
QString join(const QString &separator) const const

References QString::arg(), QLowEnergyService::characteristics(), PokitDevice::charcteristicToString(), QStringList::join(), QObject::Q_EMIT(), service, and QObject::tr().

Referenced by createServiceObject().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ toHexString()

QString AbstractPokitServicePrivate::toHexString ( const QByteArray & data,
const int maxSize = 20 )
static

Returns up to maxSize bytes of data as a human readable hexadecimal string.

If data exceeds maxSize, then data is elided in the middle. For example:

toHex(QBytArray("\x1\x2\x3\x4\x5\x6", 4); // "0x01,02,...,05,06"

Definition at line 424 of file abstractpokitservice.cpp.

425{
426 return (data.size() <= maxSize)
427 ? QString::fromLatin1("0x%1").arg(QLatin1String(data.toHex(',')))
428 : QString::fromLatin1("0x%1,...,%2").arg(
429 QLatin1String(data.left(maxSize/2-1).toHex(',')),
430 QLatin1String(data.right(maxSize/2-1).toHex(',')));
431}
QByteArray left(int len) const const
QByteArray right(int len) const const
QByteArray toHex() const const
QString fromLatin1(const char *str, int size)

References QString::arg(), QString::fromLatin1(), QByteArray::left(), QByteArray::right(), QByteArray::size(), and QByteArray::toHex().

Referenced by characteristicChanged(), characteristicRead(), characteristicWritten(), checkSize(), DataLoggerServicePrivate::parseMetadata(), DataLoggerServicePrivate::parseSamples(), and DsoServicePrivate::parseSamples().

Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ TestAbstractPokitService

friend class TestAbstractPokitService
friend

Definition at line 76 of file abstractpokitservice_p.h.

Member Data Documentation

◆ autoDiscover

bool AbstractPokitServicePrivate::autoDiscover { true }

Whether autodiscovery is enabled or not.

Definition at line 34 of file abstractpokitservice_p.h.

34{ true }; ///< Whether autodiscovery is enabled or not.

Referenced by connected(), and createServiceObject().

◆ controller

QLowEnergyController* AbstractPokitServicePrivate::controller { nullptr }

BLE controller to fetch the service from.

Definition at line 35 of file abstractpokitservice_p.h.

35{ nullptr }; ///< BLE controller to fetch the service from.

Referenced by AbstractPokitServicePrivate(), connected(), createServiceObject(), and discoveryFinished().

◆ pokitProduct

std::optional<PokitProduct> AbstractPokitServicePrivate::pokitProduct

The Pokit product controller is connected to.

Definition at line 36 of file abstractpokitservice_p.h.

Referenced by createServiceObject().

◆ q_ptr

AbstractPokitService* AbstractPokitServicePrivate::q_ptr
protected

Internal q-pointer.

Definition at line 57 of file abstractpokitservice_p.h.

◆ service

QLowEnergyService* AbstractPokitServicePrivate::service { nullptr }

BLE service to read/write characteristics.

Definition at line 37 of file abstractpokitservice_p.h.

37{ nullptr }; ///< BLE service to read/write characteristics.

Referenced by createServiceObject(), disableCharacteristicNotificatons(), enableCharacteristicNotificatons(), getCharacteristic(), readCharacteristic(), serviceDiscovered(), and stateChanged().

◆ serviceUuid


The documentation for this class was generated from the following files: