13#include "pokitproducts_p.h"
113 : AbstractPokitService(d,
parent)
151 if (!characteristic.
isValid()) {
160 d->service->writeCharacteristic(characteristic, value);
161 return (d->service->error() != QLowEnergyService::ServiceError::CharacteristicWriteError);
175 qCWarning(d->lc).noquote() <<
tr(
"Settings command must not be 'ResendData'.");
323 static_assert(
sizeof(settings.
command) == 1,
"Expected to be 1 byte.");
324 static_assert(
sizeof(settings.
triggerLevel) == 4,
"Expected to be 2 bytes.");
325 static_assert(
sizeof(settings.
mode) == 1,
"Expected to be 1 byte.");
326 static_assert(
sizeof(settings.
range) == 1,
"Expected to be 1 byte.");
327 static_assert(
sizeof(settings.
samplingWindow) == 4,
"Expected to be 4 bytes.");
328 static_assert(
sizeof(settings.
numberOfSamples) == 2,
"Expected to be 2 bytes.");
337 Q_ASSERT(value.
size() == 13);
356 metadata.scale = qFromLittleEndian<float>(value.
mid(1,4).
constData());
358 metadata.range =
static_cast<quint8
>(value.
at(6));
359 metadata.samplingWindow = qFromLittleEndian<quint32>(value.
mid(7,4).
constData());
360 metadata.numberOfSamples = qFromLittleEndian<quint16>(value.
mid(11,2).
constData());
361 metadata.samplingRate = qFromLittleEndian<quint32>(value.
mid(13,4).
constData());
371 if ((value.
size()%2) != 0) {
372 qCWarning(lc).noquote() <<
tr(
"Samples value has odd size %1 (should be even): %2")
376 while ((samples.
size()*2) < value.
size()) {
379 qCDebug(lc).noquote() <<
tr(
"Read %n sample/s from %1-bytes.",
nullptr, samples.
size()).
arg(value.
size());
393 qCWarning(lc).noquote() <<
tr(
"Settings characteristic is write-only, but somehow read")
405 qCWarning(lc).noquote() <<
tr(
"Reading characteristic is notify-only")
410 qCWarning(lc).noquote() <<
tr(
"Unknown characteristic read for DSO service")
425 Q_EMIT q->settingsWritten();
430 qCWarning(lc).noquote() <<
tr(
"Metadata characteristic is read/notify, but somehow written")
436 qCWarning(lc).noquote() <<
tr(
"Reading characteristic is notify-only, but somehow written")
441 qCWarning(lc).noquote() <<
tr(
"Unknown characteristic written for DSO service")
456 qCWarning(lc).noquote() <<
tr(
"Settings characteristic is write-only, but somehow updated")
471 qCWarning(lc).noquote() <<
tr(
"Unknown characteristic notified for DSO 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 QString toHexString(const QByteArray &data, const int maxSize=20)
Returns up to maxSize bytes of data as a human readable hexadecimal string.
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 DsoServicePrivate class provides private implementation for DsoService.
void characteristicRead(const QLowEnergyCharacteristic &characteristic, const QByteArray &value) override
Implements AbstractPokitServicePrivate::characteristicRead to parse value, then emit a specialised si...
static DsoService::Samples parseSamples(const QByteArray &value)
Parses the Reading value into a DsoService::Samples vector.
void characteristicChanged(const QLowEnergyCharacteristic &characteristic, const QByteArray &newValue) override
Implements AbstractPokitServicePrivate::characteristicChanged to parse newValue, then emit a speciali...
void characteristicWritten(const QLowEnergyCharacteristic &characteristic, const QByteArray &newValue) override
Implements AbstractPokitServicePrivate::characteristicWritten to parse newValue, then emit a speciali...
DsoServicePrivate(QLowEnergyController *controller, DsoService *const q)
static QByteArray encodeSettings(const DsoService::Settings &settings)
Returns settings in the format Pokit devices expect.
static DsoService::Metadata parseMetadata(const QByteArray &value)
Parses the Metadata value into a DsoService::Metatdata struct.
The DsoService class accesses the DSO (Digital Storage Oscilloscope) service of Pokit devices.
DsoService(QLowEnergyController *const pokitDevice, QObject *parent=nullptr)
Constructs a new Pokit service with parent.
bool disableMetadataNotifications()
Disables client-side notifications of DSO metadata changes.
QVector< qint16 > Samples
Raw samples from the Reading characteristic.
bool startDso(const Settings &settings)
Start the DSO with settings.
bool setSettings(const Settings &settings)
Configures the Pokit device's DSO mode.
bool fetchSamples()
Fetch DSO samples.
bool enableMetadataNotifications()
Enables client-side notifications of DSO metadata changes.
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.
DsoStatus
Values supported by the Status attribute of the Metadata characteristic.
@ Error
An error has occurred.
bool readCharacteristics() override
Read all characteristics.
bool enableReadingNotifications()
Enables client-side notifications of DSO readings.
static QString toString(const Mode &mode)
Returns mode as a user-friendly string.
bool readMetadataCharacteristic()
Reads the DSO service's Metadata characteristic.
Mode
Values supported by the Mode attribute of the Settings and Metadata characteristics.
@ DcVoltage
Measure DC voltage.
@ AcCurrent
Measure AC current.
@ AcVoltage
Measure AC voltage.
@ DcCurrent
Measure DC current.
@ ResendData
Resend the last acquired data.
bool disableReadingNotifications()
Disables client-side notifications of DSO readings.
Metadata metadata() const
Returns the most recent value of the DSO service's Metadata characteristic.
Declares the DsoService class.
Declares the DsoServicePrivate class.
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.
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.
Declares the PokitMeter namespace.
Declares the PokitPro namespace.
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)
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
void append(const T &value)
static const QBluetoothUuid metadata
UUID of the DSO service's Metadata characterstic.
static const QBluetoothUuid reading
UUID of the DSO service's Reading characterstic.
static const QBluetoothUuid settings
UUID of the DSO service's Settings characterstic.
Attributes included in the Settings characterstic.
Mode mode
Desired operation mode.
quint8 range
Desired range, eg settings.range = +PokitPro::CurrentRange::AutoRange;.
Command command
Custom operation request.
quint32 samplingWindow
Desired sampling window in microseconds.
float triggerLevel
Trigger threshold level in Volts or Amps, depending on mode.
quint16 numberOfSamples
Desired number of samples to acquire.