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

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

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

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

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

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

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

444{
445 if (!controller) {
446 qCWarning(lc).noquote() << tr("Connected with no controller set") << sender();
447 return;
448 }
449
450 qCDebug(lc).noquote() << tr(R"(Connected to "%1" (%2) at %3.)").arg(
451 controller->remoteName(), controller->remoteDeviceUuid().toString(),
452 controller->remoteAddress().toString());
453 if (autoDiscover) {
454 controller->discoverServices();
455 }
456}
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 367 of file abstractpokitservice.cpp.

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

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

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

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

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

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.

Returns

Definition at line 268 of file abstractpokitservice.cpp.

269{
270 if (!service) {
271 qCDebug(lc).noquote() << tr(R"(Characteristic %1 "%2" requested before service assigned.)")
273 return QLowEnergyCharacteristic();
274 }
275
276 if (const QLowEnergyCharacteristic characteristic = service->characteristic(uuid); characteristic.isValid()) {
277 return characteristic;
278 }
279
280 if (service->state() != QLowEnergyService::
281 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
282 ServiceDiscovered
283 #else
284 RemoteServiceDiscovered
285 #endif
286 ) {
287 qCWarning(lc).noquote() << tr(R"(Characteristic %1 "%2" requested before service %3 "%4" discovered.)")
289 service->serviceUuid().toString(), PokitDevice::serviceToString(service->serviceUuid()));
290 qCInfo(lc).noquote() << tr("Current service state:") << service->state();
291 return QLowEnergyCharacteristic();
292 }
293
294 qCWarning(lc).noquote() << tr(R"(Characteristic %1 "%2" not found in service %3 "%4".)")
296 service->serviceUuid().toString(), PokitDevice::serviceToString(service->serviceUuid()));
297 return QLowEnergyCharacteristic();
298}
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 312 of file abstractpokitservice.cpp.

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

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

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

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

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

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