Skip to content

Commit

Permalink
pqm/pqmdatalogger: Rms data logging.
Browse files Browse the repository at this point in the history
Signed-off-by: andreidanila1 <[email protected]>
  • Loading branch information
andreidanila1 committed Nov 19, 2024
1 parent 82197e4 commit f0e977f
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 13 deletions.
12 changes: 10 additions & 2 deletions plugins/pqm/include/pqm/pqmdatalogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,17 @@ 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<QString, QMap<QString, QString>> pqmAttr);
void acquirePqEvents(QString event);
void log();
void writeToFile();
public Q_SLOTS:
void logPressed(ActiveInstrument instr, const QString &filePath = "");

private:
void acquireHarmonics(QString attrName, QString value, QString chId);
void acquireHarmonics(QMap<QString, QMap<QString, QString>> pqmAttr);
void acquireRmsChnlAttr(QMap<QString, QMap<QString, QString>> pqmAttr);
void acquireRmsDeviceAttr(QMap<QString, QMap<QString, QString>> pqmAttr);
void createHeader();

ActiveInstrument m_crtInstr;
Expand All @@ -62,6 +64,12 @@ public Q_SLOTS:
QQueue<QString> m_logQue;
QFutureWatcher<void> *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<QString, QStringList> m_rmsDeviceAttr{
{"voltage", {"u2", "u0", "sneg_voltage", "spos_voltage", "szro_voltage"}},
{"current", {"i2", "i0", "sneg_current", "spos_current", "szro_current"}}};
};

} // namespace scopy::pqm
Expand Down
2 changes: 1 addition & 1 deletion plugins/pqm/src/acquisitionmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
63 changes: 53 additions & 10 deletions plugins/pqm/src/pqmdatalogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<QString, QMap<QString, QString>> 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<QString, QMap<QString, QString>> 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<QString, QMap<QString, QString>> 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<QString, QMap<QString, QString>> pqmAttr)
{
if(m_crtInstr == Harmonics) {
acquireHarmonics(attrName, value, chId);
acquireHarmonics(pqmAttr);
}
if(m_crtInstr == Rms) {
acquireRmsChnlAttr(pqmAttr);
acquireRmsDeviceAttr(pqmAttr);
}
}

Expand Down Expand Up @@ -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 << ",";
}
Expand Down

0 comments on commit f0e977f

Please sign in to comment.