13#include "pokitproducts_p.h"
129 : AbstractPokitService(d,
parent)
167 if (!characteristic.
isValid()) {
176 d->service->writeCharacteristic(characteristic, value);
177 return (d->service->error() != QLowEnergyService::ServiceError::CharacteristicWriteError);
191 qCWarning(d->lc).noquote() <<
tr(
"Settings command must not be 'ResendData'.");
339 static_assert(
sizeof(settings.
command) == 1,
"Expected to be 1 byte.");
340 static_assert(
sizeof(settings.
triggerLevel) == 4,
"Expected to be 2 bytes.");
341 static_assert(
sizeof(settings.
mode) == 1,
"Expected to be 1 byte.");
342 static_assert(
sizeof(settings.
range) == 1,
"Expected to be 1 byte.");
343 static_assert(
sizeof(settings.
samplingWindow) == 4,
"Expected to be 4 bytes.");
344 static_assert(
sizeof(settings.
numberOfSamples) == 2,
"Expected to be 2 bytes.");
353 Q_ASSERT(value.
size() == 13);
367 if (!
checkSize(u
"Metadata"_s, value, 17, 17)) {
374 metadata.
range =
static_cast<quint8
>(value.
at(6));
387 if ((value.
size()%2) != 0) {
388 qCWarning(lc).noquote() <<
tr(
"Samples value has odd size %1 (should be even): %2")
392 while ((samples.
size()*2) < value.
size()) {
395 qCDebug(lc).noquote() <<
tr(
"Read %n sample/s from %1-bytes.",
nullptr, samples.
size()).
arg(value.
size());
409 qCWarning(lc).noquote() <<
tr(
"Settings characteristic is write-only, but somehow read")
421 qCWarning(lc).noquote() <<
tr(
"Reading characteristic is notify-only")
426 qCWarning(lc).noquote() <<
tr(
"Unknown characteristic read for DSO service")
441 Q_EMIT q->settingsWritten();
446 qCWarning(lc).noquote() <<
tr(
"Metadata characteristic is read/notify, but somehow written")
452 qCWarning(lc).noquote() <<
tr(
"Reading characteristic is notify-only, but somehow written")
457 qCWarning(lc).noquote() <<
tr(
"Unknown characteristic written for DSO service")
472 qCWarning(lc).noquote() <<
tr(
"Settings characteristic is write-only, but somehow updated")
487 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.
static QString toString(const Command &command)
Returns command as a user-friendly string.
bool enableReadingNotifications()
Enables client-side notifications of DSO readings.
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.
Command
Values supported by the Command attribute of the Settings characteristic.
@ ResendData
Resend the last acquired data.
@ FreeRunning
Run free, without waiting for edge triggers.
@ RisingEdgeTrigger
Trigger on a rising edge.
@ FallingEdgeTrigger
Trigger on a falling edge.
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
#define QTPOKIT_BEGIN_NAMESPACE
Macro for starting the QtPokit library's top-most namespace (if one is defined).
#define QTPOKIT_END_NAMESPACE
Macro for ending the QtPokit library's top-most namespace (if one is defined).
void append(const T &value)
Declares the DOKIT_USE_STRINGLITERALS macro, and related functions.
#define DOKIT_USE_STRINGLITERALS
Internal macro for using either official Qt string literals (added in Qt 6.4), or our own equivalent ...
static const QBluetoothUuid metadata
UUID of the DSO service's Metadata characteristic.
static const QBluetoothUuid reading
UUID of the DSO service's Reading characteristic.
static const QBluetoothUuid settings
UUID of the DSO service's Settings characteristic.
Attributes included in the Settings characteristic.
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.