diff --git a/plugins/samplesource/localinput/localinput.cpp b/plugins/samplesource/localinput/localinput.cpp index 90d724021e..8c1ec680b4 100644 --- a/plugins/samplesource/localinput/localinput.cpp +++ b/plugins/samplesource/localinput/localinput.cpp @@ -77,7 +77,7 @@ void LocalInput::destroy() void LocalInput::init() { - applySettings(m_settings, true); + applySettings(m_settings, QList(), true); } bool LocalInput::start() @@ -106,12 +106,12 @@ bool LocalInput::deserialize(const QByteArray& data) success = false; } - MsgConfigureLocalInput* message = MsgConfigureLocalInput::create(m_settings, true); + MsgConfigureLocalInput* message = MsgConfigureLocalInput::create(m_settings, QList(), true); m_inputMessageQueue.push(message); if (m_guiMessageQueue) { - MsgConfigureLocalInput* messageToGUI = MsgConfigureLocalInput::create(m_settings, true); + MsgConfigureLocalInput* messageToGUI = MsgConfigureLocalInput::create(m_settings, QList(), true); m_guiMessageQueue->push(messageToGUI); } @@ -195,7 +195,7 @@ bool LocalInput::handleMessage(const Message& message) { qDebug() << "LocalInput::handleMessage:" << message.getIdentifier(); MsgConfigureLocalInput& conf = (MsgConfigureLocalInput&) message; - applySettings(conf.getSettings(), conf.getForce()); + applySettings(conf.getSettings(), conf.getSettingsKeys(), conf.getForce()); return true; } else @@ -204,21 +204,14 @@ bool LocalInput::handleMessage(const Message& message) } } -void LocalInput::applySettings(const LocalInputSettings& settings, bool force) +void LocalInput::applySettings(const LocalInputSettings& settings, const QList& settingsKeys, bool force) { + qDebug() << "LocalInput::applySettings: force: " << force << settings.getDebugString(settingsKeys, force); QMutexLocker mutexLocker(&m_mutex); std::ostringstream os; QString remoteAddress; - QList reverseAPIKeys; - if ((m_settings.m_dcBlock != settings.m_dcBlock) || force) { - reverseAPIKeys.append("dcBlock"); - } - if ((m_settings.m_iqCorrection != settings.m_iqCorrection) || force) { - reverseAPIKeys.append("iqCorrection"); - } - - if ((m_settings.m_dcBlock != settings.m_dcBlock) || (m_settings.m_iqCorrection != settings.m_iqCorrection) || force) + if (settingsKeys.contains("dcBlock") || settingsKeys.contains("iqCorrection") || force) { m_deviceAPI->configureCorrections(settings.m_dcBlock, settings.m_iqCorrection); qDebug("LocalInput::applySettings: corrections: DC block: %s IQ imbalance: %s", @@ -228,22 +221,22 @@ void LocalInput::applySettings(const LocalInputSettings& settings, bool force) mutexLocker.unlock(); - if (settings.m_useReverseAPI) + if (settingsKeys.contains("useReverseAPI")) { - bool fullUpdate = ((m_settings.m_useReverseAPI != settings.m_useReverseAPI) && settings.m_useReverseAPI) || - (m_settings.m_reverseAPIAddress != settings.m_reverseAPIAddress) || - (m_settings.m_reverseAPIPort != settings.m_reverseAPIPort) || - (m_settings.m_reverseAPIDeviceIndex != settings.m_reverseAPIDeviceIndex); - webapiReverseSendSettings(reverseAPIKeys, settings, fullUpdate || force); + bool fullUpdate = (settingsKeys.contains("useReverseAPI") && settings.m_useReverseAPI) || + settingsKeys.contains("reverseAPIAddress") || + settingsKeys.contains("reverseAPIPort") || + settingsKeys.contains("reverseAPIDeviceIndex"); + webapiReverseSendSettings(settingsKeys, settings, fullUpdate || force); } - m_settings = settings; - m_remoteAddress = remoteAddress; + if (force) { + m_settings = settings; + } else { + m_settings.applySettings(settingsKeys, settings); + } - qDebug() << "LocalInput::applySettings: " - << " m_dcBlock: " << m_settings.m_dcBlock - << " m_iqCorrection: " << m_settings.m_iqCorrection - << " m_remoteAddress: " << m_remoteAddress; + m_remoteAddress = remoteAddress; } int LocalInput::webapiRunGet( @@ -295,12 +288,12 @@ int LocalInput::webapiSettingsPutPatch( LocalInputSettings settings = m_settings; webapiUpdateDeviceSettings(settings, deviceSettingsKeys, response); - MsgConfigureLocalInput *msg = MsgConfigureLocalInput::create(settings, force); + MsgConfigureLocalInput *msg = MsgConfigureLocalInput::create(settings, deviceSettingsKeys, force); m_inputMessageQueue.push(msg); if (m_guiMessageQueue) // forward to GUI if any { - MsgConfigureLocalInput *msgToGUI = MsgConfigureLocalInput::create(settings, force); + MsgConfigureLocalInput *msgToGUI = MsgConfigureLocalInput::create(settings, deviceSettingsKeys, force); m_guiMessageQueue->push(msgToGUI); } @@ -367,7 +360,7 @@ void LocalInput::webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& response response.getLocalInputReport()->setSampleRate(m_sampleRate); } -void LocalInput::webapiReverseSendSettings(QList& deviceSettingsKeys, const LocalInputSettings& settings, bool force) +void LocalInput::webapiReverseSendSettings(const QList& deviceSettingsKeys, const LocalInputSettings& settings, bool force) { SWGSDRangel::SWGDeviceSettings *swgDeviceSettings = new SWGSDRangel::SWGDeviceSettings(); swgDeviceSettings->setDirection(0); // single Rx diff --git a/plugins/samplesource/localinput/localinput.h b/plugins/samplesource/localinput/localinput.h index 8a01571d99..64ea4490e6 100644 --- a/plugins/samplesource/localinput/localinput.h +++ b/plugins/samplesource/localinput/localinput.h @@ -43,20 +43,23 @@ class LocalInput : public DeviceSampleSource { public: const LocalInputSettings& getSettings() const { return m_settings; } + const QList& getSettingsKeys() const { return m_settingsKeys; } bool getForce() const { return m_force; } - static MsgConfigureLocalInput* create(const LocalInputSettings& settings, bool force = false) + static MsgConfigureLocalInput* create(const LocalInputSettings& settings, const QList& settingsKeys, bool force = false) { - return new MsgConfigureLocalInput(settings, force); + return new MsgConfigureLocalInput(settings, settingsKeys, force); } private: LocalInputSettings m_settings; + QList m_settingsKeys; bool m_force; - MsgConfigureLocalInput(const LocalInputSettings& settings, bool force) : + MsgConfigureLocalInput(const LocalInputSettings& settings, const QList& settingsKeys, bool force) : Message(), m_settings(settings), + m_settingsKeys(settingsKeys), m_force(force) { } }; @@ -165,9 +168,9 @@ class LocalInput : public DeviceSampleSource { QNetworkAccessManager *m_networkManager; QNetworkRequest m_networkRequest; - void applySettings(const LocalInputSettings& settings, bool force = false); + void applySettings(const LocalInputSettings& settings, const QList& settingsKeys, bool force = false); void webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& response); - void webapiReverseSendSettings(QList& deviceSettingsKeys, const LocalInputSettings& settings, bool force); + void webapiReverseSendSettings(const QList& deviceSettingsKeys, const LocalInputSettings& settings, bool force); void webapiReverseSendStartStop(bool start); private slots: diff --git a/plugins/samplesource/localinput/localinputgui.cpp b/plugins/samplesource/localinput/localinputgui.cpp index b37a63b754..b3f6da06dc 100644 --- a/plugins/samplesource/localinput/localinputgui.cpp +++ b/plugins/samplesource/localinput/localinputgui.cpp @@ -157,7 +157,13 @@ bool LocalInputGui::handleMessage(const Message& message) if (LocalInput::MsgConfigureLocalInput::match(message)) { const LocalInput::MsgConfigureLocalInput& cfg = (LocalInput::MsgConfigureLocalInput&) 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); @@ -255,12 +261,14 @@ void LocalInputGui::sendSettings() void LocalInputGui::on_dcOffset_toggled(bool checked) { m_settings.m_dcBlock = checked; + m_settingsKeys.append("dcBlock"); sendSettings(); } void LocalInputGui::on_iqImbalance_toggled(bool checked) { m_settings.m_iqCorrection = checked; + m_settingsKeys.append("iqCorrection"); sendSettings(); } @@ -279,9 +287,10 @@ void LocalInputGui::updateHardware() { qDebug() << "LocalInputGui::updateHardware"; LocalInput::MsgConfigureLocalInput* message = - LocalInput::MsgConfigureLocalInput::create(m_settings, m_forceSettings); + LocalInput::MsgConfigureLocalInput::create(m_settings, m_settingsKeys, m_forceSettings); m_sampleSource->getInputMessageQueue()->push(message); m_forceSettings = false; + m_settingsKeys.clear(); m_updateTimer.stop(); } } @@ -332,6 +341,10 @@ void LocalInputGui::openDeviceSettingsDialog(const QPoint& p) m_settings.m_reverseAPIAddress = dialog.getReverseAPIAddress(); m_settings.m_reverseAPIPort = dialog.getReverseAPIPort(); m_settings.m_reverseAPIDeviceIndex = dialog.getReverseAPIDeviceIndex(); + m_settingsKeys.append("useReverseAPI"); + m_settingsKeys.append("reverseAPIAddress"); + m_settingsKeys.append("reverseAPIPort"); + m_settingsKeys.append("reverseAPIDeviceIndex"); sendSettings(); } diff --git a/plugins/samplesource/localinput/localinputgui.h b/plugins/samplesource/localinput/localinputgui.h index 11ef79cc83..bdafb77b7e 100644 --- a/plugins/samplesource/localinput/localinputgui.h +++ b/plugins/samplesource/localinput/localinputgui.h @@ -54,6 +54,7 @@ class LocalInputGui : public DeviceGUI { Ui::LocalInputGui* ui; LocalInputSettings m_settings; //!< current settings + QList m_settingsKeys; LocalInput* m_sampleSource; bool m_acquisition; int m_streamSampleRate; //!< Sample rate of received stream diff --git a/plugins/samplesource/localinput/localinputsettings.cpp b/plugins/samplesource/localinput/localinputsettings.cpp index f567857ab3..9e3505af72 100644 --- a/plugins/samplesource/localinput/localinputsettings.cpp +++ b/plugins/samplesource/localinput/localinputsettings.cpp @@ -85,5 +85,50 @@ bool LocalInputSettings::deserialize(const QByteArray& data) } } +void LocalInputSettings::applySettings(const QStringList& settingsKeys, const LocalInputSettings& settings) +{ + if (settingsKeys.contains("dcBlock")) { + m_dcBlock = settings.m_dcBlock; + } + if (settingsKeys.contains("iqCorrection")) { + m_iqCorrection = settings.m_iqCorrection; + } + 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 LocalInputSettings::getDebugString(const QStringList& settingsKeys, bool force) const +{ + std::ostringstream ostr; + if (settingsKeys.contains("dcBlock") || force) { + ostr << " m_dcBlock: " << m_dcBlock; + } + if (settingsKeys.contains("iqCorrection") || force) { + ostr << " m_iqCorrection: " << m_iqCorrection; + } + 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/samplesource/localinput/localinputsettings.h b/plugins/samplesource/localinput/localinputsettings.h index 42689d4976..5ed842138a 100644 --- a/plugins/samplesource/localinput/localinputsettings.h +++ b/plugins/samplesource/localinput/localinputsettings.h @@ -33,6 +33,8 @@ struct LocalInputSettings { void resetToDefaults(); QByteArray serialize() const; bool deserialize(const QByteArray& data); + void applySettings(const QStringList& settingsKeys, const LocalInputSettings& settings); + QString getDebugString(const QStringList& settingsKeys, bool force=false) const; }; #endif /* PLUGINS_SAMPLESOURCE_LOCALINPUT_LOCALINPUTSETTINGS_H_ */