4#include "loggerstartcommand.h"
10#include <QJsonDocument>
62 mode.
startsWith(u
"ac v"_s) || mode.startsWith(u
"vac"_s)) {
65 }
else if (mode.startsWith(u
"dc v"_s) || mode.startsWith(u
"vdc"_s)) {
68 }
else if (mode.startsWith(u
"ac c"_s) || mode.startsWith(u
"aac"_s)) {
71 }
else if (mode.startsWith(u
"dc c"_s) || mode.startsWith(u
"adc"_s)) {
74 }
else if (mode.startsWith(u
"temp"_s)) {
79 errors.
append(
tr(
"Unknown logger mode: %1").arg(parser.
value(u
"mode"_s)));
85 if (parser.
isSet(u
"range"_s)) {
97 qCInfo(lc).noquote() <<
tr(
"Ignoring range value: %1").
arg(value);
100 errors.
append(
tr(
"Invalid range value: %1").arg(value));
103 errors.
append(
tr(
"Missing required option for logger mode '%1': range").arg(parser.
value(u
"mode"_s)));
107 if (parser.
isSet(u
"interval"_s)) {
111 errors.
append(
tr(
"Invalid interval value: %1").arg(value));
119 if (parser.
isSet(u
"timestamp"_s)) {
122 static_assert(
sizeof(uint) ==
sizeof(
settings.timestamp),
"QLocale has no toUint32().");
123 const int timestamp = locale.
toUInt(value, &ok);
125 errors.
append(
tr(
"Invalid timestamp value: %1").arg(value));
183 qCDebug(lc).noquote() <<
tr(
"Settings written; data logger has started.");
186 std::cout << qUtf8Printable(
tr(
"logger_start_result\nsuccess\n"));
189 std::cout << qUtf8Printable(u
"true\n"_s);
192 std::cout << qUtf8Printable(
tr(
"Done.\n"));
virtual QStringList supportedOptions(const QCommandLineParser &parser) const
Returns a list of CLI option names supported by this command.
static quint32 parseNumber(const QString &value, const QString &unit, const quint32 sensibleMinimum=0)
Returns value as an integer multiple of the ratio R.
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.
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.
@ Temperature
Measure temperature.
@ DcCurrent
Measure DC current.
void settingsWritten()
This signal is emitted when the Settings characteristic has been written successfully.
PokitDevice * device
Pokit Bluetooth device (if any) this command interacts with.
DeviceCommand(QObject *const parent=nullptr)
Construct a new DeviceCommand object with parent.
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...
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.
QStringList processOptions(const QCommandLineParser &parser) override
Processes the relevant options from the command line parser.
DataLoggerService::Settings settings
Settings for the Pokit device's data logger mode.
quint32 rangeOptionValue
The parsed value of range option.
void settingsWritten()
Invoked when the data logger settings have been written.
void serviceDetailsDiscovered() override
Handles service detail discovery events.
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.
LoggerStartCommand(QObject *const parent=nullptr)
Construct a new LoggerStartCommand object with parent.
DataLoggerService * service
Bluetooth service this command interacts with.
Declares the PokitDevice class.
bool isSet(const QString &name) const const
QString value(const QString &optionName) const const
qint64 currentSecsSinceEpoch()
void append(const T &value)
bool isEmpty() const const
uint toUInt(const QString &s, bool *ok) const const
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
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
QString fromLatin1(const char *str, int size)
bool isNull() const const
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const const
QString toLower() const const
QString trimmed() const const
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 ...