From 622ac932505fe1320d980a0acff432f8058e0825 Mon Sep 17 00:00:00 2001 From: f4exb Date: Mon, 4 Sep 2017 23:35:57 +0200 Subject: [PATCH] FCDPro input: moved FileRecord out of the GUI --- plugins/samplesource/fcdpro/fcdprogui.cpp | 21 +++++-------------- plugins/samplesource/fcdpro/fcdprogui.h | 2 -- plugins/samplesource/fcdpro/fcdproinput.cpp | 23 +++++++++++++++++++++ plugins/samplesource/fcdpro/fcdproinput.h | 21 +++++++++++++++++++ 4 files changed, 49 insertions(+), 18 deletions(-) diff --git a/plugins/samplesource/fcdpro/fcdprogui.cpp b/plugins/samplesource/fcdpro/fcdprogui.cpp index a2ea94658..b211c9ee0 100644 --- a/plugins/samplesource/fcdpro/fcdprogui.cpp +++ b/plugins/samplesource/fcdpro/fcdprogui.cpp @@ -24,7 +24,6 @@ #include "fcdprogui.h" #include -#include #include "fcdproconst.h" FCDProGui::FCDProGui(DeviceSourceAPI *deviceAPI, QWidget* parent) : @@ -144,18 +143,11 @@ FCDProGui::FCDProGui(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); } FCDProGui::~FCDProGui() { - m_deviceAPI->removeSink(m_fileSink); - delete m_fileSink; delete ui; } @@ -233,7 +225,6 @@ void FCDProGui::handleDSPMessages() m_deviceCenterFrequency = notif->getCenterFrequency(); qDebug("FCDProGui::handleDSPMessages: SampleRate:%d, CenterFrequency:%llu", notif->getSampleRate(), notif->getCenterFrequency()); updateSampleRateAndFrequency(); - m_fileSink->handleMessage(*notif); // forward to file sink delete message; } @@ -440,16 +431,14 @@ void FCDProGui::on_startStop_toggled(bool checked) void FCDProGui::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(); } + + FCDProInput::MsgFileRecord* message = FCDProInput::MsgFileRecord::create(checked); + m_sampleSource->getInputMessageQueue()->push(message); } void FCDProGui::updateStatus() diff --git a/plugins/samplesource/fcdpro/fcdprogui.h b/plugins/samplesource/fcdpro/fcdprogui.h index dba35177a..72839e6cd 100644 --- a/plugins/samplesource/fcdpro/fcdprogui.h +++ b/plugins/samplesource/fcdpro/fcdprogui.h @@ -24,7 +24,6 @@ #include "fcdproinput.h" class DeviceSourceAPI; -class FileRecord; class QWidget; namespace Ui { @@ -59,7 +58,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; diff --git a/plugins/samplesource/fcdpro/fcdproinput.cpp b/plugins/samplesource/fcdpro/fcdproinput.cpp index a0a9a6b5f..d015e1d94 100644 --- a/plugins/samplesource/fcdpro/fcdproinput.cpp +++ b/plugins/samplesource/fcdpro/fcdproinput.cpp @@ -23,6 +23,7 @@ #include "dsp/dspcommands.h" #include "dsp/dspengine.h" +#include "dsp/filerecord.h" #include "fcdproinput.h" #include @@ -33,6 +34,7 @@ #include "fcdproconst.h" MESSAGE_CLASS_DEFINITION(FCDProInput::MsgConfigureFCD, Message) +MESSAGE_CLASS_DEFINITION(FCDProInput::MsgFileRecord, Message) FCDProInput::FCDProInput(DeviceSourceAPI *deviceAPI) : m_deviceAPI(deviceAPI), @@ -43,11 +45,18 @@ FCDProInput::FCDProInput(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); } FCDProInput::~FCDProInput() { if (m_running) stop(); + m_deviceAPI->removeSink(m_fileSink); + delete m_fileSink; closeDevice(); } @@ -164,6 +173,19 @@ bool FCDProInput::handleMessage(const Message& message) applySettings(conf.getSettings(), false); return true; } + else if (MsgFileRecord::match(message)) + { + MsgFileRecord& conf = (MsgFileRecord&) message; + qDebug() << "FCDProInput::handleMessage: MsgFileRecord: " << conf.getStartStop(); + + if (conf.getStartStop()) { + m_fileSink->startRecording(); + } else { + m_fileSink->stopRecording(); + } + + return true; + } else { return false; @@ -373,6 +395,7 @@ void FCDProInput::applySettings(const FCDProSettings& settings, bool force) { DSPSignalNotification *notif = new DSPSignalNotification(fcd_traits::sampleRate, m_settings.m_centerFrequency); m_deviceAPI->getDeviceInputMessageQueue()->push(notif); + m_fileSink->handleMessage(*notif); // forward to file sink } } diff --git a/plugins/samplesource/fcdpro/fcdproinput.h b/plugins/samplesource/fcdpro/fcdproinput.h index c4500cdcf..ab1ce4d61 100644 --- a/plugins/samplesource/fcdpro/fcdproinput.h +++ b/plugins/samplesource/fcdpro/fcdproinput.h @@ -32,6 +32,7 @@ struct fcd_buffer { class DeviceSourceAPI; class FCDProThread; +class FileRecord; class FCDProInput : public DeviceSampleSource { public: @@ -55,6 +56,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) + { } + }; + FCDProInput(DeviceSourceAPI *deviceAPI); virtual ~FCDProInput(); @@ -99,6 +119,7 @@ private: FCDProThread* m_FCDThread; QString m_deviceDescription; bool m_running; + FileRecord *m_fileSink; //!< File sink to record device I/Q output }; #endif // INCLUDE_FCDPROINPUT_H