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

The LoggerStartCommand class implements the logger CLI command. More...

Inheritance diagram for LoggerStartCommand:
[legend]
Collaboration diagram for LoggerStartCommand:
[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

 LoggerStartCommand (QObject *const parent=nullptr)
 Construct a new LoggerStartCommand 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 data logger settings have been written.
 

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.
 
DataLoggerServiceservice { nullptr }
 Bluetooth service this command interracts with.
 
DataLoggerService::Settings settings
 Settings for the Pokit device's data logger mode.
 

Friends

class TestLoggerStartCommand
 

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 LoggerStartCommand class implements the logger CLI command.

Definition at line 10 of file loggerstartcommand.h.

Constructor & Destructor Documentation

◆ LoggerStartCommand()

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

Construct a new LoggerStartCommand object with parent.

Definition at line 23 of file loggerstartcommand.cpp.

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

Member Function Documentation

◆ getService()

AbstractPokitService * LoggerStartCommand::getService ( )
overrideprotectedvirtual

Returns a Pokit service object for the derived command class.

This override returns a pointer to a DataLoggerService object.

Implements DeviceCommand.

Definition at line 136 of file loggerstartcommand.cpp.

137{
138 Q_ASSERT(device);
139 if (!service) {
141 Q_ASSERT(service);
144 }
145 return service;
146}
void settingsWritten()
This signal is emitted when the Settings characteristic has been written successfully.
PokitDevice * device
Pokit Bluetooth device (if any) this command inerracts with.
void settingsWritten()
Invoked when the data logger settings have been written.
DataLoggerService * service
Bluetooth service this command interracts with.
DataLoggerService * dataLogger()
Returns a pointer to a DataLoggerService 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(), PokitDevice::dataLogger(), DeviceCommand::device, service, DataLoggerService::settingsWritten(), and settingsWritten().

Here is the call graph for this function:

◆ processOptions

QStringList LoggerStartCommand::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 50 of file loggerstartcommand.cpp.

51{
53 if (!errors.isEmpty()) {
54 return errors;
55 }
56
57 // Parse the (required) mode option.
58 const QString mode = parser.value(QLatin1String("mode")).trimmed().toLower();
59 if (mode.startsWith(QLatin1String("ac v")) || mode.startsWith(QLatin1String("vac"))) {
62 } else if (mode.startsWith(QLatin1String("dc v")) || mode.startsWith(QLatin1String("vdc"))) {
65 } else if (mode.startsWith(QLatin1String("ac c")) || mode.startsWith(QLatin1String("aac"))) {
68 } else if (mode.startsWith(QLatin1String("dc c")) || mode.startsWith(QLatin1String("adc"))) {
71 } else if (mode.startsWith(QLatin1String("temp"))) {
73 minRangeFunc = nullptr;
74 } else {
75 minRangeFunc = nullptr;
76 errors.append(tr("Unknown logger mode: %1").arg(parser.value(QLatin1String("mode"))));
77 return errors;
78 }
79
80 // Parse the range option.
82 if (parser.isSet(QLatin1String("range"))) {
83 const QString value = parser.value(QLatin1String("range"));
84 switch (settings.mode) {
87 rangeOptionValue = parseNumber<std::milli>(value, QLatin1String("V"), 50); // mV.
88 break;
91 rangeOptionValue = parseNumber<std::milli>(value, QLatin1String("A"), 5); // mA.
92 break;
93 default:
94 qCInfo(lc).noquote() << tr("Ignoring range value: %1").arg(value);
95 }
96 if ((minRangeFunc != nullptr) && (rangeOptionValue == 0)) {
97 errors.append(tr("Invalid range value: %1").arg(value));
98 }
100 errors.append(tr("Missing required option for logger mode '%1': range")
101 .arg(parser.value(QLatin1String("mode"))));
102 }
103
104 // Parse the interval option.
105 if (parser.isSet(QLatin1String("interval"))) {
106 const QString value = parser.value(QLatin1String("interval"));
107 const quint32 interval = parseNumber<std::milli>(value, QLatin1String("s"), 500);
108 if (interval == 0) {
109 errors.append(tr("Invalid interval value: %1").arg(value));
110 } else {
111 settings.updateInterval = interval;
112 }
113 }
114
115 // Parse the timestamp option.
116 settings.timestamp = (quint32)QDateTime::currentSecsSinceEpoch(); // Note, subject to Y2038 epochalypse.
117 if (parser.isSet(QLatin1String("timestamp"))) {
118 const QString value = parser.value(QLatin1String("timestamp"));
119 QLocale locale; bool ok;
120 static_assert(sizeof(uint) == sizeof(settings.timestamp), "QLocale has no toUint32().");
121 const int timestamp = locale.toUInt(value, &ok);
122 if (!ok) {
123 errors.append(tr("Invalid timestamp value: %1").arg(value));
124 } else {
125 settings.timestamp = timestamp;
126 }
127 }
128 return errors;
129}
virtual QStringList processOptions(const QCommandLineParser &parser)
Processes the relevant options from the command line parser.
@ DcVoltage
Measure DC voltage.
@ AcCurrent
Measure AC current.
@ AcVoltage
Measure AC voltage.
@ Temperature
Measure temperature.
@ DcCurrent
Measure DC current.
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),...
quint8(* minRangeFunc)(const PokitProduct product, const quint32 maxValue)
Pointer to function for converting rangeOptionValue to a Pokit device's range enumerator.
DataLoggerService::Settings settings
Settings for the Pokit device's data logger mode.
quint32 rangeOptionValue
The parsed value of range option.
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
QString tr(const char *sourceText, const char *disambiguation, int n)
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const const
QString toLower() const const
QString trimmed() const const
quint32 timestamp
Custom timestamp for start time in retrieved metadata.
Mode mode
Desired operation mode.
quint32 updateInterval
Desired update interval in milliseconds.

