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.
Public Types | Public Member Functions | Private Types | Private Slots | Private Member Functions | Private Attributes | List of all members
DSPDeviceSinkEngine Class Reference

#include <dspdevicesinkengine.h>

Inherits QThread.

+ Collaboration diagram for DSPDeviceSinkEngine:

Public Types

enum  State {
  StNotStarted, StIdle, StReady, StRunning,
  StError
}
 

Public Member Functions

 DSPDeviceSinkEngine (uint32_t uid, QObject *parent=NULL)
 
 ~DSPDeviceSinkEngine ()
 
uint32_t getUID () const
 
MessageQueuegetInputMessageQueue ()
 
void start ()
 This thread start. More...
 
void stop ()
 This thread stop. More...
 
bool initGeneration ()
 Initialize generation sequence. More...
 
bool startGeneration ()
 Start generation sequence. More...
 
void stopGeneration ()
 Stop generation sequence. More...
 
void setSink (DeviceSampleSink *sink)
 Set the sample sink type. More...
 
DeviceSampleSinkgetSink ()
 
void setSinkSequence (int sequence)
 Set the sample sink sequence in type. More...
 
void addThreadedSource (ThreadedBasebandSampleSource *source)
 Add a baseband sample source that will run on its own thread. More...
 
void removeThreadedSource (ThreadedBasebandSampleSource *source)
 Remove a baseband sample source that runs on its own thread. More...
 
void addSpectrumSink (BasebandSampleSink *spectrumSink)
 Add a spectrum vis baseband sample sink. More...
 
void removeSpectrumSink (BasebandSampleSink *spectrumSink)
 Add a spectrum vis baseband sample sink. More...
 
State state () const
 Return DSP engine current state. More...
 
QString errorMessage ()
 Return the current error message. More...
 
QString sinkDeviceDescription ()
 Return the sink device description. More...
 

Private Types

typedef std::list< BasebandSampleSource * > BasebandSampleSources
 
typedef std::list< ThreadedBasebandSampleSource * > ThreadedBasebandSampleSources
 
typedef std::map< BasebandSampleSource *, SampleVector::iterator > BasebandSampleSourcesIteratorMap
 
typedef std::pair< BasebandSampleSource *, SampleVector::iterator > BasebandSampleSourcesIteratorMapKV
 
typedef std::map< ThreadedBasebandSampleSource *, SampleVector::iterator > ThreadedBasebandSampleSourcesIteratorMap
 
typedef std::pair< ThreadedBasebandSampleSource *, SampleVector::iterator > ThreadedBasebandSampleSourcesIteratorMapKV
 

Private Slots

void handleData (int nbSamples)
 Handle data when samples have to be written to the sample FIFO. More...
 
void handleInputMessages ()
 Handle input message queue. More...
 
void handleSynchronousMessages ()
 Handle synchronous messages with the thread. More...
 
void handleForwardToSpectrumSink (int nbSamples)
 

Private Member Functions

void run ()
 
void work (int nbWriteSamples)
 transfer samples from beseband sources to sink if in running state More...
 
State gotoIdle ()
 Go to the idle state. More...
 
State gotoInit ()
 Go to the acquisition init state from idle. More...
 
State gotoRunning ()
 Go to the running state from ready state. More...
 
State gotoError (const QString &errorMsg)
 Go to an error state. More...
 
void handleSetSink (DeviceSampleSink *sink)
 Manage sink setting. More...
 
void checkNumberOfBasebandSources ()
 

Private Attributes

uint32_t m_uid
 unique ID More...
 
MessageQueue m_inputMessageQueue
 
SyncMessenger m_syncMessenger
 Used to process messages synchronously with the thread. More...
 
State m_state
 
QString m_errorMessage
 
QString m_deviceDescription
 
DeviceSampleSinkm_deviceSampleSink
 
int m_sampleSinkSequence
 
BasebandSampleSources m_basebandSampleSources
 baseband sample sources within main thread (usually file input) More...
 
ThreadedBasebandSampleSources m_threadedBasebandSampleSources
 baseband sample sources on their own threads (usually channels) More...
 
BasebandSampleSourcesIteratorMap m_basebandSampleSourcesIteratorMap
 
ThreadedBasebandSampleSourcesIteratorMap m_threadedBasebandSampleSourcesIteratorMap
 
BasebandSampleSinkm_spectrumSink
 
uint32_t m_sampleRate
 
quint64 m_centerFrequency
 
uint32_t m_multipleSourcesDivisionFactor
 

Detailed Description

Definition at line 40 of file dspdevicesinkengine.h.

Member Typedef Documentation

◆ BasebandSampleSources

Definition at line 95 of file dspdevicesinkengine.h.

◆ BasebandSampleSourcesIteratorMap

typedef std::map<BasebandSampleSource*, SampleVector::iterator> DSPDeviceSinkEngine::BasebandSampleSourcesIteratorMap
private

Definition at line 101 of file dspdevicesinkengine.h.

◆ BasebandSampleSourcesIteratorMapKV

typedef std::pair<BasebandSampleSource*, SampleVector::iterator> DSPDeviceSinkEngine::BasebandSampleSourcesIteratorMapKV
private

Definition at line 102 of file dspdevicesinkengine.h.

◆ ThreadedBasebandSampleSources

Definition at line 98 of file dspdevicesinkengine.h.

◆ ThreadedBasebandSampleSourcesIteratorMap

Definition at line 105 of file dspdevicesinkengine.h.

◆ ThreadedBasebandSampleSourcesIteratorMapKV

Definition at line 106 of file dspdevicesinkengine.h.

Member Enumeration Documentation

◆ State

Enumerator
StNotStarted 

engine is before initialization

StIdle 

engine is idle

StReady 

engine is ready to run

StRunning 

engine is running

StError 

engine is in error

Definition at line 44 of file dspdevicesinkengine.h.

44  {
45  StNotStarted,
46  StIdle,
47  StReady,
48  StRunning,
49  StError
50  };
engine is before initialization
engine is ready to run

Constructor & Destructor Documentation

◆ DSPDeviceSinkEngine()

DSPDeviceSinkEngine::DSPDeviceSinkEngine ( uint32_t  uid,
QObject *  parent = NULL 
)

Definition at line 32 of file dspdevicesinkengine.cpp.

References handleInputMessages(), handleSynchronousMessages(), m_inputMessageQueue, and m_syncMessenger.

32  :
33  QThread(parent),
34  m_uid(uid),
36  m_deviceSampleSink(nullptr),
39  m_spectrumSink(nullptr),
40  m_sampleRate(0),
43 {
44  connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()), Qt::QueuedConnection);
45  connect(&m_syncMessenger, SIGNAL(messageSent()), this, SLOT(handleSynchronousMessages()), Qt::QueuedConnection);
46 
47  moveToThread(this);
48 }
engine is before initialization
void handleSynchronousMessages()
Handle synchronous messages with the thread.
DeviceSampleSink * m_deviceSampleSink
BasebandSampleSink * m_spectrumSink
BasebandSampleSources m_basebandSampleSources
baseband sample sources within main thread (usually file input)
SyncMessenger m_syncMessenger
Used to process messages synchronously with the thread.
MessageQueue m_inputMessageQueue
uint32_t m_uid
unique ID
uint32_t m_multipleSourcesDivisionFactor
void handleInputMessages()
Handle input message queue.
+ Here is the call graph for this function:

◆ ~DSPDeviceSinkEngine()

DSPDeviceSinkEngine::~DSPDeviceSinkEngine ( )

Definition at line 50 of file dspdevicesinkengine.cpp.

References stop().

51 {
52  stop();
53  wait();
54 }
void stop()
This thread stop.
+ Here is the call graph for this function:

Member Function Documentation

◆ addSpectrumSink()

void DSPDeviceSinkEngine::addSpectrumSink ( BasebandSampleSink spectrumSink)

Add a spectrum vis baseband sample sink.

Definition at line 130 of file dspdevicesinkengine.cpp.

References m_syncMessenger, and SyncMessenger::sendWait().

Referenced by DeviceAPI::addAncillarySink(), and MainWindow::addSinkDevice().

131 {
132  qDebug() << "DSPDeviceSinkEngine::addSpectrumSink: " << spectrumSink->objectName().toStdString().c_str();
133  DSPAddSpectrumSink cmd(spectrumSink);
135 }
SyncMessenger m_syncMessenger
Used to process messages synchronously with the thread.
int sendWait(Message &message, unsigned long msPollTime=100)
Send message and waits for its process completion.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addThreadedSource()

void DSPDeviceSinkEngine::addThreadedSource ( ThreadedBasebandSampleSource source)

Add a baseband sample source that will run on its own thread.

Definition at line 116 of file dspdevicesinkengine.cpp.

References m_syncMessenger, and SyncMessenger::sendWait().

Referenced by DeviceAPI::addChannelSource().

117 {
118  qDebug() << "DSPDeviceSinkEngine::addThreadedSource: " << source->objectName().toStdString().c_str();
121 }
SyncMessenger m_syncMessenger
Used to process messages synchronously with the thread.
int sendWait(Message &message, unsigned long msPollTime=100)
Send message and waits for its process completion.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkNumberOfBasebandSources()

void DSPDeviceSinkEngine::checkNumberOfBasebandSources ( )
private

Definition at line 570 of file dspdevicesinkengine.cpp.

References DeviceSampleSink::getSampleFifo(), handleData(), m_basebandSampleSources, m_deviceSampleSink, m_multipleSourcesDivisionFactor, and m_threadedBasebandSampleSources.

Referenced by handleSynchronousMessages().

571 {
573 
574  // single channel source handling
575  if ((m_threadedBasebandSampleSources.size() + m_basebandSampleSources.size()) == 1)
576  {
577  qDebug("DSPDeviceSinkEngine::checkNumberOfBasebandSources: single channel mode");
578  disconnect(sampleFifo, SIGNAL(dataWrite(int)), this, SLOT(handleData(int)));
579 
580  if (m_threadedBasebandSampleSources.size() == 1) {
581  m_threadedBasebandSampleSources.back()->setDeviceSampleSourceFifo(sampleFifo);
582  } else if (m_basebandSampleSources.size() == 1) {
583  m_basebandSampleSources.back()->setDeviceSampleSourceFifo(sampleFifo);
584  }
585 
586  m_multipleSourcesDivisionFactor = 1; // for consistency but it is not used in this case
587  }
588  // null or multiple channel sources handling
589  else
590  {
591  int nbSources = 0;
592 
593  for (ThreadedBasebandSampleSources::iterator it = m_threadedBasebandSampleSources.begin(); it != m_threadedBasebandSampleSources.end(); ++it)
594  {
595  (*it)->setDeviceSampleSourceFifo(0);
596  nbSources++;
597  }
598 
599  for (BasebandSampleSources::iterator it = m_basebandSampleSources.begin(); it != m_basebandSampleSources.end(); ++it)
600  {
601  (*it)->setDeviceSampleSourceFifo(0);
602  nbSources++;
603  }
604 
605  if (nbSources == 0) {
607  } else if (nbSources < 3) {
609  } else {
610  m_multipleSourcesDivisionFactor = 1<<nbSources;
611  }
612 
613  if (nbSources > 1) {
614  connect(sampleFifo, SIGNAL(dataWrite(int)), this, SLOT(handleData(int)), Qt::QueuedConnection);
615  }
616 
617  qDebug("DSPDeviceSinkEngine::checkNumberOfBasebandSources: handle %d channel(s)", nbSources);
618  }
619 }
DeviceSampleSink * m_deviceSampleSink
BasebandSampleSources m_basebandSampleSources
baseband sample sources within main thread (usually file input)
void handleData(int nbSamples)
Handle data when samples have to be written to the sample FIFO.
SampleSourceFifo * getSampleFifo()
uint32_t m_multipleSourcesDivisionFactor
ThreadedBasebandSampleSources m_threadedBasebandSampleSources
baseband sample sources on their own threads (usually channels)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ errorMessage()

QString DSPDeviceSinkEngine::errorMessage ( )

Return the current error message.

Definition at line 144 of file dspdevicesinkengine.cpp.

References DSPGetErrorMessage::getErrorMessage(), m_syncMessenger, and SyncMessenger::sendWait().

Referenced by DeviceAPI::errorMessage(), and gotoError().

145 {
146  qDebug() << "DSPDeviceSinkEngine::errorMessage";
147  DSPGetErrorMessage cmd;
149  return cmd.getErrorMessage();
150 }
const QString & getErrorMessage() const
Definition: dspcommands.h:86
SyncMessenger m_syncMessenger
Used to process messages synchronously with the thread.
int sendWait(Message &message, unsigned long msPollTime=100)
Send message and waits for its process completion.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getInputMessageQueue()

MessageQueue* DSPDeviceSinkEngine::getInputMessageQueue ( )
inline

Definition at line 57 of file dspdevicesinkengine.h.

Referenced by DeviceAPI::getDeviceEngineInputMessageQueue().

57 { return &m_inputMessageQueue; }
MessageQueue m_inputMessageQueue
+ Here is the caller graph for this function:

◆ getSink()

DeviceSampleSink* DSPDeviceSinkEngine::getSink ( )
inline

◆ getUID()

uint32_t DSPDeviceSinkEngine::getUID ( ) const
inline

Definition at line 55 of file dspdevicesinkengine.h.

Referenced by MainCore::addSinkDevice(), MainWindow::addSinkDevice(), DeviceAPI::getDeviceUID(), and LocalSource::getLocalDevice().

55 { return m_uid; }
uint32_t m_uid
unique ID
+ Here is the caller graph for this function:

◆ gotoError()

DSPDeviceSinkEngine::State DSPDeviceSinkEngine::gotoError ( const QString &  errorMsg)
private

Go to an error state.

Definition at line 378 of file dspdevicesinkengine.cpp.

References errorMessage(), m_deviceDescription, m_errorMessage, m_state, and StError.

Referenced by gotoInit(), and gotoRunning().

379 {
380  qDebug() << "DSPDeviceSinkEngine::gotoError";
381 
383  m_deviceDescription.clear();
384  m_state = StError;
385  return StError;
386 }
QString errorMessage()
Return the current error message.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gotoIdle()

DSPDeviceSinkEngine::State DSPDeviceSinkEngine::gotoIdle ( )
private

Go to the idle state.

Definition at line 212 of file dspdevicesinkengine.cpp.

References DeviceSampleSink::getSampleFifo(), handleForwardToSpectrumSink(), m_basebandSampleSources, m_deviceDescription, m_deviceSampleSink, m_sampleRate, m_spectrumSink, m_state, m_threadedBasebandSampleSources, StError, StIdle, StNotStarted, DeviceSampleSink::stop(), BasebandSampleSink::stop(), StReady, and StRunning.

Referenced by handleSetSink(), handleSynchronousMessages(), and stop().

213 {
214  qDebug() << "DSPDeviceSinkEngine::gotoIdle";
215 
216  switch(m_state) {
217  case StNotStarted:
218  return StNotStarted;
219 
220  case StIdle:
221  case StError:
222  return StIdle;
223 
224  case StReady:
225  case StRunning:
226  break;
227  }
228 
229  if(m_deviceSampleSink == 0)
230  {
231  return StIdle;
232  }
233 
234  // stop everything
235 
236  for(BasebandSampleSources::const_iterator it = m_basebandSampleSources.begin(); it != m_basebandSampleSources.end(); it++)
237  {
238  qDebug() << "DSPDeviceSinkEngine::gotoIdle: stopping " << (*it)->objectName().toStdString().c_str();
239  (*it)->stop();
240  }
241 
242  for(ThreadedBasebandSampleSources::const_iterator it = m_threadedBasebandSampleSources.begin(); it != m_threadedBasebandSampleSources.end(); it++)
243  {
244  qDebug() << "DSPDeviceSinkEngine::gotoIdle: stopping ThreadedSampleSource(" << (*it)->getSampleSourceObjectName().toStdString().c_str() << ")";
245  (*it)->stop();
246  }
247 
248  if (m_spectrumSink)
249  {
250  disconnect(m_deviceSampleSink->getSampleFifo(), SIGNAL(dataRead(int)), this, SLOT(handleForwardToSpectrumSink(int)));
251  m_spectrumSink->stop();
252  }
253 
255  m_deviceDescription.clear();
256  m_sampleRate = 0;
257 
258  return StIdle;
259 }
engine is before initialization
engine is ready to run
DeviceSampleSink * m_deviceSampleSink
BasebandSampleSink * m_spectrumSink
virtual void stop()=0
BasebandSampleSources m_basebandSampleSources
baseband sample sources within main thread (usually file input)
void handleForwardToSpectrumSink(int nbSamples)
SampleSourceFifo * getSampleFifo()
virtual void stop()=0
ThreadedBasebandSampleSources m_threadedBasebandSampleSources
baseband sample sources on their own threads (usually channels)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gotoInit()

DSPDeviceSinkEngine::State DSPDeviceSinkEngine::gotoInit ( )
private

Go to the acquisition init state from idle.

Definition at line 261 of file dspdevicesinkengine.cpp.

References DeviceSampleSink::getCenterFrequency(), DeviceSampleSink::getDeviceDescription(), DeviceSampleSink::getMessageQueueToGUI(), DeviceSampleSink::getSampleRate(), gotoError(), BasebandSampleSink::handleMessage(), m_basebandSampleSources, m_centerFrequency, m_deviceDescription, m_deviceSampleSink, m_sampleRate, m_spectrumSink, m_state, m_threadedBasebandSampleSources, MessageQueue::push(), StError, StIdle, StNotStarted, StReady, and StRunning.

Referenced by handleSynchronousMessages().

262 {
263  switch(m_state) {
264  case StNotStarted:
265  return StNotStarted;
266 
267  case StRunning: // FIXME: assumes it goes first through idle state. Could we get back to init from running directly?
268  return StRunning;
269 
270  case StReady:
271  return StReady;
272 
273  case StIdle:
274  case StError:
275  break;
276  }
277 
278  if (m_deviceSampleSink == 0)
279  {
280  return gotoError("DSPDeviceSinkEngine::gotoInit: No sample source configured");
281  }
282 
283  // init: pass sample rate and center frequency to all sample rate and/or center frequency dependent sinks and wait for completion
284 
288 
289  qDebug() << "DSPDeviceSinkEngine::gotoInit: "
290  << " m_deviceDescription: " << m_deviceDescription.toStdString().c_str()
291  << " sampleRate: " << m_sampleRate
292  << " centerFrequency: " << m_centerFrequency;
293 
294  DSPSignalNotification notif(m_sampleRate, m_centerFrequency);
295 
296  for (BasebandSampleSources::const_iterator it = m_basebandSampleSources.begin(); it != m_basebandSampleSources.end(); ++it)
297  {
298  qDebug() << "DSPDeviceSinkEngine::gotoInit: initializing " << (*it)->objectName().toStdString().c_str();
299  (*it)->handleMessage(notif);
300  }
301 
302  for (ThreadedBasebandSampleSources::const_iterator it = m_threadedBasebandSampleSources.begin(); it != m_threadedBasebandSampleSources.end(); ++it)
303  {
304  qDebug() << "DSPDeviceSinkEngine::gotoInit: initializing ThreadedSampleSource(" << (*it)->getSampleSourceObjectName().toStdString().c_str() << ")";
305  (*it)->handleSourceMessage(notif);
306  }
307 
308  if (m_spectrumSink) {
310  }
311 
312  // pass data to listeners
314  {
315  DSPSignalNotification* rep = new DSPSignalNotification(notif); // make a copy for the output queue
317  }
318 
319  return StReady;
320 }
engine is before initialization
engine is ready to run
void push(Message *message, bool emitSignal=true)
Push message onto queue.
DeviceSampleSink * m_deviceSampleSink
BasebandSampleSink * m_spectrumSink
virtual bool handleMessage(const Message &cmd)=0
Processing of a message. Returns true if message has actually been processed.
BasebandSampleSources m_basebandSampleSources
baseband sample sources within main thread (usually file input)
virtual quint64 getCenterFrequency() const =0
Center frequency exposed by the sink.
State gotoError(const QString &errorMsg)
Go to an error state.
virtual int getSampleRate() const =0
Sample rate exposed by the sink.
MessageQueue * getMessageQueueToGUI()
ThreadedBasebandSampleSources m_threadedBasebandSampleSources
baseband sample sources on their own threads (usually channels)
virtual const QString & getDeviceDescription() const =0
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gotoRunning()

DSPDeviceSinkEngine::State DSPDeviceSinkEngine::gotoRunning ( )
private

Go to the running state from ready state.

Definition at line 322 of file dspdevicesinkengine.cpp.

References DeviceSampleSink::getSampleFifo(), gotoError(), handleForwardToSpectrumSink(), m_basebandSampleSources, m_deviceDescription, m_deviceSampleSink, m_inputMessageQueue, m_spectrumSink, m_state, m_threadedBasebandSampleSources, MessageQueue::size(), DeviceSampleSink::start(), BasebandSampleSink::start(), StError, StIdle, StNotStarted, StReady, and StRunning.

Referenced by handleSynchronousMessages().

323 {
324  qDebug() << "DSPDeviceSinkEngine::gotoRunning";
325 
326  switch(m_state)
327  {
328  case StNotStarted:
329  return StNotStarted;
330 
331  case StIdle:
332  return StIdle;
333 
334  case StRunning:
335  return StRunning;
336 
337  case StReady:
338  case StError:
339  break;
340  }
341 
342  if(m_deviceSampleSink == 0) {
343  return gotoError("DSPDeviceSinkEngine::gotoRunning: No sample source configured");
344  }
345 
346  qDebug() << "DSPDeviceSinkEngine::gotoRunning: " << m_deviceDescription.toStdString().c_str() << " started";
347 
348  // Start everything
349 
350  if(!m_deviceSampleSink->start())
351  {
352  return gotoError("DSPDeviceSinkEngine::gotoRunning: Could not start sample sink");
353  }
354 
355  for(BasebandSampleSources::const_iterator it = m_basebandSampleSources.begin(); it != m_basebandSampleSources.end(); it++)
356  {
357  qDebug() << "DSPDeviceSinkEngine::gotoRunning: starting " << (*it)->objectName().toStdString().c_str();
358  (*it)->start();
359  }
360 
361  for (ThreadedBasebandSampleSources::const_iterator it = m_threadedBasebandSampleSources.begin(); it != m_threadedBasebandSampleSources.end(); ++it)
362  {
363  qDebug() << "DSPDeviceSinkEngine::gotoRunning: starting ThreadedSampleSource(" << (*it)->getSampleSourceObjectName().toStdString().c_str() << ")";
364  (*it)->start();
365  }
366 
367  if (m_spectrumSink)
368  {
369  connect(m_deviceSampleSink->getSampleFifo(), SIGNAL(dataRead(int)), this, SLOT(handleForwardToSpectrumSink(int)));
371  }
372 
373  qDebug() << "DSPDeviceSinkEngine::gotoRunning: input message queue pending: " << m_inputMessageQueue.size();
374 
375  return StRunning;
376 }
engine is before initialization
engine is ready to run
int size()
Returns queue size.
DeviceSampleSink * m_deviceSampleSink
BasebandSampleSink * m_spectrumSink
virtual void start()=0
BasebandSampleSources m_basebandSampleSources
baseband sample sources within main thread (usually file input)
void handleForwardToSpectrumSink(int nbSamples)
SampleSourceFifo * getSampleFifo()
MessageQueue m_inputMessageQueue
virtual bool start()=0
State gotoError(const QString &errorMsg)
Go to an error state.
ThreadedBasebandSampleSources m_threadedBasebandSampleSources
baseband sample sources on their own threads (usually channels)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ handleData

void DSPDeviceSinkEngine::handleData ( int  nbSamples)
privateslot

Handle data when samples have to be written to the sample FIFO.

Definition at line 401 of file dspdevicesinkengine.cpp.

References m_state, StRunning, and work().

Referenced by checkNumberOfBasebandSources().

402 {
403  if(m_state == StRunning)
404  {
405  work(nbSamples);
406  }
407 }
void work(int nbWriteSamples)
transfer samples from beseband sources to sink if in running state
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ handleForwardToSpectrumSink

void DSPDeviceSinkEngine::handleForwardToSpectrumSink ( int  nbSamples)
privateslot

Definition at line 559 of file dspdevicesinkengine.cpp.

References BasebandSampleSink::feed(), SampleSourceFifo::getReadIterator(), DeviceSampleSink::getSampleFifo(), m_deviceSampleSink, and m_spectrumSink.

Referenced by gotoIdle(), and gotoRunning().

560 {
561  if (m_spectrumSink)
562  {
564  SampleVector::iterator readUntil;
565  sampleFifo->getReadIterator(readUntil);
566  m_spectrumSink->feed(readUntil - nbSamples, readUntil, false);
567  }
568 }
DeviceSampleSink * m_deviceSampleSink
BasebandSampleSink * m_spectrumSink
virtual void feed(const SampleVector::const_iterator &begin, const SampleVector::const_iterator &end, bool positiveOnly)=0
SampleSourceFifo * getSampleFifo()
void getReadIterator(SampleVector::iterator &readUntil)
get iterator past the last sample of a read advance operation (i.e. current read iterator) ...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ handleInputMessages

void DSPDeviceSinkEngine::handleInputMessages ( )
privateslot

Handle input message queue.

Definition at line 508 of file dspdevicesinkengine.cpp.

References DSPSignalNotification::getCenterFrequency(), Message::getIdentifier(), DeviceSampleSink::getMessageQueueToGUI(), DSPSignalNotification::getSampleRate(), m_basebandSampleSources, m_centerFrequency, m_deviceSampleSink, m_inputMessageQueue, m_sampleRate, m_threadedBasebandSampleSources, Message::match(), MessageQueue::pop(), and MessageQueue::push().

Referenced by DSPDeviceSinkEngine().

509 {
510  Message* message;
511 
512  while ((message = m_inputMessageQueue.pop()) != 0)
513  {
514  qDebug("DSPDeviceSinkEngine::handleInputMessages: message: %s", message->getIdentifier());
515 
516  if (DSPSignalNotification::match(*message))
517  {
518  DSPSignalNotification *notif = (DSPSignalNotification *) message;
519 
520  // update DSP values
521 
522  m_sampleRate = notif->getSampleRate();
524 
525  qDebug() << "DSPDeviceSinkEngine::handleInputMessages: DSPSignalNotification:"
526  << " m_sampleRate: " << m_sampleRate
527  << " m_centerFrequency: " << m_centerFrequency;
528 
529  // forward source changes to sources with immediate execution
530 
531  for(BasebandSampleSources::const_iterator it = m_basebandSampleSources.begin(); it != m_basebandSampleSources.end(); it++)
532  {
533  qDebug() << "DSPDeviceSinkEngine::handleInputMessages: forward message to " << (*it)->objectName().toStdString().c_str();
534  (*it)->handleMessage(*message);
535  }
536 
537  for (ThreadedBasebandSampleSources::const_iterator it = m_threadedBasebandSampleSources.begin(); it != m_threadedBasebandSampleSources.end(); ++it)
538  {
539  qDebug() << "DSPDeviceSinkEngine::handleSourceMessages: forward message to ThreadedSampleSource(" << (*it)->getSampleSourceObjectName().toStdString().c_str() << ")";
540  (*it)->handleSourceMessage(*message);
541  }
542 
543  // forward changes to listeners on DSP output queue
544 
546  qDebug("DSPDeviceSinkEngine::handleInputMessages: DSPSignalNotification: guiMessageQueue: %p", guiMessageQueue);
547 
548  if (guiMessageQueue)
549  {
550  DSPSignalNotification* rep = new DSPSignalNotification(*notif); // make a copy for the output queue
551  guiMessageQueue->push(rep);
552  }
553 
554  delete message;
555  }
556  }
557 }
Message * pop()
Pop message from queue.
void push(Message *message, bool emitSignal=true)
Push message onto queue.
DeviceSampleSink * m_deviceSampleSink
qint64 getCenterFrequency() const
Definition: dspcommands.h:329
BasebandSampleSources m_basebandSampleSources
baseband sample sources within main thread (usually file input)
MessageQueue m_inputMessageQueue
static bool match(const Message *message)
Definition: message.cpp:45
int getSampleRate() const
Definition: dspcommands.h:328
virtual const char * getIdentifier() const
Definition: message.cpp:35
MessageQueue * getMessageQueueToGUI()
ThreadedBasebandSampleSources m_threadedBasebandSampleSources
baseband sample sources on their own threads (usually channels)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ handleSetSink()

void DSPDeviceSinkEngine::handleSetSink ( DeviceSampleSink sink)
private

Manage sink setting.

Definition at line 388 of file dspdevicesinkengine.cpp.

References DeviceSampleSink::getDeviceDescription(), gotoIdle(), and m_deviceSampleSink.

Referenced by handleSynchronousMessages().

389 {
390  gotoIdle();
391 
392  m_deviceSampleSink = sink;
393 
394  if(m_deviceSampleSink != 0) {
395  qDebug("DSPDeviceSinkEngine::handleSetSink: set %s", qPrintable(sink->getDeviceDescription()));
396  } else {
397  qDebug("DSPDeviceSinkEngine::handleSetSource: set none");
398  }
399 }
DeviceSampleSink * m_deviceSampleSink
State gotoIdle()
Go to the idle state.
virtual const QString & getDeviceDescription() const =0
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ handleSynchronousMessages

void DSPDeviceSinkEngine::handleSynchronousMessages ( )
privateslot

Handle synchronous messages with the thread.

Definition at line 409 of file dspdevicesinkengine.cpp.

References checkNumberOfBasebandSources(), SyncMessenger::done(), Message::getIdentifier(), SyncMessenger::getMessage(), gotoIdle(), gotoInit(), gotoRunning(), BasebandSampleSource::handleMessage(), handleSetSink(), ThreadedBasebandSampleSource::handleSourceMessage(), m_basebandSampleSources, m_centerFrequency, m_deviceDescription, m_errorMessage, m_sampleRate, m_spectrumSink, m_state, m_syncMessenger, m_threadedBasebandSampleSources, Message::match(), BasebandSampleSource::start(), ThreadedBasebandSampleSource::start(), StIdle, BasebandSampleSource::stop(), ThreadedBasebandSampleSource::stop(), BasebandSampleSink::stop(), StReady, and StRunning.

Referenced by DSPDeviceSinkEngine(), and stopGeneration().

410 {
411  Message *message = m_syncMessenger.getMessage();
412  qDebug() << "DSPDeviceSinkEngine::handleSynchronousMessages: " << message->getIdentifier();
413 
414  if (DSPGenerationInit::match(*message))
415  {
416  m_state = gotoIdle();
417 
418  if(m_state == StIdle) {
419  m_state = gotoInit(); // State goes ready if init is performed
420  }
421  }
422  else if (DSPGenerationStart::match(*message))
423  {
424  if(m_state == StReady) {
425  m_state = gotoRunning();
426  }
427  }
428  else if (DSPGenerationStop::match(*message))
429  {
430  m_state = gotoIdle();
431  }
432  else if (DSPGetSinkDeviceDescription::match(*message))
433  {
434  ((DSPGetSinkDeviceDescription*) message)->setDeviceDescription(m_deviceDescription);
435  }
436  else if (DSPGetErrorMessage::match(*message))
437  {
438  ((DSPGetErrorMessage*) message)->setErrorMessage(m_errorMessage);
439  }
440  else if (DSPSetSink::match(*message)) {
441  handleSetSink(((DSPSetSink*) message)->getSampleSink());
442  }
443  else if (DSPAddSpectrumSink::match(*message))
444  {
445  m_spectrumSink = ((DSPAddSpectrumSink*) message)->getSampleSink();
446  }
447  else if (DSPRemoveSpectrumSink::match(*message))
448  {
449  BasebandSampleSink* spectrumSink = ((DSPRemoveSpectrumSink*) message)->getSampleSink();
450 
451  if(m_state == StRunning) {
452  spectrumSink->stop();
453  }
454 
455  m_spectrumSink = 0;
456  }
457  else if (DSPAddBasebandSampleSource::match(*message))
458  {
459  BasebandSampleSource* source = ((DSPAddBasebandSampleSource*) message)->getSampleSource();
460  m_basebandSampleSources.push_back(source);
462  source->handleMessage(notif);
464 
465  if (m_state == StRunning)
466  {
467  source->start();
468  }
469  }
470  else if (DSPRemoveBasebandSampleSource::match(*message))
471  {
472  BasebandSampleSource* source = ((DSPRemoveBasebandSampleSource*) message)->getSampleSource();
473 
474  if(m_state == StRunning) {
475  source->stop();
476  }
477 
478  m_basebandSampleSources.remove(source);
480  }
482  {
483  ThreadedBasebandSampleSource *threadedSource = ((DSPAddThreadedBasebandSampleSource*) message)->getThreadedSampleSource();
484  m_threadedBasebandSampleSources.push_back(threadedSource);
486  threadedSource->handleSourceMessage(notif);
488 
489  if (m_state == StRunning)
490  {
491  threadedSource->start();
492  }
493  }
495  {
496  ThreadedBasebandSampleSource* threadedSource = ((DSPRemoveThreadedBasebandSampleSource*) message)->getThreadedSampleSource();
497  if (m_state == StRunning) {
498  threadedSource->stop();
499  }
500 
501  m_threadedBasebandSampleSources.remove(threadedSource);
503  }
504 
506 }
engine is ready to run
State gotoRunning()
Go to the running state from ready state.
virtual bool handleMessage(const Message &cmd)=0
Processing of a message. Returns true if message has actually been processed.
virtual void stop()=0
BasebandSampleSink * m_spectrumSink
virtual void start()=0
BasebandSampleSources m_basebandSampleSources
baseband sample sources within main thread (usually file input)
SyncMessenger m_syncMessenger
Used to process messages synchronously with the thread.
void handleSetSink(DeviceSampleSink *sink)
Manage sink setting.
void stop()
this thread exit() and wait()
static bool match(const Message *message)
Definition: message.cpp:45
State gotoIdle()
Go to the idle state.
State gotoInit()
Go to the acquisition init state from idle.
Message * getMessage() const
Definition: syncmessenger.h:41
void done(int result=0)
Processing of the message is complete.
virtual const char * getIdentifier() const
Definition: message.cpp:35
virtual void stop()=0
ThreadedBasebandSampleSources m_threadedBasebandSampleSources
baseband sample sources on their own threads (usually channels)
bool handleSourceMessage(const Message &cmd)
Send message to source synchronously.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ initGeneration()

bool DSPDeviceSinkEngine::initGeneration ( )

Initialize generation sequence.

Definition at line 79 of file dspdevicesinkengine.cpp.

References m_syncMessenger, SyncMessenger::sendWait(), and StReady.

Referenced by DeviceAPI::initDeviceEngine().

80 {
81  qDebug() << "DSPDeviceSinkEngine::initGeneration";
83 
84  return m_syncMessenger.sendWait(cmd) == StReady;
85 }
engine is ready to run
SyncMessenger m_syncMessenger
Used to process messages synchronously with the thread.
int sendWait(Message &message, unsigned long msPollTime=100)
Send message and waits for its process completion.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ removeSpectrumSink()

void DSPDeviceSinkEngine::removeSpectrumSink ( BasebandSampleSink spectrumSink)

Add a spectrum vis baseband sample sink.

Definition at line 137 of file dspdevicesinkengine.cpp.

References m_syncMessenger, and SyncMessenger::sendWait().

Referenced by DeviceAPI::removeAncillarySink(), and MainWindow::removeLastDevice().

138 {
139  qDebug() << "DSPDeviceSinkEngine::removeSpectrumSink: " << spectrumSink->objectName().toStdString().c_str();
140  DSPRemoveSpectrumSink cmd(spectrumSink);
142 }
SyncMessenger m_syncMessenger
Used to process messages synchronously with the thread.
int sendWait(Message &message, unsigned long msPollTime=100)
Send message and waits for its process completion.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ removeThreadedSource()

void DSPDeviceSinkEngine::removeThreadedSource ( ThreadedBasebandSampleSource source)

Remove a baseband sample source that runs on its own thread.

Definition at line 123 of file dspdevicesinkengine.cpp.

References m_syncMessenger, and SyncMessenger::sendWait().

Referenced by DeviceAPI::removeChannelSource().

124 {
125  qDebug() << "DSPDeviceSinkEngine::removeThreadedSource: " << source->objectName().toStdString().c_str();
128 }
SyncMessenger m_syncMessenger
Used to process messages synchronously with the thread.
int sendWait(Message &message, unsigned long msPollTime=100)
Send message and waits for its process completion.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ run()

void DSPDeviceSinkEngine::run ( )
private

Definition at line 56 of file dspdevicesinkengine.cpp.

References m_state, and StIdle.

57 {
58  qDebug() << "DSPDeviceSinkEngine::run";
59  m_state = StIdle;
60  exec();
61 }

◆ setSink()

void DSPDeviceSinkEngine::setSink ( DeviceSampleSink sink)

Set the sample sink type.

Definition at line 103 of file dspdevicesinkengine.cpp.

References m_syncMessenger, and SyncMessenger::sendWait().

Referenced by DeviceAPI::setSampleSink().

104 {
105  qDebug() << "DSPDeviceSinkEngine::setSink";
106  DSPSetSink cmd(sink);
108 }
SyncMessenger m_syncMessenger
Used to process messages synchronously with the thread.
int sendWait(Message &message, unsigned long msPollTime=100)
Send message and waits for its process completion.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setSinkSequence()

void DSPDeviceSinkEngine::setSinkSequence ( int  sequence)

Set the sample sink sequence in type.

Definition at line 110 of file dspdevicesinkengine.cpp.

References m_sampleSinkSequence.

111 {
112  qDebug("DSPDeviceSinkEngine::setSinkSequence: seq: %d", sequence);
113  m_sampleSinkSequence = sequence;
114 }

◆ sinkDeviceDescription()

QString DSPDeviceSinkEngine::sinkDeviceDescription ( )

Return the sink device description.

Definition at line 152 of file dspdevicesinkengine.cpp.

References DSPGetSinkDeviceDescription::getDeviceDescription(), m_syncMessenger, and SyncMessenger::sendWait().

153 {
154  qDebug() << "DSPDeviceSinkEngine::sinkDeviceDescription";
157  return cmd.getDeviceDescription();
158 }
SyncMessenger m_syncMessenger
Used to process messages synchronously with the thread.
const QString & getDeviceDescription() const
Definition: dspcommands.h:75
int sendWait(Message &message, unsigned long msPollTime=100)
Send message and waits for its process completion.
+ Here is the call graph for this function:

◆ start()

void DSPDeviceSinkEngine::start ( )

This thread start.

Definition at line 63 of file dspdevicesinkengine.cpp.

Referenced by MainCore::addSinkDevice(), and MainWindow::addSinkDevice().

64 {
65  qDebug() << "DSPDeviceSinkEngine::start";
66  QThread::start();
67 }
+ Here is the caller graph for this function:

◆ startGeneration()

bool DSPDeviceSinkEngine::startGeneration ( )

Start generation sequence.

Definition at line 87 of file dspdevicesinkengine.cpp.

References m_syncMessenger, SyncMessenger::sendWait(), and StRunning.

Referenced by DeviceAPI::startDeviceEngine().

88 {
89  qDebug() << "DSPDeviceSinkEngine::startGeneration";
91 
92  return m_syncMessenger.sendWait(cmd) == StRunning;
93 }
SyncMessenger m_syncMessenger
Used to process messages synchronously with the thread.
int sendWait(Message &message, unsigned long msPollTime=100)
Send message and waits for its process completion.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ state()

State DSPDeviceSinkEngine::state ( ) const
inline

Return DSP engine current state.

Definition at line 76 of file dspdevicesinkengine.h.

Referenced by Bladerf1Input::applySettings(), DeviceAPI::getDeviceEngineStateStr(), and DeviceAPI::state().

+ Here is the caller graph for this function:

◆ stop()

void DSPDeviceSinkEngine::stop ( )

This thread stop.

Definition at line 69 of file dspdevicesinkengine.cpp.

References gotoIdle(), m_state, and StNotStarted.

Referenced by MainCore::removeLastDevice(), MainWindow::removeLastDevice(), and ~DSPDeviceSinkEngine().

70 {
71  qDebug() << "DSPDeviceSinkEngine::stop";
72  gotoIdle();
74  QThread::exit();
75 // DSPExit cmd;
76 // m_syncMessenger.sendWait(cmd);
77 }
engine is before initialization
State gotoIdle()
Go to the idle state.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ stopGeneration()

void DSPDeviceSinkEngine::stopGeneration ( )

Stop generation sequence.

Definition at line 95 of file dspdevicesinkengine.cpp.

References handleSynchronousMessages(), m_syncMessenger, and SyncMessenger::storeMessage().

Referenced by MainCore::removeLastDevice(), MainWindow::removeLastDevice(), and DeviceAPI::stopDeviceEngine().

96 {
97  qDebug() << "DSPDeviceSinkEngine::stopGeneration";
101 }
void handleSynchronousMessages()
Handle synchronous messages with the thread.
void storeMessage(Message &message)
Definition: syncmessenger.h:42
SyncMessenger m_syncMessenger
Used to process messages synchronously with the thread.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ work()

void DSPDeviceSinkEngine::work ( int  nbWriteSamples)
private

transfer samples from beseband sources to sink if in running state

Definition at line 160 of file dspdevicesinkengine.cpp.

References SampleSourceFifo::bumpIndex(), DeviceSampleSink::getSampleFifo(), SampleSourceFifo::getWriteIterator(), m_basebandSampleSources, m_deviceSampleSink, m_multipleSourcesDivisionFactor, and m_threadedBasebandSampleSources.

Referenced by handleData().

161 {
162  // multiple channel sources handling
164  {
165 // qDebug("DSPDeviceSinkEngine::work: multiple channel sources handling: %u", m_multipleSourcesDivisionFactor);
166 
167  SampleVector::iterator writeBegin;
169  sampleFifo->getWriteIterator(writeBegin);
170  SampleVector::iterator writeAt = writeBegin;
171  std::vector<SampleVector::iterator> sampleSourceIterators;
172 
173  for (ThreadedBasebandSampleSources::iterator it = m_threadedBasebandSampleSources.begin(); it != m_threadedBasebandSampleSources.end(); ++it)
174  {
175  sampleSourceIterators.push_back(SampleVector::iterator());
176  (*it)->getSampleSourceFifo().readAdvance(sampleSourceIterators.back(), nbWriteSamples);
177  sampleSourceIterators.back() -= nbWriteSamples;
178  }
179 
180  for (BasebandSampleSources::iterator it = m_basebandSampleSources.begin(); it != m_basebandSampleSources.end(); ++it)
181  {
182  sampleSourceIterators.push_back(SampleVector::iterator());
183  (*it)->getSampleSourceFifo().readAdvance(sampleSourceIterators.back(), nbWriteSamples);
184  sampleSourceIterators.back() -= nbWriteSamples;
185  }
186 
187  for (int is = 0; is < nbWriteSamples; is++)
188  {
189  // pull data from sources FIFOs and merge them in the device sample FIFO
190  for (std::vector<SampleVector::iterator>::iterator it = sampleSourceIterators.begin(); it != sampleSourceIterators.end(); ++it)
191  {
192  Sample s = (**it);
194  ++(*it);
195 
196  if (it == sampleSourceIterators.begin()) {
197  (*writeAt) = s;
198  } else {
199  (*writeAt) += s;
200  }
201  }
202 
203  sampleFifo->bumpIndex(writeAt);
204  }
205  }
206 }
DeviceSampleSink * m_deviceSampleSink
void bumpIndex(SampleVector::iterator &writeAt)
copy current item to second buffer and bump write index - write phase 2
BasebandSampleSources m_basebandSampleSources
baseband sample sources within main thread (usually file input)
SampleSourceFifo * getSampleFifo()
uint32_t m_multipleSourcesDivisionFactor
ThreadedBasebandSampleSources m_threadedBasebandSampleSources
baseband sample sources on their own threads (usually channels)
void getWriteIterator(SampleVector::iterator &writeAt)
get iterator to current item for update - write phase 1
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ m_basebandSampleSources

BasebandSampleSources DSPDeviceSinkEngine::m_basebandSampleSources
private

baseband sample sources within main thread (usually file input)

Definition at line 96 of file dspdevicesinkengine.h.

Referenced by checkNumberOfBasebandSources(), gotoIdle(), gotoInit(), gotoRunning(), handleInputMessages(), handleSynchronousMessages(), and work().

◆ m_basebandSampleSourcesIteratorMap

BasebandSampleSourcesIteratorMap DSPDeviceSinkEngine::m_basebandSampleSourcesIteratorMap
private

Definition at line 103 of file dspdevicesinkengine.h.

◆ m_centerFrequency

quint64 DSPDeviceSinkEngine::m_centerFrequency
private

Definition at line 112 of file dspdevicesinkengine.h.

Referenced by gotoInit(), handleInputMessages(), and handleSynchronousMessages().

◆ m_deviceDescription

QString DSPDeviceSinkEngine::m_deviceDescription
private

◆ m_deviceSampleSink

DeviceSampleSink* DSPDeviceSinkEngine::m_deviceSampleSink
private

◆ m_errorMessage

QString DSPDeviceSinkEngine::m_errorMessage
private

Definition at line 89 of file dspdevicesinkengine.h.

Referenced by gotoError(), and handleSynchronousMessages().

◆ m_inputMessageQueue

MessageQueue DSPDeviceSinkEngine::m_inputMessageQueue
private

Definition at line 84 of file dspdevicesinkengine.h.

Referenced by DSPDeviceSinkEngine(), gotoRunning(), and handleInputMessages().

◆ m_multipleSourcesDivisionFactor

uint32_t DSPDeviceSinkEngine::m_multipleSourcesDivisionFactor
private

Definition at line 113 of file dspdevicesinkengine.h.

Referenced by checkNumberOfBasebandSources(), and work().

◆ m_sampleRate

uint32_t DSPDeviceSinkEngine::m_sampleRate
private

◆ m_sampleSinkSequence

int DSPDeviceSinkEngine::m_sampleSinkSequence
private

Definition at line 93 of file dspdevicesinkengine.h.

Referenced by setSinkSequence().

◆ m_spectrumSink

BasebandSampleSink* DSPDeviceSinkEngine::m_spectrumSink
private

◆ m_state

State DSPDeviceSinkEngine::m_state
private

◆ m_syncMessenger

SyncMessenger DSPDeviceSinkEngine::m_syncMessenger
private

◆ m_threadedBasebandSampleSources

ThreadedBasebandSampleSources DSPDeviceSinkEngine::m_threadedBasebandSampleSources
private

baseband sample sources on their own threads (usually channels)

Definition at line 99 of file dspdevicesinkengine.h.

Referenced by checkNumberOfBasebandSources(), gotoIdle(), gotoInit(), gotoRunning(), handleInputMessages(), handleSynchronousMessages(), and work().

◆ m_threadedBasebandSampleSourcesIteratorMap

ThreadedBasebandSampleSourcesIteratorMap DSPDeviceSinkEngine::m_threadedBasebandSampleSourcesIteratorMap
private

Definition at line 107 of file dspdevicesinkengine.h.

◆ m_uid

uint32_t DSPDeviceSinkEngine::m_uid
private

unique ID

Definition at line 82 of file dspdevicesinkengine.h.


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