13#include "pokitproducts_p.h"
156 if (!characteristic.
isValid()) {
165 d->service->writeCharacteristic(characteristic, value);
166 return (d->service->error() != QLowEnergyService::ServiceError::CharacteristicWriteError);
180 qCWarning(d->lc).noquote() <<
tr(
"Settings command must not be 'ResendData'.");
328 static_assert(
sizeof(settings.
command) == 1,
"Expected to be 1 byte.");
329 static_assert(
sizeof(settings.
triggerLevel) == 4,
"Expected to be 2 bytes.");
330 static_assert(
sizeof(settings.
mode) == 1,
"Expected to be 1 byte.");
331 static_assert(
sizeof(settings.
range) == 1,
"Expected to be 1 byte.");
332 static_assert(
sizeof(settings.
samplingWindow) == 4,
"Expected to be 4 bytes.");
333 static_assert(
sizeof(settings.
numberOfSamples) == 2,
"Expected to be 2 bytes.");
342 Q_ASSERT(value.
size() == 13);
361 metadata.scale = qFromLittleEndian<float>(value.
mid(1,4).
constData());
363 metadata.range =
static_cast<quint8
>(value.
at(6));
364 metadata.samplingWindow = qFromLittleEndian<quint32>(value.
mid(7,4).
constData());
365 metadata.numberOfSamples = qFromLittleEndian<quint16>(value.
mid(11,2).
constData());
366 metadata.samplingRate = qFromLittleEndian<quint32>(value.
mid(13,4).
constData());
376 if ((value.
size()%2) != 0) {
377 qCWarning(lc).noquote() <<
tr(
"Samples value has odd size %1 (should be even): %2")
381 while ((samples.
size()*2) < value.
size()) {
384 qCDebug(lc).noquote() <<
tr(
"Read %n sample/s from %1-bytes.",
nullptr, samples.
size()).
arg(value.
size());
398 qCWarning(lc).noquote() <<
tr(
"Settings characteristic is write-only, but somehow read")
410 qCWarning(lc).noquote() <<
tr(
"Reading characteristic is notify-only")
415 qCWarning(lc).noquote() <<
tr(
"Unknown characteristic read for DSO service")
430 Q_EMIT q->settingsWritten();
435 qCWarning(lc).noquote() <<
tr(
"Metadata characteristic is read/notify, but somehow written")
441 qCWarning(lc).noquote() <<
tr(
"Reading characteristic is notify-only, but somehow written")
446 qCWarning(lc).noquote() <<
tr(
"Unknown characteristic written for DSO service")
461 qCWarning(lc).noquote() <<
tr(
"Settings characteristic is write-only, but somehow updated")
476 qCWarning(lc).noquote() <<
tr(
"Unknown characteristic notified for DSO service")
The AbstractPokitServicePrivate class provides private implementation for AbstractPokitService.
QBluetoothUuid serviceUuid
UUIDs for service.
virtual void characteristicChanged(const QLowEnergyCharacteristic &characteristic, const QByteArray &newValue)
Handles QLowEnergyService::characteristicChanged 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 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...
The AbstractPokitService class provides a common base for Pokit services classes.
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.
bool startDso(const Settings &settings)
Start the DSO with settings.
static QVariant maxValue(const PokitProduct product, const quint8 range, const Mode mode)
Returns the maximum value for range, or the string "Auto".
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.
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.
QVariant maxValue(const PokitProduct product, const quint8 range)
Returns the maximum value for product's range in (integer) microamps, or the string "Auto".
QString toString(const PokitProduct product, const quint8 range)
Returns product's current range as a human-friendly string.
QString toString(const PokitProduct product, const quint8 range)
Returns product's current range as a human-friendly string.
QVariant maxValue(const PokitProduct product, const quint8 range)
Returns the maximum value for product's range in (integer) millivolts, or the string "Auto".
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
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.