From da8f987ee9099f746f8d627edbd717892b2fb066 Mon Sep 17 00:00:00 2001 From: f4exb Date: Tue, 1 Nov 2022 19:40:00 +0100 Subject: [PATCH] TestMO source: Make settings assignments atomic. Part of #1329 --- plugins/samplemimo/testmosync/testmosync.cpp | 47 +++++++-------- plugins/samplemimo/testmosync/testmosync.h | 12 ++-- .../samplemimo/testmosync/testmosyncgui.cpp | 19 +++++- plugins/samplemimo/testmosync/testmosyncgui.h | 1 + .../testmosync/testmosyncsettings.cpp | 60 +++++++++++++++++++ .../testmosync/testmosyncsettings.h | 2 + 6 files changed, 109 insertions(+), 32 deletions(-) diff --git a/plugins/samplemimo/testmosync/testmosync.cpp b/plugins/samplemimo/testmosync/testmosync.cpp index 463eb2730..491bd74df 100644 --- a/plugins/samplemimo/testmosync/testmosync.cpp +++ b/plugins/samplemimo/testmosync/testmosync.cpp @@ -65,7 +65,7 @@ void TestMOSync::destroy() void TestMOSync::init() { - applySettings(m_settings, true); + applySettings(m_settings, QList(), true); } bool TestMOSync::startTx() @@ -143,12 +143,12 @@ bool TestMOSync::deserialize(const QByteArray& data) success = false; } - MsgConfigureTestMOSync* message = MsgConfigureTestMOSync::create(m_settings, true); + MsgConfigureTestMOSync* message = MsgConfigureTestMOSync::create(m_settings, QList(), true); m_inputMessageQueue.push(message); if (m_guiMessageQueue) { - MsgConfigureTestMOSync* messageToGUI = MsgConfigureTestMOSync::create(m_settings, true); + MsgConfigureTestMOSync* messageToGUI = MsgConfigureTestMOSync::create(m_settings, QList(), true); m_guiMessageQueue->push(messageToGUI); } @@ -197,12 +197,12 @@ void TestMOSync::setSinkCenterFrequency(qint64 centerFrequency, int index) TestMOSyncSettings settings = m_settings; settings.m_centerFrequency = centerFrequency; - MsgConfigureTestMOSync* message = MsgConfigureTestMOSync::create(settings, false); + MsgConfigureTestMOSync* message = MsgConfigureTestMOSync::create(settings, QList{"centerFrequency"}, false); m_inputMessageQueue.push(message); if (m_guiMessageQueue) { - MsgConfigureTestMOSync* messageToGUI = MsgConfigureTestMOSync::create(settings, false); + MsgConfigureTestMOSync* messageToGUI = MsgConfigureTestMOSync::create(settings, QList{"centerFrequency"}, false); m_guiMessageQueue->push(messageToGUI); } } @@ -214,7 +214,7 @@ bool TestMOSync::handleMessage(const Message& message) MsgConfigureTestMOSync& conf = (MsgConfigureTestMOSync&) message; qDebug() << "TestMOSync::handleMessage: MsgConfigureTestMOSync"; - bool success = applySettings(conf.getSettings(), conf.getForce()); + bool success = applySettings(conf.getSettings(), conf.getSettingsKeys(), conf.getForce()); if (!success) { qDebug("TestMOSync::handleMessage: config error"); @@ -259,30 +259,22 @@ void TestMOSync::setFeedSpectrumIndex(unsigned int feedSpectrumIndex) } } -bool TestMOSync::applySettings(const TestMOSyncSettings& settings, bool force) +bool TestMOSync::applySettings(const TestMOSyncSettings& settings, const QList& settingsKeys, bool force) { - QList reverseAPIKeys; + qDebug() << "TestMOSync::applySettings: force:" << force << settings.getDebugString(settingsKeys, force); bool forwardChangeTxDSP = false; - qDebug() << "TestMOSync::applySettings: common: " - << " m_sampleRate: " << settings.m_sampleRate - << " m_centerFrequency: " << settings.m_centerFrequency - << " m_log2Interp: " << settings.m_log2Interp - << " m_fcPosTx: " << settings.m_fcPosTx - << " force: " << force; - - if ((m_settings.m_centerFrequency != settings.m_centerFrequency) || force) - { + if (settingsKeys.contains("centerFrequency") || force) { forwardChangeTxDSP = true; } - if ((m_settings.m_sampleRate != settings.m_sampleRate) - || (m_settings.m_log2Interp != settings.m_log2Interp) || force) + if (settingsKeys.contains("sampleRate") + || settingsKeys.contains("log2Interp") || force) { m_sampleMOFifo.resize(SampleMOFifo::getSizePolicy(m_settings.m_sampleRate)); } - if ((m_settings.m_sampleRate != settings.m_sampleRate) || force) + if (settingsKeys.contains("sampleRate") || force) { if (m_sinkWorker) { m_sinkWorker->setSamplerate(settings.m_sampleRate); @@ -291,7 +283,7 @@ bool TestMOSync::applySettings(const TestMOSyncSettings& settings, bool force) forwardChangeTxDSP = true; } - if ((m_settings.m_fcPosTx != settings.m_fcPosTx) || force) + if (settingsKeys.contains("fcPosTx") || force) { if (m_sinkWorker) { m_sinkWorker->setFcPos((int) settings.m_fcPosTx); @@ -300,7 +292,7 @@ bool TestMOSync::applySettings(const TestMOSyncSettings& settings, bool force) forwardChangeTxDSP = true; } - if ((m_settings.m_log2Interp != settings.m_log2Interp) || force) + if (settingsKeys.contains("log2Interp") || force) { if (m_sinkWorker) { @@ -319,7 +311,12 @@ bool TestMOSync::applySettings(const TestMOSyncSettings& settings, bool force) m_deviceAPI->getDeviceEngineInputMessageQueue()->push(notif1); } - m_settings = settings; + if (force) { + m_settings = settings; + } else { + m_settings.applySettings(settingsKeys, settings); + } + return true; } @@ -392,12 +389,12 @@ int TestMOSync::webapiSettingsPutPatch( TestMOSyncSettings settings = m_settings; webapiUpdateDeviceSettings(settings, deviceSettingsKeys, response); - MsgConfigureTestMOSync *msg = MsgConfigureTestMOSync::create(settings, force); + MsgConfigureTestMOSync *msg = MsgConfigureTestMOSync::create(settings, deviceSettingsKeys, force); m_inputMessageQueue.push(msg); if (m_guiMessageQueue) // forward to GUI if any { - MsgConfigureTestMOSync *msgToGUI = MsgConfigureTestMOSync::create(settings, force); + MsgConfigureTestMOSync *msgToGUI = MsgConfigureTestMOSync::create(settings, deviceSettingsKeys, force); m_guiMessageQueue->push(msgToGUI); } diff --git a/plugins/samplemimo/testmosync/testmosync.h b/plugins/samplemimo/testmosync/testmosync.h index 11c1066f7..4f3bf3ba2 100644 --- a/plugins/samplemimo/testmosync/testmosync.h +++ b/plugins/samplemimo/testmosync/testmosync.h @@ -42,20 +42,22 @@ public: public: const TestMOSyncSettings& getSettings() const { return m_settings; } + const QList& getSettingsKeys() const { return m_settingsKeys; } bool getForce() const { return m_force; } - static MsgConfigureTestMOSync* create(const TestMOSyncSettings& settings, bool force) - { - return new MsgConfigureTestMOSync(settings, force); + static MsgConfigureTestMOSync* create(const TestMOSyncSettings& settings, const QList& settingsKeys, bool force) { + return new MsgConfigureTestMOSync(settings, settingsKeys, force); } private: TestMOSyncSettings m_settings; + QList m_settingsKeys; bool m_force; - MsgConfigureTestMOSync(const TestMOSyncSettings& settings, bool force) : + MsgConfigureTestMOSync(const TestMOSyncSettings& settings, const QList& settingsKeys, bool force) : Message(), m_settings(settings), + m_settingsKeys(settingsKeys), m_force(force) { } }; @@ -162,7 +164,7 @@ private: void startWorker(); void stopWorker(); - bool applySettings(const TestMOSyncSettings& settings, bool force); + bool applySettings(const TestMOSyncSettings& settings, const QList& settingsKeys, bool force); }; #endif // PLUGINS_SAMPLEMIMO_TESTMOSYNC_TESTMOSYNC_H_ diff --git a/plugins/samplemimo/testmosync/testmosyncgui.cpp b/plugins/samplemimo/testmosync/testmosyncgui.cpp index 5a8beee48..d7f00396b 100644 --- a/plugins/samplemimo/testmosync/testmosyncgui.cpp +++ b/plugins/samplemimo/testmosync/testmosyncgui.cpp @@ -103,6 +103,7 @@ void TestMOSyncGui::resetToDefaults() { m_settings.resetToDefaults(); displaySettings(); + m_forceSettings = true; sendSettings(); } @@ -154,7 +155,13 @@ bool TestMOSyncGui::handleMessage(const Message& message) { qDebug("TestMOSyncGui::handleMessage: message: MsgConfigureTestMOSync"); const TestMOSync::MsgConfigureTestMOSync& cfg = (TestMOSync::MsgConfigureTestMOSync&) message; - m_settings = cfg.getSettings(); + + if (cfg.getForce()) { + m_settings = cfg.getSettings(); + } else { + m_settings.applySettings(cfg.getSettingsKeys(), cfg.getSettings()); + } + blockApplySettings(true); displaySettings(); blockApplySettings(false); @@ -212,9 +219,10 @@ void TestMOSyncGui::updateHardware() if (m_doApplySettings) { qDebug() << "TestMOSyncGui::updateHardware"; - TestMOSync::MsgConfigureTestMOSync* message = TestMOSync::MsgConfigureTestMOSync::create(m_settings, m_forceSettings); + TestMOSync::MsgConfigureTestMOSync* message = TestMOSync::MsgConfigureTestMOSync::create(m_settings, m_settingsKeys, m_forceSettings); m_sampleMIMO->getInputMessageQueue()->push(message); m_forceSettings = false; + m_settingsKeys.clear(); m_updateTimer.stop(); } } @@ -252,6 +260,7 @@ void TestMOSyncGui::on_centerFrequency_changed(quint64 value) { m_settings.m_centerFrequency = value * 1000; ui->glSpectrum->setCenterFrequency(m_settings.m_centerFrequency); + m_settingsKeys.append("centerFrequency"); sendSettings(); } @@ -259,6 +268,7 @@ void TestMOSyncGui::on_sampleRate_changed(quint64 value) { m_settings.m_sampleRate = value; ui->glSpectrum->setSampleRate(m_settings.m_sampleRate*(1<glSpectrum->setSampleRate(m_settings.m_sampleRate*(1< m_settingsKeys; QTimer m_updateTimer; QTimer m_statusTimer; TestMOSync* m_sampleMIMO; diff --git a/plugins/samplemimo/testmosync/testmosyncsettings.cpp b/plugins/samplemimo/testmosync/testmosyncsettings.cpp index 020551f31..d682a7a2c 100644 --- a/plugins/samplemimo/testmosync/testmosyncsettings.cpp +++ b/plugins/samplemimo/testmosync/testmosyncsettings.cpp @@ -92,3 +92,63 @@ bool TestMOSyncSettings::deserialize(const QByteArray& data) return false; } } + +void TestMOSyncSettings::applySettings(const QStringList& settingsKeys, const TestMOSyncSettings& settings) +{ + if (settingsKeys.contains("centerFrequency")) { + m_centerFrequency = settings.m_centerFrequency; + } + if (settingsKeys.contains("sampleRate")) { + m_sampleRate = settings.m_sampleRate; + } + if (settingsKeys.contains("log2Interp")) { + m_log2Interp = settings.m_log2Interp; + } + if (settingsKeys.contains("fcPosTx")) { + m_fcPosTx = settings.m_fcPosTx; + } + if (settingsKeys.contains("useReverseAPI")) { + m_useReverseAPI = settings.m_useReverseAPI; + } + if (settingsKeys.contains("reverseAPIAddress")) { + m_reverseAPIAddress = settings.m_reverseAPIAddress; + } + if (settingsKeys.contains("reverseAPIPort")) { + m_reverseAPIPort = settings.m_reverseAPIPort; + } + if (settingsKeys.contains("reverseAPIDeviceIndex")) { + m_reverseAPIDeviceIndex = settings.m_reverseAPIDeviceIndex; + } +} + +QString TestMOSyncSettings::getDebugString(const QStringList& settingsKeys, bool force) const +{ + std::ostringstream ostr; + + if (settingsKeys.contains("centerFrequency") || force) { + ostr << " m_centerFrequency: " << m_centerFrequency; + } + if (settingsKeys.contains("sampleRate") || force) { + ostr << " m_sampleRate: " << m_sampleRate; + } + if (settingsKeys.contains("log2Interp") || force) { + ostr << " m_log2Interp: " << m_log2Interp; + } + if (settingsKeys.contains("fcPosTx") || force) { + ostr << " m_fcPosTx: " << m_fcPosTx; + } + if (settingsKeys.contains("useReverseAPI") || force) { + ostr << " m_useReverseAPI: " << m_useReverseAPI; + } + if (settingsKeys.contains("reverseAPIAddress") || force) { + ostr << " m_reverseAPIAddress: " << m_reverseAPIAddress.toStdString(); + } + if (settingsKeys.contains("reverseAPIPort") || force) { + ostr << " m_reverseAPIPort: " << m_reverseAPIPort; + } + if (settingsKeys.contains("reverseAPIDeviceIndex") || force) { + ostr << " m_reverseAPIDeviceIndex: " << m_reverseAPIDeviceIndex; + } + + return QString(ostr.str().c_str()); +} diff --git a/plugins/samplemimo/testmosync/testmosyncsettings.h b/plugins/samplemimo/testmosync/testmosyncsettings.h index 31cbe3774..aab9e60c1 100644 --- a/plugins/samplemimo/testmosync/testmosyncsettings.h +++ b/plugins/samplemimo/testmosync/testmosyncsettings.h @@ -40,6 +40,8 @@ struct TestMOSyncSettings { void resetToDefaults(); QByteArray serialize() const; bool deserialize(const QByteArray& data); + void applySettings(const QStringList& settingsKeys, const TestMOSyncSettings& settings); + QString getDebugString(const QStringList& settingsKeys, bool force=false) const; }; #endif /* PLUGINS_SAMPLEMIMO_TESTMOSYNC_TESTMOSYNCSETTINGS_H_ */