From fb562f197c03c44a4abf653f806775931367e0c5 Mon Sep 17 00:00:00 2001 From: f4exb Date: Thu, 12 Jan 2017 01:24:08 +0100 Subject: [PATCH] Added reload devices option --- sdrbase/mainwindow.cpp | 58 ++++++++++++++++++++++++- sdrbase/mainwindow.h | 1 + sdrbase/mainwindow.ui | 72 +++++++++++++++++++++++++++++--- sdrbase/plugin/pluginmanager.cpp | 34 +++++++++++++++ sdrbase/plugin/pluginmanager.h | 2 + sdrbase/readme.md | 31 +++++++------- 6 files changed, 175 insertions(+), 23 deletions(-) diff --git a/sdrbase/mainwindow.cpp b/sdrbase/mainwindow.cpp index 42b9729bc..6933ffaa1 100644 --- a/sdrbase/mainwindow.cpp +++ b/sdrbase/mainwindow.cpp @@ -22,7 +22,6 @@ #include #include #include -#include #include #include @@ -278,7 +277,7 @@ void MainWindow::removeLastDevice() ui->tabInputsSelect->removeTab(ui->tabInputsSelect->count() - 1); - m_deviceWidgetTabs.removeLast(); + m_deviceWidgetTabs.removeLast();m_pluginManager->loadPlugins(); ui->tabInputsView->clear(); for (int i = 0; i < m_deviceWidgetTabs.size(); i++) @@ -930,6 +929,61 @@ void MainWindow::on_action_removeLastDevice_triggered() } } +void MainWindow::on_action_reloadDevices_triggered() +{ + // all devices must be stopped + std::vector::iterator it = m_deviceUIs.begin(); + for (; it != m_deviceUIs.end(); ++it) + { + if ((*it)->m_deviceSourceEngine) // it is a source device + { + if ((*it)->m_deviceSourceEngine->state() == DSPDeviceSourceEngine::StRunning) + { + QMessageBox::information(this, tr("Message"), tr("Stop all devices for reload to take effect")); + return; + } + } + + if ((*it)->m_deviceSinkEngine) // it is a sink device + { + if ((*it)->m_deviceSinkEngine->state() == DSPDeviceSinkEngine::StRunning) + { + QMessageBox::information(this, tr("Message"), tr("Stop all devices for reload to take effect")); + return; + } + } + } + + // re-scan devices + m_pluginManager->updateSampleSourceDevices(); + m_pluginManager->updateSampleSinkDevices(); + + // re-populate device selectors keeping the same selection + it = m_deviceUIs.begin(); + for (; it != m_deviceUIs.end(); ++it) + { + if ((*it)->m_deviceSourceEngine) // it is a source device + { + QComboBox *deviceSelectorComboBox = (*it)->m_samplingDeviceControl->getDeviceSelector(); + bool sampleSourceSignalsBlocked = deviceSelectorComboBox->blockSignals(true); + m_pluginManager->fillSampleSourceSelector(deviceSelectorComboBox, (*it)->m_deviceSourceEngine->getUID()); + int newIndex = m_pluginManager->getSampleSourceSelectorIndex(deviceSelectorComboBox, (*it)->m_deviceSourceAPI); + deviceSelectorComboBox->setCurrentIndex(newIndex); + deviceSelectorComboBox->blockSignals(sampleSourceSignalsBlocked); + } + + if ((*it)->m_deviceSinkEngine) // it is a sink device + { + QComboBox *deviceSelectorComboBox = (*it)->m_samplingDeviceControl->getDeviceSelector(); + bool sampleSinkSignalsBlocked = deviceSelectorComboBox->blockSignals(true); + m_pluginManager->fillSampleSinkSelector(deviceSelectorComboBox, (*it)->m_deviceSinkEngine->getUID()); + int newIndex = m_pluginManager->getSampleSourceSelectorIndex(deviceSelectorComboBox, (*it)->m_deviceSourceAPI); + deviceSelectorComboBox->setCurrentIndex(newIndex); + deviceSelectorComboBox->blockSignals(sampleSinkSignalsBlocked); + } + } +} + void MainWindow::on_action_Exit_triggered() { savePresetSettings(m_settings.getWorkingPreset(), 0); diff --git a/sdrbase/mainwindow.h b/sdrbase/mainwindow.h index 575384ce5..70cde86ce 100644 --- a/sdrbase/mainwindow.h +++ b/sdrbase/mainwindow.h @@ -162,6 +162,7 @@ private slots: void on_action_addSourceDevice_triggered(); void on_action_addSinkDevice_triggered(); void on_action_removeLastDevice_triggered(); + void on_action_reloadDevices_triggered(); void on_action_Exit_triggered(); void tabInputViewIndexChanged(); }; diff --git a/sdrbase/mainwindow.ui b/sdrbase/mainwindow.ui index 2ac1dcc8d..86c1027cc 100644 --- a/sdrbase/mainwindow.ui +++ b/sdrbase/mainwindow.ui @@ -33,7 +33,16 @@ - + + 0 + + + 0 + + + 0 + + 0 @@ -94,6 +103,7 @@ + @@ -164,7 +174,16 @@ - + + 2 + + + 2 + + + 2 + + 2 @@ -392,7 +411,16 @@ 3 - + + 2 + + + 2 + + + 2 + + 2 @@ -423,7 +451,16 @@ 3 - + + 2 + + + 2 + + + 2 + + 2 @@ -460,7 +497,16 @@ 3 - + + 2 + + + 2 + + + 2 + + 2 @@ -488,7 +534,16 @@ 3 - + + 2 + + + 2 + + + 2 + + 2 @@ -625,6 +680,11 @@ Add sink device + + + Reload devices + + presetDock channelDock diff --git a/sdrbase/plugin/pluginmanager.cpp b/sdrbase/plugin/pluginmanager.cpp index a4ffaa51c..2b407c577 100644 --- a/sdrbase/plugin/pluginmanager.cpp +++ b/sdrbase/plugin/pluginmanager.cpp @@ -295,6 +295,23 @@ void PluginManager::fillSampleSourceSelector(QComboBox* comboBox, uint deviceUID } } +int PluginManager::getSampleSourceSelectorIndex(QComboBox* comboBox, DeviceSourceAPI *deviceSourceAPI) +{ + for (int i = 0; i < comboBox->count(); i++) + { + SamplingDevice *samplingDevice = (SamplingDevice*) (comboBox->itemData(i)).value(); + + if ((samplingDevice->m_deviceId == deviceSourceAPI->getSampleSourceId()) && + (samplingDevice->m_deviceSerial == deviceSourceAPI->getSampleSourceSerial()) && + (samplingDevice->m_deviceSequence == deviceSourceAPI->getSampleSourceSequence())) + { + return i; + } + } + + return 0; // default to first item +} + void PluginManager::fillSampleSinkSelector(QComboBox* comboBox, uint deviceUID) { comboBox->clear(); @@ -313,6 +330,23 @@ void PluginManager::fillSampleSinkSelector(QComboBox* comboBox, uint deviceUID) } } +int PluginManager::getSampleSinkSelectorIndex(QComboBox* comboBox, DeviceSinkAPI *deviceSinkAPI) +{ + for (int i = 0; i < comboBox->count(); i++) + { + SamplingDevice *samplingDevice = (SamplingDevice*) (comboBox->itemData(i)).value(); + + if ((samplingDevice->m_deviceId == deviceSinkAPI->getSampleSinkId()) && + (samplingDevice->m_deviceSerial == deviceSinkAPI->getSampleSinkSerial()) && + (samplingDevice->m_deviceSequence == deviceSinkAPI->getSampleSinkSequence())) + { + return i; + } + } + + return 0; // default to first item +} + int PluginManager::selectSampleSourceByIndex(int index, DeviceSourceAPI *deviceAPI) { qDebug("PluginManager::selectSampleSourceByIndex: index: %d", index); diff --git a/sdrbase/plugin/pluginmanager.h b/sdrbase/plugin/pluginmanager.h index 72e37f75b..4e8bf9991 100644 --- a/sdrbase/plugin/pluginmanager.h +++ b/sdrbase/plugin/pluginmanager.h @@ -53,10 +53,12 @@ public: void updateSampleSourceDevices(); void duplicateLocalSampleSourceDevices(uint deviceUID); void fillSampleSourceSelector(QComboBox* comboBox, uint deviceUID); + int getSampleSourceSelectorIndex(QComboBox* comboBox, DeviceSourceAPI *deviceSourceAPI); void updateSampleSinkDevices(); void duplicateLocalSampleSinkDevices(uint deviceUID); void fillSampleSinkSelector(QComboBox* comboBox, uint deviceUID); + int getSampleSinkSelectorIndex(QComboBox* comboBox, DeviceSinkAPI *deviceSinkAPI); int selectSampleSourceByIndex(int index, DeviceSourceAPI *deviceAPI); int selectFirstSampleSource(const QString& sourceId, DeviceSourceAPI *deviceAPI); diff --git a/sdrbase/readme.md b/sdrbase/readme.md index 9c25208ac..34c8c458c 100644 --- a/sdrbase/readme.md +++ b/sdrbase/readme.md @@ -29,26 +29,27 @@ In each slave tab group (2), (3), (4) and (5) an individual tab corresponding to The following items are presented hierarchically from left to right: - File: - - Exit (shortcut Ctl-Q): Exit the program + - _Exit_ (shortcut Ctl-Q): Exit the program - View: - - Fullscreen (Shortcut F11): Toggle full screen mode + - _Fullscreen_ (Shortcut F11): Toggle full screen mode - Devices: - - Add source device: adds a new source (receiver) device slot to the device stack (last position) - - Add sink device: adds a new sink (transmitter) device slot to the device stack (last position) - - Remove device: removes the last device slot from thte device stack + - _Add source device_: adds a new source (receiver) device slot to the device stack (last position) + - _Add sink device_: adds a new sink (transmitter) device slot to the device stack (last position) + - _Remove device_: removes the last device slot from thte device stack + - _Reload devices_: re-scan the system for devices. Devices selectors are updated with new devices and missing devices are removed. All devices must be stopped for this to take effect. - Window: presents the list of dockable windows. Check to make it visible. Uncheck to hide. These windows are: - - Sampling devices control: control of which sampling devices is used and add channels - - Sampling devices: the sampling devices UIs - - Spectrum display: the main spectrum displays (output from the sampling devices) - - Presets: the saved presets - - Channels: the channels active for each device + - _Sampling devices control_: control of which sampling devices is used and add channels + - _Sampling devices_: the sampling devices UIs + - _Spectrum display_: the main spectrum displays (output from the sampling devices) + - _Presets_: the saved presets + - _Channels_: the channels active for each device - Preferences: - - Audio: opens a dialog to choose the audio output device (see 1.1 below for details) - - DV Serial: if you have one or more AMBE3000 serial devices for AMBE digital voice check to connect them. If unchecked DV decoding will resort to mbelib if available else no audio will be produced for AMBE digital voice - - My Position: opens a dialog to enter your station ("My Position") coordinates in decimal degrees with north latitudes positive and east longitudes positive. This is used whenever positional data is to be displayed (APRS, DPRS, ...). For it now only works with D-Star $$CRC frames. See [DSD demod plugin](../plugins/channel/demoddsd/readme.md) for details on how to decode Digital Voice modes. + - _Audio_: opens a dialog to choose the audio output device (see 1.1 below for details) + - _DV Serial_: if you have one or more AMBE3000 serial devices for AMBE digital voice check to connect them. If unchecked DV decoding will resort to mbelib if available else no audio will be produced for AMBE digital voice + - _My Position_: opens a dialog to enter your station ("My Position") coordinates in decimal degrees with north latitudes positive and east longitudes positive. This is used whenever positional data is to be displayed (APRS, DPRS, ...). For it now only works with D-Star $$CRC frames. See [DSD demod plugin](../plugins/channel/demoddsd/readme.md) for details on how to decode Digital Voice modes. - Help: - - Loaded Plugins: shows details about the loaded plugins (see 1.2 below for details) - - About: current version and blah blah. + - _Loaded Plugins_: shows details about the loaded plugins (see 1.2 below for details) + - _About_: current version and blah blah.

1.1. Preferences - Audio