2019-12-12 12:24:50 -05:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Copyright (C) 2019 Edouard Griffiths, F4EXB //
|
|
|
|
// //
|
|
|
|
// 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 //
|
|
|
|
// (at your option) any later version. //
|
|
|
|
// //
|
|
|
|
// 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 "remoteoutputfifo.h"
|
|
|
|
|
|
|
|
RemoteOutputFifo::RemoteOutputFifo(QObject *parent) :
|
|
|
|
QObject(parent)
|
|
|
|
{}
|
|
|
|
|
|
|
|
RemoteOutputFifo::RemoteOutputFifo(unsigned int size, QObject *parent) :
|
|
|
|
QObject(parent)
|
|
|
|
{
|
|
|
|
resize(size);
|
|
|
|
}
|
|
|
|
|
|
|
|
RemoteOutputFifo::~RemoteOutputFifo()
|
|
|
|
{}
|
|
|
|
|
|
|
|
void RemoteOutputFifo::resize(unsigned int size)
|
|
|
|
{
|
|
|
|
QMutexLocker mutexLocker(&m_mutex);
|
|
|
|
m_size = size;
|
|
|
|
m_data.resize(m_size);
|
|
|
|
m_readHead = 0;
|
|
|
|
m_servedHead = 0;
|
|
|
|
m_writeHead = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RemoteOutputFifo::reset()
|
|
|
|
{
|
|
|
|
m_readHead = 0;
|
|
|
|
m_servedHead = 0;
|
|
|
|
m_writeHead = 0;
|
|
|
|
}
|
|
|
|
|
2021-12-12 04:44:58 -05:00
|
|
|
RemoteDataFrame *RemoteOutputFifo::getDataFrame()
|
2019-12-12 12:24:50 -05:00
|
|
|
{
|
|
|
|
QMutexLocker mutexLocker(&m_mutex);
|
|
|
|
m_servedHead = m_writeHead;
|
|
|
|
|
|
|
|
if (m_writeHead < m_size - 1) {
|
|
|
|
m_writeHead++;
|
|
|
|
} else {
|
|
|
|
m_writeHead = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
emit dataBlockServed();
|
|
|
|
return &m_data[m_servedHead];
|
|
|
|
}
|
|
|
|
|
2021-12-12 04:44:58 -05:00
|
|
|
unsigned int RemoteOutputFifo::readDataFrame(RemoteDataFrame **dataFrame)
|
2019-12-12 12:24:50 -05:00
|
|
|
{
|
|
|
|
QMutexLocker mutexLocker(&m_mutex);
|
|
|
|
|
|
|
|
if (calculateRemainder() == 0)
|
|
|
|
{
|
2021-12-12 04:44:58 -05:00
|
|
|
*dataFrame = nullptr;
|
2019-12-12 12:24:50 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-12-12 04:44:58 -05:00
|
|
|
*dataFrame = &m_data[m_readHead];
|
2019-12-12 12:24:50 -05:00
|
|
|
m_readHead = m_readHead < m_size - 1 ? m_readHead + 1 : 0;
|
|
|
|
return calculateRemainder();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int RemoteOutputFifo::getRemainder()
|
|
|
|
{
|
|
|
|
QMutexLocker mutexLocker(&m_mutex);
|
|
|
|
return calculateRemainder();
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int RemoteOutputFifo::calculateRemainder()
|
|
|
|
{
|
|
|
|
if (m_readHead <= m_servedHead) {
|
|
|
|
return m_servedHead - m_readHead;
|
|
|
|
} else {
|
|
|
|
return m_size - (m_readHead - m_servedHead);
|
|
|
|
}
|
2021-12-12 04:44:58 -05:00
|
|
|
}
|