1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2026-06-01 21:54:55 -04:00

MIMO: add channel to testMI (2)

This commit is contained in:
f4exb
2019-05-27 02:52:33 +02:00
parent eff28e8b63
commit f9a8523714
10 changed files with 182 additions and 38 deletions
+119 -10
View File
@@ -122,10 +122,10 @@ void DSPDeviceMIMOEngine::setMIMOSequence(int sequence)
m_sampleMIMOSequence = sequence;
}
void DSPDeviceMIMOEngine::addSourceStream()
void DSPDeviceMIMOEngine::addSourceStream(bool connect)
{
qDebug("DSPDeviceMIMOEngine::addSourceStream");
AddSourceStream cmd;
AddSourceStream cmd(connect);
m_syncMessenger.sendWait(cmd);
}
@@ -136,10 +136,10 @@ void DSPDeviceMIMOEngine::removeLastSourceStream()
m_syncMessenger.sendWait(cmd);
}
void DSPDeviceMIMOEngine::addSinkStream()
void DSPDeviceMIMOEngine::addSinkStream(bool connect)
{
qDebug("DSPDeviceMIMOEngine::addSinkStream");
AddSinkStream cmd;
AddSinkStream cmd(connect);
m_syncMessenger.sendWait(cmd);
}
@@ -335,6 +335,81 @@ void DSPDeviceMIMOEngine::work(int nbWriteSamples)
// TODO: sinks
}
void DSPDeviceMIMOEngine::workSampleSink(unsigned int sinkIndex)
{
if (m_state != StRunning) {
return;
}
SampleSinkFifo* sampleFifo = m_deviceSampleMIMO->getSampleSinkFifo(sinkIndex);
int samplesDone = 0;
bool positiveOnly = false;
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);
// first part of FIFO data
if (part1begin != part1end)
{
// TODO: DC and IQ corrections
// feed data to direct sinks
if (sinkIndex < m_basebandSampleSinks.size())
{
for (BasebandSampleSinks::const_iterator it = m_basebandSampleSinks[sinkIndex].begin(); it != m_basebandSampleSinks[sinkIndex].end(); ++it) {
(*it)->feed(part1begin, part1end, positiveOnly);
}
}
// possibly feed data to spectrum sink
if ((m_spectrumSink) && (m_spectrumInputSourceElseSink) && (sinkIndex == m_spectrumInputIndex)) {
m_spectrumSink->feed(part1begin, part1end, positiveOnly);
}
// feed data to threaded sinks
for (ThreadedBasebandSampleSinks::const_iterator it = m_threadedBasebandSampleSinks[sinkIndex].begin(); it != m_threadedBasebandSampleSinks[sinkIndex].end(); ++it)
{
(*it)->feed(part1begin, part1end, positiveOnly);
}
}
// second part of FIFO data (used when block wraps around)
if(part2begin != part2end)
{
// TODO: DC and IQ corrections
// feed data to direct sinks
if (sinkIndex < m_basebandSampleSinks.size())
{
for (BasebandSampleSinks::const_iterator it = m_basebandSampleSinks[sinkIndex].begin(); it != m_basebandSampleSinks[sinkIndex].end(); ++it) {
(*it)->feed(part2begin, part2end, positiveOnly);
}
}
// possibly feed data to spectrum sink
if ((m_spectrumSink) && (m_spectrumInputSourceElseSink) && (sinkIndex == m_spectrumInputIndex)) {
m_spectrumSink->feed(part2begin, part2end, positiveOnly);
}
// feed data to threaded sinks
for (ThreadedBasebandSampleSinks::const_iterator it = m_threadedBasebandSampleSinks[sinkIndex].begin(); it != m_threadedBasebandSampleSinks[sinkIndex].end(); ++it)
{
(*it)->feed(part2begin, part2end, positiveOnly);
}
}
// adjust FIFO pointers
sampleFifo->readCommit((unsigned int) count);
samplesDone += count;
}
}
// notStarted -> idle -> init -> running -+
// ^ |
// +-----------------------+
@@ -544,7 +619,7 @@ DSPDeviceMIMOEngine::State DSPDeviceMIMOEngine::gotoError(const QString& errorMe
void DSPDeviceMIMOEngine::handleData()
{
if(m_state == StRunning)
if (m_state == StRunning)
{
work(0); // TODO: implement Tx side
}
@@ -554,14 +629,38 @@ void DSPDeviceMIMOEngine::handleSetMIMO(DeviceSampleMIMO* mimo)
{
m_deviceSampleMIMO = mimo;
if (mimo && (mimo->getNbSinkFifos() > 0))
if (mimo)
{
// if there is at least one Rx then the first Rx drives the FIFOs
qDebug("DSPDeviceMIMOEngine::handleSetMIMO: set %s", qPrintable(mimo->getDeviceDescription()));
connect(m_deviceSampleMIMO->getSampleSinkFifo(0), SIGNAL(dataReady()), this, SLOT(handleData()), Qt::QueuedConnection);
if ((m_sampleSinkConnectionIndexes.size() == 1) && (m_sampleSourceConnectionIndexes.size() == 0)) // true MIMO (synchronous FIFOs)
{
qDebug("DSPDeviceMIMOEngine::handleSetMIMO: synchronous set %s", qPrintable(mimo->getDeviceDescription()));
// connect(m_deviceSampleMIMO->getSampleSinkFifo(m_sampleSinkConnectionIndexes[0]), SIGNAL(dataReady()), this, SLOT(handleData()), Qt::QueuedConnection);
QObject::connect(
m_deviceSampleMIMO->getSampleSinkFifo(m_sampleSinkConnectionIndexes[0]),
&SampleSinkFifo::dataReady,
this,
[=](){ this->handleData(); }, // lambda function is not strictly needed here
Qt::QueuedConnection
);
}
else if (m_sampleSinkConnectionIndexes.size() != 0) // asynchronous FIFOs
{
for (unsigned int isink = 0; isink < m_sampleSinkConnectionIndexes.size(); isink++)
{
qDebug("DSPDeviceMIMOEngine::handleSetMIMO: asynchronous sources set %s channel %u",
qPrintable(mimo->getDeviceDescription()), isink);
QObject::connect(
m_deviceSampleMIMO->getSampleSinkFifo(m_sampleSinkConnectionIndexes[isink]),
&SampleSinkFifo::dataReady,
this,
[=](){ this->workSampleSink(isink); },
Qt::QueuedConnection
);
}
}
}
// TODO: only Tx
// TODO: Tx
}
void DSPDeviceMIMOEngine::handleSynchronousMessages()
@@ -601,8 +700,13 @@ void DSPDeviceMIMOEngine::handleSynchronousMessages()
else if (AddSourceStream::match(*message))
{
m_basebandSampleSinks.push_back(BasebandSampleSinks());
int currentIndex = m_threadedBasebandSampleSinks.size();
m_threadedBasebandSampleSinks.push_back(ThreadedBasebandSampleSinks());
m_sourcesCorrections.push_back(SourceCorrection());
if (((AddSourceStream *) message)->getConnect()) {
m_sampleSinkConnectionIndexes.push_back(currentIndex);
}
}
else if (RemoveLastSourceStream::match(*message))
{
@@ -611,7 +715,12 @@ void DSPDeviceMIMOEngine::handleSynchronousMessages()
}
else if (AddSinkStream::match(*message))
{
int currentIndex = m_threadedBasebandSampleSources.size();
m_threadedBasebandSampleSources.push_back(ThreadedBasebandSampleSources());
if (((AddSinkStream *) message)->getConnect()) {
m_sampleSourceConnectionIndexes.push_back(currentIndex);
}
}
else if (RemoveLastSinkStream::match(*message))
{