From ad4827f36c2dc66324f60843e9340924ba74becb Mon Sep 17 00:00:00 2001 From: f4exb Date: Sun, 19 May 2019 12:54:22 +0200 Subject: [PATCH] MIMO: handle channel and ancillary source / sink lists add / remove items --- plugins/samplemimo/testmi/testmi.cpp | 2 + sdrbase/device/deviceapi.cpp | 32 +++++++++++- sdrbase/device/deviceapi.h | 6 +++ sdrbase/dsp/dspdevicemimoengine.cpp | 78 ++++++++++++++++++++++++---- sdrbase/dsp/dspdevicemimoengine.h | 41 +++++++++++++++ 5 files changed, 147 insertions(+), 12 deletions(-) diff --git a/plugins/samplemimo/testmi/testmi.cpp b/plugins/samplemimo/testmi/testmi.cpp index 0307f4c0c..c7c562f51 100644 --- a/plugins/samplemimo/testmi/testmi.cpp +++ b/plugins/samplemimo/testmi/testmi.cpp @@ -50,6 +50,7 @@ TestMI::TestMI(DeviceAPI *deviceAPI) : m_masterTimer(deviceAPI->getMasterTimer()) { m_fileSink = new FileRecord(QString("test_%1.sdriq").arg(m_deviceAPI->getDeviceUID())); + m_deviceAPI->addSourceStream(); // Add a new source stream data set in the engine m_deviceAPI->addAncillarySink(m_fileSink); m_sampleSinkFifos.push_back(SampleSinkFifo(96000 * 4)); m_networkManager = new QNetworkAccessManager(); @@ -66,6 +67,7 @@ TestMI::~TestMI() } m_deviceAPI->removeAncillarySink(m_fileSink); + m_deviceAPI->removeLastSourceStream(); // Remove the last source stream data set in the engine delete m_fileSink; } diff --git a/sdrbase/device/deviceapi.cpp b/sdrbase/device/deviceapi.cpp index 49108bdc2..edd029a03 100644 --- a/sdrbase/device/deviceapi.cpp +++ b/sdrbase/device/deviceapi.cpp @@ -56,6 +56,34 @@ DeviceAPI::~DeviceAPI() { } +void DeviceAPI::addSourceStream() +{ + if (m_deviceMIMOEngine) { + m_deviceMIMOEngine->addSourceStream(); + } +} + +void DeviceAPI::removeLastSourceStream() +{ + if (m_deviceMIMOEngine) { + m_deviceMIMOEngine->removeLastSourceStream(); + } +} + +void DeviceAPI::addSinkStream() +{ + if (m_deviceMIMOEngine) { + m_deviceMIMOEngine->addSinkStream(); + } +} + +void DeviceAPI::removeLastSinkStream() +{ + if (m_deviceMIMOEngine) { + m_deviceMIMOEngine->removeLastSinkStream(); + } +} + void DeviceAPI::addAncillarySink(BasebandSampleSink *sink) { if (m_deviceSourceEngine) { @@ -83,10 +111,10 @@ void DeviceAPI::setSpectrumSinkInput(bool sourceElseSink, unsigned int index) void DeviceAPI::addChannelSink(ThreadedBasebandSampleSink* sink, int streamIndex) { - (void) streamIndex; - if (m_deviceSourceEngine) { m_deviceSourceEngine->addThreadedSink(sink); + } else if (m_deviceMIMOEngine) { + m_deviceMIMOEngine->addChannelSink(sink, streamIndex); } } diff --git a/sdrbase/device/deviceapi.h b/sdrbase/device/deviceapi.h index 735ece4b7..1bd70cb1e 100644 --- a/sdrbase/device/deviceapi.h +++ b/sdrbase/device/deviceapi.h @@ -66,6 +66,12 @@ public: ); ~DeviceAPI(); + // MIMO Engine baseband / channel lists management + void addSourceStream(); + void removeLastSourceStream(); + void addSinkStream(); + void removeLastSinkStream(); + void addAncillarySink(BasebandSampleSink* sink); //!< Adds a sink to receive full baseband and that is not a channel (e.g. spectrum) void removeAncillarySink(BasebandSampleSink* sink); //!< Removes it void setSpectrumSinkInput(bool sourceElseSink = true, unsigned int index = 0); //!< Used in the MIMO case to select which stream is used as input to main spectrum diff --git a/sdrbase/dsp/dspdevicemimoengine.cpp b/sdrbase/dsp/dspdevicemimoengine.cpp index 225c382c8..3f6390d31 100644 --- a/sdrbase/dsp/dspdevicemimoengine.cpp +++ b/sdrbase/dsp/dspdevicemimoengine.cpp @@ -26,6 +26,10 @@ #include "dspdevicemimoengine.h" MESSAGE_CLASS_DEFINITION(DSPDeviceMIMOEngine::SetSampleMIMO, Message) +MESSAGE_CLASS_DEFINITION(DSPDeviceMIMOEngine::AddSourceStream, Message) +MESSAGE_CLASS_DEFINITION(DSPDeviceMIMOEngine::RemoveLastSourceStream, Message) +MESSAGE_CLASS_DEFINITION(DSPDeviceMIMOEngine::AddSinkStream, Message) +MESSAGE_CLASS_DEFINITION(DSPDeviceMIMOEngine::RemoveLastSinkStream, Message) MESSAGE_CLASS_DEFINITION(DSPDeviceMIMOEngine::AddThreadedBasebandSampleSource, Message) MESSAGE_CLASS_DEFINITION(DSPDeviceMIMOEngine::RemoveThreadedBasebandSampleSource, Message) MESSAGE_CLASS_DEFINITION(DSPDeviceMIMOEngine::AddThreadedBasebandSampleSink, Message) @@ -118,6 +122,34 @@ void DSPDeviceMIMOEngine::setMIMOSequence(int sequence) m_sampleMIMOSequence = sequence; } +void DSPDeviceMIMOEngine::addSourceStream() +{ + qDebug("DSPDeviceMIMOEngine::addSourceStream"); + AddSourceStream cmd; + m_syncMessenger.sendWait(cmd); +} + +void DSPDeviceMIMOEngine::removeLastSourceStream() +{ + qDebug("DSPDeviceMIMOEngine::removeLastSourceStream"); + RemoveLastSourceStream cmd; + m_syncMessenger.sendWait(cmd); +} + +void DSPDeviceMIMOEngine::addSinkStream() +{ + qDebug("DSPDeviceMIMOEngine::addSinkStream"); + AddSinkStream cmd; + m_syncMessenger.sendWait(cmd); +} + +void DSPDeviceMIMOEngine::removeLastSinkStream() +{ + qDebug("DSPDeviceMIMOEngine::removeLastSinkStream"); + RemoveLastSourceStream cmd; + m_syncMessenger.sendWait(cmd); +} + void DSPDeviceMIMOEngine::addChannelSource(ThreadedBasebandSampleSource* source, int index) { qDebug() << "DSPDeviceMIMOEngine::addThreadedSource: " @@ -294,7 +326,6 @@ void DSPDeviceMIMOEngine::work(int nbWriteSamples) } } - // adjust FIFO pointers sampleFifo->readCommit((unsigned int) count); samplesDone += count; @@ -422,11 +453,18 @@ DSPDeviceMIMOEngine::State DSPDeviceMIMOEngine::gotoInit() } } - // pass data to listeners - // if (m_deviceSampleSource->getMessageQueueToGUI()) - // { - // DSPSignalNotification* rep = new DSPSignalNotification(notif); // make a copy for the output queue - // m_deviceSampleSource->getMessageQueueToGUI()->push(rep); + // Probably not necessary + // // possibly forward to spectrum sink + // if ((m_spectrumSink) && (m_spectrumInputSourceElseSink) && (isource == m_spectrumInputIndex)) { + // m_spectrumSink->handleMessage(notif); + // } + + // // forward changes to MIMO GUI input queue + // MessageQueue *guiMessageQueue = m_deviceSampleMIMO->getMessageQueueToGUI(); + + // if (guiMessageQueue) { + // SignalNotification* rep = new SignalNotification(sourceStreamSampleRate, sourceCenterFrequency, true, isource); // make a copy for the MIMO GUI + // guiMessageQueue->push(rep); // } } @@ -560,13 +598,32 @@ void DSPDeviceMIMOEngine::handleSynchronousMessages() else if (SetSampleMIMO::match(*message)) { handleSetMIMO(((SetSampleMIMO*) message)->getSampleMIMO()); } + else if (AddSourceStream::match(*message)) + { + m_basebandSampleSinks.push_back(BasebandSampleSinks()); + m_threadedBasebandSampleSinks.push_back(ThreadedBasebandSampleSinks()); + m_sourcesCorrections.push_back(SourceCorrection()); + } + else if (RemoveLastSourceStream::match(*message)) + { + m_basebandSampleSinks.pop_back(); + m_threadedBasebandSampleSinks.pop_back(); + } + else if (AddSinkStream::match(*message)) + { + m_threadedBasebandSampleSources.push_back(ThreadedBasebandSampleSources()); + } + else if (RemoveLastSinkStream::match(*message)) + { + m_threadedBasebandSampleSources.pop_back(); + } else if (AddBasebandSampleSink::match(*message)) { const AddBasebandSampleSink *msg = (AddBasebandSampleSink *) message; BasebandSampleSink* sink = msg->getSampleSink(); unsigned int isource = msg->getIndex(); - if ((isource < m_basebandSampleSinks.size()) && (isource < m_deviceSampleMIMO->getNbSourceStreams())) + if (isource < m_basebandSampleSinks.size()) { m_basebandSampleSinks[isource].push_back(sink); // initialize sample rate and center frequency in the sink: @@ -601,7 +658,7 @@ void DSPDeviceMIMOEngine::handleSynchronousMessages() ThreadedBasebandSampleSink *threadedSink = msg->getThreadedSampleSink(); unsigned int isource = msg->getIndex(); - if ((isource < m_threadedBasebandSampleSinks.size()) && (isource < m_deviceSampleMIMO->getNbSourceStreams())) + if (isource < m_threadedBasebandSampleSinks.size()) { m_threadedBasebandSampleSinks[isource].push_back(threadedSink); // initialize sample rate and center frequency in the sink: @@ -633,7 +690,7 @@ void DSPDeviceMIMOEngine::handleSynchronousMessages() ThreadedBasebandSampleSource *threadedSource = msg->getThreadedSampleSource(); unsigned int isink = msg->getIndex(); - if ((isink < m_threadedBasebandSampleSources.size()) && (isink < m_deviceSampleMIMO->getNbSinkStreams())) + if (isink < m_threadedBasebandSampleSources.size()) { m_threadedBasebandSampleSources[isink].push_back(threadedSource); // initialize sample rate and center frequency in the sink: @@ -751,7 +808,8 @@ void DSPDeviceMIMOEngine::handleInputMessages() m_sourcesCorrections[isource].m_imbalance = 65536; } } - + m_sourcesCorrections[isource].m_iBeta.reset(); + m_sourcesCorrections[isource].m_qBeta.reset(); m_sourcesCorrections[isource].m_avgAmp.reset(); m_sourcesCorrections[isource].m_avgII.reset(); m_sourcesCorrections[isource].m_avgII2.reset(); diff --git a/sdrbase/dsp/dspdevicemimoengine.h b/sdrbase/dsp/dspdevicemimoengine.h index 8b7a829cc..fd7f3a299 100644 --- a/sdrbase/dsp/dspdevicemimoengine.h +++ b/sdrbase/dsp/dspdevicemimoengine.h @@ -60,6 +60,22 @@ public: unsigned int m_index; }; + class AddSourceStream : public Message { + MESSAGE_CLASS_DECLARATION + }; + + class RemoveLastSourceStream : public Message { + MESSAGE_CLASS_DECLARATION + }; + + class AddSinkStream : public Message { + MESSAGE_CLASS_DECLARATION + }; + + class RemoveLastSinkStream : public Message { + MESSAGE_CLASS_DECLARATION + }; + class RemoveThreadedBasebandSampleSource : public Message { MESSAGE_CLASS_DECLARATION @@ -250,6 +266,11 @@ public: void setMIMOSequence(int sequence); //!< Set the sample MIMO sequence in type uint getUID() const { return m_uid; } + void addSourceStream(); + void removeLastSourceStream(); + void addSinkStream(); + void removeLastSinkStream(); + void addChannelSource(ThreadedBasebandSampleSource* source, int index = 0); //!< Add a channel source that will run on its own thread void removeChannelSource(ThreadedBasebandSampleSource* source, int index = 0); //!< Remove a channel source that runs on its own thread void addChannelSink(ThreadedBasebandSampleSink* sink, int index = 0); //!< Add a channel sink that will run on its own thread @@ -298,6 +319,26 @@ private: MovingAverageUtil m_avgPhi; MovingAverageUtil m_avgAmp; #endif + SourceCorrection() + { + m_dcOffsetCorrection = false; + m_iqImbalanceCorrection = false; + m_iOffset = 0; + m_qOffset = 0; + m_iRange = 1 << 16; + m_qRange = 1 << 16; + m_imbalance = 65536; + m_iBeta.reset(); + m_qBeta.reset(); + m_avgAmp.reset(); + m_avgII.reset(); + m_avgII2.reset(); + m_avgIQ.reset(); + m_avgPhi.reset(); + m_avgQQ2.reset(); + m_iBeta.reset(); + m_qBeta.reset(); + } }; uint32_t m_uid; //!< unique ID