Dokit
Internal development documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Pages
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 characteristic 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.
 

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

175{
176 if (controller) {
179
182
185
187 }
188}
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(), q_ptr, serviceDiscovered(), QLowEnergyController::serviceDiscovered(), and serviceUuid.

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

Here is the call graph for this function:
Here is the caller 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 specialised signal.

Reimplemented in DataLoggerServicePrivate, DsoServicePrivate, and MultimeterServicePrivate.

Definition at line 594 of file abstractpokitservice.cpp.

596{
597 qCDebug(lc).noquote() << tr(R"(Characteristic %1 "%2" changed to %Ln byte/s: %3)", nullptr, newValue.size())
598 .arg(characteristic.uuid().toString(), PokitDevice::charcteristicToString(characteristic.uuid()), toHexString(newValue));
599}
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 specialised signal.

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

Definition at line 565 of file abstractpokitservice.cpp.

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

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 specialised signal.

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

Definition at line 579 of file abstractpokitservice.cpp.

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

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

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

See also
AbstractPokitService::autoDiscover()

Definition at line 444 of file abstractpokitservice.cpp.

445{
446 if (!controller) {
447 qCWarning(lc).noquote() << tr("Connected with no controller set") << sender();
448 return;
449 }
450
451 qCDebug(lc).noquote() << tr(R"(Connected to "%1" (%2) at %3.)").arg(
452 controller->remoteName(), controller->remoteDeviceUuid().toString(),
453 controller->remoteAddress().toString());
454 if (autoDiscover) {
455 controller->discoverServices();
456 }
457}
bool autoDiscover
Whether autodiscovery is enabled or not.
QObject * sender() const const

References QString::arg(), autoDiscover, controller, QObject::sender(), 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 197 of file abstractpokitservice.cpp.

198{
199 if (!controller) {
200 return false;
201 }
202
203 if (service) {
204 qCDebug(lc).noquote() << tr("Already have service object:") << service;
205 return true;
206 }
207
208 if (serviceUuid.isNull()) {
209 qCDebug(lc).noquote() << tr("Service UUID not assigned yet.");
210 return false;
211 }
212
213 service = controller->createServiceObject(serviceUuid, this);
214 if (!service) {
215 return false;
216 }
217 qCDebug(lc).noquote() << tr("Service object created for %1 device:").arg(toString(*this->pokitProduct)) << service;
218
227
229 [](const QLowEnergyDescriptor &descriptor, const QByteArray &value){
230 qCDebug(lc).noquote() << tr(R"(Descriptor "%1" (%2) read.)")
231 .arg(descriptor.name(), descriptor.uuid().toString());
232 Q_UNUSED(value)
233 });
234
236 [](const QLowEnergyDescriptor &descriptor, const QByteArray &newValue){
237 qCDebug(lc).noquote() << tr(R"(Descriptor "%1" (%2) written.)")
238 .arg(descriptor.name(), descriptor.uuid().toString());
239 Q_UNUSED(newValue)
240 });
241
243 #if (QT_VERSION < QT_VERSION_CHECK(6, 2, 0))
244 QOverload<QLowEnergyService::ServiceError>::of(&QLowEnergyService::error),
245 #else
246 &QLowEnergyService::errorOccurred,
247 #endif
249
250 if (autoDiscover) {
251 service->discoverDetails();
252 }
253 return true;
254}
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.
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)

References QString::arg(), autoDiscover, characteristicChanged(), QLowEnergyService::characteristicChanged(), characteristicRead(), QLowEnergyService::characteristicRead(), characteristicWritten(), QLowEnergyService::characteristicWritten(), QObject::connect(), controller, QLowEnergyService::descriptorRead(), QLowEnergyService::descriptorWritten(), QLowEnergyService::error(), errorOccurred(), 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 notification disable request was successfully queued, false otherwise.

See also
AbstractPokitServicePrivate::characteristicChanged
AbstractPokitServicePrivate::enableCharacteristicNotificatons

Definition at line 368 of file abstractpokitservice.cpp.

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

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

Here is the call graph for this function:

◆ discoveryFinished

void AbstractPokitServicePrivate::discoveryFinished ( )
protectedslot

Handles QLowEnergyController::discoveryFinished events.

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

Definition at line 465 of file abstractpokitservice.cpp.

466{
467 if (!controller) {
468 qCWarning(lc).noquote() << tr("Discovery finished with no controller set") << sender();
469 return;
470 }
471
472 qCDebug(lc).noquote() << tr(R"(Discovery finished for "%1" (%2) at %3.)").arg(
473 controller->remoteName(), controller->remoteDeviceUuid().toString(),
474 controller->remoteAddress().toString());
475
476 if (!createServiceObject()) {
477 qCWarning(lc).noquote() << tr("Discovery finished, but service not found.");
478 Q_Q(AbstractPokitService);
479 Q_EMIT q->serviceErrorOccurred(QLowEnergyService::ServiceError::UnknownError);
480 }
481}
Q_EMITQ_EMIT

References QString::arg(), controller, createServiceObject(), QObject::Q_EMIT(), QObject::sender(), 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 notification enable request was successfully queued, false otherwise.

See also
AbstractPokitServicePrivate::characteristicChanged
AbstractPokitServicePrivate::disableCharacteristicNotificatons

Definition at line 333 of file abstractpokitservice.cpp.

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

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

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

489{
490 Q_Q(AbstractPokitService);
491 qCDebug(lc).noquote() << tr("Service error") << newError;
492 Q_EMIT q->serviceErrorOccurred(newError);
493}

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 characteristic from the underlying service.

This helper function is equivalent to

return service->characteristic(uuid);

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

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

References QString::arg(), PokitDevice::charcteristicToString(), service, PokitDevice::serviceToString(), 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 successful, 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 313 of file abstractpokitservice.cpp.

314{
315 const QLowEnergyCharacteristic characteristic = getCharacteristic(uuid);
316 if (!characteristic.isValid()) {
317 return false;
318 }
319 qCDebug(lc).noquote() << tr(R"(Reading characteristic %1 "%2".)")
321 service->readCharacteristic(characteristic);
322 return true;
323}

References QString::arg(), PokitDevice::charcteristicToString(), getCharacteristic(), QLowEnergyCharacteristic::isValid(), 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 502 of file abstractpokitservice.cpp.

503{
504 if ((!service) && (newService == serviceUuid)) {
505 qCDebug(lc).noquote() << tr("Service discovered") << newService;
507 }
508}

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

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

References QString::arg(), 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 428 of file abstractpokitservice.cpp.

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

Member Data Documentation

◆ autoDiscover

bool AbstractPokitServicePrivate::autoDiscover { true }

Whether autodiscovery is enabled or not.

Definition at line 32 of file abstractpokitservice_p.h.

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

Referenced by connected(), and createServiceObject().

◆ controller

◆ pokitProduct

std::optional<PokitProduct> AbstractPokitServicePrivate::pokitProduct

The Pokit product controller is connected to.

Definition at line 34 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.

Referenced by AbstractPokitServicePrivate().

◆ service

QLowEnergyService* AbstractPokitServicePrivate::service { nullptr }

BLE service to read/write characteristics.

Definition at line 35 of file abstractpokitservice_p.h.

35{ 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: