Skip to content

Commit

Permalink
pqm: Change ping handle.
Browse files Browse the repository at this point in the history
Signed-off-by: andrei.danila <[email protected]>
  • Loading branch information
andreidanila1 committed Jun 26, 2024
1 parent 0cea353 commit 7024235
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
3 changes: 2 additions & 1 deletion plugins/pqm/include/pqm/acquisitionmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ private Q_SLOTS:
bool readPqmAttributes();
bool readBufferedData();
void setData(QMap<QString, QMap<QString, QString>>);
void runPing();

iio_context *m_ctx;
iio_buffer *m_buffer;
Expand All @@ -53,6 +54,7 @@ private Q_SLOTS:
PingTask *m_pingTask = nullptr;
QFutureWatcher<void> *m_readFw;
QFutureWatcher<void> *m_setFw;
std::mutex m_mutex;

QVector<QString> m_chnlsName;
QMap<QString, QMap<QString, QString>> m_pqmAttr;
Expand All @@ -61,7 +63,6 @@ private Q_SLOTS:

bool m_attrHaveBeenRead = false;
bool m_buffHaveBeenRead = false;
bool m_enPing = false;
const int THREAD_FINISH_TIMEOUT = 10000;
};
} // namespace scopy::pqm
Expand Down
36 changes: 27 additions & 9 deletions plugins/pqm/src/acquisitionmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ AcquisitionManager::AcquisitionManager(iio_context *ctx, PingTask *pingTask, QOb
m_pingTimer->setInterval(2000);
connect(m_pingTimer, &QTimer::timeout, this, &AcquisitionManager::pingTimerTimeout);
connect(m_readFw, &QFutureWatcher<void>::finished, this, &AcquisitionManager::onReadFinished);

m_dataRefreshTimer->start();
} else {
qWarning(CAT_PQM_ACQ) << "The PQM device is not available!";
}
Expand Down Expand Up @@ -81,7 +79,22 @@ void AcquisitionManager::enableBufferChnls(iio_device *dev)
}
}

void AcquisitionManager::toolEnabled(bool en, QString toolName) { m_tools[toolName] = en; }
void AcquisitionManager::toolEnabled(bool en, QString toolName)
{
m_tools[toolName] = en;
QMap<QString, bool>::const_iterator it = std::find(m_tools.cbegin(), m_tools.cend(), true);
if(!m_dataRefreshTimer) {
qWarning(CAT_PQM_ACQ) << "Unable to start data acquisition!";
return;
}
if(it != m_tools.cend()) {
if(!m_dataRefreshTimer->isActive()) {
m_dataRefreshTimer->start();
}
} else {
m_dataRefreshTimer->stop();
}
}

void AcquisitionManager::futureReadData()
{
Expand All @@ -93,17 +106,14 @@ void AcquisitionManager::futureReadData()

void AcquisitionManager::readData()
{
if(m_enPing) {
m_pingTask->start();
m_pingTask->wait(THREAD_FINISH_TIMEOUT);
m_enPing = false;
}
m_mutex.lock();
if(m_tools["rms"] || m_tools["harmonics"] || m_tools["settings"]) {
m_attrHaveBeenRead = readPqmAttributes();
}
if(m_tools["waveform"]) {
m_buffHaveBeenRead = readBufferedData();
}
m_mutex.unlock();
}

bool AcquisitionManager::readPqmAttributes()
Expand Down Expand Up @@ -180,7 +190,7 @@ void AcquisitionManager::onReadFinished()
}
}

void AcquisitionManager::pingTimerTimeout() { m_enPing = true; }
void AcquisitionManager::pingTimerTimeout() { QtConcurrent::run(this, &AcquisitionManager::runPing); }

int AcquisitionManager::readGetNewMeasurement(iio_device *dev)
{
Expand Down Expand Up @@ -255,4 +265,12 @@ void AcquisitionManager::setData(QMap<QString, QMap<QString, QString>> attr)
m_readFw->resume();
}

void AcquisitionManager::runPing()
{
m_mutex.lock();
m_pingTask->start();
m_pingTask->wait(THREAD_FINISH_TIMEOUT);
m_mutex.unlock();
}

#include "moc_acquisitionmanager.cpp"
3 changes: 3 additions & 0 deletions plugins/pqm/src/pqmplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ void PQMPlugin::stopPingTask() { m_acqManager->stopPing(); }

void PQMPlugin::onPausePingTask(bool pause)
{
if(!m_acqManager) {
return;
}
if(pause) {
m_acqManager->stopPing();
} else {
Expand Down

0 comments on commit 7024235

Please sign in to comment.