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 591 of file abstractpokitservice.cpp.

593{
594 qCDebug(lc).noquote() << tr(R"(Characteristic %1 "%2" changed to %Ln byte/s: %3)", nullptr, newValue.size())
595 .arg(characteristic.uuid().toString(), PokitDevice::charcteristicToString(characteristic.uuid()), toHexString(newValue));
596}
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 562 of file abstractpokitservice.cpp.

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

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 576 of file abstractpokitservice.cpp.

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

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 400 of file abstractpokitservice.cpp.

403{
404 if (data.size() < minSize) {
405 qCWarning(lc).noquote() << tr("%1 requires %n byte/s, but only %2 present: %3", nullptr, minSize)
406 .arg(label).arg(data.size()).arg(toHexString(data));
407 return false;
408 }
409 if ((maxSize >= 0) && (data.size() > maxSize)) {
410 qCWarning(lc).noquote() << tr("%1 has %n extraneous byte/s: %2", nullptr, data.size()-maxSize)
411 .arg(label, toHexString(data.mid(maxSize)));
412 return (!failOnMax);
413 }
414 return true;
415}
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 441 of file abstractpokitservice.cpp.

442{
443 if (!controller) {
444 qCWarning(lc).noquote() << tr("Connected with no controller set") << sender();
445 return;
446 }
447
448 qCDebug(lc).noquote() << tr(R"(Connected to "%1" (%2) at %3.)").arg(
451 if (autoDiscover) {
453 }
454}
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 365 of file abstractpokitservice.cpp.

366{
367 qCDebug(lc).noquote() << tr(R"(Disabling CCCD for characteristic %1 "%2".)")
369 QLowEnergyCharacteristic characteristic = getCharacteristic(uuid);
370 if (!characteristic.isValid()) {
371 return false;
372 }
373
374 QLowEnergyDescriptor descriptor = characteristic.descriptor(
375 QBluetoothUuid::DescriptorType::ClientCharacteristicConfiguration);
376 if (!descriptor.isValid()) {
377 qCWarning(lc).noquote() << tr(R"(Characteristic %1 "%2" has no client configuration descriptor.)")
379 return false;
380 }
381
382 service->writeDescriptor(descriptor,
383 #if (QT_VERSION >= QT_VERSION_CHECK(6, 2, 0))
384 QLowEnergyCharacteristic::CCCDDisable
385 #else
386 QByteArray::fromHex("0000") // See Qt6's QLowEnergyCharacteristic::CCCDDisable.
387 #endif
388 );
389 return true;
390}
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 462 of file abstractpokitservice.cpp.

463{
464 if (!controller) {
465 qCWarning(lc).noquote() << tr("Discovery finished with no controller set") << sender();
466 return;
467 }
468
469 qCDebug(lc).noquote() << tr(R"(Discovery finished for "%1" (%2) at %3.)").arg(
472
473 if (!createServiceObject()) {
474 qCWarning(lc).noquote() << tr("Discovery finished, but service not found.");
476 Q_EMIT q->serviceErrorOccurred(QLowEnergyService::ServiceError::UnknownError);
477 }
478}
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 330 of file abstractpokitservice.cpp.

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

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 485 of file abstractpokitservice.cpp.

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

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 const QLowEnergyCharacteristic characteristic = service->characteristic(uuid);
274 if (characteristic.isValid()) {
275 return characteristic;
276 }
277
279 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
280 ServiceDiscovered
281 #else
282 RemoteServiceDiscovered
283 #endif
284 ) {
285 qCWarning(lc).noquote() << tr(R"(Characteristic %1 "%2" requested before service %3 "%4" discovered.)")
288 qCInfo(lc).noquote() << tr("Current service state:") << service->state();
290 }
291
292 qCWarning(lc).noquote() << tr(R"(Characteristic %1 "%2" not found in service %3 "%4".)")
296}
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(), QLowEnergyCharacteristic::isValid(), 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 310 of file abstractpokitservice.cpp.

311{
312 const QLowEnergyCharacteristic characteristic = getCharacteristic(uuid);
313 if (!characteristic.isValid()) {
314 return false;
315 }
316 qCDebug(lc).noquote() << tr(R"(Reading characteristic %1 "%2".)")
318 service->readCharacteristic(characteristic);
319 return true;
320}
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 499 of file abstractpokitservice.cpp.

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

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 515 of file abstractpokitservice.cpp.

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

426{
427 return (data.size() <= maxSize)
428 ? QString::fromLatin1("0x%1").arg(QLatin1String(data.toHex(',')))
429 : QString::fromLatin1("0x%1,...,%2").arg(
430 QLatin1String(data.left(maxSize/2-1).toHex(',')),
431 QLatin1String(data.right(maxSize/2-1).toHex(',')));
432}
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 74 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 55 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: