Dokit
Internal development documentation
Loading...
Searching...
No Matches
MeterCommand Class Reference

The MeterCommand class implements the meter CLI command. More...

Inheritance diagram for MeterCommand:
[legend]
Collaboration diagram for MeterCommand:
[legend]

Public Slots

QStringList processOptions (const QCommandLineParser &parser) override
 Processes the relevant options from the command line parser.
 
- Public Slots inherited from DeviceCommand
bool start () override
 Begins scanning for the Pokit device.
 
- Public Slots inherited from AbstractCommand
virtual QStringList processOptions (const QCommandLineParser &parser)
 Processes the relevant options from the command line parser.
 
virtual bool start ()=0
 Begins the functionality of this command, and returns true if begun successfully, false otherwise.
 

Public Member Functions

 MeterCommand (QObject *const parent=nullptr)
 Construct a new MeterCommand object with parent.
 
QStringList requiredOptions (const QCommandLineParser &parser) const override
 Returns a list of CLI option names required by this command.
 
QStringList supportedOptions (const QCommandLineParser &parser) const override
 Returns a list of CLI option names supported by this command.
 
- Public Member Functions inherited from DeviceCommand
 DeviceCommand (QObject *const parent=nullptr)
 Construct a new DeviceCommand object with parent.
 
- Public Member Functions inherited from AbstractCommand
 AbstractCommand (QObject *const parent=nullptr)
 Constructs a new command with parent.
 
- Public Member Functions inherited from QObject
virtual const QMetaObjectmetaObject () const const
 
 QObject (QObject *parent)
 
virtual bool event (QEvent *e)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
QString objectName () const const
 
void setObjectName (const QString &name)
 
bool isWidgetType () const const
 
bool isWindowType () const const
 
bool signalsBlocked () const const
 
bool blockSignals (bool block)
 
QThreadthread () const const
 
void moveToThread (QThread *targetThread)
 
int startTimer (int interval, Qt::TimerType timerType)
 
int startTimer (std::chrono::milliseconds time, Qt::TimerType timerType)
 
void killTimer (int id)
 
findChild (const QString &name, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QString &name, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegExp &regExp, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const
 
const QObjectListchildren () const const
 
void setParent (QObject *parent)
 
void installEventFilter (QObject *filterObj)
 
void removeEventFilter (QObject *obj)
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const const
 
bool disconnect (const char *signal, const QObject *receiver, const char *method) const const
 
bool disconnect (const QObject *receiver, const char *method) const const
 
void dumpObjectTree ()
 
void dumpObjectInfo ()
 
void dumpObjectTree () const const
 
void dumpObjectInfo () const const
 
bool setProperty (const char *name, const QVariant &value)
 
QVariant property (const char *name) const const
 
QList< QByteArraydynamicPropertyNames () const const
 
void destroyed (QObject *obj)
 
void objectNameChanged (const QString &objectName)
 
QObjectparent () const const
 
bool inherits (const char *className) const const
 
void deleteLater ()
 
 Q_DISABLE_COPY (Class)
 
 Q_DISABLE_MOVE (Class)
 
 Q_DISABLE_COPY_MOVE (Class)
 
qobject_cast (QObject *object)
 
qobject_cast (const QObject *object)
 
qFindChild (const QObject *obj, const QString &name)
 
QList< T > qFindChildren (const QObject *obj, const QString &name)
 
QList< T > qFindChildren (const QObject *obj, const QRegExp &regExp)
 
 Q_CLASSINFO (Name, Value)
 
 Q_INTERFACES (...)
 
 Q_PROPERTY (...)
 
 Q_ENUMS (...)
 
 Q_FLAGS (...)
 
 Q_ENUM (...)
 
 Q_FLAG (...)
 
 Q_ENUM_NS (...)
 
 Q_FLAG_NS (...)
 
 Q_OBJECT Q_OBJECT
 
 Q_GADGET Q_GADGET
 
 Q_NAMESPACE Q_NAMESPACE
 
 Q_NAMESPACE_EXPORT (EXPORT_MACRO)
 
 Q_SIGNALS Q_SIGNALS
 
 Q_SIGNAL Q_SIGNAL
 
 Q_SLOTS Q_SLOTS
 
 Q_SLOT Q_SLOT
 
 Q_EMIT Q_EMIT
 
 Q_INVOKABLE Q_INVOKABLE
 
 Q_REVISION Q_REVISION
 
 Q_SET_OBJECT_NAME (Object)
 
 QT_NO_NARROWING_CONVERSIONS_IN_CONNECT QT_NO_NARROWING_CONVERSIONS_IN_CONNECT
 

Protected Slots

void serviceDetailsDiscovered () override
 Handles service detail discovery events.
 
- Protected Slots inherited from DeviceCommand
virtual void controllerError (const QLowEnergyController::Error error)
 Handles controller error events.
 
virtual void deviceDisconnected ()
 Handles devics disconnection events.
 
virtual void serviceError (const QLowEnergyService::ServiceError error)
 Handles service error events.
 
virtual void serviceDetailsDiscovered ()
 Handles service detail discovery events.
 
- Protected Slots inherited from AbstractCommand
virtual void deviceDiscovered (const QBluetoothDeviceInfo &info)=0
 Handles PokitDiscoveryAgent::pokitDeviceDiscovered signal.
 
virtual void deviceDiscoveryFinished ()=0
 Handles PokitDiscoveryAgent::deviceDiscoveryFinished signal.
 

Protected Member Functions

AbstractPokitServicegetService () override
 Returns a Pokit service object for the derived command class.
 
- Protected Member Functions inherited from DeviceCommand
void disconnect (int exitCode=EXIT_SUCCESS)
 Disconnects the underlying Pokit device, and sets exitCode to be return to the OS once the disconnection has taken place.
 
- Protected Member Functions inherited from QObject
QObjectsender () const const
 
int senderSignalIndex () const const
 
int receivers (const char *signal) const const
 
bool isSignalConnected (const QMetaMethod &signal) const const
 
virtual void timerEvent (QTimerEvent *event)
 
virtual void childEvent (QChildEvent *event)
 
virtual void customEvent (QEvent *event)
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 

Private Slots

void settingsWritten ()
 Invoked when the multimeter settings have been written, to begin reading the meter values.
 
void outputReading (const MultimeterService::Reading &reading)
 Outputs meter reading in the selected ouput format.
 

Private Attributes

quint8(* minRangeFunc )(const PokitProduct product, const quint32 maxValue)
 Pointer to function for converting rangeOptionValue to a Pokit device's range enumerator.
 
quint32 rangeOptionValue { 0 }
 The parsed value of range option, if one was supplied.
 
MultimeterServiceservice { nullptr }
 Bluetooth service this command interracts with.
 
MultimeterService::Settings settings { MultimeterService::Mode::DcVoltage, +PokitMeter::VoltageRange::AutoRange, 1000 }
 < Settings for the Pokit device's multimeter mode.
 
int samplesToGo { -1 }
 Number of samples to read, if specified on the CLI.
 
bool showCsvHeader { true }
 Whether or not to show a header as the first line of CSV output.
 

Friends

class TestMeterCommand
 

Additional Inherited Members

- Public Types inherited from AbstractCommand
enum class  OutputFormat { Csv , Json , Text }
 Supported output formats. More...
 
- Static Public Member Functions inherited from AbstractCommand
static QString escapeCsvField (const QString &field)
 Returns an RFC 4180 compliant version of field.
 
template<typename R >
static quint32 parseNumber (const QString &value, const QString &unit, const quint32 sensibleMinimum=0)
 Returns value as an integer multiple of the ratio R.
 
- Static Public Member Functions inherited from QObject
QString tr (const char *sourceText, const char *disambiguation, int n)
 
QString trUtf8 (const char *sourceText, const char *disambiguation, int n)
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, Functor functor)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type)
 
bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)
 
bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method)
 
bool disconnect (const QMetaObject::Connection &connection)
 
bool disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method)
 
- Public Attributes inherited from QObject
typedef QObjectList
 
- Static Protected Member Functions inherited from DeviceCommand
template<typename T >
static T minRange (const quint32 maxValue)
 
static quint8 minCapacitanceRange (const PokitProduct product, const quint32 maxValue)
 Returns the product's lowest capacitance range that can measure at least up to maxValue (nF), or AutoRange if no such range is available.
 
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), or AutoRange if no such range is available.
 
static quint8 minResistanceRange (const PokitProduct product, const quint32 maxValue)
 Returns the product's lowest resistance range that can measure at least up to maxValue (Ω), or AutoRange if no such range is available.
 
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), or AutoRange if no such range is available.
 
- Static Protected Member Functions inherited from AbstractCommand
static Q_LOGGING_CATEGORY (lc, "dokit.cli.command", QtInfoMsg)
 Logging category for UI commands.
 
- Protected Attributes inherited from DeviceCommand
PokitDevicedevice { nullptr }
 Pokit Bluetooth device (if any) this command inerracts with.
 
int exitCodeOnDisconnect { EXIT_FAILURE }
 Exit code to return on device disconnection.
 
- Protected Attributes inherited from AbstractCommand
QString deviceToScanFor
 Device (if any) that were passed to processOptions().
 
PokitDiscoveryAgentdiscoveryAgent
 Agent for Pokit device descovery.
 
OutputFormat format { OutputFormat::Text }
 Selected output format.
 
- Properties inherited from QObject
 objectName
 

Detailed Description

The MeterCommand class implements the meter CLI command.

Definition at line 10 of file metercommand.h.

Constructor & Destructor Documentation

◆ MeterCommand()

MeterCommand::MeterCommand ( QObject *const parent = nullptr)
explicit

Construct a new MeterCommand object with parent.

Definition at line 22 of file metercommand.cpp.

23{
24
25}
DeviceCommand(QObject *const parent=nullptr)
Construct a new DeviceCommand object with parent.
QObject * parent() const const

Member Function Documentation

◆ getService()

AbstractPokitService * MeterCommand::getService ( )
overrideprotectedvirtual

Returns a Pokit service object for the derived command class.

This override returns a pointer to a MultimeterService object.

Implements DeviceCommand.

Definition at line 148 of file metercommand.cpp.

149{
150 Q_ASSERT(device);
151 if (!service) {
153 Q_ASSERT(service);
156 }
157 return service;
158}
PokitDevice * device
Pokit Bluetooth device (if any) this command inerracts with.
void settingsWritten()
Invoked when the multimeter settings have been written, to begin reading the meter values.
MultimeterService * service
Bluetooth service this command interracts with.
void settingsWritten()
This signal is emitted when the Settings characteristic has been written successfully.
MultimeterService * multimeter()
Returns a pointer to MultimeterService instance that uses this device's controller for access.
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)

References QObject::connect(), DeviceCommand::device, PokitDevice::multimeter(), service, MultimeterService::settingsWritten(), and settingsWritten().

Here is the call graph for this function:

◆ outputReading

void MeterCommand::outputReading ( const MultimeterService::Reading & reading)
privateslot

Outputs meter reading in the selected ouput format.

Definition at line 204 of file metercommand.cpp.

205{
206 QString status;
208 status = QLatin1String("Error");
209 } else switch (reading.mode) {
211 break;
219 ? tr("Auto Range On") : tr("Auto Range Off");
220 break;
223 ? tr("Continuity") : tr("No continuity");
224 break;
228 status = tr("Ok");
229 break;
230 }
231
232 QString unit;
233 switch (reading.mode) {
235 case MultimeterService::Mode::DcVoltage: unit = QLatin1String("Vdc"); break;
236 case MultimeterService::Mode::AcVoltage: unit = QLatin1String("Vac"); break;
237 case MultimeterService::Mode::DcCurrent: unit = QLatin1String("Adc"); break;
238 case MultimeterService::Mode::AcCurrent: unit = QLatin1String("Aac"); break;
245 }
246
247 const QString range = service->toString(reading.range, reading.mode);
248
249 switch (format) {
251 for (; showCsvHeader; showCsvHeader = false) {
252 std::cout << qUtf8Printable(tr("mode,value,unit,status,range\n"));
253 }
254 std::cout << qUtf8Printable(QString::fromLatin1("%1,%2,%3,%4,%5\n")
256 .arg(reading.value, 0, 'f').arg(unit, status, range)
257 );
258 break;
259 case OutputFormat::Json: {
260 QJsonObject object{
261 { QLatin1String("status"), status },
262 { QLatin1String("value"), qIsInf(reading.value) ?
263 QJsonValue(tr("Infinity")) : QJsonValue(reading.value) },
264 { QLatin1String("mode"), MultimeterService::toString(reading.mode) },
265 };
266 if (!unit.isNull()) {
267 object.insert(QLatin1String("unit"), unit);
268 }
269 if (!range.isNull()) {
270 object.insert(QLatin1String("range"), range);
271 }
272 std::cout << QJsonDocument(object).toJson().toStdString();
273 } break;
275 std::cout << qUtf8Printable(tr("Mode: %1 (0x%2)\n").arg(MultimeterService::toString(reading.mode))
276 .arg((quint8)reading.mode,2,16,QLatin1Char('0')));
277 std::cout << qUtf8Printable(tr("Value: %1 %2\n").arg(reading.value,0,'f').arg(unit));
278 std::cout << qUtf8Printable(tr("Status: %1 (0x%2)\n").arg(status)
279 .arg((quint8)reading.status,2,16,QLatin1Char('0')));
280 std::cout << qUtf8Printable(tr("Range: %1 (0x%2)\n").arg(range)
281 .arg((quint8)reading.range,2,16,QLatin1Char('0')));
282 break;
283 }
284
285 if ((samplesToGo > 0) && (--samplesToGo == 0)) {
286 if (device) disconnect(); // Will exit the application once disconnected.
287 }
288}
OutputFormat format
Selected output format.
@ Text
Plain unstructured text.
@ Csv
RFC 4180 compliant CSV text.
@ Json
RFC 8259 compliant JSON text.
static QString escapeCsvField(const QString &field)
Returns an RFC 4180 compliant version of field.
void disconnect(int exitCode=EXIT_SUCCESS)
Disconnects the underlying Pokit device, and sets exitCode to be return to the OS once the disconnect...
bool showCsvHeader
Whether or not to show a header as the first line of CSV output.
int samplesToGo
Number of samples to read, if specified on the CLI.
@ AutoRangeOn
Auto-range is enabled (voltage, current and resistance modes only).
@ Error
Error (all modes).
@ Continuity
Continuity (continuity mode only).
@ Diode
Measure diode.
@ DcVoltage
Measure DC voltage.
@ Capacitance
Measure capacitance.
@ AcCurrent
Measure AC current.
@ ExternalTemperature
Measure temperature via an external temperature probe.
@ Resistance
Measure resistance.
@ AcVoltage
Measure AC voltage.
@ Idle
Make device idle.
@ Temperature
Measure temperature.
@ DcCurrent
Measure DC current.
@ Continuity
Measure continuity.
static QString toString(const Mode &mode)
Returns mode as a user-friendly string.
std::string toStdString() const const
QByteArray toJson() 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)
QString fromUtf8(const char *str, int size)
QString & insert(int position, QChar ch)
bool isNull() const const
MeterStatus status
Current multimeter status.
Mode mode
Current operation mode.
float value
Last acquired value.
quint8 range
Current range.

References MultimeterService::AcCurrent, MultimeterService::AcVoltage, QString::arg(), MultimeterService::AutoRangeOn, MultimeterService::Capacitance, MultimeterService::Continuity, AbstractCommand::Csv, MultimeterService::DcCurrent, MultimeterService::DcVoltage, DeviceCommand::device, MultimeterService::Diode, DeviceCommand::disconnect(), MultimeterService::Error, AbstractCommand::escapeCsvField(), MultimeterService::ExternalTemperature, AbstractCommand::format, QString::fromLatin1(), QString::fromUtf8(), MultimeterService::Idle, QString::insert(), QString::isNull(), AbstractCommand::Json, MultimeterService::Reading::mode, MultimeterService::Reading::range, MultimeterService::Resistance, samplesToGo, service, showCsvHeader, MultimeterService::Reading::status, MultimeterService::Temperature, AbstractCommand::Text, QJsonDocument::toJson(), QByteArray::toStdString(), MultimeterService::toString(), QObject::tr(), and MultimeterService::Reading::value.

Referenced by settingsWritten().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ processOptions

QStringList MeterCommand::processOptions ( const QCommandLineParser & parser)
overrideslot

Processes the relevant options from the command line parser.

This implementation extends DeviceCommand::processOptions to process additional CLI options supported (or required) by this command.

Definition at line 49 of file metercommand.cpp.

50{
52 if (!errors.isEmpty()) {
53 return errors;
54 }
55
56 // Parse the (required) mode option.
57 const QString mode = parser.value(QLatin1String("mode")).trimmed().toLower();
58 if (mode.startsWith(QLatin1String("ac v")) || mode.startsWith(QLatin1String("vac"))) {
61 } else if (mode.startsWith(QLatin1String("dc v")) || mode.startsWith(QLatin1String("vdc"))) {
64 } else if (mode.startsWith(QLatin1String("ac c")) || mode.startsWith(QLatin1String("aac"))) {
67 } else if (mode.startsWith(QLatin1String("dc c")) || mode.startsWith(QLatin1String("adc"))) {
70 } else if (mode.startsWith(QLatin1String("res"))) {
73 } else if (mode.startsWith(QLatin1String("dio"))) {
75 minRangeFunc = nullptr;
76 } else if (mode.startsWith(QLatin1String("cont"))) {
78 minRangeFunc = nullptr;
79 } else if (mode.startsWith(QLatin1String("temp"))) {
81 minRangeFunc = nullptr;
82 } else if (mode.startsWith(QLatin1String("cap"))) {
85 } else {
86 errors.append(tr("Unknown meter mode: %1").arg(parser.value(QLatin1String("mode"))));
87 return errors;
88 }
89
90 // Parse the interval option.
91 if (parser.isSet(QLatin1String("interval"))) {
92 const QString value = parser.value(QLatin1String("interval"));
93 const quint32 interval = parseNumber<std::milli>(value, QLatin1String("s"), 500);
94 if (interval == 0) {
95 errors.append(tr("Invalid interval value: %1").arg(value));
96 } else {
97 settings.updateInterval = interval;
98 }
99 }
100
101 // Parse the range option.
102 rangeOptionValue = 0; // Default to auto.
103 if (parser.isSet(QLatin1String("range"))) {
104 const QString value = parser.value(QLatin1String("range"));
105 if (value.trimmed().compare(QLatin1String("auto"), Qt::CaseInsensitive) != 0) {
106 switch (settings.mode) {
109 rangeOptionValue = parseNumber<std::milli>(value, QLatin1String("V"), 50); // mV.
110 break;
113 rangeOptionValue = parseNumber<std::milli>(value, QLatin1String("A"), 5); // mA.
114 break;
116 rangeOptionValue = parseNumber<std::ratio<1>>(value, QLatin1String("ohms"));
117 break;
119 rangeOptionValue = parseNumber<std::nano>(value, QLatin1String("F"), 500); // pF.
120 break;
121 default:
122 qCInfo(lc).noquote() << tr("Ignoring range value: %1").arg(value);
123 }
124 if ((minRangeFunc != nullptr) && (rangeOptionValue == 0)) {
125 errors.append(tr("Invalid range value: %1").arg(value));
126 }
127 }
128 }
129
130 // Parse the samples option.
131 if (parser.isSet(QLatin1String("samples"))) {
132 const QString value = parser.value(QLatin1String("samples"));
133 const quint32 samples = parseNumber<std::ratio<1>>(value, QLatin1String("S"));
134 if (samples == 0) {
135 errors.append(tr("Invalid samples value: %1").arg(value));
136 } else {
137 samplesToGo = samples;
138 }
139 }
140 return errors;
141}
virtual QStringList processOptions(const QCommandLineParser &parser)
Processes the relevant options from the command line parser.
static quint8 minResistanceRange(const PokitProduct product, const quint32 maxValue)
Returns the product's lowest resistance range that can measure at least up to maxValue (Ω),...
static quint8 minCapacitanceRange(const PokitProduct product, const quint32 maxValue)
Returns the product's lowest capacitance range that can measure at least up to maxValue (nF),...
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),...
quint32 rangeOptionValue
The parsed value of range option, if one was supplied.
MultimeterService::Settings settings
< Settings for the Pokit device's multimeter mode.
quint8(* minRangeFunc)(const PokitProduct product, const quint32 maxValue)
Pointer to function for converting rangeOptionValue to a Pokit device's range enumerator.
bool isSet(const QString &name) const const
QString value(const QString &optionName) const const
void append(const T &value)
bool isEmpty() const const
int compare(const QString &other, Qt::CaseSensitivity cs) const const
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const const
QString toLower() const const
QString trimmed() const const
CaseInsensitive
quint32 updateInterval
Desired update interval in milliseconds.
Mode mode
Desired operation mode.

