49 m_state(StNotStarted),
50 m_deviceSampleMIMO(
nullptr),
51 m_spectrumInputSourceElseSink(true),
52 m_spectrumInputIndex(0)
54 connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()),
this, SLOT(handleInputMessages()), Qt::QueuedConnection);
55 connect(&m_syncMessenger, SIGNAL(messageSent()),
this, SLOT(handleSynchronousMessages()), Qt::QueuedConnection);
68 qDebug() <<
"DSPDeviceMIMOEngine::run";
75 qDebug() <<
"DSPDeviceMIMOEngine::start";
81 qDebug() <<
"DSPDeviceMIMOEngine::stop";
89 qDebug() <<
"DSPDeviceMIMOEngine::initGeneration";
97 qDebug() <<
"DSPDeviceMIMOEngine::startGeneration";
105 qDebug() <<
"DSPDeviceMIMOEngine::stopGeneration";
113 qDebug() <<
"DSPDeviceMIMOEngine::setMIMO";
120 qDebug(
"DSPDeviceMIMOEngine::setSinkSequence: seq: %d", sequence);
126 qDebug(
"DSPDeviceMIMOEngine::addSourceStream");
133 qDebug(
"DSPDeviceMIMOEngine::removeLastSourceStream");
140 qDebug(
"DSPDeviceMIMOEngine::addSinkStream");
147 qDebug(
"DSPDeviceMIMOEngine::removeLastSinkStream");
154 qDebug() <<
"DSPDeviceMIMOEngine::addThreadedSource: " 155 << source->objectName().toStdString().c_str()
164 qDebug() <<
"DSPDeviceMIMOEngine::removeThreadedSource: " 165 << source->objectName().toStdString().c_str()
174 qDebug() <<
"DSPDeviceMIMOEngine::addThreadedSink: " 175 << sink->objectName().toStdString().c_str()
184 qDebug() <<
"DSPDeviceMIMOEngine::removeThreadedSink: " 185 << sink->objectName().toStdString().c_str()
194 qDebug() <<
"DSPDeviceMIMOEngine::addSink: " 195 << sink->objectName().toStdString().c_str()
204 qDebug() <<
"DSPDeviceMIMOEngine::removeSink: " 205 << sink->objectName().toStdString().c_str()
214 qDebug() <<
"DSPDeviceMIMOEngine::addSpectrumSink: " << spectrumSink->objectName().toStdString().c_str();
221 qDebug() <<
"DSPDeviceSinkEngine::removeSpectrumSink: " << spectrumSink->objectName().toStdString().c_str();
228 qDebug() <<
"DSPDeviceSinkEngine::setSpectrumSinkInput: " 229 <<
" sourceElseSink: " << sourceElseSink
230 <<
" index: " << index;
237 qDebug() <<
"DSPDeviceMIMOEngine::errorMessage";
245 qDebug() <<
"DSPDeviceMIMOEngine::deviceDescription";
257 (void) nbWriteSamples;
263 bool positiveOnly =
false;
265 while ((sampleFifo->
fill() > 0) && (
m_inputMessageQueue.
size() == 0) && (samplesDone < m_deviceSampleMIMO->getSourceSampleRate(isource)))
267 SampleVector::iterator part1begin;
268 SampleVector::iterator part1end;
269 SampleVector::iterator part2begin;
270 SampleVector::iterator part2end;
272 std::size_t count = sampleFifo->
readBegin(sampleFifo->
fill(), &part1begin, &part1end, &part2begin, &part2end);
275 if (part1begin != part1end)
283 (*it)->feed(part1begin, part1end, positiveOnly);
296 (*it)->feed(part1begin, part1end, positiveOnly);
302 if(part2begin != part2end)
310 (*it)->feed(part2begin, part2end, positiveOnly);
323 (*it)->feed(part2begin, part2end, positiveOnly);
330 samplesDone += count;
345 bool positiveOnly =
false;
347 while ((sampleFifo->
fill() > 0) && (
m_inputMessageQueue.
size() == 0) && (samplesDone < m_deviceSampleMIMO->getSourceSampleRate(sinkIndex)))
349 SampleVector::iterator part1begin;
350 SampleVector::iterator part1end;
351 SampleVector::iterator part2begin;
352 SampleVector::iterator part2end;
354 std::size_t count = sampleFifo->
readBegin(sampleFifo->
fill(), &part1begin, &part1end, &part2begin, &part2end);
357 if (part1begin != part1end)
368 (*it)->feed(part1begin, part1end, positiveOnly);
380 (*it)->feed(part1begin, part1end, positiveOnly);
385 if(part2begin != part2end)
396 (*it)->feed(part2begin, part2end, positiveOnly);
408 (*it)->feed(part2begin, part2end, positiveOnly);
414 samplesDone += count;
424 qDebug() <<
"DSPDeviceMIMOEngine::gotoIdle";
449 for (BasebandSampleSinks::const_iterator it = vbit->begin(); it != vbit->end(); ++it) {
458 for (ThreadedBasebandSampleSinks::const_iterator it = vtit->begin(); it != vtit->end(); ++it) {
487 return gotoError(
"No sample MIMO configured");
495 qDebug() <<
"DSPDeviceMIMOEngine::gotoInit: " 513 qDebug(
"DSPDeviceMIMOEngine::gotoInit: m_sourceCenterFrequencies[%d] = %llu", isource, sourceCenterFrequency);
514 qDebug(
"DSPDeviceMIMOEngine::gotoInit: m_sourceStreamSampleRates[%d] = %d", isource, sourceStreamSampleRate);
522 qDebug() <<
"DSPDeviceMIMOEngine::gotoInit: initializing " << (*it)->objectName().toStdString().c_str();
523 (*it)->handleMessage(notif);
531 qDebug() <<
"DSPDeviceMIMOEngine::gotoInit: initializing ThreadedSampleSink(" << (*it)->getSampleSinkObjectName().toStdString().c_str() <<
")";
532 (*it)->handleSinkMessage(notif);
558 qDebug() <<
"DSPDeviceMIMOEngine::gotoRunning";
577 return gotoError(
"DSPDeviceMIMOEngine::gotoRunning: No sample source configured");
580 qDebug() <<
"DSPDeviceMIMOEngine::gotoRunning: " <<
m_deviceDescription.toStdString().c_str() <<
" started";
585 return gotoError(
"Could not start sample source");
592 for (BasebandSampleSinks::const_iterator it = vbit->begin(); it != vbit->end(); ++it)
594 qDebug() <<
"DSPDeviceMIMOEngine::gotoRunning: starting " << (*it)->objectName().toStdString().c_str();
603 for (ThreadedBasebandSampleSinks::const_iterator it = vtit->begin(); it != vtit->end(); ++it)
605 qDebug() <<
"DSPDeviceMIMOEngine::gotoRunning: starting ThreadedSampleSink(" << (*it)->getSampleSinkObjectName().toStdString().c_str() <<
")";
617 qDebug() <<
"DSPDeviceMIMOEngine::gotoError: " <<
errorMessage;
641 qDebug(
"DSPDeviceMIMOEngine::handleSetMIMO: synchronous set %s", qPrintable(mimo->
getDeviceDescription()));
655 qDebug(
"DSPDeviceMIMOEngine::handleSetMIMO: asynchronous sources set %s channel %u",
674 qDebug() <<
"DSPDeviceMIMOEngine::handleSynchronousMessages: " << message->
getIdentifier();
738 unsigned int isource = msg->
getIndex();
758 unsigned int isource = msg->
getIndex();
773 unsigned int isource = msg->
getIndex();
785 threadedSink->
start();
793 unsigned int isource = msg->
getIndex();
797 threadedSink->
stop();
805 unsigned int isink = msg->
getIndex();
817 threadedSource->
start();
825 unsigned int isink = msg->
getIndex();
829 threadedSource->
stop();
840 spectrumSink->
stop();
854 unsigned int spectrumInputIndex = msg->
getIndex();
864 if ((!spectrumInputSourceElseSink) && (spectrumInputIndex < m_deviceSampleMIMO->getNbSinkStreams()))
878 if (
m_spectrumSink && (spectrumInputSourceElseSink) && (spectrumInputIndex < m_deviceSampleMIMO->getNbSinkFifos()))
900 qDebug(
"DSPDeviceMIMOEngine::handleInputMessages: message: %s", message->
getIdentifier());
905 unsigned int isource = conf->
getIndex();
946 unsigned int istream = notif->
getIndex();
950 qDebug() <<
"DeviceMIMOEngine::handleInputMessages: DSPMIMOSignalNotification:" 951 <<
" sourceElseSink: " << sourceElseSink
952 <<
" istream: " << istream
953 <<
" sampleRate: " << sampleRate
954 <<
" centerFrequency: " << centerFrequency;
958 if ((istream < m_deviceSampleMIMO->getNbSourceStreams()))
967 qDebug() <<
"DSPDeviceMIMOEngine::gotoRunning: starting " << (*it)->objectName().toStdString().c_str();
968 (*it)->handleMessage(*message);
977 qDebug() <<
"DSPDeviceMIMOEngine::handleSourceMessages: forward message to ThreadedSampleSink(" << (*it)->getSampleSinkObjectName().toStdString().c_str() <<
")";
978 (*it)->handleSinkMessage(*message);
984 qDebug(
"DeviceMIMOEngine::handleInputMessages: DSPMIMOSignalNotification: guiMessageQueue: %p", guiMessageQueue);
986 if (guiMessageQueue) {
988 guiMessageQueue->
push(rep);
1001 if ((istream < m_deviceSampleMIMO->getNbSinkStreams()))
1010 qDebug() <<
"DSPDeviceMIMOEngine::handleSinkMessages: forward message to ThreadedSampleSource(" << (*it)->getSampleSourceObjectName().toStdString().c_str() <<
")";
1011 (*it)->handleSourceMessage(*message);
1017 qDebug(
"DSPDeviceMIMOEngine::handleInputMessages: DSPSignalNotification: guiMessageQueue: %p", guiMessageQueue);
1019 if (guiMessageQueue) {
1021 guiMessageQueue->
push(rep);
1040 qDebug() <<
"DSPDeviceMIMOEngine::configureCorrections";
1048 if ((
m_spectrumSink) && (m_spectrumInputIndex < m_deviceSampleMIMO->getNbSinkStreams()))
1051 SampleVector::iterator readUntil;
1059 for(SampleVector::iterator it = begin; it < end; it++)
1064 if (imbalanceCorrection)
1100 it->m_real = yi >> 5;
1101 it->m_imag = zq >> 5;
void handleData()
Handle data when samples have to be processed.
Message * pop()
Pop message from queue.
void removeChannelSource(ThreadedBasebandSampleSource *source, int index=0)
Remove a channel source that runs on its own thread.
qint64 getCenterFrequency() const
SyncMessenger m_syncMessenger
Used to process messages synchronously with the thread.
std::vector< ThreadedBasebandSampleSinks > m_threadedBasebandSampleSinks
channel sample sinks on their own thread (per input stream)
void setMIMO(DeviceSampleMIMO *mimo)
Set the sample MIMO type.
void push(Message *message, bool emitSignal=true)
Push message onto queue.
int size()
Returns queue size.
QString deviceDescription()
Return the device description.
void removeChannelSink(ThreadedBasebandSampleSink *sink, int index=0)
Remove a channel sink that runs on its own thread.
void handleInputMessages()
Handle input message queue.
virtual const QString & getDeviceDescription() const =0
bool handleSinkMessage(const Message &cmd)
Send message to sink synchronously.
QString errorMessage()
Return the current error message.
BasebandSampleSink * getSampleSink() const
unsigned int getNbSourceStreams() const
Commodity function same as getNbSinkFifos (Rx or source streams)
void start()
this thread start()
unsigned int getIndex() const
std::list< ThreadedBasebandSampleSink * > ThreadedBasebandSampleSinks
void handleSynchronousMessages()
Handle synchronous messages with the thread.
bool m_spectrumInputSourceElseSink
Source else sink stream to be used as spectrum sink input.
engine is before initialization
void storeMessage(Message &message)
void stopProcess()
Stop process sequence.
virtual quint64 getSourceCenterFrequency(int index) const =0
Center frequency exposed by the source at index.
virtual int getSinkSampleRate(int index) const =0
Sample rate exposed by the sink at index.
virtual void feed(const SampleVector::const_iterator &begin, const SampleVector::const_iterator &end, bool positiveOnly)=0
BasebandSampleSink * m_spectrumSink
The spectrum sink.
bool initProcess()
Initialize process sequence.
std::vector< SourceCorrection > m_sourcesCorrections
int getSampleRate() const
uint readCommit(uint count)
bool getSourceOrSink() const
std::list< BasebandSampleSink * > BasebandSampleSinks
ThreadedBasebandSampleSource * getThreadedSampleSource() const
State gotoError(const QString &errorMsg)
Go to an error state.
void handleForwardToSpectrumSink(int nbSamples)
unsigned int getIndex() const
virtual bool handleMessage(const Message &cmd)=0
Processing of a message. Returns true if message has actually been processed.
void setSpectrumSinkInput(bool sourceElseSink, int index)
unsigned int getIndex() const
#define MESSAGE_CLASS_DEFINITION(Name, BaseClass)
std::list< ThreadedBasebandSampleSource * > ThreadedBasebandSampleSources
void removeSpectrumSink(BasebandSampleSink *spectrumSink)
Add a spectrum vis baseband sample sink.
void configureCorrections(bool dcOffsetCorrection, bool iqImbalanceCorrection, int isource)
Configure source DSP corrections.
std::vector< int > m_sampleSinkConnectionIndexes
DeviceSampleMIMO * m_deviceSampleMIMO
void workSampleSink(unsigned int sinkIndex)
ThreadedBasebandSampleSink * getThreadedSampleSink() const
SampleSinkFifo * getSampleSinkFifo(unsigned int index)
Get Rx FIFO at index.
void handleSetMIMO(DeviceSampleMIMO *mimo)
Manage MIMO device setting.
void removeAncillarySink(BasebandSampleSink *sink, int index=0)
Remove an ancillary sample sink.
void stop()
this thread exit() and wait()
QString m_deviceDescription
static bool match(const Message *message)
void stop()
This thread stop.
SampleSourceFifo * getSampleSourceFifo(unsigned int index)
Get Tx FIFO at index.
State gotoIdle()
Go to the idle state.
void iqCorrections(SampleVector::iterator begin, SampleVector::iterator end, int isource, bool imbalanceCorrection)
std::vector< BasebandSampleSinks > m_basebandSampleSinks
ancillary sample sinks on main thread (per input stream)
Fixed< IntType, IntBits > sqrt(Fixed< IntType, IntBits > const &x)
const QString & getDeviceDescription() const
unsigned int getIndex() const
State gotoRunning()
Go to the running state from ready state.
unsigned int getNbSinkFifos() const
Get the number of Rx FIFOs.
void setMIMOSequence(int sequence)
Set the sample MIMO sequence in type.
IntType as_internal() const
Message * getMessage() const
void addAncillarySink(BasebandSampleSink *sink, int index=0)
Add an ancillary sink like a I/Q recorder.
void addChannelSource(ThreadedBasebandSampleSource *source, int index=0)
Add a channel source that will run on its own thread.
MessageQueue * getMessageQueueToGUI()
virtual quint64 getSinkCenterFrequency(int index) const =0
Center frequency exposed by the sink at index.
void done(int result=0)
Processing of the message is complete.
unsigned int getIndex() const
State gotoInit()
Go to the acquisition init state from idle.
void stop()
this thread exit() and wait()
unsigned int m_spectrumInputIndex
Index of the stream to be used as spectrum sink input.
void start()
This thread start.
ThreadedBasebandSampleSink * getThreadedSampleSink() const
ThreadedBasebandSampleSource * getThreadedSampleSource() const
virtual const char * getIdentifier() const
virtual int getSourceSampleRate(int index) const =0
Sample rate exposed by the source at index.
void addChannelSink(ThreadedBasebandSampleSink *sink, int index=0)
Add a channel sink that will run on its own thread.
void removeLastSourceStream()
void addSourceStream(bool connect)
const QString & getErrorMessage() const
unsigned int getIndex() const
int sendWait(Message &message, unsigned long msPollTime=100)
Send message and waits for its process completion.
void start()
this thread start()
unsigned int getIndex() const
std::vector< ThreadedBasebandSampleSources > m_threadedBasebandSampleSources
channel sample sources on their own threads (per output stream)
std::vector< int > m_sampleSourceConnectionIndexes
uint readBegin(uint count, SampleVector::iterator *part1Begin, SampleVector::iterator *part1End, SampleVector::iterator *part2Begin, SampleVector::iterator *part2End)
void getReadIterator(SampleVector::iterator &readUntil)
get iterator past the last sample of a read advance operation (i.e. current read iterator) ...
void removeLastSinkStream()
void addSpectrumSink(BasebandSampleSink *spectrumSink)
Add a spectrum vis baseband sample sink.
void work(int nbWriteSamples)
transfer samples if in running state
bool handleSourceMessage(const Message &cmd)
Send message to source synchronously.
void addSinkStream(bool connect)
MessageQueue m_inputMessageQueue
bool startProcess()
Start process sequence.