1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-15 21:01:45 -05:00

HackRF input: moved FileRecord out of the GUI

This commit is contained in:
f4exb 2017-09-04 23:49:51 +02:00
parent fc303cc218
commit 9da26ad8b3
4 changed files with 52 additions and 20 deletions

View File

@ -23,6 +23,7 @@
#include "util/simpleserializer.h" #include "util/simpleserializer.h"
#include "dsp/dspcommands.h" #include "dsp/dspcommands.h"
#include "dsp/dspengine.h" #include "dsp/dspengine.h"
#include "dsp/filerecord.h"
#include "device/devicesourceapi.h" #include "device/devicesourceapi.h"
#include "device/devicesinkapi.h" #include "device/devicesinkapi.h"
#include "hackrf/devicehackrfvalues.h" #include "hackrf/devicehackrfvalues.h"
@ -33,6 +34,7 @@
MESSAGE_CLASS_DEFINITION(HackRFInput::MsgConfigureHackRF, Message) MESSAGE_CLASS_DEFINITION(HackRFInput::MsgConfigureHackRF, Message)
MESSAGE_CLASS_DEFINITION(HackRFInput::MsgReportHackRF, Message) MESSAGE_CLASS_DEFINITION(HackRFInput::MsgReportHackRF, Message)
MESSAGE_CLASS_DEFINITION(HackRFInput::MsgFileRecord, Message)
HackRFInput::HackRFInput(DeviceSourceAPI *deviceAPI) : HackRFInput::HackRFInput(DeviceSourceAPI *deviceAPI) :
m_deviceAPI(deviceAPI), m_deviceAPI(deviceAPI),
@ -43,12 +45,20 @@ HackRFInput::HackRFInput(DeviceSourceAPI *deviceAPI) :
m_running(false) m_running(false)
{ {
openDevice(); 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); m_deviceAPI->setBuddySharedPtr(&m_sharedParams);
} }
HackRFInput::~HackRFInput() HackRFInput::~HackRFInput()
{ {
if (m_running) stop(); if (m_running) stop();
m_deviceAPI->removeSink(m_fileSink);
delete m_fileSink;
closeDevice(); closeDevice();
m_deviceAPI->setBuddySharedPtr(0); m_deviceAPI->setBuddySharedPtr(0);
} }
@ -193,6 +203,19 @@ bool HackRFInput::handleMessage(const Message& message)
qDebug("HackRFInput::handleMessage: config error"); qDebug("HackRFInput::handleMessage: config error");
} }
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; return true;
} }
else else
@ -441,6 +464,7 @@ bool HackRFInput::applySettings(const HackRFInputSettings& settings, bool force)
int sampleRate = devSampleRate/(1<<m_settings.m_log2Decim); int sampleRate = devSampleRate/(1<<m_settings.m_log2Decim);
DSPSignalNotification *notif = new DSPSignalNotification(sampleRate, m_settings.m_centerFrequency); DSPSignalNotification *notif = new DSPSignalNotification(sampleRate, m_settings.m_centerFrequency);
m_deviceAPI->getDeviceInputMessageQueue()->push(notif); m_deviceAPI->getDeviceInputMessageQueue()->push(notif);
m_fileSink->handleMessage(*notif); // forward to file sink
} }
m_settings.m_linkTxFrequency = settings.m_linkTxFrequency; m_settings.m_linkTxFrequency = settings.m_linkTxFrequency;

View File

@ -27,6 +27,7 @@
class DeviceSourceAPI; class DeviceSourceAPI;
class HackRFInputThread; class HackRFInputThread;
class FileRecord;
class HackRFInput : public DeviceSampleSource { class HackRFInput : public DeviceSampleSource {
public: 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); HackRFInput(DeviceSourceAPI *deviceAPI);
virtual ~HackRFInput(); virtual ~HackRFInput();
@ -98,6 +118,7 @@ private:
QString m_deviceDescription; QString m_deviceDescription;
DeviceHackRFParams m_sharedParams; DeviceHackRFParams m_sharedParams;
bool m_running; bool m_running;
FileRecord *m_fileSink; //!< File sink to record device I/Q output
}; };
#endif // INCLUDE_HACKRFINPUT_H #endif // INCLUDE_HACKRFINPUT_H

