From 70242359cdffc6463d010ef6ad3d45545b4106c6 Mon Sep 17 00:00:00 2001 From: "andrei.danila" Date: Wed, 26 Jun 2024 12:37:05 +0300 Subject: [PATCH] pqm: Change ping handle. Signed-off-by: andrei.danila --- plugins/pqm/include/pqm/acquisitionmanager.h | 3 +- plugins/pqm/src/acquisitionmanager.cpp | 36 +++++++++++++++----- plugins/pqm/src/pqmplugin.cpp | 3 ++ 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/plugins/pqm/include/pqm/acquisitionmanager.h b/plugins/pqm/include/pqm/acquisitionmanager.h index c210e0e9d9..dbf70fb3b2 100644 --- a/plugins/pqm/include/pqm/acquisitionmanager.h +++ b/plugins/pqm/include/pqm/acquisitionmanager.h @@ -45,6 +45,7 @@ private Q_SLOTS: bool readPqmAttributes(); bool readBufferedData(); void setData(QMap>); + void runPing(); iio_context *m_ctx; iio_buffer *m_buffer; @@ -53,6 +54,7 @@ private Q_SLOTS: PingTask *m_pingTask = nullptr; QFutureWatcher *m_readFw; QFutureWatcher *m_setFw; + std::mutex m_mutex; QVector m_chnlsName; QMap> m_pqmAttr; @@ -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 diff --git a/plugins/pqm/src/acquisitionmanager.cpp b/plugins/pqm/src/acquisitionmanager.cpp index 7d176a4534..64397eac93 100644 --- a/plugins/pqm/src/acquisitionmanager.cpp +++ b/plugins/pqm/src/acquisitionmanager.cpp @@ -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::finished, this, &AcquisitionManager::onReadFinished); - - m_dataRefreshTimer->start(); } else { qWarning(CAT_PQM_ACQ) << "The PQM device is not available!"; } @@ -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::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() { @@ -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() @@ -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) { @@ -255,4 +265,12 @@ void AcquisitionManager::setData(QMap> 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" diff --git a/plugins/pqm/src/pqmplugin.cpp b/plugins/pqm/src/pqmplugin.cpp index bb2623f6a6..dbd3288084 100644 --- a/plugins/pqm/src/pqmplugin.cpp +++ b/plugins/pqm/src/pqmplugin.cpp @@ -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 {