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

The StatusServicePrivate class provides private implementation for StatusService. More...

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

Public Member Functions

 StatusServicePrivate (QLowEnergyController *controller, StatusService *const q)
 
- Public Member Functions inherited from AbstractPokitServicePrivate
 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 StatusService::DeviceCharacteristics parseDeviceCharacteristics (const QByteArray &value)
 Parses the Device Characteristics value into a DeviceCharacteristics struct.
 
static StatusService::Status parseStatus (const QByteArray &value)
 Parses the Status value into a Status struct.
 
static std::optional< StatusService::TorchStatusparseTorchStatus (const QByteArray &value)
 Parses the torch status value, and returns the corresponding TorchStatus.
 
static std::optional< StatusService::ButtonStatusparseButtonPress (const QByteArray &value)
 Parses the button press value, and returns the corresponding ButtonStatus.
 
- Static Public Member Functions inherited from AbstractPokitServicePrivate
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)
 

Protected Member Functions

void serviceDiscovered (const QBluetoothUuid &newService) override
 Handles QLowEnergyController::serviceDiscovered events.
 
void characteristicRead (const QLowEnergyCharacteristic &characteristic, const QByteArray &value) override
 Implements AbstractPokitServicePrivate::characteristicRead to parse value, then emit a specialised signal, for each supported characteristic.
 
void characteristicWritten (const QLowEnergyCharacteristic &characteristic, const QByteArray &newValue) override
 Implements AbstractPokitServicePrivate::characteristicWritten to parse newValue, then emit a specialised signal, for each supported characteristic.
 
- 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)
 

Friends

class TestStatusService
 

Additional Inherited Members

- Public Attributes inherited from AbstractPokitServicePrivate
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 inherited from AbstractPokitServicePrivate
void connected ()
 Handles QLowEnergyController::connected events.
 
void discoveryFinished ()
 Handles QLowEnergyController::discoveryFinished events.
 
void errorOccurred (const QLowEnergyService::ServiceError newError)
 Handles QLowEnergyController::errorOccurred events.
 
void stateChanged (QLowEnergyService::ServiceState newState)
 Handles QLowEnergyController::stateChanged events.
 
virtual void characteristicChanged (const QLowEnergyCharacteristic &characteristic, const QByteArray &newValue)
 Handles QLowEnergyService::characteristicChanged events.
 
- Protected Attributes inherited from AbstractPokitServicePrivate
AbstractPokitServiceq_ptr
 Internal q-pointer.
 
- Properties inherited from QObject
 objectName
 

Detailed Description

The StatusServicePrivate class provides private implementation for StatusService.

Definition at line 20 of file statusservice_p.h.

Constructor & Destructor Documentation

◆ StatusServicePrivate()

StatusServicePrivate::StatusServicePrivate ( QLowEnergyController * controller,
StatusService *const q )
explicit

Constructs a new StatusServicePrivate object with public implementation q.

Definition at line 566 of file statusservice.cpp.

569{
570
571}
AbstractPokitServicePrivate(const QBluetoothUuid &serviceUuid, QLowEnergyController *controller, AbstractPokitService *const q)
QLowEnergyController * controller
BLE controller to fetch the service from.

Member Function Documentation

◆ characteristicRead()

void StatusServicePrivate::characteristicRead ( const QLowEnergyCharacteristic & characteristic,
const QByteArray & value )
overrideprotectedvirtual

Implements AbstractPokitServicePrivate::characteristicRead to parse value, then emit a specialised signal, for each supported characteristic.

Reimplemented from AbstractPokitServicePrivate.

Definition at line 727 of file statusservice.cpp.

729{
731
732 Q_Q(StatusService);
734 Q_EMIT q->deviceCharacteristicsRead(parseDeviceCharacteristics(value));
735 return;
736 }
737
738 if (characteristic.uuid() == StatusService::CharacteristicUuids::status) {
739 Q_EMIT q->deviceStatusRead(parseStatus(value));
740 return;
741 }
742
743 if (characteristic.uuid() == StatusService::CharacteristicUuids::name) {
744 const QString deviceName = QString::fromUtf8(value);
745 qCDebug(lc).noquote() << tr(R"(Device name: "%1")").arg(deviceName);
746 Q_EMIT q->deviceNameRead(deviceName);
747 return;
748 }
749
750 if (characteristic.uuid() == StatusService::CharacteristicUuids::flashLed) {
751 qCWarning(lc).noquote() << tr("Flash LED characteristic is write-only, but somehow read")
752 << serviceUuid << characteristic.name() << characteristic.uuid();
753 return;
754 }
755
756 if (characteristic.uuid() == StatusService::CharacteristicUuids::torch) {
757 if (!checkSize(QLatin1String("Torch"), value, 1, 1)) {
758 return;
759 }
760 const StatusService::TorchStatus status = static_cast<StatusService::TorchStatus>(value.at(0));
761 qCDebug(lc).noquote() << tr("Torch status: %1 (%2)").arg((quint8)status).arg(StatusService::toString(status));
762 Q_EMIT q->torchStatusRead(status);
763 return;
764 }
765
767 if (!checkSize(QLatin1String("Torch"), value, 2, 2)) {
768 return;
769 }
770 const StatusService::ButtonStatus status = static_cast<StatusService::ButtonStatus>(value.at(1));
771 qCDebug(lc).noquote() << tr("Button status: %1 (%2)").arg((quint8)status).arg(StatusService::toString(status));
772 Q_EMIT q->buttonPressRead(value.at(0), status);
773 return;
774 }
775
776 qCWarning(lc).noquote() << tr("Unknown characteristic read for Status service")
777 << serviceUuid << characteristic.name() << characteristic.uuid();
778}
QBluetoothUuid serviceUuid
UUIDs for service.
virtual void characteristicRead(const QLowEnergyCharacteristic &characteristic, const QByteArray &value)
Handles QLowEnergyService::characteristicRead events.
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 max...
static StatusService::Status parseStatus(const QByteArray &value)
Parses the Status value into a Status struct.
static StatusService::DeviceCharacteristics parseDeviceCharacteristics(const QByteArray &value)
Parses the Device Characteristics value into a DeviceCharacteristics struct.
The StatusService class accesses the Pokit Status service of Pokit devices.
ButtonStatus
Values supported by the second byte of the attribute of the (undocumented) Button Press characteristi...
static QString toString(const StatusService::DeviceStatus &status)
Returns a string version of the status enum label.
TorchStatus
Values supported by the single byte of the attribute of the (undocumented) Torch characteristic.
char at(int i) const const
QString name() const const
QBluetoothUuid uuid() const const
Q_EMITQ_EMIT
QString tr(const char *sourceText, const char *disambiguation, int n)
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
QString fromUtf8(const char *str, int size)
static const QBluetoothUuid name
UUID of the Pokit Status service's Device Name characterstic.
static const QBluetoothUuid torch
UUID of the Pokit Status service's (undocumented) Torch characterstic.
static const QBluetoothUuid deviceCharacteristics
UUID of the Pokit Status service's Device Characteristics characterstic.
static const QBluetoothUuid buttonPress
UUID of the Pokit Status service's (undocumented) Button Press characterstic.
static const QBluetoothUuid flashLed
UUID of the Pokit Status service's Flash LED characterstic.
static const QBluetoothUuid status
UUID of the Pokit Status service's Status characterstic.

References QString::arg(), QByteArray::at(), StatusService::CharacteristicUuids::buttonPress, AbstractPokitServicePrivate::characteristicRead(), AbstractPokitServicePrivate::checkSize(), StatusService::CharacteristicUuids::deviceCharacteristics, StatusService::CharacteristicUuids::flashLed, QString::fromUtf8(), QLowEnergyCharacteristic::name(), StatusService::CharacteristicUuids::name, parseDeviceCharacteristics(), parseStatus(), QObject::Q_EMIT(), AbstractPokitServicePrivate::serviceUuid, StatusService::CharacteristicUuids::status, StatusService::CharacteristicUuids::torch, StatusService::toString(), QObject::tr(), and QLowEnergyCharacteristic::uuid().

Here is the call graph for this function:

◆ characteristicWritten()

void StatusServicePrivate::characteristicWritten ( const QLowEnergyCharacteristic & characteristic,
const QByteArray & newValue )
overrideprotectedvirtual

Implements AbstractPokitServicePrivate::characteristicWritten to parse newValue, then emit a specialised signal, for each supported characteristic.

Reimplemented from AbstractPokitServicePrivate.

Definition at line 784 of file statusservice.cpp.