References DataLoggerService::AcCurrent, DataLoggerService::AcVoltage, QList::append(), QString::arg(), QDateTime::currentSecsSinceEpoch(), DataLoggerService::DcCurrent, DataLoggerService::DcVoltage, QList::isEmpty(), QCommandLineParser::isSet(), DeviceCommand::minCurrentRange(), minRangeFunc, DeviceCommand::minVoltageRange(), DataLoggerService::Settings::mode, AbstractCommand::processOptions(), rangeOptionValue, settings, QString::startsWith(), DataLoggerService::Temperature, DataLoggerService::Settings::timestamp, QString::toLower(), QLocale::toUInt(), QObject::tr(), QString::trimmed(), DataLoggerService::Settings::updateInterval, and QCommandLineParser::value().

Here is the call graph for this function:

◆ requiredOptions()

QStringList LoggerStartCommand::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 28 of file loggerstartcommand.cpp.

29{
31 QLatin1String("mode"),
32 };
33}
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 LoggerStartCommand::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 153 of file loggerstartcommand.cpp.

154{
155 DeviceCommand::serviceDetailsDiscovered(); // Just logs consistently.
158 qCInfo(lc).noquote() << tr("Logging %1, with range %2, every %L3ms.").arg(
160 (range.isNull()) ? QString::fromLatin1("N/A") : range).arg(settings.updateInterval);
162}
bool setSettings(const Settings &settings)
Configures the Pokit device's data logger mode.
static QString toString(const Mode &mode)
Returns mode as a user-friendly string.
virtual void serviceDetailsDiscovered()
Handles service detail discovery events.
QTPOKIT_EXPORT PokitProduct pokitProduct(const QBluetoothDeviceInfo &info)
Returns the PokitProduct corresponding the Bluetotoh device info.
QString fromLatin1(const char *str, int size)
bool isNull() const const

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

Here is the call graph for this function:

◆ settingsWritten

void LoggerStartCommand::settingsWritten ( )
privateslot

Invoked when the data logger settings have been written.

Definition at line 181 of file loggerstartcommand.cpp.

182{
183 qCDebug(lc).noquote() << tr("Settings written; data logger has started.");
184 switch (format) {
186 std::cout << qUtf8Printable(tr("logger_start_result\nsuccess\n"));
187 break;
189 std::cout << qUtf8Printable(QLatin1String("true\n"));
190 break;
192 std::cout << qUtf8Printable(tr("Done.\n"));
193 break;
194 }
195 if (device) disconnect(); // Will exit the application once disconnected.
196}
OutputFormat format
Selected output format.
@ Text
Plain unstructured text.
@ Csv
RFC 4180 compliant CSV text.
@ Json
RFC 8259 compliant JSON text.
void disconnect(int exitCode=EXIT_SUCCESS)
Disconnects the underlying Pokit device, and sets exitCode to be return to the OS once the disconnect...

References AbstractCommand::Csv, DeviceCommand::device, DeviceCommand::disconnect(), AbstractCommand::format, AbstractCommand::Json, AbstractCommand::Text, and QObject::tr().

Referenced by getService().

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

◆ supportedOptions()

QStringList LoggerStartCommand::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 35 of file loggerstartcommand.cpp.

36{
38 QLatin1String("interval"),
39 QLatin1String("range"), // May still be required by processOptions(), depending on the --mode option's value.
40 QLatin1String("timestamp"),
41 };
42}

References AbstractCommand::supportedOptions().

Here is the call graph for this function:

Friends And Related Symbol Documentation

◆ TestLoggerStartCommand

friend class TestLoggerStartCommand
friend

Definition at line 41 of file loggerstartcommand.h.

Member Data Documentation

◆ minRangeFunc

LoggerStartCommand::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 loggerstartcommand.h.

30{ nullptr };

Referenced by processOptions(), and serviceDetailsDiscovered().

◆ rangeOptionValue

quint32 LoggerStartCommand::rangeOptionValue { 0 }
private

The parsed value of range option.

Definition at line 31 of file loggerstartcommand.h.

31{ 0 }; ///< The parsed value of range option.

Referenced by processOptions(), and serviceDetailsDiscovered().

◆ service

DataLoggerService* LoggerStartCommand::service { nullptr }
private

Bluetooth service this command interracts with.

Definition at line 32 of file loggerstartcommand.h.

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

Referenced by getService(), and serviceDetailsDiscovered().

◆ settings

DataLoggerService::Settings LoggerStartCommand::settings
private
Initial value:

Settings for the Pokit device's data logger mode.

Definition at line 33 of file loggerstartcommand.h.

33 { ///< Settings for the Pokit device's data logger mode.
36 };

Referenced by processOptions(), and serviceDetailsDiscovered().


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