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

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

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

Public Member Functions

 LoggerFetchCommand (QObject *const parent=nullptr)
 Construct a new LoggerFetchCommand object with parent.
 
- 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.
 
virtual QStringList requiredOptions (const QCommandLineParser &parser) const
 Returns a list of CLI option names required by this command.
 
virtual QStringList supportedOptions (const QCommandLineParser &parser) const
 Returns a list of CLI option names supported by this command.
 
- 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 metadataRead (const DataLoggerService::Metadata &data)
 Invoked when metadata has been received from the data logger.
 
void outputSamples (const DataLoggerService::Samples &samples)
 Outputs logger samples in the selected ouput format.
 

Private Attributes

DataLoggerServiceservice { nullptr }
 Bluetooth service this command interracts with.
 
DataLoggerService::Metadata metadata
 Most recent data logging metadata.
 
qint32 samplesToGo { 0 }
 Number of samples we're still expecting to receive.
 
quint64 timestamp { 0 }
 Current sample's epoch milliseconds timestamp.
 
bool showCsvHeader { true }
 Whether or not to show a header as the first line of CSV output.
 

Friends

class TestLoggerFetchCommand
 

Additional Inherited Members

- Public Types inherited from AbstractCommand
enum class  OutputFormat { Csv , Json , Text }
 Supported output formats. More...
 
- 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.
 
- 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 interracts 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 LoggerFetchCommand class implements the logger CLI command.

Definition at line 8 of file loggerfetchcommand.h.

Constructor & Destructor Documentation

◆ LoggerFetchCommand()

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

Construct a new LoggerFetchCommand object with parent.

Definition at line 32 of file loggerfetchcommand.cpp.

33{
34
35}
DeviceCommand(QObject *const parent=nullptr)
Construct a new DeviceCommand object with parent.
QObject * parent() const const

Member Function Documentation

◆ getService()

AbstractPokitService * LoggerFetchCommand::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 42 of file loggerfetchcommand.cpp.

43{
44 Q_ASSERT(device);
45 if (!service) {
47 Q_ASSERT(service);
50 }
51 return service;
52}
void samplesRead(const DataLoggerService::Samples &samples)
This signal is emitted when the Reading characteristic has been notified.
void metadataRead(const DataLoggerService::Metadata &meta)
This signal is emitted when the Metadata characteristic has been read successfully.
PokitDevice * device
Pokit Bluetooth device (if any) this command interracts with.
DataLoggerService * service
Bluetooth service this command interracts with.
void outputSamples(const DataLoggerService::Samples &samples)
Outputs logger samples in the selected ouput format.
void metadataRead(const DataLoggerService::Metadata &data)
Invoked when metadata has been received from the data logger.
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, DataLoggerService::metadataRead(), metadataRead(), outputSamples(), DataLoggerService::samplesRead(), and service.

Here is the call graph for this function:

◆ metadataRead

void LoggerFetchCommand::metadataRead ( const DataLoggerService::Metadata & data)
privateslot

Invoked when metadata has been received from the data logger.

Definition at line 71 of file loggerfetchcommand.cpp.

72{
73 qCDebug(lc) << "status:" << (int)(data.status);
74 qCDebug(lc) << "scale:" << data.scale;
75 qCDebug(lc) << "mode:" << DataLoggerService::toString(data.mode) << (quint8)data.mode;
76 qCDebug(lc) << "range:" << service->toString(data.range, data.mode) << data.range;
77 qCDebug(lc) << "updateInterval:" << (int)data.updateInterval;
78 qCDebug(lc) << "numberOfSamples:" << data.numberOfSamples;
79 qCDebug(lc) << "timestamp:" << data.timestamp << QDateTime::fromSecsSinceEpoch(data.timestamp, DOKIT_QT_UTC);
80 this->metadata = data;
81 this->samplesToGo = data.numberOfSamples;
82 this->timestamp = (quint64)data.timestamp * (quint64)1000;
83 qCInfo(lc).noquote() << tr("Fetching %Ln logger sample/s...", nullptr, data.numberOfSamples);
84}
static QString toString(const Mode &mode)
Returns mode as a user-friendly string.
qint32 samplesToGo
Number of samples we're still expecting to receive.
DataLoggerService::Metadata metadata
Most recent data logging metadata.
quint64 timestamp
Current sample's epoch milliseconds timestamp.
QDateTime fromSecsSinceEpoch(qint64 secs, Qt::TimeSpec spec, int offsetSeconds)
QString tr(const char *sourceText, const char *disambiguation, int n)
quint16 numberOfSamples
Number of samples acquired (1 to 6192).
quint32 timestamp
Timestamp stored at the beginning of the logging session.
float scale
Scale to apply to read samples.
LoggerStatus status
Current data logger status.
quint32 updateInterval
Current logging interval in milliseconds.
Mode mode
Current operation mode.

References QDateTime::fromSecsSinceEpoch(), metadata, DataLoggerService::Metadata::mode, DataLoggerService::Metadata::numberOfSamples, DataLoggerService::Metadata::range, samplesToGo, DataLoggerService::Metadata::scale, service, DataLoggerService::Metadata::status, DataLoggerService::Metadata::timestamp, timestamp, DataLoggerService::toString(), QObject::tr(), and DataLoggerService::Metadata::updateInterval.

Referenced by getService().

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

◆ outputSamples

void LoggerFetchCommand::outputSamples ( const DataLoggerService::Samples & samples)
privateslot

Outputs logger samples in the selected ouput format.

Definition at line 89 of file loggerfetchcommand.cpp.

90{
91 QString unit;
92 switch (metadata.mode) {
93 case DataLoggerService::Mode::DcVoltage: unit = QLatin1String("Vdc"); break;
94 case DataLoggerService::Mode::AcVoltage: unit = QLatin1String("Vac"); break;
95 case DataLoggerService::Mode::DcCurrent: unit = QLatin1String("Adc"); break;
96 case DataLoggerService::Mode::AcCurrent: unit = QLatin1String("Aac"); break;
98 default:
99 qCDebug(lc).noquote() << tr(R"(No known unit for mode %1 "%2".)").arg((int)metadata.mode)
101 }
103
104 for (const qint16 &sample: samples) {
105 const QString timeString = (metadata.timestamp == 0) ? QString::number(timestamp)
107 const float value = sample * metadata.scale;
108 switch (format) {
110 for (; showCsvHeader; showCsvHeader = false) {
111 std::cout << qUtf8Printable(tr("timestamp,value,unit,range\n"));
112 }
113 std::cout << qUtf8Printable(QString::fromLatin1("%1,%2,%3,%4\n")
114 .arg(timeString).arg(value).arg(unit, range));
115 break;
116 case OutputFormat::Json: {
117 QJsonObject object{
118 { QLatin1String("timestamp"), timeString },
119 { QLatin1String("value"), value },
120 { QLatin1String("unit"), unit },
122 };
123 if (!range.isEmpty()) {
124 object.insert(QLatin1String("range"), range);
125 }
126 std::cout << QJsonDocument(object).toJson().toStdString();
127 } break;
129 std::cout << qUtf8Printable(tr("%1 %2 %3\n").arg(timeString).arg(value).arg(unit));
130 break;
131 }
133 --samplesToGo;
134 }
135 if (samplesToGo <= 0) {
136 qCInfo(lc).noquote() << tr("Finished fetching %Ln sample/s (with %L1 remaining).",
138 if (device) disconnect(); // Will exit the application once disconnected.
139 }
140}
OutputFormat format
Selected output format.
@ Text
Plain unstructured text.
@ Csv
RFC 4180 compliant CSV text.
@ Json
RFC 8259 compliant JSON text.
@ DcVoltage
Measure DC voltage.
@ AcCurrent
Measure AC current.
@ AcVoltage
Measure AC voltage.
@ Temperature
Measure temperature.
@ DcCurrent
Measure DC current.
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.
std::string toStdString() const const
QDateTime fromMSecsSinceEpoch(qint64 msecs)
QString toString(Qt::DateFormat format) const const
QByteArray toJson() const const
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 isEmpty() const const
QString number(int n, int base)
ISODateWithMs

References DataLoggerService::AcCurrent, DataLoggerService::AcVoltage, QString::arg(), AbstractCommand::Csv, DataLoggerService::DcCurrent, DataLoggerService::DcVoltage, DeviceCommand::device, DeviceCommand::disconnect(), AbstractCommand::format, QString::fromLatin1(), QDateTime::fromMSecsSinceEpoch(), QString::fromUtf8(), QString::insert(), QString::isEmpty(), Qt::ISODateWithMs, AbstractCommand::Json, metadata, DataLoggerService::Metadata::mode, QString::number(), DataLoggerService::Metadata::numberOfSamples, DataLoggerService::Metadata::range, samplesToGo, DataLoggerService::Metadata::scale, service, showCsvHeader, DataLoggerService::Temperature, AbstractCommand::Text, DataLoggerService::Metadata::timestamp, timestamp, QJsonDocument::toJson(), QByteArray::toStdString(), DataLoggerService::toString(), QDateTime::toString(), QObject::tr(), and DataLoggerService::Metadata::updateInterval.

Referenced by getService().

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

◆ serviceDetailsDiscovered

void LoggerFetchCommand::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 59 of file loggerfetchcommand.cpp.

60{
61 DeviceCommand::serviceDetailsDiscovered(); // Just logs consistently.
62 qCInfo(lc).noquote() << tr("Fetching logger samples...");
66}
bool enableMetadataNotifications()
Enables client-side notifications of Data Logger metadata changes.
bool enableReadingNotifications()
Enables client-side notifications of Data Logger readings.
bool fetchSamples()
Start the data logger.
virtual void serviceDetailsDiscovered()
Handles service detail discovery events.

References DataLoggerService::enableMetadataNotifications(), DataLoggerService::enableReadingNotifications(), DataLoggerService::fetchSamples(), service, DeviceCommand::serviceDetailsDiscovered(), and QObject::tr().

Here is the call graph for this function:

Friends And Related Symbol Documentation

◆ TestLoggerFetchCommand

friend class TestLoggerFetchCommand
friend

Definition at line 32 of file loggerfetchcommand.h.

Member Data Documentation

◆ metadata

DataLoggerService::Metadata LoggerFetchCommand::metadata
private

Most recent data logging metadata.

Definition at line 23 of file loggerfetchcommand.h.

Referenced by metadataRead(), and outputSamples().

◆ samplesToGo

qint32 LoggerFetchCommand::samplesToGo { 0 }
private

Number of samples we're still expecting to receive.

Definition at line 24 of file loggerfetchcommand.h.

24{ 0 }; ///< Number of samples we're still expecting to receive.

Referenced by metadataRead(), and outputSamples().

◆ service

DataLoggerService* LoggerFetchCommand::service { nullptr }
private

Bluetooth service this command interracts with.

Definition at line 22 of file loggerfetchcommand.h.

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

Referenced by getService(), metadataRead(), outputSamples(), and serviceDetailsDiscovered().

◆ showCsvHeader

bool LoggerFetchCommand::showCsvHeader { true }
private

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

Definition at line 26 of file loggerfetchcommand.h.

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

Referenced by outputSamples().

◆ timestamp

quint64 LoggerFetchCommand::timestamp { 0 }
private

Current sample's epoch milliseconds timestamp.

Definition at line 25 of file loggerfetchcommand.h.

25{ 0 }; ///< Current sample's epoch milliseconds timestamp.

Referenced by metadataRead(), and outputSamples().


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