8#include <QJsonDocument>
77 quint32 sensibleMinimum = 0;
98 errors.
append(
tr(
"Invalid range value: %1").arg(value));
105 const quint32 level = parseNumber<std::micro>(value, unit);
107 errors.
append(
tr(
"Invalid trigger-level value: %1").arg(value));
131 errors.
append(
tr(
"If either option is provided, then both must be: trigger-level, trigger-mode"));
137 const quint32 interval = parseNumber<std::micro>(value,
QLatin1String(
"s"), 500'000);
139 errors.
append(
tr(
"Invalid interval value: %1").arg(value));
148 const quint32 samples = parseNumber<std::ratio<1>>(value,
QLatin1String(
"S"));
150 errors.
append(
tr(
"Invalid samples value: %1").
arg(value));
151 }
else if (samples > std::numeric_limits<quint16>::max()) {
152 errors.
append(
tr(
"Samples value (%1) must be no greater than %2")
153 .
arg(value).
arg(std::numeric_limits<quint16>::max()));
155 if (samples > 8192) {
156 qCWarning(lc).noquote() <<
tr(
"Pokit devices do not officially support great than 8192 samples");
217 qCDebug(lc).noquote() <<
tr(
"Settings written; DSO has started.");
229 qCDebug(lc) <<
"status:" << (int)(data.
status);
230 qCDebug(lc) <<
"scale:" << data.
scale;
235 qCDebug(lc) <<
"samplingRate:" << data.
samplingRate <<
"Hz";
252 qCDebug(lc).noquote() <<
tr(R
"(No known unit for mode %1 "%2".)").arg((int)
metadata.
mode)
257 for (
const qint16 &sample: samples) {
258 static int sampleNumber = 0; ++sampleNumber;
263 std::cout << qUtf8Printable(
tr(
"sample_number,value,unit,range\n"));
266 .arg(sampleNumber).arg(value).arg(unit, range));
274 }).toJson().toStdString();
277 std::cout << qUtf8Printable(
tr(
"%1 %2 %3\n").arg(sampleNumber).arg(value).arg(unit));
283 qCInfo(lc).noquote() <<
tr(
"Finished fetching %Ln sample/s (with %L2 to remaining).",
virtual QStringList supportedOptions(const QCommandLineParser &parser) const
Returns a list of CLI option names supported by this command.
OutputFormat format
Selected output format.
@ Text
Plain unstructured text.
@ Csv
RFC 4180 compliant CSV text.
@ Json
RFC 8259 compliant JSON text.
virtual QStringList processOptions(const QCommandLineParser &parser)
Processes the relevant options from the command line parser.
virtual QStringList requiredOptions(const QCommandLineParser &parser) const
Returns a list of CLI option names required by this command.
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 AbstractCommand class extends AbstractCommand to add a PokitDevice instance.
PokitDevice * device
Pokit Bluetooth device (if any) this command interracts with.
virtual void serviceDetailsDiscovered()
Handles service detail discovery events.
static quint8 minVoltageRange(const PokitProduct product, const quint32 maxValue)
t Returns the product's lowest voltage range that can measure at least up to maxValue (mV),...
static quint8 minCurrentRange(const PokitProduct product, const quint32 maxValue)
Returns the product's lowest current range that can measure at least up to maxValue (µA),...
void disconnect(int exitCode=EXIT_SUCCESS)
Disconnects the underlying Pokit device, and sets exitCode to be return to the OS once the disconnect...
DsoService::Settings settings
Settings for the Pokit device's DSO mode.
qint32 samplesToGo
Number of samples we're expecting in the current window.
bool showCsvHeader
Whether or not to show a header as the first line of CSV output.
void serviceDetailsDiscovered() override
Handles service detail discovery events.
void outputSamples(const DsoService::Samples &samples)
Outputs DSO samples in the selected ouput format.
quint8(* minRangeFunc)(const PokitProduct product, const quint32 maxValue)
Pointer to function for converting rangeOptionValue to a Pokit device's range enumerator.
QStringList supportedOptions(const QCommandLineParser &parser) const override
Returns a list of CLI option names supported by this command.
DsoCommand(QObject *const parent=nullptr)
Construct a new DsoCommand object with parent.
DsoService * service
Bluetooth service this command interracts with.
QStringList processOptions(const QCommandLineParser &parser) override
Processes the relevant options from the command line parser.
void settingsWritten()
Invoked when the DSO settings have been written.
quint32 rangeOptionValue
The parsed value of range option.
QStringList requiredOptions(const QCommandLineParser &parser) const override
Returns a list of CLI option names required by this command.
AbstractPokitService * getService() override
Returns a Pokit service object for the derived command class.
DsoService::Metadata metadata
Most recent DSO metadata.
void metadataRead(const DsoService::Metadata &data)
Invoked when metadata has been received from the DSO.
bool setSettings(const Settings &settings)
Configures the Pokit device's DSO mode.
bool enableMetadataNotifications()
Enables client-side notifications of DSO metadata changes.
void metadataRead(const DsoService::Metadata &meta)
This signal is emitted when the Metadata characteristic has been read successfully.
void samplesRead(const DsoService::Samples &samples)
This signal is emitted when the Reading characteristic has been notified.
bool enableReadingNotifications()
Enables client-side notifications of DSO readings.
static QString toString(const Mode &mode)
Returns mode as a user-friendly string.
@ DcVoltage
Measure DC voltage.
@ AcCurrent
Measure AC current.
@ AcVoltage
Measure AC voltage.
@ DcCurrent
Measure DC current.
void settingsWritten()
This signal is emitted when the Settings characteristic has been written successfully.
@ FreeRunning
Run free, without waiting for edge triggers.
@ RisingEdgeTrigger
Trigger on a rising edge.
@ FallingEdgeTrigger
Trigger on a falling edge.
DsoService * dso()
Returns a pointer to DsoService instance that uses this device's controller for access.
Declares the PokitDevice class.
bool isSet(const QString &name) const const
QString value(const QString &optionName) const const
void append(const T &value)
bool isEmpty() const const
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QString tr(const char *sourceText, const char *disambiguation, int n)
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
QString fromLatin1(const char *str, int size)
bool isEmpty() const const
bool isNull() const const
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const const
QString toLower() const const
QString trimmed() const const
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.