11#include "pokitproducts_p.h"
136 : AbstractPokitService(d,
parent)
174 if (!characteristic.
isValid()) {
183 d->service->writeCharacteristic(characteristic, value);
184 return (d->service->error() != QLowEnergyService::ServiceError::CharacteristicWriteError);
277 static_assert(
sizeof(settings.
mode) == 1,
"Expected to be 1 byte.");
278 static_assert(
sizeof(settings.
range) == 1,
"Expected to be 1 byte.");
279 static_assert(
sizeof(settings.
updateInterval) == 4,
"Expected to be 4 bytes.");
287 Q_ASSERT(value.
size() == 6);
298 std::numeric_limits<float>::quiet_NaN(),
307 reading.value = qFromLittleEndian<float>(value.
mid(1,4).
constData());
309 reading.range =
static_cast<quint8
>(value.
at(6));
329 qCWarning(lc).noquote() <<
tr(
"Settings characteristic is write-only, but somehow read")
334 qCWarning(lc).noquote() <<
tr(
"Unknown characteristic read for Multimeter service")
349 Q_EMIT q->settingsWritten();
354 qCWarning(lc).noquote() <<
tr(
"Reading characteristic is read/notify, but somehow written")
359 qCWarning(lc).noquote() <<
tr(
"Unknown characteristic written for Multimeter service")
374 qCWarning(lc).noquote() <<
tr(
"Settings characteristic is write-only, but somehow updated")
384 qCWarning(lc).noquote() <<
tr(
"Unknown characteristic notified for Multimeter service")
QBluetoothUuid serviceUuid
UUIDs for service.
virtual void characteristicChanged(const QLowEnergyCharacteristic &characteristic, const QByteArray &newValue)
Handles QLowEnergyService::characteristicChanged events.
AbstractPokitServicePrivate(const QBluetoothUuid &serviceUuid, QLowEnergyController *controller, AbstractPokitService *const q)
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.
QLowEnergyController * controller
BLE controller to fetch the service from.
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...
std::optional< PokitProduct > pokitProduct() const
Returns the Pokit product this service is attached to.
The MultimeterServicePrivate class provides private implementation for MultimeterService.
void characteristicRead(const QLowEnergyCharacteristic &characteristic, const QByteArray &value) override
Implements AbstractPokitServicePrivate::characteristicRead to parse value, then emit a specialised si...
MultimeterServicePrivate(QLowEnergyController *controller, MultimeterService *const q)
static QByteArray encodeSettings(const MultimeterService::Settings &settings)
Returns settings in the format Pokit devices expect.
void characteristicWritten(const QLowEnergyCharacteristic &characteristic, const QByteArray &newValue) override
Implements AbstractPokitServicePrivate::characteristicWritten to parse newValue, then emit a speciali...
static MultimeterService::Reading parseReading(const QByteArray &value)
Parses the Reading value into a MultimeterService::Reading struct.
void characteristicChanged(const QLowEnergyCharacteristic &characteristic, const QByteArray &newValue) override
Implements AbstractPokitServicePrivate::characteristicChanged to parse newValue, then emit a speciali...
The MultimeterService class accesses the Multimeter service of Pokit devices.
static quint32 maxValue(const PokitProduct product, const quint8 range, const Mode mode)
Returns the maximum value for range, or 0 if range is not a known value for product's mode.
bool enableReadingNotifications()
Enables client-side notifications of meter readings.
MeterStatus
Values supported by the Status attribute of the Settings characteristic.
@ Error
Error (all modes).
Mode
Values supported by the Mode attribute of the Settings and Reading characteristics.
@ DcVoltage
Measure DC voltage.
@ Capacitance
Measure capacitance.
@ AcCurrent
Measure AC current.
@ ExternalTemperature
Measure temperature via an external temperature probe.
@ Resistance
Measure resistance.
@ AcVoltage
Measure AC voltage.
@ Temperature
Measure temperature.
@ DcCurrent
Measure DC current.
@ Continuity
Measure continuity.
bool readCharacteristics() override
Read all characteristics.
static QString toString(const Mode &mode)
Returns mode as a user-friendly string.
MultimeterService(QLowEnergyController *const pokitDevice, QObject *parent=nullptr)
Constructs a new Pokit service with parent.
bool readReadingCharacteristic()
Read the Multimeter service's Reading characteristic.
bool setSettings(const Settings &settings)
Configures the Pokit device's multimeter mode.
Reading reading() const
Returns the most recent value of the Multimeter service's Reading characteristic.
bool disableReadingNotifications()
Disables client-side notifications of meter readings.
Declares the MultimeterService class.
Declares the MultimeterServicePrivate class.
QString toString(const PokitProduct product, const quint8 range)
Returns product's capacitance range as a human-friendly string.
quint32 maxValue(const PokitProduct product, const quint8 range)
Returns the maximum value for range in nanofarads, or 0 if range is not a known value for product.
QString toString(const PokitProduct product, const quint8 range)
Returns product's current range as a human-friendly string.
quint32 maxValue(const PokitProduct product, const quint8 range)
Returns the maximum value for range in microamps, or 0 if range is not a known value for product.
QString toString(const PokitProduct product, const quint8 range)
Returns product's current range as a human-friendly string.
quint32 maxValue(const PokitProduct product, const quint8 range)
Returns the maximum value for range in ohms, or 0 if range is not a known value for product.
quint32 maxValue(const PokitProduct product, const quint8 range)
Returns the maximum value for range in millivolts, or 0 if range is not a known value for product.
QString toString(const PokitProduct product, const quint8 range)
Returns product's current range as a human-friendly string.
PokitProduct
Pokit products known to, and supported by, the QtPokit library.
char at(int i) const const
const char * constData() const const
bool isNull() const const
QByteArray mid(int pos, int len) const const
void setByteOrder(QDataStream::ByteOrder bo)
void setFloatingPointPrecision(QDataStream::FloatingPointPrecision precision)
bool isValid() const const
QString name() const const
QBluetoothUuid uuid() const const
QByteArray value() const const
QObject * parent() const const
QString tr(const char *sourceText, const char *disambiguation, int n)
static const QBluetoothUuid reading
UUID of the Multimeter service's Reading characterstic.
static const QBluetoothUuid settings
UUID of the Multimeter service's Settings characterstic.
Attributes included in the Reading characterstic.
MeterStatus status
Current multimeter status.
Attributes included in the Settings characterstic.
quint32 updateInterval
Desired update interval in milliseconds.
quint8 range
Desired range.
Mode mode
Desired operation mode.