References MultimeterService::AcCurrent, MultimeterService::AcVoltage, QList::append(), QString::arg(), MultimeterService::Capacitance, Qt::CaseInsensitive, QString::compare(), MultimeterService::Continuity, MultimeterService::DcCurrent, MultimeterService::DcVoltage, MultimeterService::Diode, QList::isEmpty(), QCommandLineParser::isSet(), DeviceCommand::minCapacitanceRange(), DeviceCommand::minCurrentRange(), minRangeFunc, DeviceCommand::minResistanceRange(), DeviceCommand::minVoltageRange(), MultimeterService::Settings::mode, AbstractCommand::processOptions(), rangeOptionValue, MultimeterService::Resistance, samplesToGo, settings, QString::startsWith(), MultimeterService::Temperature, QString::toLower(), QObject::tr(), QString::trimmed(), MultimeterService::Settings::updateInterval, and QCommandLineParser::value().

Here is the call graph for this function:

◆ requiredOptions()

QStringList MeterCommand::requiredOptions ( const QCommandLineParser & parser) const
overridevirtual

Returns a list of CLI option names required by this command.

The main console appication may use this list to output an eror (and exit) if any of the returned names are not found in the parsed CLI options.

The (already parsed) parser may be used adjust the returned required options depending on the value of other options. For example, the logger command only requires the --mode option if the --command option is start.

This base implementation simply returns an empty list. Derived classes should override this function to include any required options.

Reimplemented from AbstractCommand.

Definition at line 27 of file metercommand.cpp.

28{
30 QLatin1String("mode"),
31 };
32}
virtual QStringList requiredOptions(const QCommandLineParser &parser) const
Returns a list of CLI option names required by this command.

References AbstractCommand::requiredOptions().

Here is the call graph for this function:

◆ serviceDetailsDiscovered

void MeterCommand::serviceDetailsDiscovered ( )
overrideprotectedslot

Handles service detail discovery events.

This override fetches the current device's status, and outputs it in the selected format.

Definition at line 165 of file metercommand.cpp.

166{
167 DeviceCommand::serviceDetailsDiscovered(); // Just logs consistently.
170 qCInfo(lc).noquote() << tr("Measuring %1, with range %2, every %L3ms.").arg(
172 (range.isNull()) ? QString::fromLatin1("N/A") : range).arg(settings.updateInterval);
174}
virtual void serviceDetailsDiscovered()
Handles service detail discovery events.
bool setSettings(const Settings &settings)
Configures the Pokit device's multimeter mode.
QTPOKIT_EXPORT PokitProduct pokitProduct(const QBluetoothDeviceInfo &info)
Returns the PokitProduct corresponding the Bluetotoh device info.

References QString::arg(), QString::fromLatin1(), QString::isNull(), minRangeFunc, MultimeterService::Settings::mode, AbstractPokitService::pokitProduct(), MultimeterService::Settings::range, rangeOptionValue, service, DeviceCommand::serviceDetailsDiscovered(), MultimeterService::setSettings(), settings, MultimeterService::toString(), QObject::tr(), and MultimeterService::Settings::updateInterval.

Here is the call graph for this function:

◆ settingsWritten

