From f0e977f8c55f55b312c2244cb824cdcbfa758af2 Mon Sep 17 00:00:00 2001 From: andreidanila1 Date: Tue, 19 Nov 2024 15:56:43 +0200 Subject: [PATCH] pqm/pqmdatalogger: Rms data logging. Signed-off-by: andreidanila1 --- plugins/pqm/include/pqm/pqmdatalogger.h | 12 ++++- plugins/pqm/src/acquisitionmanager.cpp | 2 +- plugins/pqm/src/pqmdatalogger.cpp | 63 +++++++++++++++++++++---- 3 files changed, 64 insertions(+), 13 deletions(-) diff --git a/plugins/pqm/include/pqm/pqmdatalogger.h b/plugins/pqm/include/pqm/pqmdatalogger.h index aeccc4c4f..b8a0f960b 100644 --- a/plugins/pqm/include/pqm/pqmdatalogger.h +++ b/plugins/pqm/include/pqm/pqmdatalogger.h @@ -44,7 +44,7 @@ class PqmDataLogger : public QObject void setChnlsName(QStringList chnlsName); void acquireBufferData(double val, int chIdx); - void acquireAttrData(QString attrName, QString value, QString chId); + void acquireAttrData(QMap> pqmAttr); void acquirePqEvents(QString event); void log(); void writeToFile(); @@ -52,7 +52,9 @@ public Q_SLOTS: void logPressed(ActiveInstrument instr, const QString &filePath = ""); private: - void acquireHarmonics(QString attrName, QString value, QString chId); + void acquireHarmonics(QMap> pqmAttr); + void acquireRmsChnlAttr(QMap> pqmAttr); + void acquireRmsDeviceAttr(QMap> pqmAttr); void createHeader(); ActiveInstrument m_crtInstr; @@ -62,6 +64,12 @@ public Q_SLOTS: QQueue m_logQue; QFutureWatcher *m_writeFw; QMutex m_mutex; + const QString ATTR_HARMONICS = "harmonics"; + const QString PQM_DEVICE = "pqm"; + const QStringList m_rmsHeader{"rms", "angle", "deviation_under", "deviation_over", "pinst", "pst", "plt"}; + const QMap m_rmsDeviceAttr{ + {"voltage", {"u2", "u0", "sneg_voltage", "spos_voltage", "szro_voltage"}}, + {"current", {"i2", "i0", "sneg_current", "spos_current", "szro_current"}}}; }; } // namespace scopy::pqm diff --git a/plugins/pqm/src/acquisitionmanager.cpp b/plugins/pqm/src/acquisitionmanager.cpp index 5725b8dfd..303c41b27 100644 --- a/plugins/pqm/src/acquisitionmanager.cpp +++ b/plugins/pqm/src/acquisitionmanager.cpp @@ -172,9 +172,9 @@ bool AcquisitionManager::readPqmAttributes() attrName = iio_channel_get_attr(chnl, j); iio_channel_attr_read(chnl, attrName, dest, MAX_ATTR_SIZE); m_pqmAttr[chnlId][attrName] = QString(dest); - m_pqmLog->acquireAttrData(attrName, dest, chnlId); } } + m_pqmLog->acquireAttrData(m_pqmAttr); handlePQEvents(); m_pqmLog->log(); return true; diff --git a/plugins/pqm/src/pqmdatalogger.cpp b/plugins/pqm/src/pqmdatalogger.cpp index 82f5b8554..4a2d11033 100644 --- a/plugins/pqm/src/pqmdatalogger.cpp +++ b/plugins/pqm/src/pqmdatalogger.cpp @@ -63,20 +63,64 @@ void PqmDataLogger::acquireBufferData(double val, int chIdx) m_logQue.enqueue(QString::number(val) + ","); } -void PqmDataLogger::acquireHarmonics(QString attrName, QString value, QString chId) +void PqmDataLogger::acquireHarmonics(QMap> pqmAttr) { - if(attrName.compare("harmonics") != 0) { - return; + QMutexLocker locker(&m_mutex); + for(const QString &ch : qAsConst(m_chnlsName)) { + if(!pqmAttr[ch].contains(ATTR_HARMONICS)) { + continue; + } + QString harmonics = pqmAttr[ch][ATTR_HARMONICS]; + m_logQue.enqueue(QTime::currentTime().toString("hh:mm:ss.zzz") + "," + ch + "," + + harmonics.split(" ").join(",") + "\n"); } +} + +void PqmDataLogger::acquireRmsChnlAttr(QMap> pqmAttr) +{ QMutexLocker locker(&m_mutex); - m_logQue.enqueue(QTime::currentTime().toString("hh:mm:ss.zzz") + "," + chId + "," + value.split(" ").join(",") + - "\n"); + m_logQue.enqueue("Time,Phase," + m_rmsHeader.join(",") + "\n"); + for(const QString &ch : qAsConst(m_chnlsName)) { + m_logQue.enqueue(QTime::currentTime().toString("hh:mm:ss.zzz") + "," + ch + ","); + for(const QString &attr : m_rmsHeader) { + if(!pqmAttr[ch].contains(attr)) { + m_logQue.enqueue("-,"); + continue; + } + m_logQue.enqueue(pqmAttr[ch][attr] + ","); + } + m_logQue.enqueue("\n"); + } + m_logQue.enqueue("\n"); } -void PqmDataLogger::acquireAttrData(QString attrName, QString value, QString chId) +void PqmDataLogger::acquireRmsDeviceAttr(QMap> pqmAttr) +{ + QMutexLocker locker(&m_mutex); + for(auto it = m_rmsDeviceAttr.begin(); it != m_rmsDeviceAttr.end(); ++it) { + const QStringList attributes = it.value(); + m_logQue.enqueue(QTime::currentTime().toString("hh:mm:ss.zzz") + "," + it.key() + "," + + attributes.join(",") + "\n,,"); + for(const QString &attr : attributes) { + if(!pqmAttr[PQM_DEVICE].contains(attr)) { + m_logQue.enqueue("-,"); + continue; + } + m_logQue.enqueue(pqmAttr[PQM_DEVICE][attr] + ","); + } + m_logQue.enqueue("\n"); + } + m_logQue.enqueue("\n"); +} + +void PqmDataLogger::acquireAttrData(QMap> pqmAttr) { if(m_crtInstr == Harmonics) { - acquireHarmonics(attrName, value, chId); + acquireHarmonics(pqmAttr); + } + if(m_crtInstr == Rms) { + acquireRmsChnlAttr(pqmAttr); + acquireRmsDeviceAttr(pqmAttr); } } @@ -149,13 +193,12 @@ void PqmDataLogger::createHeader() QFile f(m_filePath); if(f.open(QIODevice::WriteOnly)) { QTextStream stream(&f); - stream << "Time ,"; switch(m_crtInstr) { case Waveform: - stream << m_chnlsName.join(","); + stream << "Time," << m_chnlsName.join(","); break; case Harmonics: - stream << "Phase ,"; + stream << "Time,Phase,"; for(int i = 0; i <= 50; i++) { stream << i << ","; }