mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-16 05:11:49 -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
|
perseusplugin.cpp
|
||||||
perseussettings.cpp
|
perseussettings.cpp
|
||||||
perseuswebapiadapter.cpp
|
perseuswebapiadapter.cpp
|
||||||
perseusthread.cpp
|
perseusworker.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
set(perseus_HEADERS
|
set(perseus_HEADERS
|
||||||
@ -13,7 +13,7 @@ set(perseus_HEADERS
|
|||||||
perseusplugin.h
|
perseusplugin.h
|
||||||
perseussettings.h
|
perseussettings.h
|
||||||
perseuswebapiadapter.h
|
perseuswebapiadapter.h
|
||||||
perseusthread.h
|
perseusworker.h
|
||||||
)
|
)
|
||||||
|
|
||||||
include_directories(
|
include_directories(
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
#include "perseus/deviceperseus.h"
|
#include "perseus/deviceperseus.h"
|
||||||
|
|
||||||
#include "perseusinput.h"
|
#include "perseusinput.h"
|
||||||
#include "perseusthread.h"
|
#include "perseusworker.h"
|
||||||
|
|
||||||
MESSAGE_CLASS_DEFINITION(PerseusInput::MsgConfigurePerseus, Message)
|
MESSAGE_CLASS_DEFINITION(PerseusInput::MsgConfigurePerseus, Message)
|
||||||
MESSAGE_CLASS_DEFINITION(PerseusInput::MsgFileRecord, Message)
|
MESSAGE_CLASS_DEFINITION(PerseusInput::MsgFileRecord, Message)
|
||||||
@ -41,10 +41,10 @@ MESSAGE_CLASS_DEFINITION(PerseusInput::MsgStartStop, Message)
|
|||||||
|
|
||||||
PerseusInput::PerseusInput(DeviceAPI *deviceAPI) :
|
PerseusInput::PerseusInput(DeviceAPI *deviceAPI) :
|
||||||
m_deviceAPI(deviceAPI),
|
m_deviceAPI(deviceAPI),
|
||||||
m_fileSink(0),
|
m_fileSink(nullptr),
|
||||||
m_deviceDescription("PerseusInput"),
|
m_deviceDescription("PerseusInput"),
|
||||||
m_running(false),
|
m_running(false),
|
||||||
m_perseusThread(nullptr),
|
m_perseusWorker(nullptr),
|
||||||
m_perseusDescriptor(0)
|
m_perseusDescriptor(0)
|
||||||
{
|
{
|
||||||
openDevice();
|
openDevice();
|
||||||
@ -77,19 +77,21 @@ void PerseusInput::init()
|
|||||||
|
|
||||||
bool PerseusInput::start()
|
bool PerseusInput::start()
|
||||||
{
|
{
|
||||||
if (m_running) stop();
|
if (m_running) {
|
||||||
|
stop();
|
||||||
|
}
|
||||||
|
|
||||||
// start / stop streaming is done in the thread.
|
// start / stop streaming is done in the thread.
|
||||||
|
|
||||||
m_perseusThread = new PerseusThread(m_perseusDescriptor, &m_sampleFifo);
|
m_perseusWorker = new PerseusWorker(m_perseusDescriptor, &m_sampleFifo);
|
||||||
qDebug("PerseusInput::start: thread created");
|
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);
|
applySettings(m_settings, true);
|
||||||
|
|
||||||
m_perseusThread->setIQOrder(m_settings.m_iqOrder);
|
|
||||||
m_perseusThread->setLog2Decimation(m_settings.m_log2Decim);
|
|
||||||
m_perseusThread->startWork();
|
|
||||||
|
|
||||||
m_running = true;
|
m_running = true;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -97,16 +99,29 @@ bool PerseusInput::start()
|
|||||||
|
|
||||||
void PerseusInput::stop()
|
void PerseusInput::stop()
|
||||||
{
|
{
|
||||||
if (m_perseusThread)
|
if (m_perseusWorker)
|
||||||
{
|
{
|
||||||
m_perseusThread->stopWork();
|
stopWorker();
|
||||||
delete m_perseusThread;
|
delete m_perseusWorker;
|
||||||
m_perseusThread = nullptr;
|
m_perseusWorker = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_running = false;
|
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
|
QByteArray PerseusInput::serialize() const
|
||||||
{
|
{
|
||||||
return m_settings.serialize();
|
return m_settings.serialize();
|
||||||
@ -342,9 +357,9 @@ bool PerseusInput::applySettings(const PerseusSettings& settings, bool force)
|
|||||||
reverseAPIKeys.append("log2Decim");
|
reverseAPIKeys.append("log2Decim");
|
||||||
forwardChange = true;
|
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));
|
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");
|
reverseAPIKeys.append("iqOrder");
|
||||||
|
|
||||||
if (m_perseusThread) {
|
if (m_perseusWorker) {
|
||||||
m_perseusThread->setIQOrder(settings.m_iqOrder);
|
m_perseusWorker->setIQOrder(settings.m_iqOrder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <QNetworkRequest>
|
#include <QNetworkRequest>
|
||||||
|
#include <QThread>
|
||||||
|
|
||||||
#include "perseus-sdr.h"
|
#include "perseus-sdr.h"
|
||||||
#include "dsp/devicesamplesource.h"
|
#include "dsp/devicesamplesource.h"
|
||||||
@ -31,7 +32,7 @@ class QNetworkAccessManager;
|
|||||||
class QNetworkReply;
|
class QNetworkReply;
|
||||||
class DeviceAPI;
|
class DeviceAPI;
|
||||||
class FileRecord;
|
class FileRecord;
|
||||||
class PerseusThread;
|
class PerseusWorker;
|
||||||
|
|
||||||
class PerseusInput : public DeviceSampleSource {
|
class PerseusInput : public DeviceSampleSource {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -162,12 +163,15 @@ private:
|
|||||||
QString m_deviceDescription;
|
QString m_deviceDescription;
|
||||||
PerseusSettings m_settings;
|
PerseusSettings m_settings;
|
||||||
bool m_running;
|
bool m_running;
|
||||||
PerseusThread *m_perseusThread;
|
PerseusWorker *m_perseusWorker;
|
||||||
|
QThread m_perseusWorkerThread;
|
||||||
perseus_descr *m_perseusDescriptor;
|
perseus_descr *m_perseusDescriptor;
|
||||||
std::vector<uint32_t> m_sampleRates;
|
std::vector<uint32_t> m_sampleRates;
|
||||||
QNetworkAccessManager *m_networkManager;
|
QNetworkAccessManager *m_networkManager;
|
||||||
QNetworkRequest m_networkRequest;
|
QNetworkRequest m_networkRequest;
|
||||||
|
|
||||||
|
void startWorker();
|
||||||
|
void stopWorker();
|
||||||
bool openDevice();
|
bool openDevice();
|
||||||
void closeDevice();
|
void closeDevice();
|
||||||
void setDeviceCenterFrequency(quint64 freq, const PerseusSettings& settings);
|
void setDeviceCenterFrequency(quint64 freq, const PerseusSettings& settings);
|
||||||
|
@ -17,12 +17,12 @@
|
|||||||
|
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
#include <algorithm>
|
#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) :
|
PerseusWorker::PerseusWorker(perseus_descr* dev, SampleSinkFifo* sampleFifo, QObject* parent) :
|
||||||
QThread(parent),
|
QObject(parent),
|
||||||
m_running(false),
|
m_running(false),
|
||||||
m_dev(dev),
|
m_dev(dev),
|
||||||
m_convertBuffer(PERSEUS_NBSAMPLES),
|
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);
|
std::fill(m_buf, m_buf + 2*PERSEUS_NBSAMPLES, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
PerseusThread::~PerseusThread()
|
PerseusWorker::~PerseusWorker()
|
||||||
{
|
{
|
||||||
stopWork();
|
stopWork();
|
||||||
m_this = 0;
|
m_this = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PerseusThread::startWork()
|
void PerseusWorker::startWork()
|
||||||
{
|
{
|
||||||
qDebug("PerseusThread::startWork");
|
qDebug("PerseusWorker::startWork");
|
||||||
m_startWaitMutex.lock();
|
int rc = perseus_start_async_input(m_dev, PERSEUS_BLOCKSIZE, rx_callback, 0);
|
||||||
start();
|
|
||||||
while(!m_running)
|
if (rc < 0)
|
||||||
m_startWaiter.wait(&m_startWaitMutex, 100);
|
{
|
||||||
m_startWaitMutex.unlock();
|
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;
|
m_running = false;
|
||||||
wait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PerseusThread::setLog2Decimation(unsigned int log2_decim)
|
void PerseusWorker::setLog2Decimation(unsigned int log2_decim)
|
||||||
{
|
{
|
||||||
m_log2Decim = 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);
|
void PerseusWorker::callbackIQ(const uint8_t* buf, qint32 len)
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
SampleVector::iterator it = m_convertBuffer.begin();
|
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);
|
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();
|
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);
|
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;
|
(void) extra;
|
||||||
qint32 nbIAndQ = buf_size / 3; // 3 bytes per I or Q
|
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/>. //
|
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
||||||
///////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef PLUGINS_SAMPLESOURCE_PERSEUS_PERSEUSTHREAD_H_
|
#ifndef PLUGINS_SAMPLESOURCE_PERSEUS_PERSEUSWORKER_H_
|
||||||
#define PLUGINS_SAMPLESOURCE_PERSEUS_PERSEUSTHREAD_H_
|
#define PLUGINS_SAMPLESOURCE_PERSEUS_PERSEUSWORKER_H_
|
||||||
|
|
||||||
#include <QThread>
|
#include <QObject>
|
||||||
#include <QMutex>
|
|
||||||
#include <QWaitCondition>
|
|
||||||
#include "perseus-sdr.h"
|
#include "perseus-sdr.h"
|
||||||
|
|
||||||
#include "dsp/samplesinkfifo.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_NBSAMPLES 2048 // Number of I/Q samples in each callback from Perseus
|
||||||
#define PERSEUS_BLOCKSIZE 6*PERSEUS_NBSAMPLES // Perseus sends 2*3 bytes samples
|
#define PERSEUS_BLOCKSIZE 6*PERSEUS_NBSAMPLES // Perseus sends 2*3 bytes samples
|
||||||
|
|
||||||
class PerseusThread : public QThread {
|
class PerseusWorker : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PerseusThread(perseus_descr* dev, SampleSinkFifo* sampleFifo, QObject* parent = 0);
|
PerseusWorker(perseus_descr* dev, SampleSinkFifo* sampleFifo, QObject* parent = 0);
|
||||||
~PerseusThread();
|
~PerseusWorker();
|
||||||
|
|
||||||
void startWork();
|
void startWork();
|
||||||
void stopWork();
|
void stopWork();
|
||||||
@ -42,8 +40,6 @@ public:
|
|||||||
void setIQOrder(bool iqOrder) { m_iqOrder = iqOrder; }
|
void setIQOrder(bool iqOrder) { m_iqOrder = iqOrder; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QMutex m_startWaitMutex;
|
|
||||||
QWaitCondition m_startWaiter;
|
|
||||||
volatile bool m_running;
|
volatile bool m_running;
|
||||||
|
|
||||||
perseus_descr* m_dev;
|
perseus_descr* m_dev;
|
||||||
@ -53,17 +49,16 @@ private:
|
|||||||
|
|
||||||
unsigned int m_log2Decim;
|
unsigned int m_log2Decim;
|
||||||
bool m_iqOrder;
|
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<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<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<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)
|
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 callbackIQ(const uint8_t* buf, qint32 len); // inner call back
|
||||||
void callbackQI(const uint8_t* buf, qint32 len);
|
void callbackQI(const uint8_t* buf, qint32 len);
|
||||||
static int rx_callback(void *buf, int buf_size, void *extra); // call back from Perseus
|
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