Multi device support: basic multi device creation and deletion

This commit is contained in:
f4exb 2016-05-13 11:42:03 +02:00
parent df661cc366
commit dec0addc25
7 changed files with 96 additions and 44 deletions

View File

@ -99,7 +99,6 @@ void DSPDeviceEngine::stopAcquistion()
m_syncMessenger.storeMessage(cmd); m_syncMessenger.storeMessage(cmd);
handleSynchronousMessages(); handleSynchronousMessages();
if(m_dcOffsetCorrection) if(m_dcOffsetCorrection)
{ {
qDebug("DC offset:%f,%f", m_iOffset, m_qOffset); qDebug("DC offset:%f,%f", m_iOffset, m_qOffset);

View File

@ -59,6 +59,7 @@ void DSPEngine::removeLastDeviceEngine()
DSPDeviceEngine *lastDeviceEngine = m_deviceEngines.back(); DSPDeviceEngine *lastDeviceEngine = m_deviceEngines.back();
delete lastDeviceEngine; delete lastDeviceEngine;
m_deviceEngines.pop_back(); m_deviceEngines.pop_back();
m_deviceEnginesUIDSequence--;
} }
} }

View File

@ -159,21 +159,24 @@ MainWindow::MainWindow(QWidget* parent) :
MainWindow::~MainWindow() MainWindow::~MainWindow()
{ {
m_dspEngine->stopAllAcquisitions(); saveSettings();
saveSettings(); while (m_deviceUIs.size() > 0)
{
m_pluginManager->freeAll(); removeLastDevice();
}
for (int i = 0; i < m_deviceUIs.size(); i++)
{
delete m_deviceUIs[i];
}
delete m_pluginManager;
m_dspEngine->stopAllDeviceEngines();
// m_dspEngine->stopAllAcquisitions(); // FIXME: also present in m_pluginManager->freeAll()
// //m_pluginManager->freeAll();
// for (int i = 0; i < m_deviceUIs.size(); i++)
// {
// m_deviceUIs[i]->m_pluginManager->freeAll();
// delete m_deviceUIs[i];
// }
//
// m_dspEngine->stopAllDeviceEngines();
//
// //delete m_pluginManager;
delete m_dateTimeWidget; delete m_dateTimeWidget;
delete m_showSystemWidget; delete m_showSystemWidget;
@ -185,23 +188,57 @@ void MainWindow::addDevice()
DSPDeviceEngine *dspDeviceEngine = m_dspEngine->addDeviceEngine(); DSPDeviceEngine *dspDeviceEngine = m_dspEngine->addDeviceEngine();
dspDeviceEngine->start(); dspDeviceEngine->start();
uint dspDeviceEngineUID = dspDeviceEngine->getUID();
char tabNameCStr[16]; char tabNameCStr[16];
sprintf(tabNameCStr, "R%d", dspDeviceEngine->getUID()); sprintf(tabNameCStr, "R%d", dspDeviceEngineUID);
m_deviceUIs.push_back(new DeviceUISet(m_masterTimer)); m_deviceUIs.push_back(new DeviceUISet(m_masterTimer));
m_deviceUIs.back()->m_deviceEngine = dspDeviceEngine;
m_pluginManager = new PluginManager(this, dspDeviceEngine, m_deviceUIs.back()->m_spectrum); PluginManager *pluginManager = new PluginManager(this, dspDeviceEngine, m_deviceUIs.back()->m_spectrum);
m_pluginManager->loadPlugins(); m_deviceUIs.back()->m_pluginManager = pluginManager;
pluginManager->loadPlugins();
dspDeviceEngine->addSink(m_deviceUIs.back()->m_spectrumVis);
ui->tabSpectra->addTab(m_deviceUIs.back()->m_spectrum, tabNameCStr); ui->tabSpectra->addTab(m_deviceUIs.back()->m_spectrum, tabNameCStr);
ui->tabSpectraGUI->addTab(m_deviceUIs.back()->m_spectrumGUI, tabNameCStr); ui->tabSpectraGUI->addTab(m_deviceUIs.back()->m_spectrumGUI, tabNameCStr);
dspDeviceEngine->addSink(m_deviceUIs.back()->m_spectrumVis);
ui->tabChannels->addTab(m_deviceUIs.back()->m_channelWindow, tabNameCStr); ui->tabChannels->addTab(m_deviceUIs.back()->m_channelWindow, tabNameCStr);
bool sampleSourceSignalsBlocked = m_deviceUIs.back()->m_sampleSource->blockSignals(true); bool sampleSourceSignalsBlocked = m_deviceUIs.back()->m_sampleSource->blockSignals(true);
m_pluginManager->fillSampleSourceSelector(m_deviceUIs.back()->m_sampleSource); pluginManager->fillSampleSourceSelector(m_deviceUIs.back()->m_sampleSource);
connect(m_deviceUIs.back()->m_sampleSource, SIGNAL(currentIndexChanged(int)), this, SLOT(on_sampleSource_currentIndexChanged(int))); connect(m_deviceUIs.back()->m_sampleSource, SIGNAL(currentIndexChanged(int)), this, SLOT(on_sampleSource_currentIndexChanged(int)));
m_deviceUIs.back()->m_sampleSource->blockSignals(sampleSourceSignalsBlocked); m_deviceUIs.back()->m_sampleSource->blockSignals(sampleSourceSignalsBlocked);
ui->tabInputs->addTab(m_deviceUIs.back()->m_sampleSource, tabNameCStr); ui->tabInputs->addTab(m_deviceUIs.back()->m_sampleSource, tabNameCStr);
if (dspDeviceEngineUID == 0)
{
m_pluginManager = pluginManager;
}
}
void MainWindow::removeLastDevice()
{
DSPDeviceEngine *lastDeviceEngine = m_deviceUIs.back()->m_deviceEngine;
lastDeviceEngine->stopAcquistion();
lastDeviceEngine->removeSink(m_deviceUIs.back()->m_spectrumVis);
ui->tabChannels->removeTab(ui->tabChannels->count() - 1);
ui->tabSpectraGUI->removeTab(ui->tabSpectraGUI->count() - 1);
ui->tabSpectra->removeTab(ui->tabSpectra->count() - 1);
// PluginManager destructor does freeAll() which does stopAcquistion() but stopAcquistion()
// can be done several times only the first is active so it is fine to do it here
// On the other hand freeAll() must be executed only once
delete m_deviceUIs.back()->m_pluginManager;
//m_deviceUIs.back()->m_pluginManager->freeAll();
lastDeviceEngine->stop();
m_dspEngine->removeLastDeviceEngine();
ui->tabInputs->removeTab(ui->tabInputs->count() - 1);
delete m_deviceUIs.back();
m_deviceUIs.pop_back();
} }
void MainWindow::addChannelCreateAction(QAction* action) void MainWindow::addChannelCreateAction(QAction* action)
@ -622,9 +659,22 @@ void MainWindow::on_action_About_triggered()
dlg.exec(); dlg.exec();
} }
void MainWindow::on_action_addDevice_triggered()
{
addDevice();
}
void MainWindow::on_action_removeDevice_triggered()
{
if (m_deviceUIs.size() > 1)
{
removeLastDevice();
}
}
void MainWindow::updateStatus() void MainWindow::updateStatus()
{ {
m_dateTimeWidget->setText(QDateTime::currentDateTime().toString("yyyy-MM-ddThh:mm:ss t")); m_dateTimeWidget->setText(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss t"));
} }
MainWindow::DeviceUISet::DeviceUISet(QTimer& timer) MainWindow::DeviceUISet::DeviceUISet(QTimer& timer)
@ -637,6 +687,7 @@ MainWindow::DeviceUISet::DeviceUISet(QTimer& timer)
m_channelWindow = new ChannelWindow; m_channelWindow = new ChannelWindow;
m_sampleSource = new QComboBox; m_sampleSource = new QComboBox;
m_deviceEngine = 0; m_deviceEngine = 0;
m_pluginManager = 0;
// m_spectrum needs to have its font to be set since it cannot be inherited from the main window // m_spectrum needs to have its font to be set since it cannot be inherited from the main window
QFont font; QFont font;

View File

@ -60,6 +60,7 @@ public:
ChannelWindow *m_channelWindow; ChannelWindow *m_channelWindow;
QComboBox *m_sampleSource; QComboBox *m_sampleSource;
DSPDeviceEngine *m_deviceEngine; DSPDeviceEngine *m_deviceEngine;
PluginManager *m_pluginManager;
DeviceUISet(QTimer& timer); DeviceUISet(QTimer& timer);
~DeviceUISet(); ~DeviceUISet();
@ -94,8 +95,6 @@ private:
MainSettings m_settings; MainSettings m_settings;
SpectrumVis* m_rxSpectrumVis;
std::vector<DeviceUISet*> m_deviceUIs; std::vector<DeviceUISet*> m_deviceUIs;
DSPEngine* m_dspEngine; DSPEngine* m_dspEngine;
@ -147,6 +146,8 @@ private slots:
void on_action_DV_Serial_triggered(bool checked); void on_action_DV_Serial_triggered(bool checked);
void on_sampleSource_currentIndexChanged(int index); void on_sampleSource_currentIndexChanged(int index);
void on_action_About_triggered(); void on_action_About_triggered();
void on_action_addDevice_triggered();
void on_action_removeDevice_triggered();
}; };
#endif // INCLUDE_MAINWINDOW_H #endif // INCLUDE_MAINWINDOW_H

View File

@ -91,8 +91,8 @@
<property name="title"> <property name="title">
<string>&amp;Acquisition</string> <string>&amp;Acquisition</string>
</property> </property>
<addaction name="action_Start_Recording"/> <addaction name="action_addDevice"/>
<addaction name="action_Stop_Recording"/> <addaction name="action_removeDevice"/>
</widget> </widget>
<widget class="QMenu" name="menu_View"> <widget class="QMenu" name="menu_View">
<property name="font"> <property name="font">
@ -545,27 +545,21 @@
<font/> <font/>
</property> </property>
</action> </action>
<action name="action_Start_Recording"> <action name="action_addDevice">
<property name="text"> <property name="text">
<string>Start Recording</string> <string>Add device</string>
</property> </property>
<property name="font"> <property name="font">
<font/> <font/>
</property> </property>
<property name="shortcut">
<string>F7</string>
</property>
</action> </action>
<action name="action_Stop_Recording"> <action name="action_removeDevice">
<property name="text"> <property name="text">
<string>Stop Recording</string> <string>Remove device</string>
</property> </property>
<property name="font"> <property name="font">
<font/> <font/>
</property> </property>
<property name="shortcut">
<string>F8</string>
</property>
</action> </action>
<action name="action_Audio"> <action name="action_Audio">
<property name="text"> <property name="text">

