SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
FileRecord Class Reference

#include <filerecord.h>

+ Inheritance diagram for FileRecord:
+ Collaboration diagram for FileRecord:

Classes

struct  Header
 

Public Member Functions

 FileRecord ()
 
 FileRecord (const QString &filename)
 
virtual ~FileRecord ()
 
quint64 getByteCount () const
 
void setFileName (const QString &filename)
 
void genUniqueFileName (uint deviceUID, int istream=-1)
 
virtual void feed (const SampleVector::const_iterator &begin, const SampleVector::const_iterator &end, bool positiveOnly)
 
virtual void start ()
 
virtual void stop ()
 
virtual bool handleMessage (const Message &message)
 Processing of a message. Returns true if message has actually been processed. More...
 
void startRecording ()
 
void stopRecording ()
 
bool isRecording () const
 
- Public Member Functions inherited from BasebandSampleSink
 BasebandSampleSink ()
 
virtual ~BasebandSampleSink ()
 
MessageQueuegetInputMessageQueue ()
 Get the queue for asynchronous inbound communication. More...
 
virtual void setMessageQueueToGUI (MessageQueue *queue)
 
MessageQueuegetMessageQueueToGUI ()
 

Static Public Member Functions

static bool readHeader (std::ifstream &samplefile, Header &header)
 returns true if CRC checksum is correct else false More...
 
static void writeHeader (std::ofstream &samplefile, Header &header)
 

Private Member Functions

void handleConfigure (const QString &fileName)
 
void writeHeader ()
 

Private Attributes

QString m_fileName
 
quint32 m_sampleRate
 
quint64 m_centerFrequency
 
bool m_recordOn
 
bool m_recordStart
 
std::ofstream m_sampleFile
 
quint64 m_byteCount
 

Additional Inherited Members

- Protected Slots inherited from BasebandSampleSink
void handleInputMessages ()
 
- Protected Attributes inherited from BasebandSampleSink
MessageQueue m_inputMessageQueue
 Queue for asynchronous inbound communication. More...
 
MessageQueuem_guiMessageQueue
 Input message queue to the GUI. More...
 

Detailed Description

Definition at line 31 of file filerecord.h.

Constructor & Destructor Documentation

◆ FileRecord() [1/2]

FileRecord::FileRecord ( )

Definition at line 30 of file filerecord.cpp.

30  :
32  m_fileName("test.sdriq"),
33  m_sampleRate(0),
35  m_recordOn(false),
36  m_recordStart(false),
37  m_byteCount(0)
38 {
39  setObjectName("FileSink");
40 }
quint64 m_byteCount
Definition: filerecord.h:72
bool m_recordStart
Definition: filerecord.h:70
quint32 m_sampleRate
Definition: filerecord.h:67
quint64 m_centerFrequency
Definition: filerecord.h:68
bool m_recordOn
Definition: filerecord.h:69
QString m_fileName
Definition: filerecord.h:66

◆ FileRecord() [2/2]

FileRecord::FileRecord ( const QString &  filename)

Definition at line 42 of file filerecord.cpp.

42  :
44  m_fileName(filename),
45  m_sampleRate(0),
47  m_recordOn(false),
48  m_recordStart(false),
49  m_byteCount(0)
50 {
51  setObjectName("FileRecord");
52 }
quint64 m_byteCount
Definition: filerecord.h:72
bool m_recordStart
Definition: filerecord.h:70
quint32 m_sampleRate
Definition: filerecord.h:67
quint64 m_centerFrequency
Definition: filerecord.h:68
bool m_recordOn
Definition: filerecord.h:69
QString m_fileName
Definition: filerecord.h:66

◆ ~FileRecord()

FileRecord::~FileRecord ( )
virtual

Definition at line 54 of file filerecord.cpp.

References stopRecording().

55 {
56  stopRecording();
57 }
void stopRecording()
Definition: filerecord.cpp:117
+ Here is the call graph for this function:

Member Function Documentation

◆ feed()

void FileRecord::feed ( const SampleVector::const_iterator &  begin,
const SampleVector::const_iterator &  end,
bool  positiveOnly 
)
virtual

Implements BasebandSampleSink.

Definition at line 76 of file filerecord.cpp.

References m_byteCount, m_recordOn, m_recordStart, m_sampleFile, and writeHeader().

77 {
78  (void) positiveOnly;
79  // if no recording is active, send the samples to /dev/null
80  if(!m_recordOn)
81  return;
82 
83  if (begin < end) // if there is something to put out
84  {
85  if (m_recordStart)
86  {
87  writeHeader();
88  m_recordStart = false;
89  }
90 
91  m_sampleFile.write(reinterpret_cast<const char*>(&*(begin)), (end - begin)*sizeof(Sample));
92  m_byteCount += end - begin;
93  }
94 }
quint64 m_byteCount
Definition: filerecord.h:72
bool m_recordStart
Definition: filerecord.h:70
void writeHeader()
Definition: filerecord.cpp:155
std::ofstream m_sampleFile
Definition: filerecord.h:71
bool m_recordOn
Definition: filerecord.h:69
+ Here is the call graph for this function:

◆ genUniqueFileName()

void FileRecord::genUniqueFileName ( uint  deviceUID,
int  istream = -1 
)

Definition at line 67 of file filerecord.cpp.

References arg(), and setFileName().

Referenced by TestSourceInput::handleMessage(), AirspyInput::handleMessage(), PerseusInput::handleMessage(), RTLSDRInput::handleMessage(), AirspyHFInput::handleMessage(), PlutoSDRInput::handleMessage(), Bladerf1Input::handleMessage(), FCDProInput::handleMessage(), FCDProPlusInput::handleMessage(), HackRFInput::handleMessage(), KiwiSDRInput::handleMessage(), LocalInput::handleMessage(), SDRPlayInput::handleMessage(), BladeRF2Input::handleMessage(), SoapySDRInput::handleMessage(), LimeSDRInput::handleMessage(), and RemoteInput::handleMessage().

68 {
69  if (istream < 0) {
70  setFileName(QString("rec%1_%2.sdriq").arg(deviceUID).arg(QDateTime::currentDateTimeUtc().toString("yyyy-MM-ddTHH_mm_ss_zzz")));
71  } else {
72  setFileName(QString("rec%1_%2_%3.sdriq").arg(deviceUID).arg(istream).arg(QDateTime::currentDateTimeUtc().toString("yyyy-MM-ddTHH_mm_ss_zzz")));
73  }
74 }
void setFileName(const QString &filename)
Definition: filerecord.cpp:59
Fixed< IntType, IntBits > arg(const std::complex< Fixed< IntType, IntBits > > &val)
Definition: fixed.h:2401
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getByteCount()

quint64 FileRecord::getByteCount ( ) const
inline

Definition at line 50 of file filerecord.h.

50 { return m_byteCount; }
quint64 m_byteCount
Definition: filerecord.h:72

◆ handleConfigure()

void FileRecord::handleConfigure ( const QString &  fileName)
private

Definition at line 145 of file filerecord.cpp.

References m_fileName, and stopRecording().

146 {
147  if (fileName != m_fileName)
148  {
149  stopRecording();
150  }
151 
152  m_fileName = fileName;
153 }
void stopRecording()
Definition: filerecord.cpp:117
QString m_fileName
Definition: filerecord.h:66
+ Here is the call graph for this function:

◆ handleMessage()

bool FileRecord::handleMessage ( const Message cmd)
virtual

Processing of a message. Returns true if message has actually been processed.

Implements BasebandSampleSink.

Definition at line 128 of file filerecord.cpp.

References DSPSignalNotification::getCenterFrequency(), DSPSignalNotification::getSampleRate(), m_centerFrequency, m_sampleRate, and Message::match().

Referenced by TestSourceInput::applySettings(), Bladerf1Input::applySettings(), PerseusInput::applySettings(), AirspyInput::applySettings(), AirspyHFInput::applySettings(), RTLSDRInput::applySettings(), PlutoSDRInput::applySettings(), HackRFInput::applySettings(), FCDProPlusInput::applySettings(), KiwiSDRInput::applySettings(), FCDProInput::applySettings(), SDRPlayInput::applySettings(), BladeRF2Input::applySettings(), SoapySDRInput::applySettings(), LimeSDRInput::applySettings(), HackRFInput::handleMessage(), LocalInput::handleMessage(), BladeRF2Input::handleMessage(), and RemoteInput::handleMessage().

129 {
130  if (DSPSignalNotification::match(message))
131  {
132  DSPSignalNotification& notif = (DSPSignalNotification&) message;
133  m_sampleRate = notif.getSampleRate();
135  qDebug() << "FileRecord::handleMessage: DSPSignalNotification: m_inputSampleRate: " << m_sampleRate
136  << " m_centerFrequency: " << m_centerFrequency;
137  return true;
138  }
139  else
140  {
141  return false;
142  }
143 }
quint32 m_sampleRate
Definition: filerecord.h:67
qint64 getCenterFrequency() const
Definition: dspcommands.h:329
quint64 m_centerFrequency
Definition: filerecord.h:68
static bool match(const Message *message)
Definition: message.cpp:45
int getSampleRate() const
Definition: dspcommands.h:328
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isRecording()

bool FileRecord::isRecording ( ) const
inline

Definition at line 61 of file filerecord.h.

61 { return m_recordOn; }
bool m_recordOn
Definition: filerecord.h:69

◆ readHeader()

bool FileRecord::readHeader ( std::ifstream &  samplefile,
Header header 
)
static

returns true if CRC checksum is correct else false

Definition at line 168 of file filerecord.cpp.

References leansdr::crc32().

Referenced by FileInput::openFileStream(), and FileSource::openFileStream().

169 {
170  sampleFile.read((char *) &header, sizeof(Header));
171  boost::crc_32_type crc32;
172  crc32.process_bytes(&header, 28);
173  return header.crc32 == crc32.checksum();
174 }
uint32_t crc32(const uint8_t *buf, int len)
Definition: crc.h:58
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setFileName()

void FileRecord::setFileName ( const QString &  filename)

◆ start()

void FileRecord::start ( )
virtual

Implements BasebandSampleSink.

Definition at line 96 of file filerecord.cpp.

97 {
98 }

◆ startRecording()

void FileRecord::startRecording ( )

◆ stop()

void FileRecord::stop ( )
virtual

Implements BasebandSampleSink.

Definition at line 100 of file filerecord.cpp.

References stopRecording().

101 {
102  stopRecording();
103 }
void stopRecording()
Definition: filerecord.cpp:117
+ Here is the call graph for this function:

◆ stopRecording()

void FileRecord::stopRecording ( )

◆ writeHeader() [1/2]

void FileRecord::writeHeader ( std::ofstream &  samplefile,
Header header 
)
static

Definition at line 176 of file filerecord.cpp.

References FileRecord::Header::crc32, and leansdr::crc32().

177 {
178  boost::crc_32_type crc32;
179  crc32.process_bytes(&header, 28);
180  header.crc32 = crc32.checksum();
181  sampleFile.write((const char *) &header, sizeof(Header));
182 }
uint32_t crc32(const uint8_t *buf, int len)
Definition: crc.h:58
+ Here is the call graph for this function:

◆ writeHeader() [2/2]

void FileRecord::writeHeader ( )
private

Definition at line 155 of file filerecord.cpp.

References FileRecord::Header::centerFrequency, FileRecord::Header::filler, m_centerFrequency, m_sampleFile, m_sampleRate, FileRecord::Header::sampleRate, FileRecord::Header::sampleSize, SDR_RX_SAMP_SZ, and FileRecord::Header::startTimeStamp.

Referenced by feed(), and FileSinkOutput::openFileStream().

156 {
157  Header header;
158  header.sampleRate = m_sampleRate;
159  header.centerFrequency = m_centerFrequency;
160  std::time_t ts = time(0);
161  header.startTimeStamp = ts;
162  header.sampleSize = SDR_RX_SAMP_SZ;
163  header.filler = 0;
164 
165  writeHeader(m_sampleFile, header);
166 }
quint32 m_sampleRate
Definition: filerecord.h:67
void writeHeader()
Definition: filerecord.cpp:155
#define SDR_RX_SAMP_SZ
Definition: dsptypes.h:32
quint64 m_centerFrequency
Definition: filerecord.h:68
std::ofstream m_sampleFile
Definition: filerecord.h:71
+ Here is the caller graph for this function:

Member Data Documentation

◆ m_byteCount

quint64 FileRecord::m_byteCount
private

Definition at line 72 of file filerecord.h.

Referenced by feed(), and startRecording().

◆ m_centerFrequency

quint64 FileRecord::m_centerFrequency
private

Definition at line 68 of file filerecord.h.

Referenced by handleMessage(), and writeHeader().

◆ m_fileName

QString FileRecord::m_fileName
private

Definition at line 66 of file filerecord.h.

Referenced by handleConfigure(), setFileName(), and startRecording().

◆ m_recordOn

bool FileRecord::m_recordOn
private

Definition at line 69 of file filerecord.h.

Referenced by feed(), setFileName(), startRecording(), and stopRecording().

◆ m_recordStart

bool FileRecord::m_recordStart
private

Definition at line 70 of file filerecord.h.

Referenced by feed(), startRecording(), and stopRecording().

◆ m_sampleFile

std::ofstream FileRecord::m_sampleFile
private

Definition at line 71 of file filerecord.h.

Referenced by feed(), startRecording(), stopRecording(), and writeHeader().

◆ m_sampleRate

quint32 FileRecord::m_sampleRate
private

Definition at line 67 of file filerecord.h.

Referenced by handleMessage(), and writeHeader().


The documentation for this class was generated from the following files: