From e750acc7dae13d15de941dc1b806292a624aec2b Mon Sep 17 00:00:00 2001 From: f4exb Date: Thu, 12 May 2016 11:10:10 +0200 Subject: [PATCH] Multi device support: Apply previous changes to RTL-SDR. --- plugins/samplesource/bladerf/bladerfgui.cpp | 4 +- plugins/samplesource/bladerf/bladerfgui.ui | 5 +- plugins/samplesource/rtlsdr/rtlsdrgui.cpp | 71 +++++++++++++++++++++ plugins/samplesource/rtlsdr/rtlsdrgui.h | 23 +++++++ plugins/samplesource/rtlsdr/rtlsdrgui.ui | 68 ++++++++++++++++---- sdrbase/mainwindow.cpp | 58 ----------------- sdrbase/mainwindow.h | 5 -- 7 files changed, 153 insertions(+), 81 deletions(-) diff --git a/plugins/samplesource/bladerf/bladerfgui.cpp b/plugins/samplesource/bladerf/bladerfgui.cpp index 815c23e3f..d97c4b8c0 100644 --- a/plugins/samplesource/bladerf/bladerfgui.cpp +++ b/plugins/samplesource/bladerf/bladerfgui.cpp @@ -156,10 +156,8 @@ void BladerfGui::handleDSPMessages() m_sampleRate = notif->getSampleRate(); m_deviceCenterFrequency = notif->getCenterFrequency(); qDebug("BladerfGui::handleDSPMessages: SampleRate:%d, CenterFrequency:%llu", notif->getSampleRate(), notif->getCenterFrequency()); -// updateCenterFreqDisplay(); updateSampleRateAndFrequency(); -// qDebug() << "MainWindow::handleDSPMessages: forward to file sink"; -// m_fileSink->handleMessage(*notif); + m_fileSink->handleMessage(*notif); // forward to file sink delete message; } diff --git a/plugins/samplesource/bladerf/bladerfgui.ui b/plugins/samplesource/bladerf/bladerfgui.ui index 08f3db25a..c245fbc15 100644 --- a/plugins/samplesource/bladerf/bladerfgui.ui +++ b/plugins/samplesource/bladerf/bladerfgui.ui @@ -55,6 +55,9 @@ + + Record I/Q samples from device + @@ -72,7 +75,7 @@ - Sample rate kS/s + I/Q sample rate kS/s 00000k diff --git a/plugins/samplesource/rtlsdr/rtlsdrgui.cpp b/plugins/samplesource/rtlsdr/rtlsdrgui.cpp index 708c736d6..fb5bdde7c 100644 --- a/plugins/samplesource/rtlsdr/rtlsdrgui.cpp +++ b/plugins/samplesource/rtlsdr/rtlsdrgui.cpp @@ -1,3 +1,19 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2015 Edouard Griffiths, F4EXB // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + #include #include @@ -5,7 +21,10 @@ #include "ui_rtlsdrgui.h" #include "plugin/pluginapi.h" #include "gui/colormapper.h" +#include "gui/glspectrum.h" #include "dsp/dspengine.h" +#include "dsp/dspcommands.h" +#include "dsp/filesink.h" RTLSDRGui::RTLSDRGui(PluginAPI* pluginAPI, QWidget* parent) : QWidget(parent), @@ -35,10 +54,19 @@ RTLSDRGui::RTLSDRGui(PluginAPI* pluginAPI, QWidget* parent) : m_sampleSource = new RTLSDRInput(); connect(m_sampleSource->getOutputMessageQueueToGUI(), SIGNAL(messageEnqueued()), this, SLOT(handleSourceMessages())); DSPEngine::instance()->setSource(m_sampleSource); + + char recFileNameCStr[30]; + sprintf(recFileNameCStr, "test_%d.sdriq", m_pluginAPI->getDeviceUID()); + m_fileSink = new FileSink(std::string(recFileNameCStr)); + m_pluginAPI->addSink(m_fileSink); + + connect(m_pluginAPI->getDeviceOutputMessageQueue(), SIGNAL(messageEnqueued()), this, SLOT(handleDSPMessages()), Qt::QueuedConnection); } RTLSDRGui::~RTLSDRGui() { + m_pluginAPI->removeSink(m_fileSink); + delete m_fileSink; delete ui; } @@ -123,6 +151,28 @@ bool RTLSDRGui::handleMessage(const Message& message) } } +void RTLSDRGui::handleDSPMessages() +{ + Message* message; + + while ((message = m_pluginAPI->getDeviceOutputMessageQueue()->pop()) != 0) + { + qDebug("RTLSDRGui::handleDSPMessages: message: %s", message->getIdentifier()); + + if (DSPSignalNotification::match(*message)) + { + DSPSignalNotification* notif = (DSPSignalNotification*) message; + m_sampleRate = notif->getSampleRate(); + m_deviceCenterFrequency = notif->getCenterFrequency(); + qDebug("RTLSDRGui::handleDSPMessages: SampleRate:%d, CenterFrequency:%llu", notif->getSampleRate(), notif->getCenterFrequency()); + updateSampleRateAndFrequency(); + m_fileSink->handleMessage(*notif); // forward to file sink + + delete message; + } + } +} + void RTLSDRGui::handleSourceMessages() { Message* message; @@ -138,6 +188,13 @@ void RTLSDRGui::handleSourceMessages() } } +void RTLSDRGui::updateSampleRateAndFrequency() +{ + m_pluginAPI->getSpectrum()->setSampleRate(m_sampleRate); + m_pluginAPI->getSpectrum()->setCenterFrequency(m_deviceCenterFrequency); + ui->deviceRateText->setText(tr("%1k").arg((float)m_sampleRate / 1000)); +} + void RTLSDRGui::displaySettings() { ui->centerFrequency->setValue(m_settings.m_centerFrequency / 1000); @@ -269,6 +326,20 @@ void RTLSDRGui::on_startStop_toggled(bool checked) } } +void RTLSDRGui::on_record_toggled(bool checked) +{ + if (checked) + { + ui->record->setStyleSheet("QToolButton { background-color : red; }"); + m_fileSink->startRecording(); + } + else + { + ui->record->setStyleSheet("QToolButton { background:rgb(79,79,79); }"); + m_fileSink->stopRecording(); + } +} + void RTLSDRGui::updateHardware() { RTLSDRInput::MsgConfigureRTLSDR* message = RTLSDRInput::MsgConfigureRTLSDR::create(m_settings); diff --git a/plugins/samplesource/rtlsdr/rtlsdrgui.h b/plugins/samplesource/rtlsdr/rtlsdrgui.h index 7e65b4d3c..b3dcc20e6 100644 --- a/plugins/samplesource/rtlsdr/rtlsdrgui.h +++ b/plugins/samplesource/rtlsdr/rtlsdrgui.h @@ -1,3 +1,19 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2015 Edouard Griffiths, F4EXB // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + #ifndef INCLUDE_RTLSDRGUI_H #define INCLUDE_RTLSDRGUI_H @@ -6,6 +22,7 @@ #include "rtlsdrinput.h" class PluginAPI; +class FileSink; namespace Ui { class RTLSDRGui; @@ -39,12 +56,17 @@ private: QTimer m_statusTimer; std::vector m_gains; SampleSource* m_sampleSource; + FileSink *m_fileSink; //!< File sink to record device I/Q output + int m_sampleRate; + quint64 m_deviceCenterFrequency; //!< Center frequency in device int m_lastEngineState; void displaySettings(); void sendSettings(); + void updateSampleRateAndFrequency(); private slots: + void handleDSPMessages(); void on_centerFrequency_changed(quint64 value); void on_dcOffset_toggled(bool checked); void on_iqImbalance_toggled(bool checked); @@ -55,6 +77,7 @@ private slots: void on_sampleRate_currentIndexChanged(int index); void on_checkBox_stateChanged(int state); void on_startStop_toggled(bool checked); + void on_record_toggled(bool checked); void updateHardware(); void updateStatus(); void handleSourceMessages(); diff --git a/plugins/samplesource/rtlsdr/rtlsdrgui.ui b/plugins/samplesource/rtlsdr/rtlsdrgui.ui index 7caaa66d0..aed73885f 100644 --- a/plugins/samplesource/rtlsdr/rtlsdrgui.ui +++ b/plugins/samplesource/rtlsdr/rtlsdrgui.ui @@ -7,7 +7,7 @@ 0 0 298 - 271 + 189 @@ -35,19 +35,59 @@ - - - start/stop acquisition - - - - - - - :/play.png - :/stop.png:/play.png - - + + + + + + + start/stop acquisition + + + + + + + :/play.png + :/stop.png:/play.png + + + + + + + Record I/Q samples from device + + + + + + + :/record_off.png + :/record_on.png:/record_off.png + + + + + + + + + + + I/Q sample rate kS/s + + + 00000k + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + diff --git a/sdrbase/mainwindow.cpp b/sdrbase/mainwindow.cpp index 572401f6f..21a414f97 100644 --- a/sdrbase/mainwindow.cpp +++ b/sdrbase/mainwindow.cpp @@ -38,7 +38,6 @@ #include "gui/audiodialog.h" #include "dsp/dspengine.h" #include "dsp/spectrumvis.h" -//#include "dsp/filesink.h" #include "dsp/dspcommands.h" #include "plugin/plugingui.h" #include "plugin/pluginapi.h" @@ -104,8 +103,6 @@ MainWindow::MainWindow(QWidget* parent) : // TODO: This will go in a create new device and device tab method: DSPDeviceEngine *dspDeviceEngine = m_dspEngine->getDeviceEngineByIndex(0); - -// connect(dspDeviceEngine->getOutputMessageQueue(), SIGNAL(messageEnqueued()), this, SLOT(handleDSPMessages()), Qt::QueuedConnection); dspDeviceEngine->start(); m_deviceUIs.push_back(new DeviceUISet(m_masterTimer)); @@ -123,9 +120,6 @@ MainWindow::MainWindow(QWidget* parent) : m_deviceUIs.back()->m_sampleSource->blockSignals(sampleSourceSignalsBlocked); ui->tabInputs->addTab(m_deviceUIs.back()->m_sampleSource, "X0"); -// m_fileSink = new FileSink(); -// dspDeviceEngine->addSink(m_fileSink); // TODO: one file sink per device engine - qDebug() << "MainWindow::MainWindow: loadSettings..."; loadSettings(); @@ -174,10 +168,6 @@ MainWindow::~MainWindow() delete m_deviceUIs[i]; } -// m_dspEngine->removeSink(m_fileSink); // TODO: one file sink per device engine -// //m_dspEngine->removeSink(m_rxSpectrumVis); -// delete m_fileSink; - //delete m_rxSpectrumVis; delete m_pluginManager; m_dspEngine->stopAllDeviceEngines(); @@ -193,8 +183,6 @@ void MainWindow::addChannelCreateAction(QAction* action) void MainWindow::addChannelRollup(QWidget* widget) { m_deviceUIs.back()->m_channelWindow->addRollupWidget(widget); - //((ChannelWindow*)ui->rxChannels)->addRollupWidget(widget); - //((ChannelWindow*)ui->channelDock->widget())->addRollupWidget(widget); ui->channelDock->show(); ui->channelDock->raise(); } @@ -206,13 +194,11 @@ void MainWindow::addViewAction(QAction* action) void MainWindow::addChannelMarker(ChannelMarker* channelMarker) { - //ui->rxSpectrum->addChannelMarker(channelMarker); m_deviceUIs.back()->m_spectrum->addChannelMarker(channelMarker); } void MainWindow::removeChannelMarker(ChannelMarker* channelMarker) { - //ui->rxSpectrum->removeChannelMarker(channelMarker); m_deviceUIs.back()->m_spectrum->removeChannelMarker(channelMarker); } @@ -243,7 +229,6 @@ void MainWindow::loadPresetSettings(const Preset* preset) qPrintable(preset->getGroup()), qPrintable(preset->getDescription())); - //ui->rxSpectrumGUI->deserialize(preset->getSpectrumConfig()); m_deviceUIs.back()->m_spectrumGUI->deserialize(preset->getSpectrumConfig()); m_pluginManager->loadSettings(preset); @@ -265,7 +250,6 @@ void MainWindow::savePresetSettings(Preset* preset) qPrintable(preset->getGroup()), qPrintable(preset->getDescription())); - //preset->setSpectrumConfig(ui->rxSpectrumGUI->serialize()); preset->setSpectrumConfig(m_deviceUIs.back()->m_spectrumGUI->serialize()); preset->clearChannels(); m_pluginManager->saveSettings(preset); @@ -290,13 +274,11 @@ void MainWindow::closeEvent(QCloseEvent*) void MainWindow::updateCenterFreqDisplay() { - //ui->rxSpectrum->setCenterFrequency(m_centerFrequency); m_deviceUIs.back()->m_spectrum->setCenterFrequency(m_centerFrequency); } void MainWindow::updateSampleRate() { - //ui->rxSpectrum->setSampleRate(m_sampleRate); m_deviceUIs.back()->m_spectrum->setSampleRate(m_sampleRate); m_sampleRateWidget->setText(tr("Rate: %1 kHz").arg((float)m_sampleRate / 1000)); } @@ -358,30 +340,6 @@ void MainWindow::applySettings() updateSampleRate(); } -void MainWindow::handleDSPMessages() -{ - Message* message; - - while ((message = m_dspEngine->getOutputMessageQueue()->pop()) != 0) - { - qDebug("MainWindow::handleDSPMessages: message: %s", message->getIdentifier()); - - if (DSPSignalNotification::match(*message)) - { - DSPSignalNotification* notif = (DSPSignalNotification*) message; - m_sampleRate = notif->getSampleRate(); - m_centerFrequency = notif->getCenterFrequency(); - qDebug("SampleRate:%d, CenterFrequency:%llu", notif->getSampleRate(), notif->getCenterFrequency()); - updateCenterFreqDisplay(); - updateSampleRate(); -// qDebug() << "MainWindow::handleDSPMessages: forward to file sink"; -// m_fileSink->handleMessage(*notif); - - delete message; - } - } -} - void MainWindow::handleMessages() { Message* message; @@ -397,18 +355,6 @@ void MainWindow::handleMessages() } } -//void MainWindow::on_action_Start_Recording_triggered() -//{ -// m_recording->setColor(Qt::red); -// m_fileSink->startRecording(); -//} -// -//void MainWindow::on_action_Stop_Recording_triggered() -//{ -// m_recording->setColor(Qt::gray); -// m_fileSink->stopRecording(); -//} - void MainWindow::on_action_View_Fullscreen_toggled(bool checked) { if(checked) @@ -535,8 +481,6 @@ void MainWindow::on_presetImport_clicked() preset->setGroup(group); // override with current group ui->presetTree->setCurrentItem(addPresetToTree(preset)); -// loadPresetSettings(preset); -// applySettings(); } else { @@ -652,8 +596,6 @@ void MainWindow::on_action_DV_Serial_triggered(bool checked) void MainWindow::on_sampleSource_currentIndexChanged(int index) { m_pluginManager->saveSourceSettings(m_settings.getWorkingPreset()); - //m_pluginManager->selectSampleSourceByIndex(ui->sampleSource->currentIndex()); - //m_settings.setSourceIndex(ui->sampleSource->currentIndex()); m_pluginManager->selectSampleSourceByIndex(m_deviceUIs.back()->m_sampleSource->currentIndex()); m_settings.setSourceIndex(m_deviceUIs.back()->m_sampleSource->currentIndex()); m_pluginManager->loadSourceSettings(m_settings.getWorkingPreset()); diff --git a/sdrbase/mainwindow.h b/sdrbase/mainwindow.h index 835a37969..ee3429c79 100644 --- a/sdrbase/mainwindow.h +++ b/sdrbase/mainwindow.h @@ -37,7 +37,6 @@ class SpectrumVis; class GLSpectrum; class GLSpectrumGUI; class ChannelWindow; -//class FileSink; class SampleSource; class PluginAPI; class PluginGUI; @@ -96,7 +95,6 @@ private: MainSettings m_settings; SpectrumVis* m_rxSpectrumVis; -// FileSink *m_fileSink; std::vector m_deviceUIs; @@ -133,10 +131,7 @@ private: void createDevice(); private slots: - void handleDSPMessages(); void handleMessages(); -// void on_action_Start_Recording_triggered(); -// void on_action_Stop_Recording_triggered(); void on_action_View_Fullscreen_toggled(bool checked); void on_presetSave_clicked(); void on_presetUpdate_clicked();