View File

@ -14,7 +14,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>. // // along with this program. If not, see <http://www.gnu.org/licenses/>. //
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
#include "../hackrfinput/hackrfinputgui.h" #include "hackrfinputgui.h"
#include <QDebug> #include <QDebug>
#include <QMessageBox> #include <QMessageBox>
@ -27,7 +27,6 @@
#include "dsp/dspcommands.h" #include "dsp/dspcommands.h"
#include "device/devicesourceapi.h" #include "device/devicesourceapi.h"
#include "device/devicesinkapi.h" #include "device/devicesinkapi.h"
#include "dsp/filerecord.h"
#include "hackrf/devicehackrfvalues.h" #include "hackrf/devicehackrfvalues.h"
#include "ui_hackrfinputgui.h" #include "ui_hackrfinputgui.h"
@ -58,11 +57,6 @@ HackRFInputGui::HackRFInputGui(DeviceSourceAPI *deviceAPI, QWidget* parent) :
displaySettings(); displaySettings();
displayBandwidths(); 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); connect(m_deviceAPI->getDeviceOutputMessageQueue(), SIGNAL(messageEnqueued()), this, SLOT(handleDSPMessages()), Qt::QueuedConnection);
sendSettings(); sendSettings();
@ -70,8 +64,6 @@ HackRFInputGui::HackRFInputGui(DeviceSourceAPI *deviceAPI, QWidget* parent) :
HackRFInputGui::~HackRFInputGui() HackRFInputGui::~HackRFInputGui()
{ {
m_deviceAPI->removeSink(m_fileSink);
delete m_fileSink;
delete m_sampleSource; // Valgrind memcheck delete m_sampleSource; // Valgrind memcheck
delete ui; delete ui;
} }
@ -159,7 +151,6 @@ void HackRFInputGui::handleDSPMessages()
m_deviceCenterFrequency = notif->getCenterFrequency(); m_deviceCenterFrequency = notif->getCenterFrequency();
qDebug("HackRFGui::handleDSPMessages: SampleRate:%d, CenterFrequency:%llu", notif->getSampleRate(), notif->getCenterFrequency()); qDebug("HackRFGui::handleDSPMessages: SampleRate:%d, CenterFrequency:%llu", notif->getSampleRate(), notif->getCenterFrequency());
updateSampleRateAndFrequency(); updateSampleRateAndFrequency();
m_fileSink->handleMessage(*notif); // forward to file sink
delete message; delete message;
} }
@ -355,16 +346,14 @@ void HackRFInputGui::on_startStop_toggled(bool checked)
void HackRFInputGui::on_record_toggled(bool checked) void HackRFInputGui::on_record_toggled(bool checked)
{ {
if (checked) if (checked) {
{
ui->record->setStyleSheet("QToolButton { background-color : red; }"); ui->record->setStyleSheet("QToolButton { background-color : red; }");
m_fileSink->startRecording(); } else {
}
else
{
ui->record->setStyleSheet("QToolButton { background:rgb(79,79,79); }"); 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() void HackRFInputGui::updateHardware()

View File

@ -21,12 +21,11 @@
#include <QTimer> #include <QTimer>
#include <QWidget> #include <QWidget>
#include "../hackrfinput/hackrfinput.h" #include "hackrfinput.h"
#define HACKRF_MAX_DEVICE (32) #define HACKRF_MAX_DEVICE (32)
class DeviceSourceAPI; class DeviceSourceAPI;
class FileRecord;
namespace Ui { namespace Ui {
class HackRFInputGui; class HackRFInputGui;
@ -67,7 +66,6 @@ private:
QTimer m_updateTimer; QTimer m_updateTimer;
QTimer m_statusTimer; QTimer m_statusTimer;
DeviceSampleSource* m_sampleSource; DeviceSampleSource* m_sampleSource;
FileRecord *m_fileSink; //!< File sink to record device I/Q output
int m_sampleRate; int m_sampleRate;
quint64 m_deviceCenterFrequency; //!< Center frequency in device quint64 m_deviceCenterFrequency; //!< Center frequency in device
int m_lastEngineState; int m_lastEngineState;