void MeterCommand::settingsWritten ( )
privateslot

Invoked when the multimeter settings have been written, to begin reading the meter values.

Definition at line 193 of file metercommand.cpp.

194{
195 qCDebug(lc).noquote() << tr("Settings written; starting meter readings...");
199}
void outputReading(const MultimeterService::Reading &reading)
Outputs meter reading in the selected ouput format.
bool enableReadingNotifications()
Enables client-side notifications of meter readings.
void readingRead(const MultimeterService::Reading &reading)
This signal is emitted when the Reading characteristic has been read successfully.

References QObject::connect(), MultimeterService::enableReadingNotifications(), outputReading(), MultimeterService::readingRead(), service, and QObject::tr().

Referenced by getService().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ supportedOptions()

QStringList MeterCommand::supportedOptions ( const QCommandLineParser & parser) const
overridevirtual

Returns a list of CLI option names supported by this command.

The main console appication may use this list to output a warning for any parsed CLI options not included in the returned list.

The (already parsed) parser may be used adjust the returned supported options depending on the value of other options. For example, the logger command only supported the --timestamp option if the --command option is start.

This base implementation simply returns requiredOptions(). Derived classes should override this function to include optional options, such as:

QStringList Derived::supportedOptions(const QCommandLineParser &parser) const
{
list.sort();
list.removeDuplicates(); // Optional, recommended.
return list;
}
virtual QStringList supportedOptions(const QCommandLineParser &parser) const
Returns a list of CLI option names supported by this command.
int removeDuplicates()
void sort(Qt::CaseSensitivity cs)

Reimplemented from AbstractCommand.

Definition at line 34 of file metercommand.cpp.

35{
37 QLatin1String("interval"),
38 QLatin1String("range"),
39 QLatin1String("samples"),
40 };
41}

References AbstractCommand::supportedOptions().

Here is the call graph for this function:

Friends And Related Symbol Documentation

◆ TestMeterCommand

friend class TestMeterCommand
friend

Definition at line 42 of file metercommand.h.

Member Data Documentation

◆ minRangeFunc

MeterCommand::minRangeFunc
inlineprivate

Pointer to function for converting rangeOptionValue to a Pokit device's range enumerator.

This function pointer is assigned during the command line parsing, but is not invoked until after the device's services are discovere, because prior to that discovery, we don't know which product (Meter vs Pro vs Clamp, etc) we're talking to and thus which enumerator list to be using.

If the current mode does not support ranges (eg diode, and continuity modes), then this member will be nullptr.

See also
processOptions
serviceDetailsDiscovered

Definition at line 30 of file metercommand.h.

30{ nullptr };

Referenced by processOptions(), and serviceDetailsDiscovered().

◆ rangeOptionValue

quint32 MeterCommand::rangeOptionValue { 0 }
private

The parsed value of range option, if one was supplied.

Definition at line 31 of file metercommand.h.

31{ 0 }; ///< The parsed value of range option, if one was supplied.

Referenced by processOptions(), and serviceDetailsDiscovered().

◆ samplesToGo

int MeterCommand::samplesToGo { -1 }
private

Number of samples to read, if specified on the CLI.

Definition at line 35 of file metercommand.h.

35{ -1 } ; ///< Number of samples to read, if specified on the CLI.

Referenced by outputReading(), and processOptions().

◆ service

MultimeterService* MeterCommand::service { nullptr }
private

Bluetooth service this command interracts with.

Definition at line 32 of file metercommand.h.

32{ nullptr }; ///< Bluetooth service this command interracts with.

Referenced by getService(), outputReading(), serviceDetailsDiscovered(), and settingsWritten().

◆ settings

< Settings for the Pokit device's multimeter mode.

Definition at line 33 of file metercommand.h.

Referenced by processOptions(), and serviceDetailsDiscovered().

◆ showCsvHeader

bool MeterCommand::showCsvHeader { true }
private

Whether or not to show a header as the first line of CSV output.

Definition at line 36 of file metercommand.h.

36{ true }; ///< Whether or not to show a header as the first line of CSV output.

Referenced by outputReading().


The documentation for this class was generated from the following files: