From 8e9305c2629513de54c208a17a6aa46347907142 Mon Sep 17 00:00:00 2001 From: f4exb Date: Mon, 4 Sep 2017 22:45:07 +0200 Subject: [PATCH] BladeRF input: moved FileRecord out of the GUI --- plugins/samplesource/airspy/airspyinput.cpp | 2 +- .../bladerfinput/bladerfinput.cpp | 24 +++++++++++++++++++ .../samplesource/bladerfinput/bladerfinput.h | 21 ++++++++++++++++ .../bladerfinput/bladerfinputgui.cpp | 21 ++++------------ .../bladerfinput/bladerfinputgui.h | 2 -- 5 files changed, 51 insertions(+), 19 deletions(-) diff --git a/plugins/samplesource/airspy/airspyinput.cpp b/plugins/samplesource/airspy/airspyinput.cpp index 2d8b781f8..bf2f0f6ac 100644 --- a/plugins/samplesource/airspy/airspyinput.cpp +++ b/plugins/samplesource/airspy/airspyinput.cpp @@ -232,7 +232,7 @@ bool AirspyInput::handleMessage(const Message& message) else if (MsgFileRecord::match(message)) { MsgFileRecord& conf = (MsgFileRecord&) message; - qDebug() << "RTLSDRInput::handleMessage: MsgFileRecord: " << conf.getStartStop(); + qDebug() << "AirspyInput::handleMessage: MsgFileRecord: " << conf.getStartStop(); if (conf.getStartStop()) { m_fileSink->startRecording(); diff --git a/plugins/samplesource/bladerfinput/bladerfinput.cpp b/plugins/samplesource/bladerfinput/bladerfinput.cpp index 6ac0bafed..8339fb6e3 100644 --- a/plugins/samplesource/bladerfinput/bladerfinput.cpp +++ b/plugins/samplesource/bladerfinput/bladerfinput.cpp @@ -23,6 +23,7 @@ #include "util/simpleserializer.h" #include "dsp/dspcommands.h" #include "dsp/dspengine.h" +#include "dsp/filerecord.h" #include "device/devicesourceapi.h" #include "device/devicesinkapi.h" @@ -30,6 +31,7 @@ #include "bladerfinputthread.h" MESSAGE_CLASS_DEFINITION(BladerfInput::MsgConfigureBladerf, Message) +MESSAGE_CLASS_DEFINITION(BladerfInput::MsgFileRecord, Message) BladerfInput::BladerfInput(DeviceSourceAPI *deviceAPI) : m_deviceAPI(deviceAPI), @@ -40,12 +42,20 @@ BladerfInput::BladerfInput(DeviceSourceAPI *deviceAPI) : m_running(false) { openDevice(); + + char recFileNameCStr[30]; + sprintf(recFileNameCStr, "test_%d.sdriq", m_deviceAPI->getDeviceUID()); + m_fileSink = new FileRecord(std::string(recFileNameCStr)); + m_deviceAPI->addSink(m_fileSink); + m_deviceAPI->setBuddySharedPtr(&m_sharedParams); } BladerfInput::~BladerfInput() { if (m_running) stop(); + m_deviceAPI->removeSink(m_fileSink); + delete m_fileSink; closeDevice(); m_deviceAPI->setBuddySharedPtr(0); } @@ -213,6 +223,19 @@ bool BladerfInput::handleMessage(const Message& message) return true; } + else if (MsgFileRecord::match(message)) + { + MsgFileRecord& conf = (MsgFileRecord&) message; + qDebug() << "BladerfInput::handleMessage: MsgFileRecord: " << conf.getStartStop(); + + if (conf.getStartStop()) { + m_fileSink->startRecording(); + } else { + m_fileSink->stopRecording(); + } + + return true; + } else { return false; @@ -487,6 +510,7 @@ bool BladerfInput::applySettings(const BladeRFInputSettings& settings, bool forc int sampleRate = m_settings.m_devSampleRate/(1<getDeviceInputMessageQueue()->push(notif); + m_fileSink->handleMessage(*notif); // forward to file sink } qDebug() << "BladerfInput::applySettings: center freq: " << m_settings.m_centerFrequency << " Hz" diff --git a/plugins/samplesource/bladerfinput/bladerfinput.h b/plugins/samplesource/bladerfinput/bladerfinput.h index c20917692..379197a0f 100644 --- a/plugins/samplesource/bladerfinput/bladerfinput.h +++ b/plugins/samplesource/bladerfinput/bladerfinput.h @@ -28,6 +28,7 @@ class DeviceSourceAPI; class BladerfInputThread; +class FileRecord; class BladerfInput : public DeviceSampleSource { public: @@ -51,6 +52,25 @@ public: { } }; + class MsgFileRecord : public Message { + MESSAGE_CLASS_DECLARATION + + public: + bool getStartStop() const { return m_startStop; } + + static MsgFileRecord* create(bool startStop) { + return new MsgFileRecord(startStop); + } + + protected: + bool m_startStop; + + MsgFileRecord(bool startStop) : + Message(), + m_startStop(startStop) + { } + }; + BladerfInput(DeviceSourceAPI *deviceAPI); virtual ~BladerfInput(); @@ -78,6 +98,7 @@ private: QString m_deviceDescription; DeviceBladeRFParams m_sharedParams; bool m_running; + FileRecord *m_fileSink; //!< File sink to record device I/Q output }; #endif // INCLUDE_BLADERFINPUT_H diff --git a/plugins/samplesource/bladerfinput/bladerfinputgui.cpp b/plugins/samplesource/bladerfinput/bladerfinputgui.cpp index fd28db1bd..de61711e7 100644 --- a/plugins/samplesource/bladerfinput/bladerfinputgui.cpp +++ b/plugins/samplesource/bladerfinput/bladerfinputgui.cpp @@ -27,7 +27,6 @@ #include "dsp/dspengine.h" #include "dsp/dspcommands.h" #include -#include BladerfInputGui::BladerfInputGui(DeviceSourceAPI *deviceAPI, QWidget* parent) : QWidget(parent), @@ -61,18 +60,11 @@ BladerfInputGui::BladerfInputGui(DeviceSourceAPI *deviceAPI, QWidget* parent) : displaySettings(); - char recFileNameCStr[30]; - sprintf(recFileNameCStr, "test_%d.sdriq", m_deviceAPI->getDeviceUID()); - m_fileSink = new FileRecord(std::string(recFileNameCStr)); - m_deviceAPI->addSink(m_fileSink); - connect(m_deviceAPI->getDeviceOutputMessageQueue(), SIGNAL(messageEnqueued()), this, SLOT(handleDSPMessages()), Qt::QueuedConnection); } BladerfInputGui::~BladerfInputGui() { - m_deviceAPI->removeSink(m_fileSink); - delete m_fileSink; delete m_sampleSource; // Valgrind memcheck delete ui; } @@ -148,7 +140,6 @@ void BladerfInputGui::handleDSPMessages() m_deviceCenterFrequency = notif->getCenterFrequency(); qDebug("BladerfGui::handleDSPMessages: SampleRate:%d, CenterFrequency:%llu", notif->getSampleRate(), notif->getCenterFrequency()); updateSampleRateAndFrequency(); - m_fileSink->handleMessage(*notif); // forward to file sink delete message; } @@ -357,16 +348,14 @@ void BladerfInputGui::on_startStop_toggled(bool checked) void BladerfInputGui::on_record_toggled(bool checked) { - if (checked) - { + if (checked) { ui->record->setStyleSheet("QToolButton { background-color : red; }"); - m_fileSink->startRecording(); - } - else - { + } else { ui->record->setStyleSheet("QToolButton { background:rgb(79,79,79); }"); - m_fileSink->stopRecording(); } + + BladerfInput::MsgFileRecord* message = BladerfInput::MsgFileRecord::create(checked); + m_sampleSource->getInputMessageQueue()->push(message); } void BladerfInputGui::updateHardware() diff --git a/plugins/samplesource/bladerfinput/bladerfinputgui.h b/plugins/samplesource/bladerfinput/bladerfinputgui.h index 6d7e737dd..700b506cd 100644 --- a/plugins/samplesource/bladerfinput/bladerfinputgui.h +++ b/plugins/samplesource/bladerfinput/bladerfinputgui.h @@ -24,7 +24,6 @@ #include "bladerfinput.h" class DeviceSourceAPI; -class FileRecord; namespace Ui { class BladerfInputGui; @@ -57,7 +56,6 @@ private: QTimer m_statusTimer; std::vector m_gains; DeviceSampleSource* m_sampleSource; - FileRecord *m_fileSink; //!< File sink to record device I/Q output int m_sampleRate; quint64 m_deviceCenterFrequency; //!< Center frequency in device int m_lastEngineState;