786{
788
789 Q_Q(StatusService);
791 qCWarning(lc).noquote() << tr("Device Characteristics is read-only, but somehow written")
792 << serviceUuid << characteristic.name() << characteristic.uuid();
793 return;
794 }
795
796 if (characteristic.uuid() == StatusService::CharacteristicUuids::status) {
797 qCWarning(lc).noquote() << tr("Status characteristic is read-only, but somehow written")
798 << serviceUuid << characteristic.name() << characteristic.uuid();
799 return;
800 }
801
802 if (characteristic.uuid() == StatusService::CharacteristicUuids::name) {
803 Q_EMIT q->deviceNameWritten();
804 return;
805 }
806
807 if (characteristic.uuid() == StatusService::CharacteristicUuids::flashLed) {
808 Q_EMIT q->deviceLedFlashed();
809 return;
810 }
811
812 if (characteristic.uuid() == StatusService::CharacteristicUuids::torch) {
813 Q_EMIT q->torchStatusWritten();
814 return;
815 }
816
817 qCWarning(lc).noquote() << tr("Unknown characteristic written for Status service")
818 << serviceUuid << characteristic.name() << characteristic.uuid();
819}
virtual void characteristicWritten(const QLowEnergyCharacteristic &characteristic, const QByteArray &newValue)
Handles QLowEnergyService::characteristicWritten events.

References AbstractPokitServicePrivate::characteristicWritten(), StatusService::CharacteristicUuids::deviceCharacteristics, StatusService::CharacteristicUuids::flashLed, QLowEnergyCharacteristic::name(), StatusService::CharacteristicUuids::name, QObject::Q_EMIT(), AbstractPokitServicePrivate::serviceUuid, StatusService::CharacteristicUuids::status, StatusService::CharacteristicUuids::torch, QObject::tr(), and QLowEnergyCharacteristic::uuid().

Here is the call graph for this function:

◆ parseButtonPress()

std::optional< StatusService::ButtonStatus > StatusServicePrivate::parseButtonPress ( const QByteArray & value)
static

Parses the button press value, and returns the corresponding ButtonStatus.

Pokit Bluetooth API errata
The button event is the second byte, but no idea what the first byte is. In all examples I've see it's always 0x02. It appears that the Pokit Android app only ever looks at bytes[1].
Pokit Bluetooth API errata
Note, we can actually write to the Button Press characteristic too. If we do, then whatever we set as the first byte persists, and (unsurprisingly) the second byte reverts to the current button state. So still no idea what that first byte is for.

Definition at line 685 of file statusservice.cpp.

686{
687 if (!checkSize(QLatin1String("Torch"), value, 2, 2)) {
688 return std::nullopt;
689 }
690
691 /*!
692 * \pokitApi The button event is the second byte, but no idea what the first byte is. In all examples
693 * I've see it's always `0x02`. It appears that the Pokit Android app only ever looks at `bytes[1]`.
694 *
695 * \pokitApi Note, we can actually write to the Button Press characteristic too. If we do, then whatever
696 * we set as the first byte persists, and (unsurprisingly) the second byte reverts to the current
697 * button state. So still no idea what that first byte is for.
698 */
699
700 const StatusService::ButtonStatus status = static_cast<StatusService::ButtonStatus>(value.at(1));
701 qCDebug(lc).noquote() << tr("Button: %1 (%2)").arg((quint8)status).arg(StatusService::toString(status));
702 return status;
703}

References QString::arg(), QByteArray::at(), AbstractPokitServicePrivate::checkSize(), StatusService::toString(), and QObject::tr().

Referenced by StatusService::buttonPress().

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

◆ parseDeviceCharacteristics()

StatusService::DeviceCharacteristics StatusServicePrivate::parseDeviceCharacteristics ( const QByteArray & value)
static

Parses the Device Characteristics value into a DeviceCharacteristics struct.

Definition at line 576 of file statusservice.cpp.

