151 return (r1 && r2 && r3 && r4 && r5);
249 return (characteristic.
isValid())
337 if (!characteristic.
isValid()) {
342 if (value.
length() > 11) {
343 qCWarning(d->lc).noquote() <<
tr(R
"(Device name "%1" is too long (%2 > 11 bytes): 0x3)")
348 d->service->writeCharacteristic(characteristic, value);
349 return (d->service->error() != QLowEnergyService::ServiceError::CharacteristicWriteError);
372 if (!characteristic.
isValid()) {
381 d->service->writeCharacteristic(characteristic, value);
382 return (d->service->error() != QLowEnergyService::ServiceError::CharacteristicWriteError);
412 if (!characteristic.
isValid()) {
417 d->service->writeCharacteristic(characteristic, value);
418 return (d->service->error() != QLowEnergyService::ServiceError::CharacteristicWriteError);
582 Q_ASSERT(characteristics.firmwareVersion.isNull());
585 return characteristics;
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());
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;
609 Q_ASSERT(!characteristics.firmwareVersion.isNull());
610 return characteristics;
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,
642 status.batteryVoltage = qFromLittleEndian<float>(value.
mid(1,4).
constData());
643 if (value.
size() >= 6) {
646 if (value.
size() >= 7) {
649 if (value.
size() >= 8) {
652 qCDebug(lc).noquote() <<
tr(
"Device status: %1 (%2)")
654 qCDebug(lc).noquote() <<
tr(
"Battery voltage: %1 volts").
arg(status.batteryVoltage);
655 qCDebug(lc).noquote() <<
tr(
"Battery status: %1 (%2)")
657 if (status.switchPosition) {
658 qCDebug(lc).noquote() <<
tr(
"Switch position: %1 (%2)")
661 if (status.chargingStatus) {
662 qCDebug(lc).noquote() <<
tr(
"Charging status: %1 (%2)")
714 qCDebug(lc).noquote() <<
tr(
"Found Status Service for a Pokit Meter device.");
717 qCDebug(lc).noquote() <<
tr(
"Found Status Service for a Pokit Pro device.");
745 qCDebug(lc).noquote() <<
tr(R
"(Device name: "%1")").arg(deviceName);
746 Q_EMIT q->deviceNameRead(deviceName);
751 qCWarning(lc).noquote() <<
tr(
"Flash LED characteristic is write-only, but somehow read")
762 Q_EMIT q->torchStatusRead(status);
772 Q_EMIT q->buttonPressRead(value.
at(0), status);
776 qCWarning(lc).noquote() <<
tr(
"Unknown characteristic read for Status service")
791 qCWarning(lc).noquote() <<
tr(
"Device Characteristics is read-only, but somehow written")
797 qCWarning(lc).noquote() <<
tr(
"Status characteristic is read-only, but somehow written")
803 Q_EMIT q->deviceNameWritten();
808 Q_EMIT q->deviceLedFlashed();
813 Q_EMIT q->torchStatusWritten();
817 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.
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.