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

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

793{
795
796 Q_Q(StatusService);
798 qCWarning(lc).noquote() << tr("Device Characteristics is read-only, but somehow written")
799 << serviceUuid << characteristic.name() << characteristic.uuid();
800 return;
801 }
802
803 if (characteristic.uuid() == StatusService::CharacteristicUuids::status) {
804 qCWarning(lc).noquote() << tr("Status characteristic is read-only, but somehow written")
805 << serviceUuid << characteristic.name() << characteristic.uuid();
806 return;
807 }
808
809 if (characteristic.uuid() == StatusService::CharacteristicUuids::name) {
810 Q_EMIT q->deviceNameWritten();
811 return;
812 }
813
814 if (characteristic.uuid() == StatusService::CharacteristicUuids::flashLed) {
815 Q_EMIT q->deviceLedFlashed();
816 return;
817 }
818
819 if (characteristic.uuid() == StatusService::CharacteristicUuids::torch) {
820 Q_EMIT q->torchStatusWritten();
821 return;
822 }
823
824 qCWarning(lc).noquote() << tr("Unknown characteristic written for Status service")
825 << serviceUuid << characteristic.name() << characteristic.uuid();
826}
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 692 of file statusservice.cpp.

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

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 is used to indicate the physical switch position, while the other extra 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 is used to indicate the physical
641 * switch position, while the other extra byte indicates the device's current charging status.
642 */
643
644 if (!checkSize(QLatin1String("Status"), value, 5, 8)) {
645 return status;
646 }
647
648 status.deviceStatus = static_cast<StatusService::DeviceStatus>(value.at(0));
649 status.batteryVoltage = qFromLittleEndian<float>(value.mid(1,4).constData());
650 if (value.size() >= 6) { // Battery Status added to Pokit API docs v1.00.
651 status.batteryStatus = static_cast<StatusService::BatteryStatus>(value.at(5));
652 }
653 if (value.size() >= 7) { // Switch Position - as yet, undocumented by Pokit Innovations.
654 status.switchPosition = static_cast<StatusService::SwitchPosition>(value.at(6));
655 }
656 if (value.size() >= 8) { // Charging Status - as yet, undocumented by Pokit Innovations.
657 status.chargingStatus = static_cast<StatusService::ChargingStatus>(value.at(7));
658 }
659 qCDebug(lc).noquote() << tr("Device status: %1 (%2)")
660 .arg((quint8)status.deviceStatus).arg(StatusService::toString(status.deviceStatus));
661 qCDebug(lc).noquote() << tr("Battery voltage: %1 volts").arg(status.batteryVoltage);
662 qCDebug(lc).noquote() << tr("Battery status: %1 (%2)")
663 .arg((quint8)status.batteryStatus).arg(StatusService::toString(status.batteryStatus));
664 if (status.switchPosition) {
665 qCDebug(lc).noquote() << tr("Switch position: %1 (%2)")
666 .arg((quint8)*status.switchPosition).arg(StatusService::toString(*status.switchPosition));
667 }
668 if (status.chargingStatus) {
669 qCDebug(lc).noquote() << tr("Charging status: %1 (%2)")
670 .arg((quint8)*status.chargingStatus).arg(StatusService::toString(*status.chargingStatus));
671 }
672 return status;
673}
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 678 of file statusservice.cpp.

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

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

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