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 Attributes | Private Slots | Private Member Functions | Private Attributes | List of all members
FileSource Class Reference

#include <filesource.h>

+ Inheritance diagram for FileSource:
+ Collaboration diagram for FileSource:

Classes

struct  MagSqLevelsStore
 
class  MsgConfigureChannelizer
 
class  MsgConfigureFileSource
 
class  MsgConfigureFileSourceName
 
class  MsgConfigureFileSourceSeek
 
class  MsgConfigureFileSourceStreamTiming
 
class  MsgConfigureFileSourceWork
 
class  MsgPlayPause
 
class  MsgReportFileSourceAcquisition
 
class  MsgReportFileSourceStreamData
 
class  MsgReportFileSourceStreamTiming
 
class  MsgReportHeaderCRC
 
class  MsgSampleRateNotification
 

Public Member Functions

 FileSource (DeviceAPI *deviceAPI)
 
 ~FileSource ()
 
virtual void destroy ()
 
virtual void pull (Sample &sample)
 
virtual void pullAudio (int nbSamples)
 
virtual void start ()
 
virtual void stop ()
 
virtual bool handleMessage (const Message &cmd)
 Processing of a message. Returns true if message has actually been processed. More...
 
virtual void getIdentifier (QString &id)
 
virtual void getTitle (QString &title)
 
virtual qint64 getCenterFrequency () const
 Applies to a default stream. More...
 
virtual int getNbSinkStreams () const
 
virtual int getNbSourceStreams () const
 
virtual qint64 getStreamCenterFrequency (int streamIndex, bool sinkElseSource) const
 
virtual QByteArray serialize () const
 
virtual bool deserialize (const QByteArray &data)
 
virtual int webapiSettingsGet (SWGSDRangel::SWGChannelSettings &response, QString &errorMessage)
 
virtual int webapiSettingsPutPatch (bool force, const QStringList &channelSettingsKeys, SWGSDRangel::SWGChannelSettings &response, QString &errorMessage)
 
virtual int webapiReportGet (SWGSDRangel::SWGChannelReport &response, QString &errorMessage)
 
void setCenterFrequency (uint64_t centerFrequency)
 
void setSampleRate (uint32_t sampleRate)
 
quint64 getSamplesCount () const
 
double getMagSq () const
 
void getMagSqLevels (double &avg, double &peak, int &nbSamples)
 
- Public Member Functions inherited from BasebandSampleSource
 BasebandSampleSource ()
 
virtual ~BasebandSampleSource ()
 
void feed (SampleSourceFifo *sampleFifo, int nbSamples)
 
SampleSourceFifogetSampleSourceFifo ()
 
MessageQueuegetInputMessageQueue ()
 Get the queue for asynchronous inbound communication. More...
 
virtual void setMessageQueueToGUI (MessageQueue *queue)
 
MessageQueuegetMessageQueueToGUI ()
 
void setDeviceSampleSourceFifo (SampleSourceFifo *deviceSampleFifo)
 
- Public Member Functions inherited from ChannelAPI
 ChannelAPI (const QString &name, StreamType streamType)
 
virtual ~ChannelAPI ()
 
virtual void setName (const QString &name)
 
virtual const QString & getName () const
 
int getIndexInDeviceSet () const
 
void setIndexInDeviceSet (int indexInDeviceSet)
 
int getDeviceSetIndex () const
 
void setDeviceSetIndex (int deviceSetIndex)
 
DeviceAPIgetDeviceAPI ()
 
void setDeviceAPI (DeviceAPI *deviceAPI)
 
uint64_t getUID () const
 
StreamType getStreamType () const
 

Static Public Attributes

static const QString m_channelIdURI = "sdrangel.channeltx.filesource"
 
static const QString m_channelId ="FileSource"
 

Private Slots

void networkManagerFinished (QNetworkReply *reply)
 

Private Member Functions

void openFileStream ()
 
void seekFileStream (int seekMillis)
 
void handleEOF ()
 
void applySettings (const FileSourceSettings &settings, bool force=false)
 
void validateFilterChainHash (FileSourceSettings &settings)
 
void calculateFrequencyOffset ()
 
void webapiFormatChannelSettings (SWGSDRangel::SWGChannelSettings &response, const FileSourceSettings &settings)
 
void webapiFormatChannelReport (SWGSDRangel::SWGChannelReport &response)
 
void webapiReverseSendSettings (QList< QString > &channelSettingsKeys, const FileSourceSettings &settings, bool force)
 

Private Attributes

DeviceAPIm_deviceAPI
 
QMutex m_mutex
 
ThreadedBasebandSampleSourcem_threadedChannelizer
 
UpChannelizerm_channelizer
 
FileSourceSettings m_settings
 
std::ifstream m_ifstream
 
QString m_fileName
 
quint32 m_sampleSize
 
quint64 m_centerFrequency
 
int64_t m_frequencyOffset
 
uint32_t m_fileSampleRate
 
quint64 m_samplesCount
 
uint32_t m_sampleRate
 
uint32_t m_deviceSampleRate
 
quint64 m_recordLength
 record length in seconds computed from file size More...
 
quint64 m_startingTimeStamp
 
QTimer m_masterTimer
 
bool m_running
 
QNetworkAccessManager * m_networkManager
 
QNetworkRequest m_networkRequest
 
double m_linearGain
 
double m_magsq
 
double m_magsqSum
 
double m_magsqPeak
 
int m_magsqCount
 
MagSqLevelsStore m_magSqLevelStore
 
MovingAverageUtil< Real, double, 16 > m_movingAverage
 

Additional Inherited Members

- Public Types inherited from ChannelAPI
enum  StreamType { StreamSingleSink, StreamSingleSource, StreamMIMO }
 < This is the same enum as in PluginInterface More...
 
- Protected Slots inherited from BasebandSampleSource
void handleInputMessages ()
 
void handleWriteToFifo (int nbSamples)
 
void handleWriteToDeviceFifo (int nbSamples)
 
- Protected Member Functions inherited from BasebandSampleSource
void handleWriteToFifo (SampleSourceFifo *sampleFifo, int nbSamples)
 
- Protected Attributes inherited from BasebandSampleSource
MessageQueue m_inputMessageQueue
 Queue for asynchronous inbound communication. More...
 
MessageQueuem_guiMessageQueue
 Input message queue to the GUI. More...
 
SampleSourceFifo m_sampleFifo
 Internal FIFO for multi-channel processing. More...
 
SampleSourceFifom_deviceSampleFifo
 Reference to the device FIFO for single channel processing. More...
 

Detailed Description

Definition at line 44 of file filesource.h.

Constructor & Destructor Documentation

◆ FileSource()

FileSource::FileSource ( DeviceAPI deviceAPI)

Definition at line 62 of file filesource.cpp.

References DeviceAPI::addChannelSource(), DeviceAPI::addChannelSourceAPI(), m_channelId, m_channelizer, m_deviceAPI, m_linearGain, m_magsq, m_magsqCount, m_magsqPeak, m_magsqSum, m_networkManager, m_threadedChannelizer, and networkManagerFinished().

Referenced by FileSource::MsgReportHeaderCRC::MsgReportHeaderCRC().

62  :
64  m_deviceAPI(deviceAPI),
65  m_fileName("..."),
66  m_sampleSize(0),
70  m_samplesCount(0),
71  m_sampleRate(0),
73  m_recordLength(0),
75  m_running(false)
76 {
77  setObjectName(m_channelId);
78 
79  m_channelizer = new UpChannelizer(this);
83 
84  m_networkManager = new QNetworkAccessManager();
85  connect(m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkManagerFinished(QNetworkReply*)));
86 
87  m_linearGain = 1.0f;
88  m_magsq = 0.0f;
89  m_magsqSum = 0.0f;
90  m_magsqPeak = 0.0f;
91  m_magsqCount = 0;
92 }
quint64 m_startingTimeStamp
Definition: filesource.h:406
QNetworkAccessManager * m_networkManager
Definition: filesource.h:409
uint32_t m_sampleRate
Definition: filesource.h:403
quint32 m_sampleSize
Definition: filesource.h:398
DeviceAPI * m_deviceAPI
Definition: filesource.h:391
QString m_fileName
Definition: filesource.h:397
void networkManagerFinished(QNetworkReply *reply)
Definition: filesource.cpp:703
uint32_t m_fileSampleRate
Definition: filesource.h:401
bool m_running
Definition: filesource.h:408
Exposes a single source stream (output, Tx)
Definition: channelapi.h:42
UpChannelizer * m_channelizer
Definition: filesource.h:394
void addChannelSource(ThreadedBasebandSampleSource *sink, int streamIndex=0)
Add a channel source (Tx)
Definition: deviceapi.cpp:138
double m_magsq
Definition: filesource.h:413
static const QString m_channelId
Definition: filesource.h:378
ChannelAPI(const QString &name, StreamType streamType)
Definition: channelapi.cpp:23
quint64 m_recordLength
record length in seconds computed from file size
Definition: filesource.h:405
double m_magsqSum
Definition: filesource.h:414
int64_t m_frequencyOffset
Definition: filesource.h:400
ThreadedBasebandSampleSource * m_threadedChannelizer
Definition: filesource.h:393
quint64 m_centerFrequency
Definition: filesource.h:399
void addChannelSourceAPI(ChannelAPI *channelAPI, int streamIndex=0)
Definition: deviceapi.cpp:174
uint32_t m_deviceSampleRate
Definition: filesource.h:404
double m_linearGain
Definition: filesource.h:412
int m_magsqCount
Definition: filesource.h:416
static const QString m_channelIdURI
Definition: filesource.h:377
double m_magsqPeak
Definition: filesource.h:415
quint64 m_samplesCount
Definition: filesource.h:402
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ~FileSource()

FileSource::~FileSource ( )

Definition at line 94 of file filesource.cpp.

References m_channelizer, m_deviceAPI, m_networkManager, m_threadedChannelizer, networkManagerFinished(), DeviceAPI::removeChannelSource(), and DeviceAPI::removeChannelSourceAPI().

Referenced by FileSource::MsgReportHeaderCRC::MsgReportHeaderCRC().

95 {
96  disconnect(m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkManagerFinished(QNetworkReply*)));
97  delete m_networkManager;
100  delete m_threadedChannelizer;
101  delete m_channelizer;
102 }
QNetworkAccessManager * m_networkManager
Definition: filesource.h:409
void removeChannelSourceAPI(ChannelAPI *channelAPI, int streamIndex=0)
Definition: deviceapi.cpp:181
DeviceAPI * m_deviceAPI
Definition: filesource.h:391
void removeChannelSource(ThreadedBasebandSampleSource *sink, int streamIndex=0)
Remove a channel source (Tx)
Definition: deviceapi.cpp:147
void networkManagerFinished(QNetworkReply *reply)
Definition: filesource.cpp:703
UpChannelizer * m_channelizer
Definition: filesource.h:394
ThreadedBasebandSampleSource * m_threadedChannelizer
Definition: filesource.h:393
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Function Documentation

◆ applySettings()

void FileSource::applySettings ( const FileSourceSettings settings,
bool  force = false 
)
private

Definition at line 465 of file filesource.cpp.

References FileSourceSettings::m_fileName, FileSourceSettings::m_gainDB, m_linearGain, FileSourceSettings::m_loop, FileSourceSettings::m_reverseAPIAddress, FileSourceSettings::m_reverseAPIChannelIndex, FileSourceSettings::m_reverseAPIDeviceIndex, FileSourceSettings::m_reverseAPIPort, m_settings, FileSourceSettings::m_useReverseAPI, CalcDb::powerFromdB(), and webapiReverseSendSettings().

Referenced by handleMessage().

466 {
467  qDebug() << "FileSource::applySettings:"
468  << " force: " << force;
469 
470  QList<QString> reverseAPIKeys;
471 
472  if ((m_settings.m_loop != settings.m_loop) || force) {
473  reverseAPIKeys.append("loop");
474  }
475  if ((m_settings.m_fileName != settings.m_fileName) || force) {
476  reverseAPIKeys.append("fileName");
477  }
478 
479  if ((m_settings.m_gainDB != settings.m_gainDB) || force)
480  {
482  reverseAPIKeys.append("gainDB");
483  }
484 
485  if (settings.m_useReverseAPI)
486  {
487  bool fullUpdate = ((m_settings.m_useReverseAPI != settings.m_useReverseAPI) && settings.m_useReverseAPI) ||
492  webapiReverseSendSettings(reverseAPIKeys, settings, fullUpdate || force);
493  }
494 
495  m_settings = settings;
496 }
uint16_t m_reverseAPIChannelIndex
uint16_t m_reverseAPIDeviceIndex
FileSourceSettings m_settings
Definition: filesource.h:395
double m_linearGain
Definition: filesource.h:412
void webapiReverseSendSettings(QList< QString > &channelSettingsKeys, const FileSourceSettings &settings, bool force)
Definition: filesource.cpp:656
static double powerFromdB(double powerdB)
Definition: db.cpp:36
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ calculateFrequencyOffset()

void FileSource::calculateFrequencyOffset ( )
private

Definition at line 509 of file filesource.cpp.

References HBFilterChainConverter::getShiftFactor(), m_deviceSampleRate, FileSourceSettings::m_filterChainHash, m_frequencyOffset, FileSourceSettings::m_log2Interp, and m_settings.

Referenced by handleMessage().

510 {
512  m_frequencyOffset = m_deviceSampleRate * shiftFactor;
513 }
int64_t m_frequencyOffset
Definition: filesource.h:400
FileSourceSettings m_settings
Definition: filesource.h:395
uint32_t m_deviceSampleRate
Definition: filesource.h:404
static double getShiftFactor(unsigned int log2, unsigned int chainHash)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deserialize()

bool FileSource::deserialize ( const QByteArray &  data)
virtual

Implements ChannelAPI.

Definition at line 337 of file filesource.cpp.

References FileSource::MsgConfigureFileSource::create(), FileSourceSettings::deserialize(), BasebandSampleSource::m_inputMessageQueue, m_settings, MessageQueue::push(), and FileSourceSettings::resetToDefaults().

Referenced by getStreamCenterFrequency().

338 {
339  (void) data;
340  if (m_settings.deserialize(data))
341  {
342  MsgConfigureFileSource *msg = MsgConfigureFileSource::create(m_settings, true);
344  return true;
345  }
346  else
347  {
349  MsgConfigureFileSource *msg = MsgConfigureFileSource::create(m_settings, true);
351  return false;
352  }
353 }
bool deserialize(const QByteArray &data)
void push(Message *message, bool emitSignal=true)
Push message onto queue.
static MsgConfigureFileSource * create(const FileSourceSettings &settings, bool force)
Definition: filesource.h:77
MessageQueue m_inputMessageQueue
Queue for asynchronous inbound communication.
FileSourceSettings m_settings
Definition: filesource.h:395
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ destroy()

virtual void FileSource::destroy ( )
inlinevirtual

Implements ChannelAPI.

Definition at line 311 of file filesource.h.

References handleMessage(), pull(), pullAudio(), start(), and stop().

311 { delete this; }
+ Here is the call graph for this function:

◆ getCenterFrequency()

virtual qint64 FileSource::getCenterFrequency ( ) const
inlinevirtual

Applies to a default stream.

Implements ChannelAPI.

Definition at line 321 of file filesource.h.

321 { return 0; }

◆ getIdentifier()

virtual void FileSource::getIdentifier ( QString &  id)
inlinevirtual

Implements ChannelAPI.

Definition at line 319 of file filesource.h.

319 { id = objectName(); }

◆ getMagSq()

double FileSource::getMagSq ( ) const
inline

Definition at line 357 of file filesource.h.

References m_magsq.

Referenced by webapiFormatChannelReport().

357 { return m_magsq; }
double m_magsq
Definition: filesource.h:413
+ Here is the caller graph for this function:

◆ getMagSqLevels()

void FileSource::getMagSqLevels ( double &  avg,
double &  peak,
int &  nbSamples 
)
inline

Definition at line 359 of file filesource.h.

References FileSource::MagSqLevelsStore::m_magsq, m_magsq, m_magsqCount, m_magSqLevelStore, FileSource::MagSqLevelsStore::m_magsqPeak, m_magsqPeak, and m_magsqSum.

Referenced by FileSourceGUI::tick().

360  {
361  if (m_magsqCount > 0)
362  {
366  }
367 
370  nbSamples = m_magsqCount == 0 ? 1 : m_magsqCount;
371 
372  m_magsqSum = 0.0f;
373  m_magsqPeak = 0.0f;
374  m_magsqCount = 0;
375  }
double m_magsq
Definition: filesource.h:413
double m_magsqSum
Definition: filesource.h:414
int m_magsqCount
Definition: filesource.h:416
MagSqLevelsStore m_magSqLevelStore
Definition: filesource.h:417
double m_magsqPeak
Definition: filesource.h:415
+ Here is the caller graph for this function:

◆ getNbSinkStreams()

virtual int FileSource::getNbSinkStreams ( ) const
inlinevirtual

Implements ChannelAPI.

Definition at line 323 of file filesource.h.

323 { return 0; }

◆ getNbSourceStreams()

virtual int FileSource::getNbSourceStreams ( ) const
inlinevirtual

Implements ChannelAPI.

Definition at line 324 of file filesource.h.

324 { return 1; }

◆ getSamplesCount()

quint64 FileSource::getSamplesCount ( ) const
inline

Definition at line 356 of file filesource.h.

References m_samplesCount.

Referenced by handleEOF(), handleMessage(), and webapiFormatChannelReport().

356 { return m_samplesCount; }
quint64 m_samplesCount
Definition: filesource.h:402
+ Here is the caller graph for this function:

◆ getStreamCenterFrequency()

virtual qint64 FileSource::getStreamCenterFrequency ( int  streamIndex,
bool  sinkElseSource 
) const
inlinevirtual

Implements ChannelAPI.

Definition at line 326 of file filesource.h.

References deserialize(), serialize(), webapiReportGet(), webapiSettingsGet(), and webapiSettingsPutPatch().

327  {
328  (void) streamIndex;
329  (void) sinkElseSource;
330  return 0;
331  }
+ Here is the call graph for this function:

◆ getTitle()

virtual void FileSource::getTitle ( QString &  title)
inlinevirtual

Implements ChannelAPI.

Definition at line 320 of file filesource.h.

References m_settings, and FileSourceSettings::m_title.

320 { title = m_settings.m_title; }
FileSourceSettings m_settings
Definition: filesource.h:395

◆ handleEOF()

void FileSource::handleEOF ( )
private

Definition at line 439 of file filesource.cpp.

References FileSource::MsgPlayPause::create(), FileSource::MsgReportFileSourceStreamTiming::create(), BasebandSampleSource::getMessageQueueToGUI(), getSamplesCount(), FileSourceSettings::m_loop, m_settings, MessageQueue::push(), seekFileStream(), start(), and stop().

Referenced by pull().

440 {
441  if (getMessageQueueToGUI())
442  {
443  MsgReportFileSourceStreamTiming *report = MsgReportFileSourceStreamTiming::create(getSamplesCount());
444  getMessageQueueToGUI()->push(report);
445  }
446 
447  if (m_settings.m_loop)
448  {
449  stop();
450  seekFileStream(0);
451  start();
452  }
453  else
454  {
455  stop();
456 
457  if (getMessageQueueToGUI())
458  {
459  MsgPlayPause *report = MsgPlayPause::create(false);
460  getMessageQueueToGUI()->push(report);
461  }
462  }
463 }
void push(Message *message, bool emitSignal=true)
Push message onto queue.
quint64 getSamplesCount() const
Definition: filesource.h:356
void seekFileStream(int seekMillis)
Definition: filesource.cpp:425
static MsgReportFileSourceStreamTiming * create(quint64 samplesCount)
Definition: filesource.h:275
static MsgPlayPause * create(bool playPause)
Definition: filesource.h:216
virtual void stop()
Definition: filesource.cpp:208
MessageQueue * getMessageQueueToGUI()
FileSourceSettings m_settings
Definition: filesource.h:395
virtual void start()
Definition: filesource.cpp:196
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ handleMessage()

bool FileSource::handleMessage ( const Message cmd)
virtual

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

Implements BasebandSampleSource.

Definition at line 220 of file filesource.cpp.

References applySettings(), calculateFrequencyOffset(), FileSource::MsgSampleRateNotification::create(), FileSource::MsgReportFileSourceStreamTiming::create(), DSPSignalNotification::getCenterFrequency(), FileSource::MsgConfigureFileSourceName::getFileName(), FileSource::MsgConfigureChannelizer::getFilterChainHash(), FileSource::MsgConfigureFileSource::getForce(), UpChannelizer::MsgChannelizerNotification::getFrequencyOffset(), BasebandSampleSource::getInputMessageQueue(), FileSource::MsgConfigureChannelizer::getLog2Interp(), BasebandSampleSource::getMessageQueueToGUI(), FileSource::MsgConfigureFileSourceSeek::getMillis(), UpChannelizer::MsgChannelizerNotification::getSampleRate(), DSPSignalNotification::getSampleRate(), getSamplesCount(), FileSource::MsgConfigureFileSource::getSettings(), FileSource::MsgConfigureFileSourceWork::isWorking(), m_channelizer, m_deviceSampleRate, m_fileName, FileSourceSettings::m_filterChainHash, BasebandSampleSource::m_guiMessageQueue, FileSourceSettings::m_log2Interp, m_settings, Message::match(), openFileStream(), MessageQueue::push(), seekFileStream(), UpChannelizer::set(), setCenterFrequency(), setSampleRate(), start(), and stop().

Referenced by destroy().

221 {
223  {
225  int sampleRate = notif.getSampleRate();
226 
227  qDebug() << "FileSource::handleMessage: MsgChannelizerNotification:"
228  << " channelSampleRate: " << sampleRate
229  << " offsetFrequency: " << notif.getFrequencyOffset();
230 
231  if (sampleRate > 0) {
232  setSampleRate(sampleRate);
233  }
234 
235  return true;
236  }
237  else if (DSPSignalNotification::match(cmd))
238  {
240 
241  qDebug() << "FileSource::handleMessage: DSPSignalNotification:"
242  << " inputSampleRate: " << notif.getSampleRate()
243  << " centerFrequency: " << notif.getCenterFrequency();
244 
247  calculateFrequencyOffset(); // This is when device sample rate changes
248 
249  // Redo the channelizer stuff with the new sample rate to re-synchronize everything
253 
254  if (m_guiMessageQueue)
255  {
256  MsgSampleRateNotification *msg = MsgSampleRateNotification::create(notif.getSampleRate());
257  m_guiMessageQueue->push(msg);
258  }
259 
260  return true;
261  }
262  else if (MsgConfigureFileSource::match(cmd))
263  {
264  MsgConfigureFileSource& cfg = (MsgConfigureFileSource&) cmd;
265  qDebug() << "FileSource::handleMessage: MsgConfigureFileSource";
266  applySettings(cfg.getSettings(), cfg.getForce());
267  return true;
268  }
269  else if (MsgConfigureChannelizer::match(cmd))
270  {
271  MsgConfigureChannelizer& cfg = (MsgConfigureChannelizer&) cmd;
272  m_settings.m_log2Interp = cfg.getLog2Interp();
273  m_settings.m_filterChainHash = cfg.getFilterChainHash();
274 
275  qDebug() << "FileSource::handleMessage: MsgConfigureChannelizer:"
276  << " log2Interp: " << m_settings.m_log2Interp
277  << " filterChainHash: " << m_settings.m_filterChainHash;
278 
282 
283  calculateFrequencyOffset(); // This is when decimation or filter chain changes
284 
285  return true;
286  }
287  else if (MsgConfigureFileSourceName::match(cmd))
288  {
289  MsgConfigureFileSourceName& conf = (MsgConfigureFileSourceName&) cmd;
290  m_fileName = conf.getFileName();
291  openFileStream();
292  return true;
293  }
294  else if (MsgConfigureFileSourceWork::match(cmd))
295  {
296  MsgConfigureFileSourceWork& conf = (MsgConfigureFileSourceWork&) cmd;
297 
298  if (conf.isWorking()) {
299  start();
300  } else {
301  stop();
302  }
303 
304  return true;
305  }
306  else if (MsgConfigureFileSourceSeek::match(cmd))
307  {
308  MsgConfigureFileSourceSeek& conf = (MsgConfigureFileSourceSeek&) cmd;
309  int seekMillis = conf.getMillis();
310  seekFileStream(seekMillis);
311 
312  return true;
313  }
315  {
316  MsgReportFileSourceStreamTiming *report;
317 
318  if (getMessageQueueToGUI())
319  {
321  getMessageQueueToGUI()->push(report);
322  }
323 
324  return true;
325  }
326  else
327  {
328  return false;
329  }
330 }
void applySettings(const FileSourceSettings &settings, bool force=false)
Definition: filesource.cpp:465
void setCenterFrequency(uint64_t centerFrequency)
Definition: filesource.h:351
void push(Message *message, bool emitSignal=true)
Push message onto queue.
QString m_fileName
Definition: filesource.h:397
void setSampleRate(uint32_t sampleRate)
Definition: filesource.h:354
quint64 getSamplesCount() const
Definition: filesource.h:356
MessageQueue * getInputMessageQueue()
Get the queue for asynchronous inbound communication.
void calculateFrequencyOffset()
Definition: filesource.cpp:509
UpChannelizer * m_channelizer
Definition: filesource.h:394
void set(MessageQueue *messageQueue, unsigned int log2Interp, unsigned int filterChainHash)
qint64 getCenterFrequency() const
Definition: dspcommands.h:329
void seekFileStream(int seekMillis)
Definition: filesource.cpp:425
static MsgReportFileSourceStreamTiming * create(quint64 samplesCount)
Definition: filesource.h:275
static bool match(const Message *message)
Definition: message.cpp:45
virtual void stop()
Definition: filesource.cpp:208
MessageQueue * getMessageQueueToGUI()
MessageQueue * m_guiMessageQueue
Input message queue to the GUI.
int getSampleRate() const
Definition: dspcommands.h:328
void openFileStream()
Definition: filesource.cpp:355
static MsgSampleRateNotification * create(int sampleRate)
Definition: filesource.h:97
FileSourceSettings m_settings
Definition: filesource.h:395
virtual void start()
Definition: filesource.cpp:196
uint32_t m_deviceSampleRate
Definition: filesource.h:404
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ networkManagerFinished

void FileSource::networkManagerFinished ( QNetworkReply *  reply)
privateslot

Definition at line 703 of file filesource.cpp.

Referenced by FileSource(), and ~FileSource().

704 {
705  QNetworkReply::NetworkError replyError = reply->error();
706 
707  if (replyError)
708  {
709  qWarning() << "FileSource::networkManagerFinished:"
710  << " error(" << (int) replyError
711  << "): " << replyError
712  << ": " << reply->errorString();
713  return;
714  }
715 
716  QString answer = reply->readAll();
717  answer.chop(1); // remove last \n
718  qDebug("FileSource::networkManagerFinished: reply:\n%s", answer.toStdString().c_str());
719 }
+ Here is the caller graph for this function:

◆ openFileStream()

void FileSource::openFileStream ( )
private

Definition at line 355 of file filesource.cpp.

References FileRecord::Header::centerFrequency, FileRecord::Header::crc32, FileSource::MsgReportFileSourceStreamData::create(), FileSource::MsgReportHeaderCRC::create(), BasebandSampleSource::getMessageQueueToGUI(), m_centerFrequency, m_fileName, m_fileSampleRate, m_ifstream, m_recordLength, m_samplesCount, m_sampleSize, m_startingTimeStamp, MessageQueue::push(), FileRecord::readHeader(), FileRecord::Header::sampleRate, FileRecord::Header::sampleSize, and FileRecord::Header::startTimeStamp.

Referenced by handleMessage().

356 {
357  //stop();
358 
359  if (m_ifstream.is_open()) {
360  m_ifstream.close();
361  }
362 
363 #ifdef Q_OS_WIN
364  m_ifstream.open(m_fileName.toStdWString().c_str(), std::ios::binary | std::ios::ate);
365 #else
366  m_ifstream.open(m_fileName.toStdString().c_str(), std::ios::binary | std::ios::ate);
367 #endif
368  quint64 fileSize = m_ifstream.tellg();
369  m_samplesCount = 0;
370 
371  if (fileSize > sizeof(FileRecord::Header))
372  {
373  FileRecord::Header header;
374  m_ifstream.seekg(0,std::ios_base::beg);
375  bool crcOK = FileRecord::readHeader(m_ifstream, header);
376  m_fileSampleRate = header.sampleRate;
379  m_sampleSize = header.sampleSize;
380  QString crcHex = QString("%1").arg(header.crc32 , 0, 16);
381 
382  if (crcOK)
383  {
384  qDebug("FileSource::openFileStream: CRC32 OK for header: %s", qPrintable(crcHex));
385  m_recordLength = (fileSize - sizeof(FileRecord::Header)) / ((m_sampleSize == 24 ? 8 : 4) * m_fileSampleRate);
386  }
387  else
388  {
389  qCritical("FileSource::openFileStream: bad CRC32 for header: %s", qPrintable(crcHex));
390  m_recordLength = 0;
391  }
392 
393  if (getMessageQueueToGUI()) {
394  MsgReportHeaderCRC *report = MsgReportHeaderCRC::create(crcOK);
395  getMessageQueueToGUI()->push(report);
396  }
397  }
398  else
399  {
400  m_recordLength = 0;
401  }
402 
403  qDebug() << "FileSource::openFileStream: " << m_fileName.toStdString().c_str()
404  << " fileSize: " << fileSize << " bytes"
405  << " length: " << m_recordLength << " seconds"
406  << " sample rate: " << m_fileSampleRate << " S/s"
407  << " center frequency: " << m_centerFrequency << " Hz"
408  << " sample size: " << m_sampleSize << " bits"
409  << " starting TS: " << m_startingTimeStamp << "s";
410 
411  if (getMessageQueueToGUI()) {
412  MsgReportFileSourceStreamData *report = MsgReportFileSourceStreamData::create(m_fileSampleRate,
413  m_sampleSize,
415  m_startingTimeStamp,
416  m_recordLength); // file stream data
417  getMessageQueueToGUI()->push(report);
418  }
419 
420  if (m_recordLength == 0) {
421  m_ifstream.close();
422  }
423 }
quint64 m_startingTimeStamp
Definition: filesource.h:406
static MsgReportHeaderCRC * create(bool ok)
Definition: filesource.h:295
void push(Message *message, bool emitSignal=true)
Push message onto queue.
quint32 m_sampleSize
Definition: filesource.h:398
QString m_fileName
Definition: filesource.h:397
quint64 centerFrequency
Definition: filerecord.h:38
uint32_t m_fileSampleRate
Definition: filesource.h:401
std::ifstream m_ifstream
Definition: filesource.h:396
quint64 m_recordLength
record length in seconds computed from file size
Definition: filesource.h:405
quint32 sampleRate
Definition: filerecord.h:37
quint64 m_centerFrequency
Definition: filesource.h:399
MessageQueue * getMessageQueueToGUI()
quint32 sampleSize
Definition: filerecord.h:40
static bool readHeader(std::ifstream &samplefile, Header &header)
returns true if CRC checksum is correct else false
Definition: filerecord.cpp:168
static MsgReportFileSourceStreamData * create(int sampleRate, quint32 sampleSize, quint64 centerFrequency, quint64 startingTimeStamp, quint64 recordLength)
Definition: filesource.h:239
quint64 startTimeStamp
Definition: filerecord.h:39
quint64 m_samplesCount
Definition: filesource.h:402
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pull()

void FileSource::pull ( Sample sample)
virtual

Implements BasebandSampleSource.

Definition at line 104 of file filesource.cpp.

References MovingAverageUtil< T, Total, N >::asDouble(), handleEOF(), m_ifstream, m_linearGain, m_magsq, m_magsqCount, m_magsqPeak, m_magsqSum, m_movingAverage, m_running, m_samplesCount, m_sampleSize, SDR_TX_SAMP_SZ, Sample::setImag(), and Sample::setReal().

Referenced by destroy().

105 {
106  Real re;
107  Real im;
108 
109  struct Sample16
110  {
111  int16_t real;
112  int16_t imag;
113  };
114 
115  struct Sample24
116  {
117  int32_t real;
118  int32_t imag;
119  };
120 
121  if (!m_running)
122  {
123  re = 0;
124  im = 0;
125  }
126  else if (m_sampleSize == 16)
127  {
128  Sample16 sample16;
129  m_ifstream.read(reinterpret_cast<char*>(&sample16), sizeof(Sample16));
130 
131  if (m_ifstream.eof()) {
132  handleEOF();
133  } else {
134  m_samplesCount++;
135  }
136 
137  // scale to +/-1.0
138  re = (sample16.real * m_linearGain) / 32760.0f;
139  im = (sample16.imag * m_linearGain) / 32760.0f;
140  }
141  else if (m_sampleSize == 24)
142  {
143  Sample24 sample24;
144  m_ifstream.read(reinterpret_cast<char*>(&sample24), sizeof(Sample24));
145 
146  if (m_ifstream.eof()) {
147  handleEOF();
148  } else {
149  m_samplesCount++;
150  }
151 
152  // scale to +/-1.0
153  re = (sample24.real * m_linearGain) / 8388608.0f;
154  im = (sample24.imag * m_linearGain) / 8388608.0f;
155  }
156  else
157  {
158  re = 0;
159  im = 0;
160  }
161 
162 
163  if (SDR_TX_SAMP_SZ == 16)
164  {
165  sample.setReal(re * 32768.0f);
166  sample.setImag(im * 32768.0f);
167  }
168  else if (SDR_TX_SAMP_SZ == 24)
169  {
170  sample.setReal(re * 8388608.0f);
171  sample.setImag(im * 8388608.0f);
172  }
173  else
174  {
175  sample.setReal(0);
176  sample.setImag(0);
177  }
178 
179  Real magsq = re*re + im*im;
180  m_movingAverage(magsq);
182  m_magsqSum += magsq;
183 
184  if (magsq > m_magsqPeak) {
185  m_magsqPeak = magsq;
186  }
187 
188  m_magsqCount++;
189 }
short int16_t
Definition: rtptypes_win.h:43
quint32 m_sampleSize
Definition: filesource.h:398
bool m_running
Definition: filesource.h:408
std::ifstream m_ifstream
Definition: filesource.h:396
void handleEOF()
Definition: filesource.cpp:439
double m_magsq
Definition: filesource.h:413
void setImag(FixReal v)
Definition: dsptypes.h:59
int int32_t
Definition: rtptypes_win.h:45
#define SDR_TX_SAMP_SZ
Definition: dsptypes.h:38
double m_magsqSum
Definition: filesource.h:414
void setReal(FixReal v)
Definition: dsptypes.h:58
double m_linearGain
Definition: filesource.h:412
int m_magsqCount
Definition: filesource.h:416
double asDouble() const
Definition: movingaverage.h:57
float Real
Definition: dsptypes.h:42
MovingAverageUtil< Real, double, 16 > m_movingAverage
Definition: filesource.h:418
double m_magsqPeak
Definition: filesource.h:415
quint64 m_samplesCount
Definition: filesource.h:402
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pullAudio()

void FileSource::pullAudio ( int  nbSamples)
virtual

Reimplemented from BasebandSampleSource.

Definition at line 191 of file filesource.cpp.

Referenced by destroy().

192 {
193  (void) nbSamples;
194 }
+ Here is the caller graph for this function:

◆ seekFileStream()

void FileSource::seekFileStream ( int  seekMillis)
private

Definition at line 425 of file filesource.cpp.

References m_fileSampleRate, m_ifstream, m_mutex, m_recordLength, m_running, m_samplesCount, and m_sampleSize.

Referenced by handleEOF(), and handleMessage().

426 {
427  QMutexLocker mutexLocker(&m_mutex);
428 
429  if ((m_ifstream.is_open()) && !m_running)
430  {
431  quint64 seekPoint = ((m_recordLength * seekMillis) / 1000) * m_fileSampleRate;
432  m_samplesCount = seekPoint;
433  seekPoint *= (m_sampleSize == 24 ? 8 : 4); // + sizeof(FileSink::Header)
434  m_ifstream.clear();
435  m_ifstream.seekg(seekPoint + sizeof(FileRecord::Header), std::ios::beg);
436  }
437 }
quint32 m_sampleSize
Definition: filesource.h:398
uint32_t m_fileSampleRate
Definition: filesource.h:401
bool m_running
Definition: filesource.h:408
std::ifstream m_ifstream
Definition: filesource.h:396
quint64 m_recordLength
record length in seconds computed from file size
Definition: filesource.h:405
QMutex m_mutex
Definition: filesource.h:392
quint64 m_samplesCount
Definition: filesource.h:402
+ Here is the caller graph for this function:

◆ serialize()

QByteArray FileSource::serialize ( ) const
virtual

Implements ChannelAPI.

Definition at line 332 of file filesource.cpp.

References m_settings, and FileSourceSettings::serialize().

Referenced by getStreamCenterFrequency().

333 {
334  return m_settings.serialize();
335 }
QByteArray serialize() const
FileSourceSettings m_settings
Definition: filesource.h:395
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setCenterFrequency()

void FileSource::setCenterFrequency ( uint64_t  centerFrequency)
inline

Set center frequency given in Hz

Definition at line 351 of file filesource.h.

References m_centerFrequency.

Referenced by handleMessage().

351 { m_centerFrequency = centerFrequency; }
quint64 m_centerFrequency
Definition: filesource.h:399
+ Here is the caller graph for this function:

◆ setSampleRate()

void FileSource::setSampleRate ( uint32_t  sampleRate)
inline

Set sample rate given in Hz

Definition at line 354 of file filesource.h.

References m_sampleRate.

Referenced by handleMessage().

354 { m_sampleRate = sampleRate; }
uint32_t m_sampleRate
Definition: filesource.h:403
+ Here is the caller graph for this function:

◆ start()

void FileSource::start ( )
virtual

Implements BasebandSampleSource.

Definition at line 196 of file filesource.cpp.

References FileSource::MsgReportFileSourceAcquisition::create(), BasebandSampleSource::getMessageQueueToGUI(), m_running, and MessageQueue::push().

Referenced by destroy(), handleEOF(), and handleMessage().

197 {
198  qDebug("FileSource::start");
199  m_running = true;
200 
201  if (getMessageQueueToGUI())
202  {
203  MsgReportFileSourceAcquisition *report = MsgReportFileSourceAcquisition::create(true); // acquisition on
204  getMessageQueueToGUI()->push(report);
205  }
206 }
void push(Message *message, bool emitSignal=true)
Push message onto queue.
static MsgReportFileSourceAcquisition * create(bool acquisition)
Definition: filesource.h:196
bool m_running
Definition: filesource.h:408
MessageQueue * getMessageQueueToGUI()
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ stop()

void FileSource::stop ( )
virtual

Implements BasebandSampleSource.

Definition at line 208 of file filesource.cpp.

References FileSource::MsgReportFileSourceAcquisition::create(), BasebandSampleSource::getMessageQueueToGUI(), m_running, and MessageQueue::push().

Referenced by destroy(), handleEOF(), and handleMessage().

209 {
210  qDebug("FileSource::stop");
211  m_running = false;
212 
213  if (getMessageQueueToGUI())
214  {
215  MsgReportFileSourceAcquisition *report = MsgReportFileSourceAcquisition::create(false); // acquisition off
216  getMessageQueueToGUI()->push(report);
217  }
218 }
void push(Message *message, bool emitSignal=true)
Push message onto queue.
static MsgReportFileSourceAcquisition * create(bool acquisition)
Definition: filesource.h:196
bool m_running
Definition: filesource.h:408
MessageQueue * getMessageQueueToGUI()
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ validateFilterChainHash()

void FileSource::validateFilterChainHash ( FileSourceSettings settings)
private

Definition at line 498 of file filesource.cpp.

References i, FileSourceSettings::m_filterChainHash, and FileSourceSettings::m_log2Interp.

Referenced by webapiSettingsPutPatch().

499 {
500  unsigned int s = 1;
501 
502  for (unsigned int i = 0; i < settings.m_log2Interp; i++) {
503  s *= 3;
504  }
505 
506  settings.m_filterChainHash = settings.m_filterChainHash >= s ? s-1 : settings.m_filterChainHash;
507 }
int32_t i
Definition: decimators.h:244
+ Here is the caller graph for this function:

◆ webapiFormatChannelReport()

void FileSource::webapiFormatChannelReport ( SWGSDRangel::SWGChannelReport response)
private

Definition at line 622 of file filesource.cpp.

References CalcDb::dbPower(), SWGSDRangel::SWGChannelReport::getFileSourceReport(), getMagSq(), getSamplesCount(), FileSourceSettings::m_fileName, m_fileSampleRate, m_recordLength, m_sampleRate, m_sampleSize, m_settings, m_startingTimeStamp, SWGSDRangel::SWGFileSourceReport::setAbsoluteTime(), SWGSDRangel::SWGFileSourceReport::setChannelPowerDb(), SWGSDRangel::SWGFileSourceReport::setDurationTime(), SWGSDRangel::SWGFileSourceReport::setElapsedTime(), SWGSDRangel::SWGFileSourceReport::setFileName(), SWGSDRangel::SWGFileSourceReport::setFileSampleRate(), SWGSDRangel::SWGFileSourceReport::setFileSampleSize(), and SWGSDRangel::SWGFileSourceReport::setSampleRate().

Referenced by webapiReportGet().

623 {
624  qint64 t_sec = 0;
625  qint64 t_msec = 0;
626  quint64 samplesCount = getSamplesCount();
627 
628  if (m_fileSampleRate > 0)
629  {
630  t_sec = samplesCount / m_fileSampleRate;
631  t_msec = (samplesCount - (t_sec * m_fileSampleRate)) * 1000 / m_fileSampleRate;
632  }
633 
634  QTime t(0, 0, 0, 0);
635  t = t.addSecs(t_sec);
636  t = t.addMSecs(t_msec);
637  response.getFileSourceReport()->setElapsedTime(new QString(t.toString("HH:mm:ss.zzz")));
638 
639  qint64 startingTimeStampMsec = m_startingTimeStamp * 1000LL;
640  QDateTime dt = QDateTime::fromMSecsSinceEpoch(startingTimeStampMsec);
641  dt = dt.addSecs(t_sec);
642  dt = dt.addMSecs(t_msec);
643  response.getFileSourceReport()->setAbsoluteTime(new QString(dt.toString("yyyy-MM-dd HH:mm:ss.zzz")));
644 
645  QTime recordLength(0, 0, 0, 0);
646  recordLength = recordLength.addSecs(m_recordLength);
647  response.getFileSourceReport()->setDurationTime(new QString(recordLength.toString("HH:mm:ss")));
648 
649  response.getFileSourceReport()->setFileName(new QString(m_settings.m_fileName));
654 }
void setSampleRate(qint32 sample_rate)
quint64 m_startingTimeStamp
Definition: filesource.h:406
void setDurationTime(QString *duration_time)
uint32_t m_sampleRate
Definition: filesource.h:403
void setFileName(QString *file_name)
quint32 m_sampleSize
Definition: filesource.h:398
static double dbPower(double magsq, double floor=1e-12)
Definition: db.cpp:22
SWGFileSourceReport * getFileSourceReport()
quint64 getSamplesCount() const
Definition: filesource.h:356
uint32_t m_fileSampleRate
Definition: filesource.h:401
void setFileSampleRate(qint32 file_sample_rate)
void setChannelPowerDb(float channel_power_db)
quint64 m_recordLength
record length in seconds computed from file size
Definition: filesource.h:405
double getMagSq() const
Definition: filesource.h:357
void setElapsedTime(QString *elapsed_time)
void setAbsoluteTime(QString *absolute_time)
FileSourceSettings m_settings
Definition: filesource.h:395
void setFileSampleSize(qint32 file_sample_size)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ webapiFormatChannelSettings()

void FileSource::webapiFormatChannelSettings ( SWGSDRangel::SWGChannelSettings response,
const FileSourceSettings settings 
)
private

Definition at line 596 of file filesource.cpp.

References SWGSDRangel::SWGChannelSettings::getFileSourceSettings(), SWGSDRangel::SWGFileSourceSettings::getReverseApiAddress(), SWGSDRangel::SWGFileSourceSettings::getTitle(), FileSourceSettings::m_filterChainHash, FileSourceSettings::m_gainDB, FileSourceSettings::m_log2Interp, FileSourceSettings::m_reverseAPIAddress, FileSourceSettings::m_reverseAPIChannelIndex, FileSourceSettings::m_reverseAPIDeviceIndex, FileSourceSettings::m_reverseAPIPort, FileSourceSettings::m_rgbColor, FileSourceSettings::m_title, FileSourceSettings::m_useReverseAPI, SWGSDRangel::SWGFileSourceSettings::setFilterChainHash(), SWGSDRangel::SWGFileSourceSettings::setGainDb(), SWGSDRangel::SWGFileSourceSettings::setLog2Interp(), SWGSDRangel::SWGFileSourceSettings::setReverseApiAddress(), SWGSDRangel::SWGFileSourceSettings::setReverseApiChannelIndex(), SWGSDRangel::SWGFileSourceSettings::setReverseApiDeviceIndex(), SWGSDRangel::SWGFileSourceSettings::setReverseApiPort(), SWGSDRangel::SWGFileSourceSettings::setRgbColor(), SWGSDRangel::SWGFileSourceSettings::setTitle(), and SWGSDRangel::SWGFileSourceSettings::setUseReverseApi().

Referenced by webapiSettingsGet(), and webapiSettingsPutPatch().

597 {
598  response.getFileSourceSettings()->setLog2Interp(settings.m_log2Interp);
600  response.getFileSourceSettings()->setGainDb(settings.m_gainDB);
601  response.getFileSourceSettings()->setRgbColor(settings.m_rgbColor);
602 
603  if (response.getFileSourceSettings()->getTitle()) {
604  *response.getFileSourceSettings()->getTitle() = settings.m_title;
605  } else {
606  response.getFileSourceSettings()->setTitle(new QString(settings.m_title));
607  }
608 
609  response.getFileSourceSettings()->setUseReverseApi(settings.m_useReverseAPI ? 1 : 0);
610 
611  if (response.getFileSourceSettings()->getReverseApiAddress()) {
613  } else {
614  response.getFileSourceSettings()->setReverseApiAddress(new QString(settings.m_reverseAPIAddress));
615  }
616 
620 }
SWGFileSourceSettings * getFileSourceSettings()
void setFilterChainHash(qint32 filter_chain_hash)
void setReverseApiPort(qint32 reverse_api_port)
uint16_t m_reverseAPIChannelIndex
void setReverseApiAddress(QString *reverse_api_address)
uint16_t m_reverseAPIDeviceIndex
void setUseReverseApi(qint32 use_reverse_api)
void setReverseApiDeviceIndex(qint32 reverse_api_device_index)
void setReverseApiChannelIndex(qint32 reverse_api_channel_index)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ webapiReportGet()

int FileSource::webapiReportGet ( SWGSDRangel::SWGChannelReport response,
QString &  errorMessage 
)
virtual

Reimplemented from ChannelAPI.

Definition at line 585 of file filesource.cpp.

References SWGSDRangel::SWGChannelReport::getFileSourceReport(), SWGSDRangel::SWGFileSourceReport::init(), SWGSDRangel::SWGChannelReport::setFileSourceReport(), and webapiFormatChannelReport().

Referenced by getStreamCenterFrequency().

588 {
589  (void) errorMessage;
591  response.getFileSourceReport()->init();
592  webapiFormatChannelReport(response);
593  return 200;
594 }
SWGFileSourceReport * getFileSourceReport()
void setFileSourceReport(SWGFileSourceReport *file_source_report)
void webapiFormatChannelReport(SWGSDRangel::SWGChannelReport &response)
Definition: filesource.cpp:622
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ webapiReverseSendSettings()

void FileSource::webapiReverseSendSettings ( QList< QString > &  channelSettingsKeys,
const FileSourceSettings settings,
bool  force 
)
private

Definition at line 656 of file filesource.cpp.

References SWGSDRangel::SWGChannelSettings::asJson(), ChannelAPI::getDeviceSetIndex(), SWGSDRangel::SWGChannelSettings::getFileSourceSettings(), ChannelAPI::getIndexInDeviceSet(), FileSourceSettings::m_filterChainHash, FileSourceSettings::m_gainDB, FileSourceSettings::m_log2Interp, m_networkManager, m_networkRequest, FileSourceSettings::m_reverseAPIAddress, FileSourceSettings::m_reverseAPIChannelIndex, FileSourceSettings::m_reverseAPIDeviceIndex, FileSourceSettings::m_reverseAPIPort, FileSourceSettings::m_rgbColor, FileSourceSettings::m_title, SWGSDRangel::SWGChannelSettings::setChannelType(), SWGSDRangel::SWGChannelSettings::setDirection(), SWGSDRangel::SWGChannelSettings::setFileSourceSettings(), SWGSDRangel::SWGFileSourceSettings::setFilterChainHash(), SWGSDRangel::SWGFileSourceSettings::setGainDb(), SWGSDRangel::SWGFileSourceSettings::setLog2Interp(), SWGSDRangel::SWGChannelSettings::setOriginatorChannelIndex(), SWGSDRangel::SWGChannelSettings::setOriginatorDeviceSetIndex(), SWGSDRangel::SWGFileSourceSettings::setRgbColor(), and SWGSDRangel::SWGFileSourceSettings::setTitle().

Referenced by applySettings().

657 {
659  swgChannelSettings->setDirection(1); // single source (Tx)
660  swgChannelSettings->setOriginatorChannelIndex(getIndexInDeviceSet());
661  swgChannelSettings->setOriginatorDeviceSetIndex(getDeviceSetIndex());
662  swgChannelSettings->setChannelType(new QString("FileSource"));
664  SWGSDRangel::SWGFileSourceSettings *swgFileSourceSettings = swgChannelSettings->getFileSourceSettings();
665 
666  // transfer data that has been modified. When force is on transfer all data except reverse API data
667 
668  if (channelSettingsKeys.contains("log2Interp") || force) {
669  swgFileSourceSettings->setLog2Interp(settings.m_log2Interp);
670  }
671  if (channelSettingsKeys.contains("filterChainHash") || force) {
672  swgFileSourceSettings->setFilterChainHash(settings.m_filterChainHash);
673  }
674  if (channelSettingsKeys.contains("gainDB") || force) {
675  swgFileSourceSettings->setGainDb(settings.m_gainDB);
676  }
677  if (channelSettingsKeys.contains("rgbColor") || force) {
678  swgFileSourceSettings->setRgbColor(settings.m_rgbColor);
679  }
680  if (channelSettingsKeys.contains("title") || force) {
681  swgFileSourceSettings->setTitle(new QString(settings.m_title));
682  }
683 
684  QString channelSettingsURL = QString("http://%1:%2/sdrangel/deviceset/%3/channel/%4/settings")
685  .arg(settings.m_reverseAPIAddress)
686  .arg(settings.m_reverseAPIPort)
687  .arg(settings.m_reverseAPIDeviceIndex)
688  .arg(settings.m_reverseAPIChannelIndex);
689  m_networkRequest.setUrl(QUrl(channelSettingsURL));
690  m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
691 
692  QBuffer *buffer=new QBuffer();
693  buffer->open((QBuffer::ReadWrite));
694  buffer->write(swgChannelSettings->asJson().toUtf8());
695  buffer->seek(0);
696 
697  // Always use PATCH to avoid passing reverse API settings
698  m_networkManager->sendCustomRequest(m_networkRequest, "PATCH", buffer);
699 
700  delete swgChannelSettings;
701 }
void setOriginatorChannelIndex(qint32 originator_channel_index)
QNetworkAccessManager * m_networkManager
Definition: filesource.h:409
SWGFileSourceSettings * getFileSourceSettings()
int getDeviceSetIndex() const
Definition: channelapi.h:89
void setChannelType(QString *channel_type)
void setOriginatorDeviceSetIndex(qint32 originator_device_set_index)
QNetworkRequest m_networkRequest
Definition: filesource.h:410
void setFileSourceSettings(SWGFileSourceSettings *file_source_settings)
void setFilterChainHash(qint32 filter_chain_hash)
uint16_t m_reverseAPIChannelIndex
virtual QString asJson() override
uint16_t m_reverseAPIDeviceIndex
int getIndexInDeviceSet() const
Definition: channelapi.h:87
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ webapiSettingsGet()

int FileSource::webapiSettingsGet ( SWGSDRangel::SWGChannelSettings response,
QString &  errorMessage 
)
virtual

Reimplemented from ChannelAPI.

Definition at line 515 of file filesource.cpp.

References SWGSDRangel::SWGChannelSettings::getFileSourceSettings(), SWGSDRangel::SWGFileSourceSettings::init(), m_settings, SWGSDRangel::SWGChannelSettings::setFileSourceSettings(), and webapiFormatChannelSettings().

Referenced by getStreamCenterFrequency().

518 {
519  (void) errorMessage;
521  response.getFileSourceSettings()->init();
523  return 200;
524 }
void webapiFormatChannelSettings(SWGSDRangel::SWGChannelSettings &response, const FileSourceSettings &settings)
Definition: filesource.cpp:596
SWGFileSourceSettings * getFileSourceSettings()
void setFileSourceSettings(SWGFileSourceSettings *file_source_settings)
FileSourceSettings m_settings
Definition: filesource.h:395
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ webapiSettingsPutPatch()

int FileSource::webapiSettingsPutPatch ( bool  force,
const QStringList &  channelSettingsKeys,
SWGSDRangel::SWGChannelSettings response,
QString &  errorMessage 
)
virtual

Reimplemented from ChannelAPI.

Definition at line 526 of file filesource.cpp.

References FileSource::MsgConfigureFileSource::create(), SWGSDRangel::SWGChannelSettings::getFileSourceSettings(), SWGSDRangel::SWGFileSourceSettings::getFilterChainHash(), SWGSDRangel::SWGFileSourceSettings::getGainDb(), SWGSDRangel::SWGFileSourceSettings::getLog2Interp(), SWGSDRangel::SWGFileSourceSettings::getReverseApiAddress(), SWGSDRangel::SWGFileSourceSettings::getReverseApiChannelIndex(), SWGSDRangel::SWGFileSourceSettings::getReverseApiDeviceIndex(), SWGSDRangel::SWGFileSourceSettings::getReverseApiPort(), SWGSDRangel::SWGFileSourceSettings::getRgbColor(), SWGSDRangel::SWGFileSourceSettings::getTitle(), SWGSDRangel::SWGFileSourceSettings::getUseReverseApi(), FileSourceSettings::m_filterChainHash, FileSourceSettings::m_gainDB, BasebandSampleSource::m_guiMessageQueue, BasebandSampleSource::m_inputMessageQueue, FileSourceSettings::m_log2Interp, FileSourceSettings::m_reverseAPIAddress, FileSourceSettings::m_reverseAPIChannelIndex, FileSourceSettings::m_reverseAPIDeviceIndex, FileSourceSettings::m_reverseAPIPort, FileSourceSettings::m_rgbColor, m_settings, FileSourceSettings::m_title, FileSourceSettings::m_useReverseAPI, MessageQueue::push(), validateFilterChainHash(), and webapiFormatChannelSettings().

Referenced by getStreamCenterFrequency().

531 {
532  (void) errorMessage;
533  FileSourceSettings settings = m_settings;
534 
535  if (channelSettingsKeys.contains("log2Interp")) {
536  settings.m_log2Interp = response.getFileSourceSettings()->getLog2Interp();
537  }
538 
539  if (channelSettingsKeys.contains("filterChainHash"))
540  {
542  validateFilterChainHash(settings);
543  }
544 
545  if (channelSettingsKeys.contains("rgbColor")) {
546  settings.m_rgbColor = response.getFileSourceSettings()->getRgbColor();
547  }
548  if (channelSettingsKeys.contains("title")) {
549  settings.m_title = *response.getFileSourceSettings()->getTitle();
550  }
551  if (channelSettingsKeys.contains("gainDB")) {
552  settings.m_gainDB = response.getFileSourceSettings()->getGainDb();
553  }
554  if (channelSettingsKeys.contains("useReverseAPI")) {
555  settings.m_useReverseAPI = response.getFileSourceSettings()->getUseReverseApi() != 0;
556  }
557  if (channelSettingsKeys.contains("reverseAPIAddress")) {
559  }
560  if (channelSettingsKeys.contains("reverseAPIPort")) {
562  }
563  if (channelSettingsKeys.contains("reverseAPIDeviceIndex")) {
565  }
566  if (channelSettingsKeys.contains("reverseAPIChannelIndex")) {
568  }
569 
570  MsgConfigureFileSource *msg = MsgConfigureFileSource::create(settings, force);
572 
573  qDebug("FileSource::webapiSettingsPutPatch: forward to GUI: %p", m_guiMessageQueue);
574  if (m_guiMessageQueue) // forward to GUI if any
575  {
576  MsgConfigureFileSource *msgToGUI = MsgConfigureFileSource::create(settings, force);
577  m_guiMessageQueue->push(msgToGUI);
578  }
579 
580  webapiFormatChannelSettings(response, settings);
581 
582  return 200;
583 }
void webapiFormatChannelSettings(SWGSDRangel::SWGChannelSettings &response, const FileSourceSettings &settings)
Definition: filesource.cpp:596
void push(Message *message, bool emitSignal=true)
Push message onto queue.
SWGFileSourceSettings * getFileSourceSettings()
void validateFilterChainHash(FileSourceSettings &settings)
Definition: filesource.cpp:498
static MsgConfigureFileSource * create(const FileSourceSettings &settings, bool force)
Definition: filesource.h:77
uint16_t m_reverseAPIChannelIndex
uint16_t m_reverseAPIDeviceIndex
MessageQueue * m_guiMessageQueue
Input message queue to the GUI.
MessageQueue m_inputMessageQueue
Queue for asynchronous inbound communication.
FileSourceSettings m_settings
Definition: filesource.h:395
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ m_centerFrequency

quint64 FileSource::m_centerFrequency
private

◆ m_channelId

const QString FileSource::m_channelId ="FileSource"
static

Definition at line 378 of file filesource.h.

Referenced by FileSource(), and FileSourcePlugin::initPlugin().

◆ m_channelIdURI

const QString FileSource::m_channelIdURI = "sdrangel.channeltx.filesource"
static

Definition at line 377 of file filesource.h.

Referenced by FileSourceGUI::FileSourceGUI(), and FileSourcePlugin::initPlugin().

◆ m_channelizer

UpChannelizer* FileSource::m_channelizer
private

Definition at line 394 of file filesource.h.

Referenced by FileSource(), handleMessage(), and ~FileSource().

◆ m_deviceAPI

DeviceAPI* FileSource::m_deviceAPI
private

Definition at line 391 of file filesource.h.

Referenced by FileSource(), and ~FileSource().

◆ m_deviceSampleRate

uint32_t FileSource::m_deviceSampleRate
private

Definition at line 404 of file filesource.h.

Referenced by calculateFrequencyOffset(), and handleMessage().

◆ m_fileName

QString FileSource::m_fileName
private

◆ m_fileSampleRate

uint32_t FileSource::m_fileSampleRate
private

Definition at line 401 of file filesource.h.

Referenced by openFileStream(), seekFileStream(), and webapiFormatChannelReport().

◆ m_frequencyOffset

int64_t FileSource::m_frequencyOffset
private

Definition at line 400 of file filesource.h.

Referenced by calculateFrequencyOffset().

◆ m_ifstream

std::ifstream FileSource::m_ifstream
private

Definition at line 396 of file filesource.h.

Referenced by openFileStream(), pull(), and seekFileStream().

◆ m_linearGain

double FileSource::m_linearGain
private

Definition at line 412 of file filesource.h.

Referenced by applySettings(), FileSource(), and pull().

◆ m_magsq

double FileSource::m_magsq
private

Definition at line 413 of file filesource.h.

Referenced by FileSource(), getMagSq(), getMagSqLevels(), and pull().

◆ m_magsqCount

int FileSource::m_magsqCount
private

Definition at line 416 of file filesource.h.

Referenced by FileSource(), getMagSqLevels(), and pull().

◆ m_magSqLevelStore

MagSqLevelsStore FileSource::m_magSqLevelStore
private

Definition at line 417 of file filesource.h.

Referenced by getMagSqLevels().

◆ m_magsqPeak

double FileSource::m_magsqPeak
private

Definition at line 415 of file filesource.h.

Referenced by FileSource(), getMagSqLevels(), and pull().

◆ m_magsqSum

double FileSource::m_magsqSum
private

Definition at line 414 of file filesource.h.

Referenced by FileSource(), getMagSqLevels(), and pull().

◆ m_masterTimer

QTimer FileSource::m_masterTimer
private

Definition at line 407 of file filesource.h.

◆ m_movingAverage

MovingAverageUtil<Real, double, 16> FileSource::m_movingAverage
private

Definition at line 418 of file filesource.h.

Referenced by pull().

◆ m_mutex

QMutex FileSource::m_mutex
private

Definition at line 392 of file filesource.h.

Referenced by seekFileStream().

◆ m_networkManager

QNetworkAccessManager* FileSource::m_networkManager
private

Definition at line 409 of file filesource.h.

Referenced by FileSource(), webapiReverseSendSettings(), and ~FileSource().

◆ m_networkRequest

QNetworkRequest FileSource::m_networkRequest
private

Definition at line 410 of file filesource.h.

Referenced by webapiReverseSendSettings().

◆ m_recordLength

quint64 FileSource::m_recordLength
private

record length in seconds computed from file size

Definition at line 405 of file filesource.h.

Referenced by FileSource::MsgReportFileSourceStreamData::getRecordLength(), openFileStream(), seekFileStream(), and webapiFormatChannelReport().

◆ m_running

bool FileSource::m_running
private

Definition at line 408 of file filesource.h.

Referenced by pull(), seekFileStream(), start(), and stop().

◆ m_sampleRate

uint32_t FileSource::m_sampleRate
private

◆ m_samplesCount

quint64 FileSource::m_samplesCount
private

◆ m_sampleSize

quint32 FileSource::m_sampleSize
private

◆ m_settings

FileSourceSettings FileSource::m_settings
private

◆ m_startingTimeStamp

quint64 FileSource::m_startingTimeStamp
private

◆ m_threadedChannelizer

ThreadedBasebandSampleSource* FileSource::m_threadedChannelizer
private

Definition at line 393 of file filesource.h.

Referenced by FileSource(), and ~FileSource().


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