RTLSDR input: moved FileRecord out of the GUI

This commit is contained in:
f4exb 2017-09-04 11:29:27 +02:00
parent 0b4ee5cfcc
commit fd851592ba
4 changed files with 47 additions and 18 deletions

View File

@ -53,12 +53,6 @@ RTLSDRGui::RTLSDRGui(DeviceSourceAPI *deviceAPI, QWidget* parent) :
displaySettings();
connect(m_sampleSource->getOutputMessageQueueToGUI(), SIGNAL(messageEnqueued()), this, SLOT(handleSourceMessages()));
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);
queryDeviceReport(); // will reply with MsgReportRTLSDR to report gain list
@ -66,8 +60,6 @@ RTLSDRGui::RTLSDRGui(DeviceSourceAPI *deviceAPI, QWidget* parent) :
RTLSDRGui::~RTLSDRGui()
{
m_deviceAPI->removeSink(m_fileSink);
delete m_fileSink;
delete ui;
delete m_sampleSource;
}
@ -169,7 +161,6 @@ void RTLSDRGui::handleDSPMessages()
m_deviceCenterFrequency = notif->getCenterFrequency();
qDebug("RTLSDRGui::handleDSPMessages: SampleRate:%d, CenterFrequency:%llu", notif->getSampleRate(), notif->getCenterFrequency());
updateSampleRateAndFrequency();
m_fileSink->handleMessage(*notif); // forward to file sink
delete message;
}
@ -329,16 +320,14 @@ void RTLSDRGui::on_startStop_toggled(bool checked)
void RTLSDRGui::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();
}
RTLSDRInput::MsgFileRecord* message = RTLSDRInput::MsgFileRecord::create(checked);
m_sampleSource->getInputMessageQueue()->push(message);
}
void RTLSDRGui::queryDeviceReport()

View File

@ -24,7 +24,6 @@
#include "rtlsdrinput.h"
class DeviceSourceAPI;
class FileRecord;
namespace Ui {
class RTLSDRGui;
@ -58,7 +57,6 @@ private:
QTimer m_statusTimer;
std::vector<int> 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;

View File

@ -26,10 +26,12 @@
#include "rtlsdrgui.h"
#include "dsp/dspcommands.h"
#include "dsp/dspengine.h"
#include "dsp/filerecord.h"
MESSAGE_CLASS_DEFINITION(RTLSDRInput::MsgConfigureRTLSDR, Message)
MESSAGE_CLASS_DEFINITION(RTLSDRInput::MsgQueryRTLSDR, Message)
MESSAGE_CLASS_DEFINITION(RTLSDRInput::MsgReportRTLSDR, Message)
MESSAGE_CLASS_DEFINITION(RTLSDRInput::MsgFileRecord, Message)
RTLSDRInput::RTLSDRInput(DeviceSourceAPI *deviceAPI) :
m_deviceAPI(deviceAPI),
@ -40,11 +42,18 @@ RTLSDRInput::RTLSDRInput(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);
}
RTLSDRInput::~RTLSDRInput()
{
if (m_running) stop();
m_deviceAPI->removeSink(m_fileSink);
delete m_fileSink;
closeDevice();
}
@ -246,6 +255,17 @@ bool RTLSDRInput::handleMessage(const Message& message)
return true;
}
else if (MsgFileRecord::match(message))
{
MsgFileRecord& conf = (MsgFileRecord&) message;
qDebug() << "RTLSDRInput::handleMessage: MsgFileRecord: " << conf.getStartStop();
if (conf.getStartStop()) {
m_fileSink->startRecording();
} else {
m_fileSink->stopRecording();
}
}
else
{
return false;
@ -400,6 +420,7 @@ bool RTLSDRInput::applySettings(const RTLSDRSettings& settings, bool force)
int sampleRate = m_settings.m_devSampleRate/(1<<m_settings.m_log2Decim);
DSPSignalNotification *notif = new DSPSignalNotification(sampleRate, m_settings.m_centerFrequency);
m_deviceAPI->getDeviceInputMessageQueue()->push(notif);
m_fileSink->handleMessage(*notif); // forward to file sink
}
return true;

View File

@ -26,6 +26,7 @@
class DeviceSourceAPI;
class RTLSDRThread;
class FileRecord;
class RTLSDRInput : public DeviceSampleSource {
public:
@ -84,6 +85,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)
{ }
};
RTLSDRInput(DeviceSourceAPI *deviceAPI);
virtual ~RTLSDRInput();
@ -101,6 +121,7 @@ public:
private:
DeviceSourceAPI *m_deviceAPI;
FileRecord *m_fileSink; //!< File sink to record device I/Q output
QMutex m_mutex;
RTLSDRSettings m_settings;
rtlsdr_dev_t* m_dev;