mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-26 01:39:05 -05:00
Perseus: refactored PerseusInputThread to PerseusInputWorker object moved to thread. Equivalent to FileInput changes
This commit is contained in:
parent
46bca49042
commit
3ff933152a
@ -5,7 +5,7 @@ set(perseus_SOURCES
|
||||
perseusplugin.cpp
|
||||
perseussettings.cpp
|
||||
perseuswebapiadapter.cpp
|
||||
perseusthread.cpp
|
||||
perseusworker.cpp
|
||||
)
|
||||
|
||||
set(perseus_HEADERS
|
||||
@ -13,7 +13,7 @@ set(perseus_HEADERS
|
||||
perseusplugin.h
|
||||
perseussettings.h
|
||||
perseuswebapiadapter.h
|
||||
perseusthread.h
|
||||
perseusworker.h
|
||||
)
|
||||
|
||||
include_directories(
|
||||
|
@ -33,7 +33,7 @@
|
||||
#include "perseus/deviceperseus.h"
|
||||
|
||||
#include "perseusinput.h"
|
||||
#include "perseusthread.h"
|
||||
#include "perseusworker.h"
|
||||
|
||||
MESSAGE_CLASS_DEFINITION(PerseusInput::MsgConfigurePerseus, Message)
|
||||
MESSAGE_CLASS_DEFINITION(PerseusInput::MsgFileRecord, Message)
|
||||
@ -41,10 +41,10 @@ MESSAGE_CLASS_DEFINITION(PerseusInput::MsgStartStop, Message)
|
||||
|
||||
PerseusInput::PerseusInput(DeviceAPI *deviceAPI) :
|
||||
m_deviceAPI(deviceAPI),
|
||||
m_fileSink(0),
|
||||
m_fileSink(nullptr),
|
||||
m_deviceDescription("PerseusInput"),
|
||||
m_running(false),
|
||||
m_perseusThread(nullptr),
|
||||
m_perseusWorker(nullptr),
|
||||
m_perseusDescriptor(0)
|
||||
{
|
||||
openDevice();
|
||||
@ -77,19 +77,21 @@ void PerseusInput::init()
|
||||
|
||||
bool PerseusInput::start()
|
||||
{
|
||||
if (m_running) stop();
|
||||
if (m_running) {
|
||||
stop();
|
||||
}
|
||||
|
||||
// start / stop streaming is done in the thread.
|
||||
|
||||
m_perseusThread = new PerseusThread(m_perseusDescriptor, &m_sampleFifo);
|
||||
qDebug("PerseusInput::start: thread created");
|
||||
m_perseusWorker = new PerseusWorker(m_perseusDescriptor, &m_sampleFifo);
|
||||
m_perseusWorker->moveToThread(&m_perseusWorkerThread);
|
||||
qDebug("PerseusInput::start: worker created");
|
||||
|
||||
m_perseusWorker->setIQOrder(m_settings.m_iqOrder);
|
||||
m_perseusWorker->setLog2Decimation(m_settings.m_log2Decim);
|
||||
startWorker();
|
||||
|
||||
applySettings(m_settings, true);
|
||||
|
||||
m_perseusThread->setIQOrder(m_settings.m_iqOrder);
|
||||
m_perseusThread->setLog2Decimation(m_settings.m_log2Decim);
|
||||
m_perseusThread->startWork();
|
||||
|
||||
m_running = true;
|
||||
|
||||
return true;
|
||||
@ -97,16 +99,29 @@ bool PerseusInput::start()
|
||||
|
||||
void PerseusInput::stop()
|
||||
{
|
||||
if (m_perseusThread)
|
||||
if (m_perseusWorker)
|
||||
{
|
||||
m_perseusThread->stopWork();
|
||||
delete m_perseusThread;
|
||||
m_perseusThread = nullptr;
|
||||
stopWorker();
|
||||
delete m_perseusWorker;
|
||||
m_perseusWorker = nullptr;
|
||||
}
|
||||
|
||||
m_running = false;
|
||||
}
|
||||
|
||||
void PerseusInput::startWorker()
|
||||
{
|
||||
m_perseusWorker->startWork();
|
||||
m_perseusWorkerThread.start();
|
||||
}
|
||||
|
||||
void PerseusInput::stopWorker()
|
||||
{
|
||||
m_perseusWorker->stopWork();
|
||||
m_perseusWorkerThread.quit();
|
||||
m_perseusWorkerThread.wait();
|
||||
}
|
||||
|
||||
QByteArray PerseusInput::serialize() const
|
||||
{
|
||||
return m_settings.serialize();
|
||||
@ -342,9 +357,9 @@ bool PerseusInput::applySettings(const PerseusSettings& settings, bool force)
|
||||
reverseAPIKeys.append("log2Decim");
|
||||
forwardChange = true;
|
||||
|
||||
if (m_perseusThread)
|
||||
if (m_perseusWorker)
|
||||
{
|
||||
m_perseusThread->setLog2Decimation(settings.m_log2Decim);
|
||||
m_perseusWorker->setLog2Decimation(settings.m_log2Decim);
|
||||
qDebug("PerseusInput: set decimation to %d", (1<<settings.m_log2Decim));
|
||||
}
|
||||
}
|
||||
@ -353,8 +368,8 @@ bool PerseusInput::applySettings(const PerseusSettings& settings, bool force)
|
||||
{
|
||||
reverseAPIKeys.append("iqOrder");
|
||||
|
||||
if (m_perseusThread) {
|
||||
m_perseusThread->setIQOrder(settings.m_iqOrder);
|
||||
if (m_perseusWorker) {
|
||||
m_perseusWorker->setIQOrder(settings.m_iqOrder);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include <QNetworkRequest>
|
||||
#include <QThread>
|
||||
|
||||
#include "perseus-sdr.h"
|
||||
#include "dsp/devicesamplesource.h"
|
||||
@ -31,7 +32,7 @@ class QNetworkAccessManager;
|
||||
class QNetworkReply;
|
||||
class DeviceAPI;
|
||||
class FileRecord;
|
||||
class PerseusThread;
|
||||
class PerseusWorker;
|
||||
|
||||
class PerseusInput : public DeviceSampleSource {
|
||||
Q_OBJECT
|
||||
@ -162,12 +163,15 @@ private:
|
||||
QString m_deviceDescription;
|
||||
PerseusSettings m_settings;
|
||||
bool m_running;
|
||||
PerseusThread *m_perseusThread;
|
||||
PerseusWorker *m_perseusWorker;
|
||||
QThread m_perseusWorkerThread;
|
||||
perseus_descr *m_perseusDescriptor;
|
||||
std::vector<uint32_t> m_sampleRates;
|
||||
QNetworkAccessManager *m_networkManager;
|
||||
QNetworkRequest m_networkRequest;
|
||||
|
||||
void startWorker();
|
||||
void stopWorker();
|
||||
bool openDevice();
|
||||
void closeDevice();
|
||||
void setDeviceCenterFrequency(quint64 freq, const PerseusSettings& settings);
|
||||
|
@ -17,12 +17,12 @@
|
||||
|
||||
#include <QtGlobal>
|
||||
#include <algorithm>
|
||||
#include "perseusthread.h"
|
||||
#include "perseusworker.h"
|
||||
|
||||
PerseusThread *PerseusThread::m_this = 0;
|
||||
PerseusWorker *PerseusWorker::m_this = 0;
|
||||
|
||||
PerseusThread::PerseusThread(perseus_descr* dev, SampleSinkFifo* sampleFifo, QObject* parent) :
|
||||
QThread(parent),
|
||||
PerseusWorker::PerseusWorker(perseus_descr* dev, SampleSinkFifo* sampleFifo, QObject* parent) :
|
||||
QObject(parent),
|
||||
m_running(false),
|
||||
m_dev(dev),
|
||||
m_convertBuffer(PERSEUS_NBSAMPLES),
|
||||
@ -34,64 +34,51 @@ PerseusThread::PerseusThread(perseus_descr* dev, SampleSinkFifo* sampleFifo, QOb
|
||||
std::fill(m_buf, m_buf + 2*PERSEUS_NBSAMPLES, 0);
|
||||
}
|
||||
|
||||
PerseusThread::~PerseusThread()
|
||||
PerseusWorker::~PerseusWorker()
|
||||
{
|
||||
stopWork();
|
||||
m_this = 0;
|
||||
}
|
||||
|
||||
void PerseusThread::startWork()
|
||||
void PerseusWorker::startWork()
|
||||
{
|
||||
qDebug("PerseusThread::startWork");
|
||||
m_startWaitMutex.lock();
|
||||
start();
|
||||
while(!m_running)
|
||||
m_startWaiter.wait(&m_startWaitMutex, 100);
|
||||
m_startWaitMutex.unlock();
|
||||
qDebug("PerseusWorker::startWork");
|
||||
int rc = perseus_start_async_input(m_dev, PERSEUS_BLOCKSIZE, rx_callback, 0);
|
||||
|
||||
if (rc < 0)
|
||||
{
|
||||
qCritical("PerseusWorker::run: failed to start Perseus Rx: %s", perseus_errorstr());
|
||||
m_running = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug("PerseusWorker::run: start Perseus Rx");
|
||||
m_running = true;
|
||||
}
|
||||
}
|
||||
|
||||
void PerseusThread::stopWork()
|
||||
void PerseusWorker::stopWork()
|
||||
{
|
||||
qDebug("PerseusThread::stopWork");
|
||||
qDebug("PerseusWorker::stopWork");
|
||||
|
||||
int rc = perseus_stop_async_input(m_dev);
|
||||
|
||||
if (rc < 0) {
|
||||
qCritical("PerseusWorker::run: failed to stop Perseus Rx: %s", perseus_errorstr());
|
||||
} else {
|
||||
qDebug("PerseusWorker::run: stopped Perseus Rx");
|
||||
}
|
||||
|
||||
m_running = false;
|
||||
wait();
|
||||
}
|
||||
|
||||
void PerseusThread::setLog2Decimation(unsigned int log2_decim)
|
||||
void PerseusWorker::setLog2Decimation(unsigned int log2_decim)
|
||||
{
|
||||
m_log2Decim = log2_decim;
|
||||
}
|
||||
|
||||
void PerseusThread::run()
|
||||
{
|
||||
m_running = true;
|
||||
m_startWaiter.wakeAll();
|
||||
|
||||
int rc = perseus_start_async_input(m_dev, PERSEUS_BLOCKSIZE, rx_callback, 0);
|
||||
|
||||
if (rc < 0) {
|
||||
qCritical("PerseusThread::run: failed to start Perseus Rx: %s", perseus_errorstr());
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug("PerseusThread::run: start Perseus Rx");
|
||||
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::callbackIQ(const uint8_t* buf, qint32 len)
|
||||
void PerseusWorker::callbackIQ(const uint8_t* buf, qint32 len)
|
||||
{
|
||||
SampleVector::iterator it = m_convertBuffer.begin();
|
||||
|
||||
@ -113,7 +100,7 @@ void PerseusThread::callbackIQ(const uint8_t* buf, qint32 len)
|
||||
m_sampleFifo->write(m_convertBuffer.begin(), it);
|
||||
}
|
||||
|
||||
void PerseusThread::callbackQI(const uint8_t* buf, qint32 len)
|
||||
void PerseusWorker::callbackQI(const uint8_t* buf, qint32 len)
|
||||
{
|
||||
SampleVector::iterator it = m_convertBuffer.begin();
|
||||
|
||||
@ -135,7 +122,7 @@ void PerseusThread::callbackQI(const uint8_t* buf, qint32 len)
|
||||
m_sampleFifo->write(m_convertBuffer.begin(), it);
|
||||
}
|
||||
|
||||
int PerseusThread::rx_callback(void *buf, int buf_size, void *extra)
|
||||
int PerseusWorker::rx_callback(void *buf, int buf_size, void *extra)
|
||||
{
|
||||
(void) extra;
|
||||
qint32 nbIAndQ = buf_size / 3; // 3 bytes per I or Q
|
@ -15,12 +15,10 @@
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef PLUGINS_SAMPLESOURCE_PERSEUS_PERSEUSTHREAD_H_
|
||||
#define PLUGINS_SAMPLESOURCE_PERSEUS_PERSEUSTHREAD_H_
|
||||
#ifndef PLUGINS_SAMPLESOURCE_PERSEUS_PERSEUSWORKER_H_
|
||||
#define PLUGINS_SAMPLESOURCE_PERSEUS_PERSEUSWORKER_H_
|
||||
|
||||
#include <QThread>
|
||||
#include <QMutex>
|
||||
#include <QWaitCondition>
|
||||
#include <QObject>
|
||||
#include "perseus-sdr.h"
|
||||
|
||||
#include "dsp/samplesinkfifo.h"
|
||||
@ -29,12 +27,12 @@
|
||||
#define PERSEUS_NBSAMPLES 2048 // Number of I/Q samples in each callback from Perseus
|
||||
#define PERSEUS_BLOCKSIZE 6*PERSEUS_NBSAMPLES // Perseus sends 2*3 bytes samples
|
||||
|
||||
class PerseusThread : public QThread {
|
||||
class PerseusWorker : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
PerseusThread(perseus_descr* dev, SampleSinkFifo* sampleFifo, QObject* parent = 0);
|
||||
~PerseusThread();
|
||||
PerseusWorker(perseus_descr* dev, SampleSinkFifo* sampleFifo, QObject* parent = 0);
|
||||
~PerseusWorker();
|
||||
|
||||
void startWork();
|
||||
void stopWork();
|
||||
@ -42,8 +40,6 @@ public:
|
||||
void setIQOrder(bool iqOrder) { m_iqOrder = iqOrder; }
|
||||
|
||||
private:
|
||||
QMutex m_startWaitMutex;
|
||||
QWaitCondition m_startWaiter;
|
||||
volatile bool m_running;
|
||||
|
||||
perseus_descr* m_dev;
|
||||
@ -53,17 +49,16 @@ private:
|
||||
|
||||
unsigned int m_log2Decim;
|
||||
bool m_iqOrder;
|
||||
static PerseusThread *m_this;
|
||||
static PerseusWorker *m_this;
|
||||
|
||||
Decimators<qint32, TripleByteLE<qint32>, SDR_RX_SAMP_SZ, 24, true> m_decimators32IQ; // for no decimation (accumulator is int32)
|
||||
Decimators<qint32, TripleByteLE<qint64>, SDR_RX_SAMP_SZ, 24, true> m_decimators64IQ; // for actual decimation (accumulator is int64)
|
||||
Decimators<qint32, TripleByteLE<qint32>, SDR_RX_SAMP_SZ, 24, false> m_decimators32QI; // for no decimation (accumulator is int32)
|
||||
Decimators<qint32, TripleByteLE<qint64>, SDR_RX_SAMP_SZ, 24, false> m_decimators64QI; // for actual decimation (accumulator is int64)
|
||||
|
||||
void run();
|
||||
void callbackIQ(const uint8_t* buf, qint32 len); // inner call back
|
||||
void callbackQI(const uint8_t* buf, qint32 len);
|
||||
static int rx_callback(void *buf, int buf_size, void *extra); // call back from Perseus
|
||||
};
|
||||
|
||||
#endif /* PLUGINS_SAMPLESOURCE_PERSEUS_PERSEUSTHREAD_H_ */
|
||||
#endif /* PLUGINS_SAMPLESOURCE_PERSEUS_PERSEUSWORKER_H_ */
|
Loading…
Reference in New Issue
Block a user