diff --git a/plugins/samplesource/hackrfinput/hackrfinput.cpp b/plugins/samplesource/hackrfinput/hackrfinput.cpp index 6a751c69b..a2595d072 100644 --- a/plugins/samplesource/hackrfinput/hackrfinput.cpp +++ b/plugins/samplesource/hackrfinput/hackrfinput.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" #include "hackrf/devicehackrfvalues.h" @@ -33,6 +34,7 @@ MESSAGE_CLASS_DEFINITION(HackRFInput::MsgConfigureHackRF, Message) MESSAGE_CLASS_DEFINITION(HackRFInput::MsgReportHackRF, Message) +MESSAGE_CLASS_DEFINITION(HackRFInput::MsgFileRecord, Message) HackRFInput::HackRFInput(DeviceSourceAPI *deviceAPI) : m_deviceAPI(deviceAPI), @@ -43,12 +45,20 @@ HackRFInput::HackRFInput(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); } HackRFInput::~HackRFInput() { if (m_running) stop(); + m_deviceAPI->removeSink(m_fileSink); + delete m_fileSink; closeDevice(); m_deviceAPI->setBuddySharedPtr(0); } @@ -195,6 +205,19 @@ bool HackRFInput::handleMessage(const Message& message) return true; } + else if (MsgFileRecord::match(message)) + { + MsgFileRecord& conf = (MsgFileRecord&) message; + qDebug() << "HackRFInput::handleMessage: MsgFileRecord: " << conf.getStartStop(); + + if (conf.getStartStop()) { + m_fileSink->startRecording(); + } else { + m_fileSink->stopRecording(); + } + + return true; + } else { return false; @@ -441,6 +464,7 @@ bool HackRFInput::applySettings(const HackRFInputSettings& settings, bool force) int sampleRate = devSampleRate/(1<getDeviceInputMessageQueue()->push(notif); + m_fileSink->handleMessage(*notif); // forward to file sink } m_settings.m_linkTxFrequency = settings.m_linkTxFrequency; diff --git a/plugins/samplesource/hackrfinput/hackrfinput.h b/plugins/samplesource/hackrfinput/hackrfinput.h index 2340dfee6..d373076cc 100644 --- a/plugins/samplesource/hackrfinput/hackrfinput.h +++ b/plugins/samplesource/hackrfinput/hackrfinput.h @@ -27,6 +27,7 @@ class DeviceSourceAPI; class HackRFInputThread; +class FileRecord; class HackRFInput : public DeviceSampleSource { public: @@ -71,6 +72,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) + { } + }; + HackRFInput(DeviceSourceAPI *deviceAPI); virtual ~HackRFInput(); @@ -98,6 +118,7 @@ private: QString m_deviceDescription; DeviceHackRFParams m_sharedParams; bool m_running; + FileRecord *m_fileSink; //!< File sink to record device I/Q output }; #endif // INCLUDE_HACKRFINPUT_H diff --git a/plugins/samplesource/hackrfinput/hackrfinputgui.cpp b/plugins/samplesource/hackrfinput/hackrfinputgui.cpp index 595b6d76d..8af31441e 100644 --- a/plugins/samplesource/hackrfinput/hackrfinputgui.cpp +++ b/plugins/samplesource/hackrfinput/hackrfinputgui.cpp @@ -14,7 +14,7 @@ // along with this program. If not, see . // /////////////////////////////////////////////////////////////////////////////////// -#include "../hackrfinput/hackrfinputgui.h" +#include "hackrfinputgui.h" #include #include @@ -27,7 +27,6 @@ #include "dsp/dspcommands.h" #include "device/devicesourceapi.h" #include "device/devicesinkapi.h" -#include "dsp/filerecord.h" #include "hackrf/devicehackrfvalues.h" #include "ui_hackrfinputgui.h" @@ -58,11 +57,6 @@ HackRFInputGui::HackRFInputGui(DeviceSourceAPI *deviceAPI, QWidget* parent) : displaySettings(); displayBandwidths(); - 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); sendSettings(); @@ -70,8 +64,6 @@ HackRFInputGui::HackRFInputGui(DeviceSourceAPI *deviceAPI, QWidget* parent) : HackRFInputGui::~HackRFInputGui() { - m_deviceAPI->removeSink(m_fileSink); - delete m_fileSink; delete m_sampleSource; // Valgrind memcheck delete ui; } @@ -159,7 +151,6 @@ void HackRFInputGui::handleDSPMessages() 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; } @@ -355,16 +346,14 @@ void HackRFInputGui::on_startStop_toggled(bool checked) void HackRFInputGui::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(); } + + HackRFInput::MsgFileRecord* message = HackRFInput::MsgFileRecord::create(checked); + m_sampleSource->getInputMessageQueue()->push(message); } void HackRFInputGui::updateHardware() diff --git a/plugins/samplesource/hackrfinput/hackrfinputgui.h b/plugins/samplesource/hackrfinput/hackrfinputgui.h index 5560167a3..27219e8e6 100644 --- a/plugins/samplesource/hackrfinput/hackrfinputgui.h +++ b/plugins/samplesource/hackrfinput/hackrfinputgui.h @@ -21,12 +21,11 @@ #include #include -#include "../hackrfinput/hackrfinput.h" +#include "hackrfinput.h" #define HACKRF_MAX_DEVICE (32) class DeviceSourceAPI; -class FileRecord; namespace Ui { class HackRFInputGui; @@ -67,7 +66,6 @@ private: QTimer m_updateTimer; QTimer m_statusTimer; 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;