View File

@ -3,15 +3,16 @@
#include "plugin/pluginmanager.h" #include "plugin/pluginmanager.h"
#include "mainwindow.h" #include "mainwindow.h"
QDockWidget* PluginAPI::createMainWindowDock(Qt::DockWidgetArea dockWidgetArea, const QString& title) // This was used in Tetra demod plugin which is not part of the build anymore
{ //QDockWidget* PluginAPI::createMainWindowDock(Qt::DockWidgetArea dockWidgetArea, const QString& title)
QDockWidget* dock = new QDockWidget(title, m_mainWindow); //{
dock->setAllowedAreas(Qt::AllDockWidgetAreas); // QDockWidget* dock = new QDockWidget(title, m_mainWindow);
dock->setAttribute(Qt::WA_DeleteOnClose); // dock->setAllowedAreas(Qt::AllDockWidgetAreas);
m_mainWindow->addDockWidget(dockWidgetArea, dock); // dock->setAttribute(Qt::WA_DeleteOnClose);
m_mainWindow->addViewAction(dock->toggleViewAction()); // m_mainWindow->addDockWidget(dockWidgetArea, dock);
return dock; // m_mainWindow->addViewAction(dock->toggleViewAction());
} // return dock;
//}
MessageQueue* PluginAPI::getMainWindowMessageQueue() MessageQueue* PluginAPI::getMainWindowMessageQueue()
{ {
@ -139,3 +140,7 @@ PluginAPI::PluginAPI(PluginManager* pluginManager, MainWindow* mainWindow) :
m_mainWindow(mainWindow) m_mainWindow(mainWindow)
{ {
} }
PluginAPI::~PluginAPI()
{
}

View File

@ -26,7 +26,7 @@ class SDRANGEL_API PluginAPI : public QObject {
public: public:
// MainWindow access // MainWindow access
QDockWidget* createMainWindowDock(Qt::DockWidgetArea dockWidgetArea, const QString& title); //QDockWidget* createMainWindowDock(Qt::DockWidgetArea dockWidgetArea, const QString& title);
MessageQueue* getMainWindowMessageQueue(); MessageQueue* getMainWindowMessageQueue();
void setInputGUI(QWidget* inputGUI); void setInputGUI(QWidget* inputGUI);
@ -68,6 +68,7 @@ protected:
MainWindow* m_mainWindow; MainWindow* m_mainWindow;
PluginAPI(PluginManager* pluginManager, MainWindow* mainWindow); PluginAPI(PluginManager* pluginManager, MainWindow* mainWindow);
~PluginAPI();
friend class PluginManager; friend class PluginManager;
}; };