2018-08-28 04:33:15 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Copyright (C) 2018 Edouard Griffiths, F4EXB. //
|
|
|
|
// //
|
|
|
|
// SDRdaemon sink channel (Rx) data blocks to read queue //
|
|
|
|
// //
|
|
|
|
// SDRdaemon is a detached SDR front end that handles the interface with a //
|
|
|
|
// physical device and sends or receives the I/Q samples stream to or from a //
|
|
|
|
// SDRangel instance via UDP. It is controlled via a Web REST API. //
|
|
|
|
// //
|
|
|
|
// This program is free software; you can redistribute it and/or modify //
|
|
|
|
// it under the terms of the GNU General Public License as published by //
|
|
|
|
// the Free Software Foundation as version 3 of the License, or //
|
|
|
|
// //
|
|
|
|
// This program is distributed in the hope that it will be useful, //
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
|
|
|
// GNU General Public License V3 for more details. //
|
|
|
|
// //
|
|
|
|
// You should have received a copy of the GNU General Public License //
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "channel/sdrdaemondatablock.h"
|
|
|
|
#include "channel/sdrdaemondatareadqueue.h"
|
|
|
|
|
2018-08-29 06:48:57 +00:00
|
|
|
const uint32_t SDRDaemonDataReadQueue::MinimumMaxSize = 10;
|
2018-08-28 04:33:15 +00:00
|
|
|
|
2018-09-13 00:33:56 +00:00
|
|
|
SDRDaemonDataReadQueue::SDRDaemonDataReadQueue() :
|
2018-08-28 04:33:15 +00:00
|
|
|
m_dataBlock(0),
|
2018-08-29 06:48:57 +00:00
|
|
|
m_maxSize(MinimumMaxSize),
|
2018-08-28 04:33:15 +00:00
|
|
|
m_blockIndex(1),
|
2018-08-28 12:04:30 +00:00
|
|
|
m_sampleIndex(0),
|
2018-09-13 00:33:56 +00:00
|
|
|
m_sampleCount(0),
|
2018-08-28 12:04:30 +00:00
|
|
|
m_full(false)
|
2018-08-28 04:33:15 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
SDRDaemonDataReadQueue::~SDRDaemonDataReadQueue()
|
|
|
|
{
|
|
|
|
SDRDaemonDataBlock* data;
|
|
|
|
|
|
|
|
while ((data = pop()) != 0)
|
|
|
|
{
|
|
|
|
qDebug("SDRDaemonDataReadQueue::~SDRDaemonDataReadQueue: data block was still in queue");
|
|
|
|
delete data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SDRDaemonDataReadQueue::push(SDRDaemonDataBlock* dataBlock)
|
|
|
|
{
|
2018-08-29 23:56:53 +00:00
|
|
|
if (length() >= m_maxSize)
|
2018-08-28 04:33:15 +00:00
|
|
|
{
|
|
|
|
qWarning("SDRDaemonDataReadQueue::push: queue is full");
|
2018-08-28 12:04:30 +00:00
|
|
|
m_full = true; // stop filling the queue
|
2018-08-28 04:33:15 +00:00
|
|
|
SDRDaemonDataBlock *data = m_dataReadQueue.takeLast();
|
|
|
|
delete data;
|
|
|
|
}
|
|
|
|
|
2018-08-28 12:04:30 +00:00
|
|
|
if (m_full) {
|
2018-08-29 23:56:53 +00:00
|
|
|
m_full = (length() > m_maxSize/2); // do not fill queue again before queue is half size
|
2018-08-28 12:04:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!m_full) {
|
|
|
|
m_dataReadQueue.append(dataBlock);
|
|
|
|
}
|
2018-08-28 04:33:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SDRDaemonDataBlock* SDRDaemonDataReadQueue::pop()
|
|
|
|
{
|
|
|
|
if (m_dataReadQueue.isEmpty())
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_blockIndex = 1;
|
|
|
|
m_sampleIndex = 0;
|
|
|
|
|
|
|
|
return m_dataReadQueue.takeFirst();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-29 06:48:57 +00:00
|
|
|
void SDRDaemonDataReadQueue::setSize(uint32_t size)
|
|
|
|
{
|
|
|
|
if (size != m_maxSize) {
|
|
|
|
m_maxSize = size < MinimumMaxSize ? MinimumMaxSize : size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-13 00:33:56 +00:00
|
|
|
void SDRDaemonDataReadQueue::readSample(Sample& s, bool scaleForTx)
|
2018-08-28 04:33:15 +00:00
|
|
|
{
|
2018-08-28 12:04:30 +00:00
|
|
|
// depletion/repletion state
|
2018-08-28 04:33:15 +00:00
|
|
|
if (m_dataBlock == 0)
|
|
|
|
{
|
2018-08-29 23:56:53 +00:00
|
|
|
if (length() >= m_maxSize/2)
|
2018-08-28 04:33:15 +00:00
|
|
|
{
|
2018-08-29 23:56:53 +00:00
|
|
|
qDebug("SDRDaemonDataReadQueue::readSample: initial pop new block: queue size: %u", length());
|
2018-08-28 04:33:15 +00:00
|
|
|
m_blockIndex = 1;
|
|
|
|
m_dataBlock = m_dataReadQueue.takeFirst();
|
2018-09-13 00:33:56 +00:00
|
|
|
convertDataToSample(s, m_blockIndex, m_sampleIndex, scaleForTx);
|
2018-08-28 04:33:15 +00:00
|
|
|
m_sampleIndex++;
|
2018-08-29 23:56:53 +00:00
|
|
|
m_sampleCount++;
|
2018-08-28 04:33:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
s = Sample{0, 0};
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-09-13 00:33:56 +00:00
|
|
|
int sampleSize = m_dataBlock->m_superBlocks[m_blockIndex].m_header.m_sampleBytes * 2;
|
|
|
|
uint32_t samplesPerBlock = SDRDaemonNbBytesPerBlock / sampleSize;
|
2018-09-10 16:52:40 +00:00
|
|
|
|
|
|
|
if (m_sampleIndex < samplesPerBlock)
|
2018-08-28 04:33:15 +00:00
|
|
|
{
|
2018-09-13 00:33:56 +00:00
|
|
|
convertDataToSample(s, m_blockIndex, m_sampleIndex, scaleForTx);
|
2018-08-28 04:33:15 +00:00
|
|
|
m_sampleIndex++;
|
2018-08-29 23:56:53 +00:00
|
|
|
m_sampleCount++;
|
2018-08-28 04:33:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_sampleIndex = 0;
|
|
|
|
m_blockIndex++;
|
|
|
|
|
|
|
|
if (m_blockIndex < SDRDaemonNbOrginalBlocks)
|
|
|
|
{
|
2018-09-13 00:33:56 +00:00
|
|
|
convertDataToSample(s, m_blockIndex, m_sampleIndex, scaleForTx);
|
2018-08-28 04:33:15 +00:00
|
|
|
m_sampleIndex++;
|
2018-08-29 23:56:53 +00:00
|
|
|
m_sampleCount++;
|
2018-08-28 04:33:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (m_dataBlock)
|
|
|
|
{
|
|
|
|
delete m_dataBlock;
|
|
|
|
m_dataBlock = 0;
|
|
|
|
|
2018-08-29 23:56:53 +00:00
|
|
|
if (length() == 0) {
|
2018-08-28 04:33:15 +00:00
|
|
|
qWarning("SDRDaemonDataReadQueue::readSample: try to pop new block but queue is empty");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-29 23:56:53 +00:00
|
|
|
if (length() > 0)
|
2018-08-28 04:33:15 +00:00
|
|
|
{
|
2018-08-29 23:56:53 +00:00
|
|
|
//qDebug("SDRDaemonDataReadQueue::readSample: pop new block: queue size: %u", length());
|
2018-08-28 04:33:15 +00:00
|
|
|
m_blockIndex = 1;
|
|
|
|
m_dataBlock = m_dataReadQueue.takeFirst();
|
2018-09-13 00:33:56 +00:00
|
|
|
convertDataToSample(s, m_blockIndex, m_sampleIndex, scaleForTx);
|
2018-08-28 04:33:15 +00:00
|
|
|
m_sampleIndex++;
|
2018-08-29 23:56:53 +00:00
|
|
|
m_sampleCount++;
|
2018-08-28 04:33:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
s = Sample{0, 0};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|