1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-08 17:46:03 -05:00
sdrangel/plugins/samplesource/perseus/perseusthread.cpp

121 lines
3.5 KiB
C++
Raw Normal View History

2018-02-07 13:56:39 -05:00
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2018 Edouard Griffiths, F4EXB //
2018-02-07 13:56:39 -05:00
// //
// 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 <QtGlobal>
#include <algorithm>
2018-02-07 13:56:39 -05:00
#include "perseusthread.h"
2018-02-08 12:37:34 -05:00
PerseusThread *PerseusThread::m_this = 0;
2018-02-07 17:44:20 -05:00
PerseusThread::PerseusThread(perseus_descr* dev, SampleSinkFifo* sampleFifo, QObject* parent) :
QThread(parent),
m_running(false),
m_dev(dev),
m_convertBuffer(PERSEUS_NBSAMPLES),
m_sampleFifo(sampleFifo),
m_log2Decim(0)
{
m_this = this;
std::fill(m_buf, m_buf + 2*PERSEUS_NBSAMPLES, 0);
2018-02-07 17:44:20 -05:00
}
PerseusThread::~PerseusThread()
{
stopWork();
m_this = 0;
}
void PerseusThread::startWork()
{
qDebug("PerseusThread::startWork");
2018-02-07 17:44:20 -05:00
m_startWaitMutex.lock();
start();
while(!m_running)
m_startWaiter.wait(&m_startWaitMutex, 100);
m_startWaitMutex.unlock();
}
void PerseusThread::stopWork()
{
2018-02-08 17:26:10 -05:00
qDebug("PerseusThread::stopWork");
2018-02-07 17:44:20 -05:00
m_running = false;
wait();
}
void PerseusThread::setLog2Decimation(unsigned int log2_decim)
{
m_log2Decim = log2_decim;
}
2018-02-07 13:56:39 -05:00
void PerseusThread::run()
{
m_running = true;
m_startWaiter.wakeAll();
2018-02-07 17:44:20 -05:00
int rc = perseus_start_async_input(m_dev, PERSEUS_BLOCKSIZE, rx_callback, 0);
2018-02-07 13:56:39 -05:00
if (rc < 0) {
qCritical("PerseusThread::run: failed to start Perseus Rx: %s", perseus_errorstr());
}
else
{
2018-02-08 17:26:10 -05:00
qDebug("PerseusThread::run: start Perseus Rx");
2018-02-07 13:56:39 -05:00
while (m_running) {
sleep(1);
}
}
rc = perseus_stop_async_input(m_dev);
if (rc < 0) {
qCritical("PerseusThread::run: failed to stop Perseus Rx: %s", perseus_errorstr());
} else {
qDebug("PerseusThread::run: stopped Perseus Rx");
}
m_running = false;
}
void PerseusThread::callback(const uint8_t* buf, qint32 len)
{
2018-02-07 17:44:20 -05:00
SampleVector::iterator it = m_convertBuffer.begin();
switch (m_log2Decim)
{
case 0:
m_decimators32.decimate1(&it, (TripleByteLE<qint32>*) buf, len);
break;
case 1:
m_decimators64.decimate2_cen(&it, (TripleByteLE<qint64>*) buf, len);
break;
case 2:
m_decimators64.decimate4_cen(&it, (TripleByteLE<qint64>*) buf, len);
break;
default:
break;
}
2018-02-07 13:56:39 -05:00
2018-02-07 17:44:20 -05:00
m_sampleFifo->write(m_convertBuffer.begin(), it);
2018-02-07 13:56:39 -05:00
}
2018-02-07 17:44:20 -05:00
int PerseusThread::rx_callback(void *buf, int buf_size, void *extra __attribute__((unused)))
2018-02-07 13:56:39 -05:00
{
qint32 nbIAndQ = buf_size / 3; // 3 bytes per I or Q
m_this->callback((uint8_t*) buf, nbIAndQ);
2018-02-07 17:44:20 -05:00
return 0;
2018-02-07 13:56:39 -05:00
}