Dokit 0.5.2-pre
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 574 of file statusservice.cpp.

577{
578
579}
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 735 of file statusservice.cpp.

737{
739
740 Q_Q(StatusService);
742 Q_EMIT q->deviceCharacteristicsRead(parseDeviceCharacteristics(value));
743 return;
744 }
745
746 if (characteristic.uuid() == StatusService::CharacteristicUuids::status) {
747 Q_EMIT q->deviceStatusRead(parseStatus(value));
748 return;
749 }
750
751 if (characteristic.uuid() == StatusService::CharacteristicUuids::name) {
752 const QString deviceName = QString::fromUtf8(value);
753 qCDebug(lc).noquote() << tr(R"(Device name: "%1")").arg(deviceName);
754 Q_EMIT q->deviceNameRead(deviceName);
755 return;
756 }
757
758 if (characteristic.uuid() == StatusService::CharacteristicUuids::flashLed) {
759 qCWarning(lc).noquote() << tr("Flash LED characteristic is write-only, but somehow read")
760 << serviceUuid << characteristic.name() << characteristic.uuid();
761 return;
762 }
763
764 if (characteristic.uuid() == StatusService::CharacteristicUuids::torch) {
765 if (!checkSize(QLatin1String("Torch"), value, 1, 1)) {
766 return;
767 }
768 const StatusService::TorchStatus status = static_cast<StatusService::TorchStatus>(value.at(0));
769 qCDebug(lc).noquote() << tr("Torch status: %1 (%2)").arg((quint8)status).arg(StatusService::toString(status));
770 Q_EMIT q->torchStatusRead(status);
771 return;
772 }
773
775 if (!checkSize(QLatin1String("Torch"), value, 2, 2)) {
776 return;
777 }
778 const StatusService::ButtonStatus status = static_cast<StatusService::ButtonStatus>(value.at(1));
779 qCDebug(lc).noquote() << tr("Button status: %1 (%2)").arg((quint8)status).arg(StatusService::toString(status));
780 Q_EMIT q->buttonPressRead(value.at(0), status);
781 return;
782 }
783
784 qCWarning(lc).noquote() << tr("Unknown characteristic read for Status service")
785 << serviceUuid << characteristic.name() << characteristic.uuid();
786}
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(), StatusService::CharacteristicUuids::name, QLowEnergyCharacteristic::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 792 of file statusservice.cpp.

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

References AbstractPokitServicePrivate::characteristicWritten(), StatusService::CharacteristicUuids::deviceCharacteristics, StatusService::CharacteristicUuids::flashLed, StatusService::CharacteristicUuids::name, QLowEnergyCharacteristic::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 693 of file statusservice.cpp.

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

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 584 of file statusservice.cpp.

586{
588 QVersionNumber(), 0, 0, 0, 0, 0, 0, QBluetoothAddress()
589 };
590 Q_ASSERT(characteristics.firmwareVersion.isNull()); // How we indicate failure.
591
592 if (!checkSize(QLatin1String("Device Characterisitcs"), value, 20, 20)) {
593 return characteristics;
594 }
595
596 characteristics.firmwareVersion = QVersionNumber(
597 qFromLittleEndian<quint8 >(value.mid(0,1).constData()),
598 qFromLittleEndian<quint8 >(value.mid(1,1).constData()));
599 characteristics.maximumVoltage = qFromLittleEndian<quint16>(value.mid(2,2).constData());
600 characteristics.maximumCurrent = qFromLittleEndian<quint16>(value.mid(4,2).constData());
601 characteristics.maximumResistance = qFromLittleEndian<quint16>(value.mid(6,2).constData());
602 characteristics.maximumSamplingRate = qFromLittleEndian<quint16>(value.mid(8,2).constData());
603 characteristics.samplingBufferSize = qFromLittleEndian<quint16>(value.mid(10,2).constData());
604 characteristics.capabilityMask = qFromLittleEndian<quint16>(value.mid(12,2).constData());
605 characteristics.macAddress = QBluetoothAddress(qFromBigEndian<quint64>
606 ((QByteArray(2, '\0') + value.mid(14,6)).constData()));
607
608 qCDebug(lc).noquote() << tr("Firmware version: ") << characteristics.firmwareVersion;
609 qCDebug(lc).noquote() << tr("Maximum voltage: ") << characteristics.maximumVoltage;
610 qCDebug(lc).noquote() << tr("Maximum current: ") << characteristics.maximumCurrent;
611 qCDebug(lc).noquote() << tr("Maximum resistance: ") << characteristics.maximumResistance;
612 qCDebug(lc).noquote() << tr("Maximum sampling rate:") << characteristics.maximumSamplingRate;
613 qCDebug(lc).noquote() << tr("Sampling buffer size: ") << characteristics.samplingBufferSize;
614 qCDebug(lc).noquote() << tr("Capability mask: ") << characteristics.capabilityMask;
615 qCDebug(lc).noquote() << tr("MAC address: ") << characteristics.macAddress;
616
617 Q_ASSERT(!characteristics.firmwareVersion.isNull()); // How we indicate success.
618 return characteristics;
619}
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 626 of file statusservice.cpp.

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

680{
681 if (!checkSize(QLatin1String("Torch"), value, 1, 1)) {
682 return std::nullopt;
683 }
684
685 const StatusService::TorchStatus status = static_cast<StatusService::TorchStatus>(value.at(0));
686 qCDebug(lc).noquote() << tr("Torch status: %1 (%2)").arg((quint8)status).arg(StatusService::toString(status));
687 return status;
688}

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 719 of file statusservice.cpp.

720{
721 if (newService == StatusService::ServiceUuids::pokitMeter) {
722 qCDebug(lc).noquote() << tr("Found Status Service for a Pokit Meter device.");
724 } else if (newService == StatusService::ServiceUuids::pokitPro) {
725 qCDebug(lc).noquote() << tr("Found Status Service for a Pokit Pro device.");
727 }
729}
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: