2016-10-02 08:30:58 +00:00
|
|
|
#include <dsp/filerecord.h>
|
2015-08-14 03:00:28 +00:00
|
|
|
#include "dsp/dspcommands.h"
|
2015-07-28 21:54:17 +00:00
|
|
|
#include "util/simpleserializer.h"
|
2016-05-12 08:31:57 +00:00
|
|
|
#include "util/message.h"
|
2015-07-28 21:54:17 +00:00
|
|
|
|
2015-08-09 08:33:04 +00:00
|
|
|
#include <QDebug>
|
2015-07-28 21:54:17 +00:00
|
|
|
|
2016-10-02 08:30:58 +00:00
|
|
|
FileRecord::FileRecord() :
|
2016-10-02 20:29:04 +00:00
|
|
|
BasebandSampleSink(),
|
2015-07-28 21:54:17 +00:00
|
|
|
m_fileName(std::string("test.sdriq")),
|
|
|
|
m_sampleRate(0),
|
|
|
|
m_centerFrequency(0),
|
|
|
|
m_recordOn(false),
|
|
|
|
m_recordStart(false),
|
|
|
|
m_byteCount(0)
|
|
|
|
{
|
2015-08-12 07:03:02 +00:00
|
|
|
setObjectName("FileSink");
|
2015-07-28 21:54:17 +00:00
|
|
|
}
|
|
|
|
|
2016-10-02 08:30:58 +00:00
|
|
|
FileRecord::FileRecord(const std::string& filename) :
|
2016-10-02 20:29:04 +00:00
|
|
|
BasebandSampleSink(),
|
2016-05-12 08:31:57 +00:00
|
|
|
m_fileName(std::string(filename)),
|
|
|
|
m_sampleRate(0),
|
|
|
|
m_centerFrequency(0),
|
|
|
|
m_recordOn(false),
|
|
|
|
m_recordStart(false),
|
|
|
|
m_byteCount(0)
|
|
|
|
{
|
2016-10-08 08:35:07 +00:00
|
|
|
setObjectName("FileRecord");
|
2016-05-12 08:31:57 +00:00
|
|
|
}
|
|
|
|
|
2016-10-02 08:30:58 +00:00
|
|
|
FileRecord::~FileRecord()
|
2015-07-28 21:54:17 +00:00
|
|
|
{
|
|
|
|
stopRecording();
|
|
|
|
}
|
|
|
|
|
2016-10-02 08:30:58 +00:00
|
|
|
void FileRecord::setFileName(const std::string& filename)
|
2015-07-28 21:54:17 +00:00
|
|
|
{
|
2016-05-12 08:31:57 +00:00
|
|
|
if (!m_recordOn)
|
|
|
|
{
|
|
|
|
m_fileName = filename;
|
|
|
|
}
|
2015-07-28 21:54:17 +00:00
|
|
|
}
|
|
|
|
|
2017-05-25 18:13:34 +00:00
|
|
|
void FileRecord::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool positiveOnly __attribute__((unused)))
|
2015-07-28 21:54:17 +00:00
|
|
|
{
|
|
|
|
// if no recording is active, send the samples to /dev/null
|
|
|
|
if(!m_recordOn)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (begin < end) // if there is something to put out
|
|
|
|
{
|
|
|
|
if (m_recordStart)
|
|
|
|
{
|
|
|
|
writeHeader();
|
|
|
|
m_recordStart = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_sampleFile.write(reinterpret_cast<const char*>(&*(begin)), (end - begin)*sizeof(Sample));
|
|
|
|
m_byteCount += end - begin;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-02 08:30:58 +00:00
|
|
|
void FileRecord::start()
|
2015-07-28 21:54:17 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-10-02 08:30:58 +00:00
|
|
|
void FileRecord::stop()
|
2015-07-28 21:54:17 +00:00
|
|
|
{
|
|
|
|
stopRecording();
|
|
|
|
}
|
|
|
|
|
2016-10-02 08:30:58 +00:00
|
|
|
void FileRecord::startRecording()
|
2015-07-28 21:54:17 +00:00
|
|
|
{
|
|
|
|
if (!m_sampleFile.is_open())
|
|
|
|
{
|
2016-10-08 08:35:07 +00:00
|
|
|
qDebug() << "FileRecord::startRecording";
|
2015-07-28 21:54:17 +00:00
|
|
|
m_sampleFile.open(m_fileName.c_str(), std::ios::binary);
|
|
|
|
m_recordOn = true;
|
|
|
|
m_recordStart = true;
|
|
|
|
m_byteCount = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-02 08:30:58 +00:00
|
|
|
void FileRecord::stopRecording()
|
2015-07-28 21:54:17 +00:00
|
|
|
{
|
|
|
|
if (m_sampleFile.is_open())
|
|
|
|
{
|
2016-10-08 08:35:07 +00:00
|
|
|
qDebug() << "FileRecord::stopRecording";
|
2015-07-28 21:54:17 +00:00
|
|
|
m_sampleFile.close();
|
|
|
|
m_recordOn = false;
|
|
|
|
m_recordStart = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-02 08:30:58 +00:00
|
|
|
bool FileRecord::handleMessage(const Message& message)
|
2015-07-28 21:54:17 +00:00
|
|
|
{
|
2016-10-08 08:35:07 +00:00
|
|
|
qDebug() << "FileRecord::handleMessage";
|
2015-08-17 06:29:34 +00:00
|
|
|
|
|
|
|
if (DSPSignalNotification::match(message))
|
|
|
|
{
|
|
|
|
DSPSignalNotification& notif = (DSPSignalNotification&) message;
|
|
|
|
m_sampleRate = notif.getSampleRate();
|
2015-08-19 20:12:52 +00:00
|
|
|
m_centerFrequency = notif.getCenterFrequency();
|
2016-10-08 08:35:07 +00:00
|
|
|
qDebug() << "FileRecord::handleMessage: DSPSignalNotification: m_inputSampleRate: " << m_sampleRate
|
2015-08-17 06:29:34 +00:00
|
|
|
<< " m_centerFrequency: " << m_centerFrequency;
|
|
|
|
return true;
|
|
|
|
}
|
2015-07-28 21:54:17 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-02 08:30:58 +00:00
|
|
|
void FileRecord::handleConfigure(const std::string& fileName)
|
2015-07-28 21:54:17 +00:00
|
|
|
{
|
2015-08-14 03:00:28 +00:00
|
|
|
if (fileName != m_fileName)
|
2015-07-28 21:54:17 +00:00
|
|
|
{
|
|
|
|
stopRecording();
|
|
|
|
}
|
2016-05-12 08:31:57 +00:00
|
|
|
|
2015-07-28 21:54:17 +00:00
|
|
|
m_fileName = fileName;
|
|
|
|
}
|
|
|
|
|
2016-10-02 08:30:58 +00:00
|
|
|
void FileRecord::writeHeader()
|
2015-07-28 21:54:17 +00:00
|
|
|
{
|
|
|
|
m_sampleFile.write((const char *) &m_sampleRate, sizeof(int));
|
|
|
|
m_sampleFile.write((const char *) &m_centerFrequency, sizeof(quint64));
|
|
|
|
std::time_t ts = time(0);
|
|
|
|
m_sampleFile.write((const char *) &ts, sizeof(std::time_t));
|
|
|
|
}
|
|
|
|
|
2016-10-02 08:30:58 +00:00
|
|
|
void FileRecord::readHeader(std::ifstream& sampleFile, Header& header)
|
2015-07-28 21:54:17 +00:00
|
|
|
{
|
|
|
|
sampleFile.read((char *) &(header.sampleRate), sizeof(int));
|
|
|
|
sampleFile.read((char *) &(header.centerFrequency), sizeof(quint64));
|
|
|
|
sampleFile.read((char *) &(header.startTimeStamp), sizeof(std::time_t));
|
|
|
|
}
|