159 return (r1 && r2 && r3 && r4 && r5);
257 return (characteristic.
isValid())
345 if (!characteristic.
isValid()) {
350 if (value.
length() > 11) {
351 qCWarning(d->lc).noquote() <<
tr(R
"(Device name "%1" is too long (%2 > 11 bytes): 0x3)")
356 d->service->writeCharacteristic(characteristic, value);
357 return (d->service->error() != QLowEnergyService::ServiceError::CharacteristicWriteError);
380 if (!characteristic.
isValid()) {
389 d->service->writeCharacteristic(characteristic, value);
390 return (d->service->error() != QLowEnergyService::ServiceError::CharacteristicWriteError);
420 if (!characteristic.
isValid()) {
425 d->service->writeCharacteristic(characteristic, value);
426 return (d->service->error() != QLowEnergyService::ServiceError::CharacteristicWriteError);
590 Q_ASSERT(characteristics.firmwareVersion.isNull());
593 return characteristics;
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());
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;
617 Q_ASSERT(!characteristics.firmwareVersion.isNull());
618 return characteristics;
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,
650 status.batteryVoltage = qFromLittleEndian<float>(value.
mid(1,4).
constData());
651 if (value.
size() >= 6) {
654 if (value.
size() >= 7) {
657 if (value.
size() >= 8) {
660 qCDebug(lc).noquote() <<
tr(
"Device status: %1 (%2)")
662 qCDebug(lc).noquote() <<
tr(
"Battery voltage: %1 volts").
arg(status.batteryVoltage);
663 qCDebug(lc).noquote() <<
tr(
"Battery status: %1 (%2)")
665 if (status.switchPosition) {
666 qCDebug(lc).noquote() <<
tr(
"Switch position: %1 (%2)")
669 if (status.chargingStatus) {
670 qCDebug(lc).noquote() <<
tr(
"Charging status: %1 (%2)")
722 qCDebug(lc).noquote() <<
tr(
"Found Status Service for a Pokit Meter device.");
725 qCDebug(lc).noquote() <<
tr(
"Found Status Service for a Pokit Pro device.");
753 qCDebug(lc).noquote() <<
tr(R
"(Device name: "%1")").arg(deviceName);
754 Q_EMIT q->deviceNameRead(deviceName);
759 qCWarning(lc).noquote() <<
tr(
"Flash LED characteristic is write-only, but somehow read")
770 Q_EMIT q->torchStatusRead(status);
780 Q_EMIT q->buttonPressRead(value.
at(0), status);
784 qCWarning(lc).noquote() <<
tr(
"Unknown characteristic read for Status service")
799 qCWarning(lc).noquote() <<
tr(
"Device Characteristics is read-only, but somehow written")
805 qCWarning(lc).noquote() <<
tr(
"Status characteristic is read-only, but somehow written")
811 Q_EMIT q->deviceNameWritten();
816 Q_EMIT q->deviceLedFlashed();
821 Q_EMIT q->torchStatusWritten();
825 qCWarning(lc).noquote() <<
tr(
"Unknown characteristic written for Status service")
The AbstractPokitServicePrivate class provides private implementation for AbstractPokitService.
QBluetoothUuid serviceUuid
UUIDs for service.
virtual void serviceDiscovered(const QBluetoothUuid &newService)
Handles QLowEnergyController::serviceDiscovered 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.
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...
The AbstractPokitService class provides a common base for Pokit services classes.
QLowEnergyService * service()
Returns a non-const pointer to the internal service object, if any.
The StatusServicePrivate class provides private implementation for StatusService.
void characteristicRead(const QLowEnergyCharacteristic &characteristic, const QByteArray &value) override
Implements AbstractPokitServicePrivate::characteristicRead to parse value, then emit a specialised si...
StatusServicePrivate(QLowEnergyController *controller, StatusService *const q)
static StatusService::Status parseStatus(const QByteArray &value)
Parses the Status value into a Status struct.
void serviceDiscovered(const QBluetoothUuid &newService) override
Handles QLowEnergyController::serviceDiscovered events.
static StatusService::DeviceCharacteristics parseDeviceCharacteristics(const QByteArray &value)
Parses the Device Characteristics value into a DeviceCharacteristics struct.
void characteristicWritten(const QLowEnergyCharacteristic &characteristic, const QByteArray &newValue) override
Implements AbstractPokitServicePrivate::characteristicWritten to parse newValue, then emit a speciali...
static std::optional< StatusService::ButtonStatus > parseButtonPress(const QByteArray &value)
Parses the button press value, and returns the corresponding ButtonStatus.
static std::optional< StatusService::TorchStatus > parseTorchStatus(const QByteArray &value)
Parses the torch status value, and returns the corresponding TorchStatus.
The StatusService class accesses the Pokit Status service of Pokit devices.
DeviceCharacteristics deviceCharacteristics() const
Returns the most recent value of the Status service's Device Characteristics characteristic.
bool enableButtonPressedNotifications()
Enables client-side notifications of button presses.
bool readStatusCharacteristic()
Read the Status service's Status characteristic.
StatusService(QLowEnergyController *const pokitDevice, QObject *parent=nullptr)
Constructs a new Pokit service with parent.
QString deviceName() const
Returns the most recent value of the Status services's Device Name characteristic.
ButtonStatus
Values supported by the second byte of the attribute of the (undocumented) Button Press characteristi...
@ Pressed
Button was pressed.
@ Released
Button was released.
@ Held
Button was held down (for typically 1,500ms).
bool readNameCharacteristic()
Read the Status service's Name characteristic.
bool disableStatusNotifications()
Disables client-side notifications of device status changes.
BatteryStatus
Values supported by the Battery Status attribute of the Status characteristic.
@ Low
Low (replace battery).
bool readButtonPressCharacteristic()
Read the Status service's (undocumented) Button Press characteristic.
bool setTorchStatus(const TorchStatus status)
Set the Pokit device's torch to status.
bool flashLed()
Flash the Pokit device's LED.
DeviceStatus
Values supported by the Status attribute of the Status characteristic.
@ MultimeterContinuity
Multimeter is measuring continuity.
@ MultimeterAcCurrent
Multimeter is measuring AC current.
@ LoggerModeSampling
Data Logger is sampling.
@ MultimeterDcVoltage
Multimeter is measuring DC voltage.
@ DsoModeSampling
DSO is sampling.
@ MultimeterDcCurrent
Multimeter is measuring DC current.
@ MultimeterTemperature
Multimeter is measuring temperature.
@ MultimeterResistance
Multimeter is measuring resistance.
@ MultimeterDiode
Multimeter is measuring diode.
@ MultimeterAcVoltage
Multimeter is measuring AC voltage.
bool enableStatusNotifications()
Enables client-side notifications of device status changes.
~StatusService() override
Destroys this StatusService object.
std::optional< ButtonStatus > buttonPress() const
Returns the most recent value of the Status services's Button Press characteristic.
bool enableTorchStatusNotifications()
Enables client-side notifications of torch status changes.
SwitchPosition
Values supported by the (undocumented) Switch Position attribute of the Status characteristic.
@ HighCurrent
Device is switched to High Current position.
@ Voltage
Device is switched to Voltage position.
@ MultiMode
Device is switched to Resistance / Low Current / Capacitance / Diode position.
bool disableTorchStatusNotifications()
Disables client-side notifications of torch status changes.
static QString toString(const StatusService::DeviceStatus &status)
Returns a string version of the status enum label.
bool disableButtonPressedNotifications()
Disables client-side notifications of button presses.
TorchStatus
Values supported by the single byte of the attribute of the (undocumented) Torch characteristic.
std::optional< TorchStatus > torchStatus() const
Returns the most recent value of the Status services's Torch characteristic.
bool readCharacteristics() override
Read all characteristics.
bool setDeviceName(const QString &name)
Set's the Pokit device's name to name.
bool readDeviceCharacteristics()
Read the Status service's Device Characteristics characteristic.
Status status() const
Returns the most recent value of the Status service's Status characteristic.
ChargingStatus
Values supported by the (undocumented) Charging Statue attribute of the Status characteristic.
@ Discharging
Battery is dischargin.
@ Charged
Battery is fully charged.
@ Charging
Battery is being charged.
bool readTorchCharacteristic()
Read the Status service's (undocumented) Torch characteristic.
char at(int i) const const
const char * constData() const const
QByteArray mid(int pos, int len) const const
QByteArray toHex() const const
bool isValid() const const
QString name() const const
QBluetoothUuid uuid() const const
QByteArray value() const const
QLowEnergyCharacteristic characteristic(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 fromUtf8(const char *str, int size)
QByteArray toUtf8() const const
Declares the StatusService class.
Declares the StatusServicePrivate class.
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.
Attributes included in the Device Characteristics characterstic.
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.
Attributes included in the Status characterstic.
DeviceStatus deviceStatus
Current Pokit device status.