From 3c3e5cf3dfa189f7a999cf66f257c1e0fdd5cf0e Mon Sep 17 00:00:00 2001 From: Jon Beniston Date: Tue, 26 Nov 2024 11:52:30 +0000 Subject: [PATCH] Stop device while changing channel set. Fixes #2332 --- sdrgui/device/deviceuiset.cpp | 48 ++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/sdrgui/device/deviceuiset.cpp b/sdrgui/device/deviceuiset.cpp index 85f1541ca3..36b63bdc02 100644 --- a/sdrgui/device/deviceuiset.cpp +++ b/sdrgui/device/deviceuiset.cpp @@ -39,6 +39,7 @@ #include "channel/channelutils.h" #include "channel/channelapi.h" #include "channel/channelgui.h" +#include "channel/channelwebapiutils.h" #include "mainspectrum/mainspectrumgui.h" #include "settings/preset.h" #include "util/simpleserializer.h" @@ -258,12 +259,47 @@ void DeviceUISet::loadDeviceSetSettings( m_mainSpectrumGUI->hide(); } - if (m_deviceSourceEngine) { // source device - loadRxChannelSettings(preset, pluginAPI, workspaces, currentWorkspace); - } else if (m_deviceSinkEngine) { // sink device - loadTxChannelSettings(preset, pluginAPI, workspaces, currentWorkspace); - } else if (m_deviceMIMOEngine) { // MIMO device - loadMIMOChannelSettings(preset, pluginAPI, workspaces, currentWorkspace); + // Stop device while changing channels + if (m_deviceAPI->state() == DeviceAPI::EngineState::StRunning) + { + int deviceIndex = m_deviceAPI->getDeviceSetIndex(); + + // Load settings after stopping device + auto connection = new QMetaObject::Connection(); + *connection = connect(m_deviceAPI, &DeviceAPI::stateChanged, this, [=]() { + if (m_deviceAPI->state() != DeviceAPI::EngineState::StRunning) + { + // Load channel settings + if (m_deviceSourceEngine) { + loadRxChannelSettings(preset, pluginAPI, workspaces, currentWorkspace); + } else if (m_deviceSinkEngine) { + loadTxChannelSettings(preset, pluginAPI, workspaces, currentWorkspace); + } else if (m_deviceMIMOEngine) { + loadMIMOChannelSettings(preset, pluginAPI, workspaces, currentWorkspace); + } + + // Restart device + ChannelWebAPIUtils::run(deviceIndex); + + QObject::disconnect(*connection); + delete connection; + } + }); + + // We use WebAPI rather than m_deviceAPI->stopDeviceEngine(); + // so that the start/stop button in the Device GUI is correctly updated + ChannelWebAPIUtils::stop(deviceIndex); + } + else + { + // Load channel settings + if (m_deviceSourceEngine) { + loadRxChannelSettings(preset, pluginAPI, workspaces, currentWorkspace); + } else if (m_deviceSinkEngine) { + loadTxChannelSettings(preset, pluginAPI, workspaces, currentWorkspace); + } else if (m_deviceMIMOEngine) { + loadMIMOChannelSettings(preset, pluginAPI, workspaces, currentWorkspace); + } } }