578{
580 QVersionNumber(), 0, 0, 0, 0, 0, 0, QBluetoothAddress()
581 };
582 Q_ASSERT(characteristics.firmwareVersion.isNull()); // How we indicate failure.
583
584 if (!checkSize(QLatin1String("Device Characteristics"), value, 20, 20)) {
585 return characteristics;
586 }
587
588 characteristics.firmwareVersion = QVersionNumber(
589 qFromLittleEndian<quint8 >(value.mid(0,1).constData()),
590 qFromLittleEndian<quint8 >(value.mid(1,1).constData()));
591 characteristics.maximumVoltage = qFromLittleEndian<quint16>(value.mid(2,2).constData());
592 characteristics.maximumCurrent = qFromLittleEndian<quint16>(value.mid(4,2).constData());
593 characteristics.maximumResistance = qFromLittleEndian<quint16>(value.mid(6,2).constData());
594 characteristics.maximumSamplingRate = qFromLittleEndian<quint16>(value.mid(8,2).constData());
595 characteristics.samplingBufferSize = qFromLittleEndian<quint16>(value.mid(10,2).constData());
596 characteristics.capabilityMask = qFromLittleEndian<quint16>(value.mid(12,2).constData());
597 characteristics.macAddress = QBluetoothAddress(qFromBigEndian<quint64>
598 ((QByteArray(2, '\0') + value.mid(14,6)).constData()));
599
600 qCDebug(lc).noquote() << tr("Firmware version: ") << characteristics.firmwareVersion;
601 qCDebug(lc).noquote() << tr("Maximum voltage: ") << characteristics.maximumVoltage;
602 qCDebug(lc).noquote() << tr("Maximum current: ") << characteristics.maximumCurrent;
603 qCDebug(lc).noquote() << tr("Maximum resistance: ") << characteristics.maximumResistance;
604 qCDebug(lc).noquote() << tr("Maximum sampling rate:") << characteristics.maximumSamplingRate;
605 qCDebug(lc).noquote() << tr("Sampling buffer size: ") << characteristics.samplingBufferSize;
606 qCDebug(lc).noquote() << tr("Capability mask: ") << characteristics.capabilityMask;
607 qCDebug(lc).noquote() << tr("MAC address: ") << characteristics.macAddress;
608
609 Q_ASSERT(!characteristics.firmwareVersion.isNull()); // How we indicate success.
610 return characteristics;
611}
const char * constData() const const
QByteArray mid(int pos, int len) const const
Attributes included in the Device Characteristics characterstic.

References AbstractPokitServicePrivate::checkSize(), QByteArray::constData(), QByteArray::mid(), and QObject::tr().

Referenced by characteristicRead(), and StatusService::deviceCharacteristics().

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

◆ parseStatus()

StatusService::Status StatusServicePrivate::parseStatus ( const QByteArray & value)
static

Parses the Status value into a Status struct.

Note, not all Pokit devices support all members in Status. Specifically, the batteryStatus member is not usually set by Pokit Meter devices, so will be an invlalid BatteryStatus enum value (255) in that case.

Pokit Bluetooth API errata
Pokit API 0.02 says the Status characteristic is 5 bytes. API 1.00 then added an additional byte for Battery Status, for 6 bytes in total. However, Pokit Pro devices return 8 bytes here. It appears that the first of those 2 extra bytes (ie the 7th byte) is used to indicate the physical switch position, while the other extra byte (ie the 8th byte) indicates the device's current charging status.

Definition at line 618 of file statusservice.cpp.

619{
621 static_cast<StatusService::DeviceStatus>
622 (std::numeric_limits<std::underlying_type_t<StatusService::DeviceStatus>>::max()),
623 std::numeric_limits<float>::quiet_NaN(),
625 (std::numeric_limits<std::underlying_type_t<StatusService::BatteryStatus>>::max()),
626 std::nullopt, std::nullopt,
627 };
628
629 /*!
630 * \pokitApi Pokit API 0.02 says the `Status` characteristic is 5 bytes. API 1.00 then added an
631 * additional byte for `Battery Status`, for 6 bytes in total. However, Pokit Pro devices return
632 * 8 bytes here. It appears that the first of those 2 extra bytes (ie the 7th byte) is used to
633 * indicate the physical switch position, while the other extra byte (ie the 8th byte) indicates
634 * the device's current charging status.
635 */
636
637 if (!checkSize(QLatin1String("Status"), value, 5, 8)) {
638 return status;
639 }
640
641 status.deviceStatus = static_cast<StatusService::DeviceStatus>(value.at(0));
642 status.batteryVoltage = qFromLittleEndian<float>(value.mid(1,4).constData());
643 if (value.size() >= 6) { // Battery Status added to Pokit API docs v1.00.
644 status.batteryStatus = static_cast<StatusService::BatteryStatus>(value.at(5));
645 }
646 if (value.size() >= 7) { // Switch Position - as yet, undocumented by Pokit Innovations.
647 status.switchPosition = static_cast<StatusService::SwitchPosition>(value.at(6));
648 }
649 if (value.size() >= 8) { // Charging Status - as yet, undocumented by Pokit Innovations.
650 status.chargingStatus = static_cast<StatusService::ChargingStatus>(value.at(7));
651 }
652 qCDebug(lc).noquote() << tr("Device status: %1 (%2)")
653 .arg((quint8)status.deviceStatus).arg(StatusService::toString(status.deviceStatus));
654 qCDebug(lc).noquote() << tr("Battery voltage: %1 volts").arg(status.batteryVoltage);
655 qCDebug(lc).noquote() << tr("Battery status: %1 (%2)")
656 .arg((quint8)status.batteryStatus).arg(StatusService::toString(status.batteryStatus));
657 if (status.switchPosition) {
658 qCDebug(lc).noquote() << tr("Switch position: %1 (%2)")
659 .arg((quint8)*status.switchPosition).arg(StatusService::toString(*status.switchPosition));
660 }
661 if (status.chargingStatus) {
662 qCDebug(lc).noquote() << tr("Charging status: %1 (%2)")
663 .arg((quint8)*status.chargingStatus).arg(StatusService::toString(*status.chargingStatus));
664 }
665 return status;
666}
BatteryStatus
Values supported by the Battery Status attribute of the Status characteristic.
DeviceStatus
Values supported by the Status attribute of the Status characteristic.
SwitchPosition
Values supported by the (undocumented) Switch Position attribute of the Status characteristic.
ChargingStatus
Values supported by the (undocumented) Charging Statue attribute of the Status characteristic.
int size() const const
Attributes included in the Status characterstic.
DeviceStatus deviceStatus
Current Pokit device status.

References QString::arg(), QByteArray::at(), AbstractPokitServicePrivate::checkSize(), QByteArray::constData(), StatusService::Status::deviceStatus, QByteArray::mid(), QByteArray::size(), StatusService::toString(), and QObject::tr().

Referenced by characteristicRead(), and StatusService::status().

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

◆ parseTorchStatus()

std::optional< StatusService::TorchStatus > StatusServicePrivate::parseTorchStatus ( const QByteArray & value)
static

Parses the torch status value, and returns the corresponding TorchStatus.

Definition at line 671 of file statusservice.cpp.

672{
673 if (!checkSize(QLatin1String("Torch"), value, 1, 1)) {
674 return std::nullopt;
675 }
676
677 const StatusService::TorchStatus status = static_cast<StatusService::TorchStatus>(value.at(0));
678 qCDebug(lc).noquote() << tr("Torch status: %1 (%2)").arg((quint8)status).arg(StatusService::toString(status));
679 return status;
680}

References QString::arg(), QByteArray::at(), AbstractPokitServicePrivate::checkSize(), StatusService::toString(), and QObject::tr().

Referenced by StatusService::torchStatus().

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

◆ serviceDiscovered()

void StatusServicePrivate::serviceDiscovered ( const QBluetoothUuid & newService)
overrideprotectedvirtual

Handles QLowEnergyController::serviceDiscovered events.

Here we override the base implementation to detect if we're looking at a Pokit Meter, or Pokit Pro device, as the two devices have very slightly different Status Service UUIDs.

Reimplemented from AbstractPokitServicePrivate.

Definition at line 711 of file statusservice.cpp.

712{
713 if (newService == StatusService::ServiceUuids::pokitMeter) {
714 qCDebug(lc).noquote() << tr("Found Status Service for a Pokit Meter device.");
716 } else if (newService == StatusService::ServiceUuids::pokitPro) {
717 qCDebug(lc).noquote() << tr("Found Status Service for a Pokit Pro device.");
719 }
721}
virtual void serviceDiscovered(const QBluetoothUuid &newService)
Handles QLowEnergyController::serviceDiscovered events.
static const QBluetoothUuid pokitPro
UUID of the Pokit Pro's Pokit Status service.
static const QBluetoothUuid pokitMeter
UUID of the Pokit Meter's Pokit Status service.

References StatusService::ServiceUuids::pokitMeter, StatusService::ServiceUuids::pokitPro, AbstractPokitServicePrivate::serviceDiscovered(), AbstractPokitServicePrivate::serviceUuid, and QObject::tr().

Here is the call graph for this function:

Friends And Related Symbol Documentation

◆ TestStatusService

friend class TestStatusService
friend

Definition at line 43 of file statusservice_p.h.


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