From 0981d04904e6902511a09505235e3d0a54cece1c Mon Sep 17 00:00:00 2001 From: f4exb Date: Tue, 8 May 2018 11:03:09 +0200 Subject: [PATCH] File record default file name fix (1) --- plugins/samplesource/airspy/airspyinput.cpp | 5 +---- plugins/samplesource/airspyhf/airspyhfinput.cpp | 5 +---- .../samplesource/bladerfinput/bladerfinput.cpp | 5 +---- plugins/samplesource/fcdpro/fcdproinput.cpp | 5 +---- .../samplesource/fcdproplus/fcdproplusinput.cpp | 5 +---- .../samplesource/hackrfinput/hackrfinput.cpp | 17 ++++++++++++----- .../hackrfinput/hackrfinputsettings.cpp | 1 + .../hackrfinput/hackrfinputsettings.h | 2 ++ .../samplesource/limesdrinput/limesdrinput.cpp | 4 +--- plugins/samplesource/perseus/perseusinput.cpp | 4 +--- .../plutosdrinput/plutosdrinput.cpp | 4 +--- plugins/samplesource/rtlsdr/rtlsdrinput.cpp | 4 +--- .../sdrdaemonsource/sdrdaemonsourceinput.cpp | 4 +--- plugins/samplesource/sdrplay/sdrplayinput.cpp | 5 +---- .../samplesource/testsource/testsourceinput.cpp | 4 +--- sdrbase/dsp/filerecord.cpp | 12 ++++++------ sdrbase/dsp/filerecord.h | 8 ++++---- 17 files changed, 37 insertions(+), 57 deletions(-) diff --git a/plugins/samplesource/airspy/airspyinput.cpp b/plugins/samplesource/airspy/airspyinput.cpp index 586cf15c0..2266b09f8 100644 --- a/plugins/samplesource/airspy/airspyinput.cpp +++ b/plugins/samplesource/airspy/airspyinput.cpp @@ -48,10 +48,7 @@ AirspyInput::AirspyInput(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_fileSink = new FileRecord(QString("test_%1.sdriq").arg(m_deviceAPI->getDeviceUID())); m_deviceAPI->addSink(m_fileSink); } diff --git a/plugins/samplesource/airspyhf/airspyhfinput.cpp b/plugins/samplesource/airspyhf/airspyhfinput.cpp index 564775a79..c817050d5 100644 --- a/plugins/samplesource/airspyhf/airspyhfinput.cpp +++ b/plugins/samplesource/airspyhf/airspyhfinput.cpp @@ -50,10 +50,7 @@ AirspyHFInput::AirspyHFInput(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_fileSink = new FileRecord(QString("test_%1.sdriq").arg(m_deviceAPI->getDeviceUID())); m_deviceAPI->addSink(m_fileSink); } diff --git a/plugins/samplesource/bladerfinput/bladerfinput.cpp b/plugins/samplesource/bladerfinput/bladerfinput.cpp index 3837f57d8..76f6f8766 100644 --- a/plugins/samplesource/bladerfinput/bladerfinput.cpp +++ b/plugins/samplesource/bladerfinput/bladerfinput.cpp @@ -45,10 +45,7 @@ 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_fileSink = new FileRecord(QString("test_%1.sdriq").arg(m_deviceAPI->getDeviceUID())); m_deviceAPI->addSink(m_fileSink); m_deviceAPI->setBuddySharedPtr(&m_sharedParams); diff --git a/plugins/samplesource/fcdpro/fcdproinput.cpp b/plugins/samplesource/fcdpro/fcdproinput.cpp index d7ab49f11..e84ec0121 100644 --- a/plugins/samplesource/fcdpro/fcdproinput.cpp +++ b/plugins/samplesource/fcdpro/fcdproinput.cpp @@ -49,10 +49,7 @@ 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_fileSink = new FileRecord(QString("test_%1.sdriq").arg(m_deviceAPI->getDeviceUID())); m_deviceAPI->addSink(m_fileSink); } diff --git a/plugins/samplesource/fcdproplus/fcdproplusinput.cpp b/plugins/samplesource/fcdproplus/fcdproplusinput.cpp index 2aeeda9bb..37d658879 100644 --- a/plugins/samplesource/fcdproplus/fcdproplusinput.cpp +++ b/plugins/samplesource/fcdproplus/fcdproplusinput.cpp @@ -48,10 +48,7 @@ FCDProPlusInput::FCDProPlusInput(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_fileSink = new FileRecord(QString("test_%1.sdriq").arg(m_deviceAPI->getDeviceUID())); m_deviceAPI->addSink(m_fileSink); } diff --git a/plugins/samplesource/hackrfinput/hackrfinput.cpp b/plugins/samplesource/hackrfinput/hackrfinput.cpp index e77151439..2559fabc7 100644 --- a/plugins/samplesource/hackrfinput/hackrfinput.cpp +++ b/plugins/samplesource/hackrfinput/hackrfinput.cpp @@ -49,9 +49,7 @@ HackRFInput::HackRFInput(DeviceSourceAPI *deviceAPI) : { openDevice(); - char recFileNameCStr[30]; - sprintf(recFileNameCStr, "test_%d.sdriq", m_deviceAPI->getDeviceUID()); - m_fileSink = new FileRecord(std::string(recFileNameCStr)); + m_fileSink = new FileRecord(QString("test_%1.sdriq").arg(m_deviceAPI->getDeviceUID())); m_deviceAPI->addSink(m_fileSink); m_deviceAPI->setBuddySharedPtr(&m_sharedParams); @@ -260,9 +258,18 @@ bool HackRFInput::handleMessage(const Message& message) MsgFileRecord& conf = (MsgFileRecord&) message; qDebug() << "HackRFInput::handleMessage: MsgFileRecord: " << conf.getStartStop(); - if (conf.getStartStop()) { + if (conf.getStartStop()) + { + if (m_settings.m_fileRecordName.size() != 0) { + m_fileSink->setFileName(m_settings.m_fileRecordName); + } else { + m_fileSink->setFileName(QString("rec_%1_%2.sdriq").arg(m_deviceAPI->getDeviceUID()).arg(QDateTime::currentDateTimeUtc().toString("yyyy-MM-ddThh:mm:ss"))); + } + m_fileSink->startRecording(); - } else { + } + else + { m_fileSink->stopRecording(); } diff --git a/plugins/samplesource/hackrfinput/hackrfinputsettings.cpp b/plugins/samplesource/hackrfinput/hackrfinputsettings.cpp index 67c667cdc..d2831bcc1 100644 --- a/plugins/samplesource/hackrfinput/hackrfinputsettings.cpp +++ b/plugins/samplesource/hackrfinput/hackrfinputsettings.cpp @@ -40,6 +40,7 @@ void HackRFInputSettings::resetToDefaults() m_iqCorrection = false; m_devSampleRate = 2400000; m_linkTxFrequency = false; + m_fileRecordName = ""; } QByteArray HackRFInputSettings::serialize() const diff --git a/plugins/samplesource/hackrfinput/hackrfinputsettings.h b/plugins/samplesource/hackrfinput/hackrfinputsettings.h index 2a5f4ed22..b2f0b3056 100644 --- a/plugins/samplesource/hackrfinput/hackrfinputsettings.h +++ b/plugins/samplesource/hackrfinput/hackrfinputsettings.h @@ -18,6 +18,7 @@ #define _HACKRF_HACKRFINPUTSETTINGS_H_ #include +#include struct HackRFInputSettings { typedef enum { @@ -39,6 +40,7 @@ struct HackRFInputSettings { bool m_dcBlock; bool m_iqCorrection; bool m_linkTxFrequency; + QString m_fileRecordName; HackRFInputSettings(); void resetToDefaults(); diff --git a/plugins/samplesource/limesdrinput/limesdrinput.cpp b/plugins/samplesource/limesdrinput/limesdrinput.cpp index 05c5f15c5..07bf4222c 100644 --- a/plugins/samplesource/limesdrinput/limesdrinput.cpp +++ b/plugins/samplesource/limesdrinput/limesdrinput.cpp @@ -57,9 +57,7 @@ LimeSDRInput::LimeSDRInput(DeviceSourceAPI *deviceAPI) : resumeTxBuddies(); resumeRxBuddies(); - char recFileNameCStr[30]; - sprintf(recFileNameCStr, "test_%d.sdriq", m_deviceAPI->getDeviceUID()); - m_fileSink = new FileRecord(std::string(recFileNameCStr)); + m_fileSink = new FileRecord(QString("test_%1.sdriq").arg(m_deviceAPI->getDeviceUID())); m_deviceAPI->addSink(m_fileSink); } diff --git a/plugins/samplesource/perseus/perseusinput.cpp b/plugins/samplesource/perseus/perseusinput.cpp index d3e933416..ad9b7e889 100644 --- a/plugins/samplesource/perseus/perseusinput.cpp +++ b/plugins/samplesource/perseus/perseusinput.cpp @@ -41,9 +41,7 @@ PerseusInput::PerseusInput(DeviceSourceAPI *deviceAPI) : m_perseusDescriptor(0) { openDevice(); - char recFileNameCStr[30]; - sprintf(recFileNameCStr, "test_%d.sdriq", m_deviceAPI->getDeviceUID()); - m_fileSink = new FileRecord(std::string(recFileNameCStr)); + m_fileSink = new FileRecord(QString("test_%1.sdriq").arg(m_deviceAPI->getDeviceUID())); m_deviceAPI->addSink(m_fileSink); } diff --git a/plugins/samplesource/plutosdrinput/plutosdrinput.cpp b/plugins/samplesource/plutosdrinput/plutosdrinput.cpp index eb786ea7e..0f977ce6e 100644 --- a/plugins/samplesource/plutosdrinput/plutosdrinput.cpp +++ b/plugins/samplesource/plutosdrinput/plutosdrinput.cpp @@ -55,9 +55,7 @@ PlutoSDRInput::PlutoSDRInput(DeviceSourceAPI *deviceAPI) : openDevice(); resumeBuddies(); - char recFileNameCStr[30]; - sprintf(recFileNameCStr, "test_%d.sdriq", m_deviceAPI->getDeviceUID()); - m_fileSink = new FileRecord(std::string(recFileNameCStr)); + m_fileSink = new FileRecord(QString("test_%1.sdriq").arg(m_deviceAPI->getDeviceUID())); m_deviceAPI->addSink(m_fileSink); } diff --git a/plugins/samplesource/rtlsdr/rtlsdrinput.cpp b/plugins/samplesource/rtlsdr/rtlsdrinput.cpp index a9d3a5b9b..9278ff555 100644 --- a/plugins/samplesource/rtlsdr/rtlsdrinput.cpp +++ b/plugins/samplesource/rtlsdr/rtlsdrinput.cpp @@ -53,9 +53,7 @@ RTLSDRInput::RTLSDRInput(DeviceSourceAPI *deviceAPI) : { openDevice(); - char recFileNameCStr[30]; - sprintf(recFileNameCStr, "test_%d.sdriq", m_deviceAPI->getDeviceUID()); - m_fileSink = new FileRecord(std::string(recFileNameCStr)); + m_fileSink = new FileRecord(QString("test_%1.sdriq").arg(m_deviceAPI->getDeviceUID())); m_deviceAPI->addSink(m_fileSink); } diff --git a/plugins/samplesource/sdrdaemonsource/sdrdaemonsourceinput.cpp b/plugins/samplesource/sdrdaemonsource/sdrdaemonsourceinput.cpp index 5652419c6..d38695119 100644 --- a/plugins/samplesource/sdrdaemonsource/sdrdaemonsourceinput.cpp +++ b/plugins/samplesource/sdrdaemonsource/sdrdaemonsourceinput.cpp @@ -63,9 +63,7 @@ SDRdaemonSourceInput::SDRdaemonSourceInput(DeviceSourceAPI *deviceAPI) : m_sampleFifo.setSize(96000 * 4); m_SDRdaemonUDPHandler = new SDRdaemonSourceUDPHandler(&m_sampleFifo, m_deviceAPI); - char recFileNameCStr[30]; - sprintf(recFileNameCStr, "test_%d.sdriq", m_deviceAPI->getDeviceUID()); - m_fileSink = new FileRecord(std::string(recFileNameCStr)); + m_fileSink = new FileRecord(QString("test_%1.sdriq").arg(m_deviceAPI->getDeviceUID())); m_deviceAPI->addSink(m_fileSink); } diff --git a/plugins/samplesource/sdrplay/sdrplayinput.cpp b/plugins/samplesource/sdrplay/sdrplayinput.cpp index 64af98d9f..d8d86e4f0 100644 --- a/plugins/samplesource/sdrplay/sdrplayinput.cpp +++ b/plugins/samplesource/sdrplay/sdrplayinput.cpp @@ -48,10 +48,7 @@ SDRPlayInput::SDRPlayInput(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_fileSink = new FileRecord(QString("test_%1.sdriq").arg(m_deviceAPI->getDeviceUID())); m_deviceAPI->addSink(m_fileSink); } diff --git a/plugins/samplesource/testsource/testsourceinput.cpp b/plugins/samplesource/testsource/testsourceinput.cpp index b6516090c..4ac79a456 100644 --- a/plugins/samplesource/testsource/testsourceinput.cpp +++ b/plugins/samplesource/testsource/testsourceinput.cpp @@ -41,9 +41,7 @@ TestSourceInput::TestSourceInput(DeviceSourceAPI *deviceAPI) : m_running(false), m_masterTimer(deviceAPI->getMasterTimer()) { - char recFileNameCStr[30]; - sprintf(recFileNameCStr, "test_%d.sdriq", m_deviceAPI->getDeviceUID()); - m_fileSink = new FileRecord(std::string(recFileNameCStr)); + m_fileSink = new FileRecord(QString("test_%1.sdriq").arg(m_deviceAPI->getDeviceUID())); m_deviceAPI->addSink(m_fileSink); if (!m_sampleFifo.setSize(96000 * 4)) { diff --git a/sdrbase/dsp/filerecord.cpp b/sdrbase/dsp/filerecord.cpp index 82fc684c8..39e947a03 100644 --- a/sdrbase/dsp/filerecord.cpp +++ b/sdrbase/dsp/filerecord.cpp @@ -7,7 +7,7 @@ FileRecord::FileRecord() : BasebandSampleSink(), - m_fileName(std::string("test.sdriq")), + m_fileName("test.sdriq"), m_sampleRate(0), m_centerFrequency(0), m_recordOn(false), @@ -17,9 +17,9 @@ FileRecord::FileRecord() : setObjectName("FileSink"); } -FileRecord::FileRecord(const std::string& filename) : +FileRecord::FileRecord(const QString& filename) : BasebandSampleSink(), - m_fileName(std::string(filename)), + m_fileName(filename), m_sampleRate(0), m_centerFrequency(0), m_recordOn(false), @@ -34,7 +34,7 @@ FileRecord::~FileRecord() stopRecording(); } -void FileRecord::setFileName(const std::string& filename) +void FileRecord::setFileName(const QString& filename) { if (!m_recordOn) { @@ -75,7 +75,7 @@ void FileRecord::startRecording() if (!m_sampleFile.is_open()) { qDebug() << "FileRecord::startRecording"; - m_sampleFile.open(m_fileName.c_str(), std::ios::binary); + m_sampleFile.open(m_fileName.toStdString().c_str(), std::ios::binary); m_recordOn = true; m_recordStart = true; m_byteCount = 0; @@ -110,7 +110,7 @@ bool FileRecord::handleMessage(const Message& message) } } -void FileRecord::handleConfigure(const std::string& fileName) +void FileRecord::handleConfigure(const QString& fileName) { if (fileName != m_fileName) { diff --git a/sdrbase/dsp/filerecord.h b/sdrbase/dsp/filerecord.h index 9272d07a7..00840c469 100644 --- a/sdrbase/dsp/filerecord.h +++ b/sdrbase/dsp/filerecord.h @@ -23,12 +23,12 @@ public: }; FileRecord(); - FileRecord(const std::string& filename); + FileRecord(const QString& filename); virtual ~FileRecord(); quint64 getByteCount() const { return m_byteCount; } - void setFileName(const std::string& filename); + void setFileName(const QString& filename); virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool positiveOnly); virtual void start(); @@ -39,7 +39,7 @@ public: static void readHeader(std::ifstream& samplefile, Header& header); private: - std::string m_fileName; + QString m_fileName; qint32 m_sampleRate; quint64 m_centerFrequency; bool m_recordOn; @@ -47,7 +47,7 @@ private: std::ofstream m_sampleFile; quint64 m_byteCount; - void handleConfigure(const std::string& fileName); + void handleConfigure(const QString& fileName); void writeHeader(); };