diff --git a/plugins/feature/rigctlserver/rigctlserver.cpp b/plugins/feature/rigctlserver/rigctlserver.cpp index b3c6d6fee3..41b0a5e165 100644 --- a/plugins/feature/rigctlserver/rigctlserver.cpp +++ b/plugins/feature/rigctlserver/rigctlserver.cpp @@ -82,7 +82,8 @@ void RigCtlServer::start() m_state = ok ? StRunning : StError; m_thread.start(); - RigCtlServerWorker::MsgConfigureRigCtlServerWorker *msg = RigCtlServerWorker::MsgConfigureRigCtlServerWorker::create(m_settings, true); + RigCtlServerWorker::MsgConfigureRigCtlServerWorker *msg = RigCtlServerWorker::MsgConfigureRigCtlServerWorker::create( + m_settings, QList(), true); m_worker->getInputMessageQueue()->push(msg); } @@ -101,7 +102,7 @@ bool RigCtlServer::handleMessage(const Message& cmd) { MsgConfigureRigCtlServer& cfg = (MsgConfigureRigCtlServer&) cmd; qDebug() << "RigCtlServer::handleMessage: MsgConfigureRigCtlServer"; - applySettings(cfg.getSettings(), cfg.getForce()); + applySettings(cfg.getSettings(), cfg.getSettingsKeys(), cfg.getForce()); return true; } @@ -125,7 +126,7 @@ bool RigCtlServer::handleMessage(const Message& cmd) qDebug() << "RigCtlServer::handleMessage: MsgChannelIndexChange: " << newChannelIndex; RigCtlServerSettings settings = m_settings; settings.m_channelIndex = newChannelIndex; - applySettings(settings, false); + applySettings(settings, QList{"channelIndex"}, false); if (getMessageQueueToGUI()) { @@ -150,76 +151,43 @@ bool RigCtlServer::deserialize(const QByteArray& data) { if (m_settings.deserialize(data)) { - MsgConfigureRigCtlServer *msg = MsgConfigureRigCtlServer::create(m_settings, true); + MsgConfigureRigCtlServer *msg = MsgConfigureRigCtlServer::create(m_settings, QList(), true); m_inputMessageQueue.push(msg); return true; } else { m_settings.resetToDefaults(); - MsgConfigureRigCtlServer *msg = MsgConfigureRigCtlServer::create(m_settings, true); + MsgConfigureRigCtlServer *msg = MsgConfigureRigCtlServer::create(m_settings, QList(), true); m_inputMessageQueue.push(msg); return false; } } -void RigCtlServer::applySettings(const RigCtlServerSettings& settings, bool force) +void RigCtlServer::applySettings(const RigCtlServerSettings& settings, const QList& settingsKeys, bool force) { - qDebug() << "RigCtlServer::applySettings:" - << " m_enabled: " << settings.m_enabled - << " m_deviceIndex: " << settings.m_deviceIndex - << " m_channelIndex: " << settings.m_channelIndex - << " m_rigCtlPort: " << settings.m_rigCtlPort - << " m_maxFrequencyOffset: " << settings.m_maxFrequencyOffset - << " m_title: " << settings.m_title - << " m_rgbColor: " << settings.m_rgbColor - << " m_useReverseAPI: " << settings.m_useReverseAPI - << " m_reverseAPIAddress: " << settings.m_reverseAPIAddress - << " m_reverseAPIPort: " << settings.m_reverseAPIPort - << " m_reverseAPIFeatureSetIndex: " << settings.m_reverseAPIFeatureSetIndex - << " m_reverseAPIFeatureIndex: " << settings.m_reverseAPIFeatureIndex - << " force: " << force; - - QList reverseAPIKeys; - - if ((m_settings.m_enabled != settings.m_enabled) || force) { - reverseAPIKeys.append("enabled"); - } - if ((m_settings.m_deviceIndex != settings.m_deviceIndex) || force) { - reverseAPIKeys.append("deviceIndex"); - } - if ((m_settings.m_channelIndex != settings.m_channelIndex) || force) { - reverseAPIKeys.append("channelIndex"); - } - if ((m_settings.m_rigCtlPort != settings.m_rigCtlPort) || force) { - reverseAPIKeys.append("rigCtlPort"); - } - if ((m_settings.m_maxFrequencyOffset != settings.m_maxFrequencyOffset) || force) { - reverseAPIKeys.append("maxFrequencyOffset"); - } - if ((m_settings.m_title != settings.m_title) || force) { - reverseAPIKeys.append("title"); - } - if ((m_settings.m_rgbColor != settings.m_rgbColor) || force) { - reverseAPIKeys.append("rgbColor"); - } + qDebug() << "RigCtlServer::applySettings:" << settings.getDebugString(settingsKeys, force) << " force: " << force; RigCtlServerWorker::MsgConfigureRigCtlServerWorker *msg = RigCtlServerWorker::MsgConfigureRigCtlServerWorker::create( - settings, force + settings, settingsKeys, force ); m_worker->getInputMessageQueue()->push(msg); - 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_reverseAPIFeatureSetIndex != settings.m_reverseAPIFeatureSetIndex) || - (m_settings.m_reverseAPIFeatureIndex != settings.m_reverseAPIFeatureIndex); - webapiReverseSendSettings(reverseAPIKeys, settings, fullUpdate || force); + bool fullUpdate = (settingsKeys.contains("useReverseAPI") && settings.m_useReverseAPI) || + settingsKeys.contains("reverseAPIAddress") || + settingsKeys.contains("reverseAPIPort") || + settingsKeys.contains("reverseAPIFeatureSetIndex") || + settingsKeys.contains("m_reverseAPIFeatureIndex"); + webapiReverseSendSettings(settingsKeys, settings, fullUpdate || force); } - m_settings = settings; + if (force) { + m_settings = settings; + } else { + m_settings.applySettings(settingsKeys, settings); + } } int RigCtlServer::webapiRun(bool run, @@ -254,13 +222,13 @@ int RigCtlServer::webapiSettingsPutPatch( RigCtlServerSettings settings = m_settings; webapiUpdateFeatureSettings(settings, featureSettingsKeys, response); - MsgConfigureRigCtlServer *msg = MsgConfigureRigCtlServer::create(settings, force); + MsgConfigureRigCtlServer *msg = MsgConfigureRigCtlServer::create(settings, featureSettingsKeys, force); m_inputMessageQueue.push(msg); qDebug("RigCtlServer::webapiSettingsPutPatch: forward to GUI: %p", m_guiMessageQueue); if (m_guiMessageQueue) // forward to GUI if any { - MsgConfigureRigCtlServer *msgToGUI = MsgConfigureRigCtlServer::create(settings, force); + MsgConfigureRigCtlServer *msgToGUI = MsgConfigureRigCtlServer::create(settings, featureSettingsKeys, force); m_guiMessageQueue->push(msgToGUI); } @@ -404,7 +372,7 @@ void RigCtlServer::webapiUpdateFeatureSettings( } } -void RigCtlServer::webapiReverseSendSettings(QList& featureSettingsKeys, const RigCtlServerSettings& settings, bool force) +void RigCtlServer::webapiReverseSendSettings(const QList& featureSettingsKeys, const RigCtlServerSettings& settings, bool force) { SWGSDRangel::SWGFeatureSettings *swgFeatureSettings = new SWGSDRangel::SWGFeatureSettings(); // swgFeatureSettings->setOriginatorFeatureIndex(getIndexInDeviceSet()); diff --git a/plugins/feature/rigctlserver/rigctlserver.h b/plugins/feature/rigctlserver/rigctlserver.h index 3ab0277dbb..46b5ea8253 100644 --- a/plugins/feature/rigctlserver/rigctlserver.h +++ b/plugins/feature/rigctlserver/rigctlserver.h @@ -45,19 +45,22 @@ class RigCtlServer : public Feature public: const RigCtlServerSettings& getSettings() const { return m_settings; } + const QList& getSettingsKeys() const { return m_settingsKeys; } bool getForce() const { return m_force; } - static MsgConfigureRigCtlServer* create(const RigCtlServerSettings& settings, bool force) { - return new MsgConfigureRigCtlServer(settings, force); + static MsgConfigureRigCtlServer* create(const RigCtlServerSettings& settings, const QList& settingsKeys, bool force) { + return new MsgConfigureRigCtlServer(settings, settingsKeys, force); } private: RigCtlServerSettings m_settings; + QList m_settingsKeys; bool m_force; - MsgConfigureRigCtlServer(const RigCtlServerSettings& settings, bool force) : + MsgConfigureRigCtlServer(const RigCtlServerSettings& settings, const QList& settingsKeys, bool force) : Message(), m_settings(settings), + m_settingsKeys(settingsKeys), m_force(force) { } }; @@ -138,8 +141,8 @@ class RigCtlServer : public Feature void start(); void stop(); - void applySettings(const RigCtlServerSettings& settings, bool force = false); - void webapiReverseSendSettings(QList& featureSettingsKeys, const RigCtlServerSettings& settings, bool force); + void applySettings(const RigCtlServerSettings& settings, const QList& settingsKeys, bool force = false); + void webapiReverseSendSettings(const QList& featureSettingsKeys, const RigCtlServerSettings& settings, bool force); void webapiFormatFeatureReport(SWGSDRangel::SWGFeatureReport& response); private slots: diff --git a/plugins/feature/rigctlserver/rigctlservergui.cpp b/plugins/feature/rigctlserver/rigctlservergui.cpp index ff8f32c039..bd448b7d3f 100644 --- a/plugins/feature/rigctlserver/rigctlservergui.cpp +++ b/plugins/feature/rigctlserver/rigctlservergui.cpp @@ -73,7 +73,13 @@ bool RigCtlServerGUI::handleMessage(const Message& message) { qDebug("RigCtlServerGUI::handleMessage: RigCtlServer::MsgConfigureRigCtlServer"); const RigCtlServer::MsgConfigureRigCtlServer& cfg = (RigCtlServer::MsgConfigureRigCtlServer&) 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); @@ -114,7 +120,6 @@ void RigCtlServerGUI::onWidgetRolled(QWidget* widget, bool rollDown) (void) rollDown; getRollupContents()->saveState(m_rollupState); - applySettings(); } RigCtlServerGUI::RigCtlServerGUI(PluginAPI* pluginAPI, FeatureUISet *featureUISet, Feature *feature, QWidget* parent) : @@ -158,6 +163,7 @@ RigCtlServerGUI::~RigCtlServerGUI() void RigCtlServerGUI::setWorkspaceIndex(int index) { m_settings.m_workspaceIndex = index; + m_settingsKeys.append("workspaceIndex"); m_feature->setWorkspaceIndex(index); } @@ -220,6 +226,7 @@ void RigCtlServerGUI::updateDeviceSetList() { qDebug("RigCtlServerGUI::updateDeviceSetLists: device index changed: %d", newDeviceIndex); m_settings.m_deviceIndex = newDeviceIndex; + m_settingsKeys.append("deviceIndex"); } updateChannelList(); @@ -270,6 +277,7 @@ bool RigCtlServerGUI::updateChannelList() { qDebug("RigCtlServerGUI::updateChannelList: channel index changed: %d", newChannelIndex); m_settings.m_channelIndex = newChannelIndex; + m_settingsKeys.append("channelIndex"); return true; } @@ -302,6 +310,14 @@ void RigCtlServerGUI::onMenuDialogCalled(const QPoint &p) setTitle(m_settings.m_title); setTitleColor(m_settings.m_rgbColor); + m_settingsKeys.append("title"); + m_settingsKeys.append("rgbColor"); + m_settingsKeys.append("useReverseAPI"); + m_settingsKeys.append("reverseAPIAddress"); + m_settingsKeys.append("reverseAPIPort"); + m_settingsKeys.append("reverseAPIFeatureSetIndex"); + m_settingsKeys.append("reverseAPIFeatureIndex"); + applySettings(); } @@ -320,6 +336,7 @@ void RigCtlServerGUI::on_startStop_toggled(bool checked) void RigCtlServerGUI::on_enable_toggled(bool checked) { m_settings.m_enabled = checked; + m_settingsKeys.append("enabled"); applySettings(); } @@ -335,6 +352,7 @@ void RigCtlServerGUI::on_device_currentIndexChanged(int index) if (index >= 0) { m_settings.m_deviceIndex = ui->device->currentData().toInt(); + m_settingsKeys.append("deviceIndex"); updateChannelList(); applySettings(); } @@ -345,6 +363,7 @@ void RigCtlServerGUI::on_channel_currentIndexChanged(int index) if (index >= 0) { m_settings.m_channelIndex = index; + m_settingsKeys.append("channelIndex"); applySettings(); } } @@ -352,12 +371,14 @@ void RigCtlServerGUI::on_channel_currentIndexChanged(int index) void RigCtlServerGUI::on_rigCtrlPort_valueChanged(int value) { m_settings.m_rigCtlPort = value; + m_settingsKeys.append("rigCtlPort"); applySettings(); } void RigCtlServerGUI::on_maxFrequencyOffset_valueChanged(int value) { m_settings.m_maxFrequencyOffset = value; + m_settingsKeys.append("maxFrequencyOffset"); applySettings(); } @@ -394,9 +415,11 @@ void RigCtlServerGUI::applySettings(bool force) { if (m_doApplySettings) { - RigCtlServer::MsgConfigureRigCtlServer* message = RigCtlServer::MsgConfigureRigCtlServer::create( m_settings, force); + RigCtlServer::MsgConfigureRigCtlServer* message = RigCtlServer::MsgConfigureRigCtlServer::create(m_settings, m_settingsKeys, force); m_rigCtlServer->getInputMessageQueue()->push(message); } + + m_settingsKeys.clear(); } void RigCtlServerGUI::makeUIConnections() diff --git a/plugins/feature/rigctlserver/rigctlservergui.h b/plugins/feature/rigctlserver/rigctlservergui.h index 21cbf50b00..84c6caa29f 100644 --- a/plugins/feature/rigctlserver/rigctlservergui.h +++ b/plugins/feature/rigctlserver/rigctlservergui.h @@ -55,6 +55,7 @@ class RigCtlServerGUI : public FeatureGUI { PluginAPI* m_pluginAPI; FeatureUISet* m_featureUISet; RigCtlServerSettings m_settings; + QList m_settingsKeys; RollupState m_rollupState; bool m_doApplySettings; diff --git a/plugins/feature/rigctlserver/rigctlserversettings.cpp b/plugins/feature/rigctlserver/rigctlserversettings.cpp index ad00529cbe..45a24fb069 100644 --- a/plugins/feature/rigctlserver/rigctlserversettings.cpp +++ b/plugins/feature/rigctlserver/rigctlserversettings.cpp @@ -134,3 +134,88 @@ bool RigCtlServerSettings::deserialize(const QByteArray& data) return false; } } + +void RigCtlServerSettings::applySettings(const QStringList& settingsKeys, const RigCtlServerSettings& settings) +{ + if (settingsKeys.contains("rigCtlPort")) { + m_rigCtlPort = settings.m_rigCtlPort; + } + if (settingsKeys.contains("maxFrequencyOffset")) { + m_maxFrequencyOffset = settings.m_maxFrequencyOffset; + } + if (settingsKeys.contains("deviceIndex")) { + m_deviceIndex = settings.m_deviceIndex; + } + if (settingsKeys.contains("channelIndex")) { + m_channelIndex = settings.m_channelIndex; + } + if (settingsKeys.contains("title")) { + m_title = settings.m_title; + } + if (settingsKeys.contains("rgbColor")) { + m_rgbColor = settings.m_rgbColor; + } + 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("reverseAPIFeatureSetIndex")) { + m_reverseAPIFeatureSetIndex = settings.m_reverseAPIFeatureSetIndex; + } + if (settingsKeys.contains("reverseAPIFeatureIndex")) { + m_reverseAPIFeatureIndex = settings.m_reverseAPIFeatureIndex; + } + if (settingsKeys.contains("workspaceIndex")) { + m_workspaceIndex = settings.m_workspaceIndex; + } +} + +QString RigCtlServerSettings::getDebugString(const QStringList& settingsKeys, bool force) const +{ + std::ostringstream ostr; + + if (settingsKeys.contains("rigCtlPort") || force) { + ostr << " m_rigCtlPort: " << m_rigCtlPort; + } + if (settingsKeys.contains("maxFrequencyOffset") || force) { + ostr << " m_maxFrequencyOffset: " << m_maxFrequencyOffset; + } + if (settingsKeys.contains("deviceIndex") || force) { + ostr << " m_deviceIndex: " << m_deviceIndex; + } + if (settingsKeys.contains("channelIndex") || force) { + ostr << " m_channelIndex: " << m_channelIndex; + } + if (settingsKeys.contains("title") || force) { + ostr << " m_title: " << m_title.toStdString(); + } + if (settingsKeys.contains("rgbColor") || force) { + ostr << " m_rgbColor: " << m_rgbColor; + } + 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("reverseAPIFeatureSetIndex") || force) { + ostr << " m_reverseAPIFeatureSetIndex: " << m_reverseAPIFeatureSetIndex; + } + if (settingsKeys.contains("reverseAPIFeatureIndex") || force) { + ostr << " m_reverseAPIFeatureIndex: " << m_reverseAPIFeatureIndex; + } + if (settingsKeys.contains("workspaceIndex") || force) { + ostr << " m_workspaceIndex: " << m_workspaceIndex; + } + + return QString(ostr.str().c_str()); +} + diff --git a/plugins/feature/rigctlserver/rigctlserversettings.h b/plugins/feature/rigctlserver/rigctlserversettings.h index b76562b380..b2d6eb9107 100644 --- a/plugins/feature/rigctlserver/rigctlserversettings.h +++ b/plugins/feature/rigctlserver/rigctlserversettings.h @@ -68,6 +68,8 @@ struct RigCtlServerSettings QByteArray serialize() const; bool deserialize(const QByteArray& data); void setRollupState(Serializable *rollupState) { m_rollupState = rollupState; } + void applySettings(const QStringList& settingsKeys, const RigCtlServerSettings& settings); + QString getDebugString(const QStringList& settingsKeys, bool force=false) const; }; #endif // INCLUDE_FEATURE_RIGCTLSERVERSETTINGS_H_ diff --git a/plugins/feature/rigctlserver/rigctlserverworker.cpp b/plugins/feature/rigctlserver/rigctlserverworker.cpp index 88f9a78829..785ae676e2 100644 --- a/plugins/feature/rigctlserver/rigctlserverworker.cpp +++ b/plugins/feature/rigctlserver/rigctlserverworker.cpp @@ -107,7 +107,7 @@ bool RigCtlServerWorker::handleMessage(const Message& cmd) MsgConfigureRigCtlServerWorker& cfg = (MsgConfigureRigCtlServerWorker&) cmd; qDebug() << "RigCtlServerWorker::handleMessage: MsgConfigureRigCtlServerWorker"; - applySettings(cfg.getSettings(), cfg.getForce()); + applySettings(cfg.getSettings(), cfg.getSettingsKeys(), cfg.getForce()); return true; } @@ -117,25 +117,21 @@ bool RigCtlServerWorker::handleMessage(const Message& cmd) } } -void RigCtlServerWorker::applySettings(const RigCtlServerSettings& settings, bool force) +void RigCtlServerWorker::applySettings(const RigCtlServerSettings& settings, const QList& settingsKeys, bool force) { - qDebug() << "RigCtlServerWorker::applySettings:" - << " m_title: " << settings.m_title - << " m_rgbColor: " << settings.m_rgbColor - << " m_enabled: " << settings.m_enabled - << " m_deviceIndex: " << settings.m_deviceIndex - << " m_channelIndex: " << settings.m_channelIndex - << " m_rigCtlPort: " << settings.m_rigCtlPort - << " m_maxFrequencyOffset: " << settings.m_maxFrequencyOffset - << " force: " << force; - - if ((settings.m_rigCtlPort != m_settings.m_rigCtlPort) || - (settings.m_enabled != m_settings.m_enabled) || force) + qDebug() << "RigCtlServerWorker::applySettings:" << settings.getDebugString(settingsKeys, force) << " force: " << force; + + if (settingsKeys.contains("rigCtlPort") || + settingsKeys.contains("enabled") || force) { restartServer(settings.m_enabled, settings.m_rigCtlPort); } - m_settings = settings; + if (force) { + m_settings = settings; + } else { + m_settings.applySettings(settingsKeys, settings); + } } void RigCtlServerWorker::restartServer(bool enabled, uint32_t port) diff --git a/plugins/feature/rigctlserver/rigctlserverworker.h b/plugins/feature/rigctlserver/rigctlserverworker.h index 0c528d6636..340ecece73 100644 --- a/plugins/feature/rigctlserver/rigctlserverworker.h +++ b/plugins/feature/rigctlserver/rigctlserverworker.h @@ -39,20 +39,23 @@ class RigCtlServerWorker : public QObject public: const RigCtlServerSettings& getSettings() const { return m_settings; } + const QList& getSettingsKeys() const { return m_settingsKeys; } bool getForce() const { return m_force; } - static MsgConfigureRigCtlServerWorker* create(const RigCtlServerSettings& settings, bool force) + static MsgConfigureRigCtlServerWorker* create(const RigCtlServerSettings& settings, const QList& settingsKeys, bool force) { - return new MsgConfigureRigCtlServerWorker(settings, force); + return new MsgConfigureRigCtlServerWorker(settings, settingsKeys, force); } private: RigCtlServerSettings m_settings; + QList m_settingsKeys; bool m_force; - MsgConfigureRigCtlServerWorker(const RigCtlServerSettings& settings, bool force) : + MsgConfigureRigCtlServerWorker(const RigCtlServerSettings& settings, const QList& settingsKeys, bool force) : Message(), m_settings(settings), + m_settingsKeys(settingsKeys), m_force(force) { } }; @@ -125,7 +128,7 @@ class RigCtlServerWorker : public QObject static const ModeDemod m_modeMap[]; bool handleMessage(const Message& cmd); - void applySettings(const RigCtlServerSettings& settings, bool force = false); + void applySettings(const RigCtlServerSettings& settings, const QList& settingsKeys, bool force = false); void restartServer(bool enabled, uint32_t port); bool setFrequency(double frequency, rig_errcode_e& rigCtlRC); bool getFrequency(double& frequency, rig_errcode_e& rigCtlRC);