From ea1f2208f7fe72bb4a80121ea862d8121f56f2ee Mon Sep 17 00:00:00 2001 From: f4exb Date: Thu, 12 May 2016 17:18:08 +0200 Subject: [PATCH] Multi device support: Aligned HackRF plugin --- plugins/samplesource/hackrf/hackrfgui.cpp | 55 +++++++++++++++++++ plugins/samplesource/hackrf/hackrfgui.h | 7 +++ plugins/samplesource/hackrf/hackrfgui.ui | 65 ++++++++++++++++++----- 3 files changed, 114 insertions(+), 13 deletions(-) diff --git a/plugins/samplesource/hackrf/hackrfgui.cpp b/plugins/samplesource/hackrf/hackrfgui.cpp index 7146e632f..5b489fd54 100644 --- a/plugins/samplesource/hackrf/hackrfgui.cpp +++ b/plugins/samplesource/hackrf/hackrfgui.cpp @@ -21,7 +21,10 @@ #include "plugin/pluginapi.h" #include "gui/colormapper.h" +#include "gui/glspectrum.h" #include "dsp/dspengine.h" +#include "dsp/dspcommands.h" +#include "dsp/filesink.h" #include "hackrfgui.h" #include "ui_hackrfgui.h" @@ -49,10 +52,19 @@ HackRFGui::HackRFGui(PluginAPI* pluginAPI, QWidget* parent) : displayBandwidths(); 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); } HackRFGui::~HackRFGui() { + m_pluginAPI->removeSink(m_fileSink); + delete m_fileSink; delete m_sampleSource; // Valgrind memcheck delete ui; } @@ -113,6 +125,35 @@ bool HackRFGui::handleMessage(const Message& message) return false; } +void HackRFGui::handleDSPMessages() +{ + Message* message; + + while ((message = m_pluginAPI->getDeviceOutputMessageQueue()->pop()) != 0) + { + qDebug("HackRFGui::handleDSPMessages: message: %s", message->getIdentifier()); + + if (DSPSignalNotification::match(*message)) + { + DSPSignalNotification* notif = (DSPSignalNotification*) message; + m_sampleRate = notif->getSampleRate(); + m_deviceCenterFrequency = notif->getCenterFrequency(); + qDebug("HackRFGui::handleDSPMessages: SampleRate:%d, CenterFrequency:%llu", notif->getSampleRate(), notif->getCenterFrequency()); + updateSampleRateAndFrequency(); + m_fileSink->handleMessage(*notif); // forward to file sink + + delete message; + } + } +} + +void HackRFGui::updateSampleRateAndFrequency() +{ + m_pluginAPI->getSpectrum()->setSampleRate(m_sampleRate); + m_pluginAPI->getSpectrum()->setCenterFrequency(m_deviceCenterFrequency); + ui->deviceRateText->setText(tr("%1k").arg((float)m_sampleRate / 1000)); +} + void HackRFGui::displaySettings() { ui->centerFrequency->setValue(m_settings.m_centerFrequency / 1000); @@ -301,6 +342,20 @@ void HackRFGui::on_startStop_toggled(bool checked) } } +void HackRFGui::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 HackRFGui::updateHardware() { qDebug() << "HackRFGui::updateHardware"; diff --git a/plugins/samplesource/hackrf/hackrfgui.h b/plugins/samplesource/hackrf/hackrfgui.h index c8b5d0bab..d98eda3bd 100644 --- a/plugins/samplesource/hackrf/hackrfgui.h +++ b/plugins/samplesource/hackrf/hackrfgui.h @@ -25,6 +25,7 @@ #define HACKRF_MAX_DEVICE (32) class PluginAPI; +class FileSink; namespace Ui { class HackRFGui; @@ -64,14 +65,19 @@ private: QTimer m_updateTimer; QTimer m_statusTimer; 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 displaySampleRates(); void displayBandwidths(); void sendSettings(); + void updateSampleRateAndFrequency(); private slots: + void handleDSPMessages(); void on_centerFrequency_changed(quint64 value); void on_LOppm_valueChanged(int value); void on_dcOffset_toggled(bool checked); @@ -85,6 +91,7 @@ private slots: void on_bbFilter_currentIndexChanged(int index); void on_vga_valueChanged(int value); void on_startStop_toggled(bool checked); + void on_record_toggled(bool checked); void updateHardware(); void updateStatus(); }; diff --git a/plugins/samplesource/hackrf/hackrfgui.ui b/plugins/samplesource/hackrf/hackrfgui.ui index 593c53f1f..cd57eae29 100644 --- a/plugins/samplesource/hackrf/hackrfgui.ui +++ b/plugins/samplesource/hackrf/hackrfgui.ui @@ -41,19 +41,58 @@ - - - start/stop acquisition - - - - - - - :/play.png - :/stop.png:/play.png - - + + + + + + + start/stop acquisition + + + + + + + :/play.png + :/stop.png:/play.png + + + + + + + Toggle record I/Q samples from device + + + + + + + :/record_off.png:/record_off.png + + + + + + + + + + + I/Q sample rate kS/s + + + 00000k + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + +