From 0a03c5d5877bdc5afef6cec6f0278e09fdacd78c Mon Sep 17 00:00:00 2001 From: f4exb Date: Tue, 10 Sep 2019 18:44:43 +0200 Subject: [PATCH] Fallback of sample sink vector in test MI source and device MIMO engine --- plugins/samplemimo/testmi/testmi.cpp | 4 +- plugins/samplemimo/testmi/testmithread.cpp | 2 +- plugins/samplemimo/testmi/testmithread.h | 7 ++- sdrbase/dsp/devicesamplemimo.cpp | 11 +++- sdrbase/dsp/devicesamplemimo.h | 7 ++- sdrbase/dsp/dspdevicemimoengine.cpp | 64 ++++++++++++++++++---- sdrbase/dsp/dspdevicemimoengine.h | 4 +- 7 files changed, 78 insertions(+), 21 deletions(-) diff --git a/plugins/samplemimo/testmi/testmi.cpp b/plugins/samplemimo/testmi/testmi.cpp index c2a6a5296..4a20c01fb 100644 --- a/plugins/samplemimo/testmi/testmi.cpp +++ b/plugins/samplemimo/testmi/testmi.cpp @@ -50,7 +50,9 @@ TestMI::TestMI(DeviceAPI *deviceAPI) : m_masterTimer(deviceAPI->getMasterTimer()) { m_mimoType = MIMOAsynchronous; - m_sampleSinkFifos.resize(2); + m_sampleSinkFifos.push_back(SampleSinkFifo(96000 * 4)); + m_sampleSinkFifos.push_back(SampleSinkFifo(96000 * 4)); + //m_sampleSinkVectors.resize(2); m_deviceAPI->setNbSourceStreams(2); m_networkManager = new QNetworkAccessManager(); connect(m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkManagerFinished(QNetworkReply*))); diff --git a/plugins/samplemimo/testmi/testmithread.cpp b/plugins/samplemimo/testmi/testmithread.cpp index e25a1272c..53457a7b4 100644 --- a/plugins/samplemimo/testmi/testmithread.cpp +++ b/plugins/samplemimo/testmi/testmithread.cpp @@ -28,7 +28,7 @@ MESSAGE_CLASS_DEFINITION(TestMIThread::MsgStartStop, Message) -TestMIThread::TestMIThread(SampleSinkVector* sampleFifo, int streamIndex, QObject* parent) : +TestMIThread::TestMIThread(SampleSinkFifo* sampleFifo, int streamIndex, QObject* parent) : QThread(parent), m_running(false), m_buf(0), diff --git a/plugins/samplemimo/testmi/testmithread.h b/plugins/samplemimo/testmi/testmithread.h index e008a39f0..59cd50317 100644 --- a/plugins/samplemimo/testmi/testmithread.h +++ b/plugins/samplemimo/testmi/testmithread.h @@ -25,7 +25,6 @@ #include #include -#include "dsp/samplesinkvector.h" #include "dsp/decimators.h" #include "dsp/ncof.h" #include "util/message.h" @@ -35,6 +34,8 @@ #define TESTMI_THROTTLE_MS 50 +class SampleSinkFifo; + class TestMIThread : public QThread { Q_OBJECT @@ -58,7 +59,7 @@ public: { } }; - TestMIThread(SampleSinkVector* sampleFifo, int streamIndex, QObject* parent = 0); + TestMIThread(SampleSinkFifo* sampleFifo, int streamIndex, QObject* parent = 0); ~TestMIThread(); void startStop(bool start); @@ -89,7 +90,7 @@ private: quint32 m_bufsize; quint32 m_chunksize; SampleVector m_convertBuffer; - SampleSinkVector* m_sampleFifo; + SampleSinkFifo* m_sampleFifo; int m_streamIndex; NCOF m_nco; NCOF m_toneNco; diff --git a/sdrbase/dsp/devicesamplemimo.cpp b/sdrbase/dsp/devicesamplemimo.cpp index a4381009e..f3afce080 100644 --- a/sdrbase/dsp/devicesamplemimo.cpp +++ b/sdrbase/dsp/devicesamplemimo.cpp @@ -52,7 +52,7 @@ SampleSourceFifo* DeviceSampleMIMO::getSampleSourceFifo(unsigned int index) } } -SampleSinkVector* DeviceSampleMIMO::getSampleSinkFifo(unsigned int index) +SampleSinkFifo* DeviceSampleMIMO::getSampleSinkFifo(unsigned int index) { if (index >= m_sampleSinkFifos.size()) { return nullptr; @@ -60,3 +60,12 @@ SampleSinkVector* DeviceSampleMIMO::getSampleSinkFifo(unsigned int index) return &m_sampleSinkFifos[index]; } } + +SampleSinkVector* DeviceSampleMIMO::getSampleSinkVector(unsigned int index) +{ + if (index >= m_sampleSinkVectors.size()) { + return nullptr; + } else { + return &m_sampleSinkVectors[index]; + } +} diff --git a/sdrbase/dsp/devicesamplemimo.h b/sdrbase/dsp/devicesamplemimo.h index bb670b1f7..248004ad9 100644 --- a/sdrbase/dsp/devicesamplemimo.h +++ b/sdrbase/dsp/devicesamplemimo.h @@ -22,6 +22,7 @@ #include #include "samplesourcefifo.h" +#include "samplesinkfifo.h" #include "samplesinkvector.h" #include "util/message.h" #include "util/messagequeue.h" @@ -133,7 +134,8 @@ public: unsigned int getNbSourceFifos() const { return m_sampleSourceFifos.size(); } //!< Get the number of Tx FIFOs unsigned int getNbSinkFifos() const { return m_sampleSinkFifos.size(); } //!< Get the number of Rx FIFOs SampleSourceFifo* getSampleSourceFifo(unsigned int index); //!< Get Tx FIFO at index - SampleSinkVector* getSampleSinkFifo(unsigned int index); //!< Get Rx FIFO at index + SampleSinkFifo* getSampleSinkFifo(unsigned int index); //!< Get Rx FIFO at index + SampleSinkVector* getSampleSinkVector(unsigned int index); //!< Get Rx vector buffer at index (TODO: remove if not used) // Streams and FIFOs are in opposed source/sink type whick makes it confusing when stream direction is involved: // Rx: source stream -> sink FIFO -> channel sinks // Tx: sink stream <- source FIFO <- channel sources @@ -146,7 +148,8 @@ protected slots: protected: MIMOType m_mimoType; std::vector m_sampleSourceFifos; //!< Tx FIFOs - std::vector m_sampleSinkFifos; //!< Rx FIFOs + std::vector m_sampleSinkFifos; //!< Rx FIFOs + std::vector m_sampleSinkVectors; //!< Rx vector buffer (TODO: remove if not used) MessageQueue m_inputMessageQueue; //!< Input queue to the sink MessageQueue *m_guiMessageQueue; //!< Input message queue to the GUI }; diff --git a/sdrbase/dsp/dspdevicemimoengine.cpp b/sdrbase/dsp/dspdevicemimoengine.cpp index 936ce1377..03d3fdae1 100644 --- a/sdrbase/dsp/dspdevicemimoengine.cpp +++ b/sdrbase/dsp/dspdevicemimoengine.cpp @@ -267,18 +267,59 @@ QString DSPDeviceMIMOEngine::deviceDescription() return cmd.getDeviceDescription(); } +void DSPDeviceMIMOEngine::workSampleSinkVector(unsigned int sinkIndex) +{ + SampleSinkVector* sampleFifo = m_deviceSampleMIMO->getSampleSinkVector(sinkIndex); + + if (!sampleFifo) { + return; + } + + SampleVector::iterator vbegin; + SampleVector::iterator vend; + sampleFifo->read(vbegin, vend); + + workSamplePart(vbegin, vend, sinkIndex); +} + +void DSPDeviceMIMOEngine::workSampleSinkFifo(unsigned int sinkIndex) +{ + SampleSinkFifo* sampleFifo = m_deviceSampleMIMO->getSampleSinkFifo(sinkIndex); + int samplesDone = 0; + + if (!sampleFifo) { + return; + } + + while ((sampleFifo->fill() > 0) && (m_inputMessageQueue.size() == 0) && (samplesDone < m_deviceSampleMIMO->getSourceSampleRate(sinkIndex))) + { + SampleVector::iterator part1begin; + SampleVector::iterator part1end; + SampleVector::iterator part2begin; + SampleVector::iterator part2end; + + std::size_t count = sampleFifo->readBegin(sampleFifo->fill(), &part1begin, &part1end, &part2begin, &part2end); + + if (part1begin != part1end) { // first part of FIFO data + workSamplePart(part1begin, part1end, sinkIndex); + } + + if (part2begin != part2end) { // second part of FIFO data (used when block wraps around) + workSamplePart(part1begin, part1end, sinkIndex); + } + + sampleFifo->readCommit((unsigned int) count); // adjust FIFO pointers + samplesDone += count; + } +} + /** * Routes samples from device source FIFO to sink channels that are registered for the FIFO * Routes samples from source channels registered for the FIFO to the device sink FIFO */ -void DSPDeviceMIMOEngine::workSampleSink(unsigned int sinkIndex) +void DSPDeviceMIMOEngine::workSamplePart(const SampleVector::iterator& vbegin, const SampleVector::iterator& vend, unsigned int sinkIndex) { - SampleSinkVector* sampleFifo = m_deviceSampleMIMO->getSampleSinkFifo(sinkIndex); - SampleVector::iterator vbegin; - SampleVector::iterator vend; bool positiveOnly = false; - sampleFifo->read(vbegin, vend); - // DC and IQ corrections if (m_sourcesCorrections[sinkIndex].m_dcOffsetCorrection) { iqCorrections(vbegin, vend, sinkIndex, m_sourcesCorrections[sinkIndex].m_iqImbalanceCorrection); @@ -558,9 +599,8 @@ void DSPDeviceMIMOEngine::handleDataRxSync() { if (m_state == StRunning) { - // Sources (move their samples into sinks) - for (unsigned int isource = 0; isource < m_deviceSampleMIMO->getNbSourceStreams(); isource++) { - workSampleSink(isource); + for (unsigned int isink = 0; isink < m_deviceSampleMIMO->getNbSinkFifos(); isink++) { + workSampleSinkFifo(isink); } } } @@ -568,7 +608,7 @@ void DSPDeviceMIMOEngine::handleDataRxSync() void DSPDeviceMIMOEngine::handleDataRxAsync(unsigned int sinkIndex) { if (m_state == StRunning) { - workSampleSink(sinkIndex); + workSampleSinkFifo(sinkIndex); } } @@ -601,7 +641,7 @@ void DSPDeviceMIMOEngine::handleSetMIMO(DeviceSampleMIMO* mimo) qPrintable(mimo->getDeviceDescription()), isink); QObject::connect( m_deviceSampleMIMO->getSampleSinkFifo(isink), - &SampleSinkVector::dataReady, + &SampleSinkFifo::dataReady, this, [=](){ this->handleDataRxSync(); }, // lambda function is not strictly needed here Qt::QueuedConnection @@ -617,7 +657,7 @@ void DSPDeviceMIMOEngine::handleSetMIMO(DeviceSampleMIMO* mimo) qPrintable(mimo->getDeviceDescription()), isink); QObject::connect( m_deviceSampleMIMO->getSampleSinkFifo(isink), - &SampleSinkVector::dataReady, + &SampleSinkFifo::dataReady, this, [=](){ this->handleDataRxAsync(isink); }, Qt::QueuedConnection diff --git a/sdrbase/dsp/dspdevicemimoengine.h b/sdrbase/dsp/dspdevicemimoengine.h index feaf2c5db..ec3c39993 100644 --- a/sdrbase/dsp/dspdevicemimoengine.h +++ b/sdrbase/dsp/dspdevicemimoengine.h @@ -379,7 +379,9 @@ private: unsigned int m_spectrumInputIndex; //!< Index of the stream to be used as spectrum sink input void run(); - void workSampleSink(unsigned int sinkIndex); //!< transfer samples of one sink (asynchronously) + void workSampleSinkFifo(unsigned int sinkIndex); //!< transfer samples of one sink (asynchronously) + void workSampleSinkVector(unsigned int sinkIndex); //!< same but sample sink vector flavor (TODO: remove if unused) + void workSamplePart(const SampleVector::iterator& vbegin, const SampleVector::iterator& vend, unsigned int sinkIndex); State gotoIdle(); //!< Go to the idle state State gotoInit(); //!< Go to the acquisition init state from idle