mirror of
https://github.com/f4exb/sdrangel.git
synced 2025-08-18 21:52:34 -04:00
AirspyHF: refactored Thread to Worker object moved to thread. Equivalent to FileInput changes
This commit is contained in:
parent
4bad01280e
commit
059d0dc4f2
@ -5,7 +5,7 @@ set(airspyhf_SOURCES
|
|||||||
airspyhfplugin.cpp
|
airspyhfplugin.cpp
|
||||||
airspyhfsettings.cpp
|
airspyhfsettings.cpp
|
||||||
airspyhfwebapiadapter.cpp
|
airspyhfwebapiadapter.cpp
|
||||||
airspyhfthread.cpp
|
airspyhfworker.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
set(airspyhf_HEADERS
|
set(airspyhf_HEADERS
|
||||||
@ -13,7 +13,7 @@ set(airspyhf_HEADERS
|
|||||||
airspyhfplugin.h
|
airspyhfplugin.h
|
||||||
airspyhfsettings.h
|
airspyhfsettings.h
|
||||||
airspyhfwebapiadapter.h
|
airspyhfwebapiadapter.h
|
||||||
airspyhfthread.h
|
airspyhfworker.h
|
||||||
)
|
)
|
||||||
|
|
||||||
include_directories(
|
include_directories(
|
||||||
|
@ -38,7 +38,7 @@
|
|||||||
|
|
||||||
#include "airspyhfplugin.h"
|
#include "airspyhfplugin.h"
|
||||||
#include "airspyhfsettings.h"
|
#include "airspyhfsettings.h"
|
||||||
#include "airspyhfthread.h"
|
#include "airspyhfworker.h"
|
||||||
|
|
||||||
MESSAGE_CLASS_DEFINITION(AirspyHFInput::MsgConfigureAirspyHF, Message)
|
MESSAGE_CLASS_DEFINITION(AirspyHFInput::MsgConfigureAirspyHF, Message)
|
||||||
MESSAGE_CLASS_DEFINITION(AirspyHFInput::MsgStartStop, Message)
|
MESSAGE_CLASS_DEFINITION(AirspyHFInput::MsgStartStop, Message)
|
||||||
@ -53,7 +53,7 @@ AirspyHFInput::AirspyHFInput(DeviceAPI *deviceAPI) :
|
|||||||
m_deviceAPI(deviceAPI),
|
m_deviceAPI(deviceAPI),
|
||||||
m_settings(),
|
m_settings(),
|
||||||
m_dev(0),
|
m_dev(0),
|
||||||
m_airspyHFThread(nullptr),
|
m_airspyHFWorker(nullptr),
|
||||||
m_deviceDescription("AirspyHF"),
|
m_deviceDescription("AirspyHF"),
|
||||||
m_running(false)
|
m_running(false)
|
||||||
{
|
{
|
||||||
@ -167,9 +167,12 @@ bool AirspyHFInput::start()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_running) { stop(); }
|
if (m_running) {
|
||||||
|
stop();
|
||||||
|
}
|
||||||
|
|
||||||
m_airspyHFThread = new AirspyHFThread(m_dev, &m_sampleFifo);
|
m_airspyHFWorker = new AirspyHFWorker(m_dev, &m_sampleFifo);
|
||||||
|
m_airspyHFWorker->moveToThread(&m_airspyHFWorkerThread);
|
||||||
int sampleRateIndex = m_settings.m_devSampleRateIndex;
|
int sampleRateIndex = m_settings.m_devSampleRateIndex;
|
||||||
|
|
||||||
if (m_settings.m_devSampleRateIndex >= m_sampleRates.size()) {
|
if (m_settings.m_devSampleRateIndex >= m_sampleRates.size()) {
|
||||||
@ -177,21 +180,45 @@ bool AirspyHFInput::start()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (sampleRateIndex >= 0) {
|
if (sampleRateIndex >= 0) {
|
||||||
m_airspyHFThread->setSamplerate(m_sampleRates[sampleRateIndex]);
|
m_airspyHFWorker->setSamplerate(m_sampleRates[sampleRateIndex]);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_airspyHFThread->setLog2Decimation(m_settings.m_log2Decim);
|
m_airspyHFWorker->setLog2Decimation(m_settings.m_log2Decim);
|
||||||
m_airspyHFThread->setIQOrder(m_settings.m_iqOrder);
|
m_airspyHFWorker->setIQOrder(m_settings.m_iqOrder);
|
||||||
m_airspyHFThread->startWork();
|
mutexLocker.unlock();
|
||||||
|
|
||||||
mutexLocker.unlock();
|
if (startWorker())
|
||||||
|
{
|
||||||
|
qDebug("AirspyHFInput::startInput: started");
|
||||||
|
applySettings(m_settings, true);
|
||||||
|
m_running = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_running = false;
|
||||||
|
}
|
||||||
|
|
||||||
applySettings(m_settings, true);
|
return m_running;
|
||||||
|
}
|
||||||
|
|
||||||
qDebug("AirspyHFInput::startInput: started");
|
bool AirspyHFInput::startWorker()
|
||||||
m_running = true;
|
{
|
||||||
|
if (m_airspyHFWorker->startWork())
|
||||||
|
{
|
||||||
|
m_airspyHFWorkerThread.start();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
void AirspyHFInput::stopWorker()
|
||||||
|
{
|
||||||
|
m_airspyHFWorker->stopWork();
|
||||||
|
m_airspyHFWorkerThread.quit();
|
||||||
|
m_airspyHFWorkerThread.wait();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AirspyHFInput::closeDevice()
|
void AirspyHFInput::closeDevice()
|
||||||
@ -211,11 +238,11 @@ void AirspyHFInput::stop()
|
|||||||
qDebug("AirspyHFInput::stop");
|
qDebug("AirspyHFInput::stop");
|
||||||
QMutexLocker mutexLocker(&m_mutex);
|
QMutexLocker mutexLocker(&m_mutex);
|
||||||
|
|
||||||
if (m_airspyHFThread)
|
if (m_airspyHFWorker)
|
||||||
{
|
{
|
||||||
m_airspyHFThread->stopWork();
|
stopWorker();
|
||||||
delete m_airspyHFThread;
|
delete m_airspyHFWorker;
|
||||||
m_airspyHFThread = nullptr;
|
m_airspyHFWorker = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_running = false;
|
m_running = false;
|
||||||
@ -446,10 +473,10 @@ bool AirspyHFInput::applySettings(const AirspyHFSettings& settings, bool force)
|
|||||||
{
|
{
|
||||||
qCritical("AirspyHFInput::applySettings: could not set sample rate index %u (%d S/s)", sampleRateIndex, m_sampleRates[sampleRateIndex]);
|
qCritical("AirspyHFInput::applySettings: could not set sample rate index %u (%d S/s)", sampleRateIndex, m_sampleRates[sampleRateIndex]);
|
||||||
}
|
}
|
||||||
else if (m_airspyHFThread)
|
else if (m_airspyHFWorker)
|
||||||
{
|
{
|
||||||
qDebug("AirspyHFInput::applySettings: sample rate set to index: %u (%d S/s)", sampleRateIndex, m_sampleRates[sampleRateIndex]);
|
qDebug("AirspyHFInput::applySettings: sample rate set to index: %u (%d S/s)", sampleRateIndex, m_sampleRates[sampleRateIndex]);
|
||||||
m_airspyHFThread->setSamplerate(m_sampleRates[sampleRateIndex]);
|
m_airspyHFWorker->setSamplerate(m_sampleRates[sampleRateIndex]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -459,9 +486,9 @@ bool AirspyHFInput::applySettings(const AirspyHFSettings& settings, bool force)
|
|||||||
reverseAPIKeys.append("log2Decim");
|
reverseAPIKeys.append("log2Decim");
|
||||||
forwardChange = true;
|
forwardChange = true;
|
||||||
|
|
||||||
if (m_airspyHFThread)
|
if (m_airspyHFWorker)
|
||||||
{
|
{
|
||||||
m_airspyHFThread->setLog2Decimation(settings.m_log2Decim);
|
m_airspyHFWorker->setLog2Decimation(settings.m_log2Decim);
|
||||||
qDebug() << "AirspyInput: set decimation to " << (1<<settings.m_log2Decim);
|
qDebug() << "AirspyInput: set decimation to " << (1<<settings.m_log2Decim);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -470,8 +497,8 @@ bool AirspyHFInput::applySettings(const AirspyHFSettings& settings, bool force)
|
|||||||
{
|
{
|
||||||
reverseAPIKeys.append("iqOrder");
|
reverseAPIKeys.append("iqOrder");
|
||||||
|
|
||||||
if (m_airspyHFThread) {
|
if (m_airspyHFWorker) {
|
||||||
m_airspyHFThread->setIQOrder(settings.m_iqOrder);
|
m_airspyHFWorker->setIQOrder(settings.m_iqOrder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -487,7 +514,7 @@ bool AirspyHFInput::applySettings(const AirspyHFSettings& settings, bool force)
|
|||||||
{
|
{
|
||||||
qCritical("AirspyHFInput::applySettings: could not set LO ppm correction to %f", settings.m_LOppmTenths / 10.0f);
|
qCritical("AirspyHFInput::applySettings: could not set LO ppm correction to %f", settings.m_LOppmTenths / 10.0f);
|
||||||
}
|
}
|
||||||
else if (m_airspyHFThread)
|
else if (m_airspyHFWorker)
|
||||||
{
|
{
|
||||||
qDebug("AirspyHFInput::applySettings: LO ppm correction set to %f", settings.m_LOppmTenths / 10.0f);
|
qDebug("AirspyHFInput::applySettings: LO ppm correction set to %f", settings.m_LOppmTenths / 10.0f);
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
#include <QNetworkRequest>
|
#include <QNetworkRequest>
|
||||||
|
#include <QThread>
|
||||||
|
|
||||||
#include <libairspyhf/airspyhf.h>
|
#include <libairspyhf/airspyhf.h>
|
||||||
#include <dsp/devicesamplesource.h>
|
#include <dsp/devicesamplesource.h>
|
||||||
@ -30,7 +31,7 @@
|
|||||||
class QNetworkAccessManager;
|
class QNetworkAccessManager;
|
||||||
class QNetworkReply;
|
class QNetworkReply;
|
||||||
class DeviceAPI;
|
class DeviceAPI;
|
||||||
class AirspyHFThread;
|
class AirspyHFWorker;
|
||||||
class FileRecord;
|
class FileRecord;
|
||||||
|
|
||||||
class AirspyHFInput : public DeviceSampleSource {
|
class AirspyHFInput : public DeviceSampleSource {
|
||||||
@ -165,7 +166,8 @@ private:
|
|||||||
QMutex m_mutex;
|
QMutex m_mutex;
|
||||||
AirspyHFSettings m_settings;
|
AirspyHFSettings m_settings;
|
||||||
airspyhf_device_t* m_dev;
|
airspyhf_device_t* m_dev;
|
||||||
AirspyHFThread* m_airspyHFThread;
|
AirspyHFWorker* m_airspyHFWorker;
|
||||||
|
QThread m_airspyHFWorkerThread;
|
||||||
QString m_deviceDescription;
|
QString m_deviceDescription;
|
||||||
std::vector<uint32_t> m_sampleRates;
|
std::vector<uint32_t> m_sampleRates;
|
||||||
bool m_running;
|
bool m_running;
|
||||||
@ -173,6 +175,8 @@ private:
|
|||||||
QNetworkAccessManager *m_networkManager;
|
QNetworkAccessManager *m_networkManager;
|
||||||
QNetworkRequest m_networkRequest;
|
QNetworkRequest m_networkRequest;
|
||||||
|
|
||||||
|
bool startWorker();
|
||||||
|
void stopWorker();
|
||||||
bool openDevice();
|
bool openDevice();
|
||||||
void closeDevice();
|
void closeDevice();
|
||||||
bool applySettings(const AirspyHFSettings& settings, bool force);
|
bool applySettings(const AirspyHFSettings& settings, bool force);
|
||||||
|
@ -20,12 +20,12 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#include "dsp/samplesinkfifo.h"
|
#include "dsp/samplesinkfifo.h"
|
||||||
#include "airspyhfthread.h"
|
#include "airspyhfworker.h"
|
||||||
|
|
||||||
AirspyHFThread *AirspyHFThread::m_this = 0;
|
AirspyHFWorker *AirspyHFWorker::m_this = 0;
|
||||||
|
|
||||||
AirspyHFThread::AirspyHFThread(airspyhf_device_t* dev, SampleSinkFifo* sampleFifo, QObject* parent) :
|
AirspyHFWorker::AirspyHFWorker(airspyhf_device_t* dev, SampleSinkFifo* sampleFifo, QObject* parent) :
|
||||||
QThread(parent),
|
QObject(parent),
|
||||||
m_running(false),
|
m_running(false),
|
||||||
m_dev(dev),
|
m_dev(dev),
|
||||||
m_convertBuffer(AIRSPYHF_BLOCKSIZE),
|
m_convertBuffer(AIRSPYHF_BLOCKSIZE),
|
||||||
@ -38,60 +38,34 @@ AirspyHFThread::AirspyHFThread(airspyhf_device_t* dev, SampleSinkFifo* sampleFif
|
|||||||
m_this = this;
|
m_this = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
AirspyHFThread::~AirspyHFThread()
|
AirspyHFWorker::~AirspyHFWorker()
|
||||||
{
|
{
|
||||||
stopWork();
|
stopWork();
|
||||||
m_this = 0;
|
m_this = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AirspyHFThread::startWork()
|
bool AirspyHFWorker::startWork()
|
||||||
{
|
{
|
||||||
m_startWaitMutex.lock();
|
qDebug("AirspyThread::startWork");
|
||||||
start();
|
airspyhf_error rc = (airspyhf_error) airspyhf_start(m_dev, rx_callback, 0);
|
||||||
while(!m_running)
|
|
||||||
m_startWaiter.wait(&m_startWaitMutex, 100);
|
|
||||||
m_startWaitMutex.unlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
void AirspyHFThread::stopWork()
|
if (rc == AIRSPYHF_SUCCESS)
|
||||||
{
|
|
||||||
qDebug("AirspyThread::stopWork");
|
|
||||||
m_running = false;
|
|
||||||
wait();
|
|
||||||
}
|
|
||||||
|
|
||||||
void AirspyHFThread::setSamplerate(uint32_t samplerate)
|
|
||||||
{
|
|
||||||
m_samplerate = samplerate;
|
|
||||||
}
|
|
||||||
|
|
||||||
void AirspyHFThread::setLog2Decimation(unsigned int log2_decim)
|
|
||||||
{
|
|
||||||
m_log2Decim = log2_decim;
|
|
||||||
}
|
|
||||||
|
|
||||||
void AirspyHFThread::run()
|
|
||||||
{
|
|
||||||
airspyhf_error rc;
|
|
||||||
|
|
||||||
m_running = true;
|
|
||||||
m_startWaiter.wakeAll();
|
|
||||||
|
|
||||||
rc = (airspyhf_error) airspyhf_start(m_dev, rx_callback, 0);
|
|
||||||
|
|
||||||
if (rc != AIRSPYHF_SUCCESS)
|
|
||||||
{
|
{
|
||||||
qCritical("AirspyHFFThread::run: failed to start Airspy HF Rx");
|
m_running = (airspyhf_is_streaming(m_dev) != 0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
while ((m_running) && (airspyhf_is_streaming(m_dev) != 0))
|
qCritical("AirspyHFFThread::run: failed to start Airspy HF Rx");
|
||||||
{
|
m_running = false;
|
||||||
sleep(1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = (airspyhf_error) airspyhf_stop(m_dev);
|
return m_running;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AirspyHFWorker::stopWork()
|
||||||
|
{
|
||||||
|
qDebug("AirspyThread::stopWork");
|
||||||
|
airspyhf_error rc = (airspyhf_error) airspyhf_stop(m_dev);
|
||||||
|
|
||||||
if (rc == AIRSPYHF_SUCCESS) {
|
if (rc == AIRSPYHF_SUCCESS) {
|
||||||
qDebug("AirspyHFFThread::run: stopped Airspy HF Rx");
|
qDebug("AirspyHFFThread::run: stopped Airspy HF Rx");
|
||||||
@ -99,11 +73,20 @@ void AirspyHFThread::run()
|
|||||||
qDebug("AirspyHFFThread::run: failed to stop Airspy HF Rx");
|
qDebug("AirspyHFFThread::run: failed to stop Airspy HF Rx");
|
||||||
}
|
}
|
||||||
|
|
||||||
m_running = false;
|
m_running = false;}
|
||||||
|
|
||||||
|
void AirspyHFWorker::setSamplerate(uint32_t samplerate)
|
||||||
|
{
|
||||||
|
m_samplerate = samplerate;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AirspyHFWorker::setLog2Decimation(unsigned int log2_decim)
|
||||||
|
{
|
||||||
|
m_log2Decim = log2_decim;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decimate according to specified log2 (ex: log2=4 => decim=16)
|
// Decimate according to specified log2 (ex: log2=4 => decim=16)
|
||||||
void AirspyHFThread::callbackIQ(const float* buf, qint32 len)
|
void AirspyHFWorker::callbackIQ(const float* buf, qint32 len)
|
||||||
{
|
{
|
||||||
SampleVector::iterator it = m_convertBuffer.begin();
|
SampleVector::iterator it = m_convertBuffer.begin();
|
||||||
|
|
||||||
@ -137,7 +120,7 @@ void AirspyHFThread::callbackIQ(const float* buf, qint32 len)
|
|||||||
m_sampleFifo->write(m_convertBuffer.begin(), it);
|
m_sampleFifo->write(m_convertBuffer.begin(), it);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AirspyHFThread::callbackQI(const float* buf, qint32 len)
|
void AirspyHFWorker::callbackQI(const float* buf, qint32 len)
|
||||||
{
|
{
|
||||||
SampleVector::iterator it = m_convertBuffer.begin();
|
SampleVector::iterator it = m_convertBuffer.begin();
|
||||||
|
|
||||||
@ -171,7 +154,7 @@ void AirspyHFThread::callbackQI(const float* buf, qint32 len)
|
|||||||
m_sampleFifo->write(m_convertBuffer.begin(), it);
|
m_sampleFifo->write(m_convertBuffer.begin(), it);
|
||||||
}
|
}
|
||||||
|
|
||||||
int AirspyHFThread::rx_callback(airspyhf_transfer_t* transfer)
|
int AirspyHFWorker::rx_callback(airspyhf_transfer_t* transfer)
|
||||||
{
|
{
|
||||||
qint32 nbIAndQ = transfer->sample_count * 2;
|
qint32 nbIAndQ = transfer->sample_count * 2;
|
||||||
|
|
@ -15,35 +15,31 @@
|
|||||||
// 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 INCLUDE_AIRSPYHFTHREAD_H
|
#ifndef INCLUDE_AIRSPYHFWORKER_H
|
||||||
#define INCLUDE_AIRSPYHFTHREAD_H
|
#define INCLUDE_AIRSPYHFWORKER_H
|
||||||
|
|
||||||
#include <dsp/decimatorsfi.h>
|
#include <dsp/decimatorsfi.h>
|
||||||
#include <QThread>
|
#include <QObject>
|
||||||
#include <QMutex>
|
|
||||||
#include <QWaitCondition>
|
|
||||||
#include <libairspyhf/airspyhf.h>
|
#include <libairspyhf/airspyhf.h>
|
||||||
|
|
||||||
#include "dsp/samplesinkfifo.h"
|
#include "dsp/samplesinkfifo.h"
|
||||||
|
|
||||||
#define AIRSPYHF_BLOCKSIZE (1<<17)
|
#define AIRSPYHF_BLOCKSIZE (1<<17)
|
||||||
|
|
||||||
class AirspyHFThread : public QThread {
|
class AirspyHFWorker : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AirspyHFThread(airspyhf_device_t* dev, SampleSinkFifo* sampleFifo, QObject* parent = 0);
|
AirspyHFWorker(airspyhf_device_t* dev, SampleSinkFifo* sampleFifo, QObject* parent = 0);
|
||||||
~AirspyHFThread();
|
~AirspyHFWorker();
|
||||||
|
|
||||||
void startWork();
|
bool startWork();
|
||||||
void stopWork();
|
void stopWork();
|
||||||
void setSamplerate(uint32_t samplerate);
|
void setSamplerate(uint32_t samplerate);
|
||||||
void setLog2Decimation(unsigned int log2_decim);
|
void setLog2Decimation(unsigned int log2_decim);
|
||||||
void setIQOrder(bool iqOrder) { m_iqOrder = iqOrder; }
|
void setIQOrder(bool iqOrder) { m_iqOrder = iqOrder; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QMutex m_startWaitMutex;
|
|
||||||
QWaitCondition m_startWaiter;
|
|
||||||
bool m_running;
|
bool m_running;
|
||||||
|
|
||||||
airspyhf_device_t* m_dev;
|
airspyhf_device_t* m_dev;
|
||||||
@ -54,15 +50,14 @@ private:
|
|||||||
int m_samplerate;
|
int m_samplerate;
|
||||||
unsigned int m_log2Decim;
|
unsigned int m_log2Decim;
|
||||||
bool m_iqOrder;
|
bool m_iqOrder;
|
||||||
static AirspyHFThread *m_this;
|
static AirspyHFWorker *m_this;
|
||||||
|
|
||||||
DecimatorsFI<true> m_decimatorsIQ;
|
DecimatorsFI<true> m_decimatorsIQ;
|
||||||
DecimatorsFI<false> m_decimatorsQI;
|
DecimatorsFI<false> m_decimatorsQI;
|
||||||
|
|
||||||
void run();
|
|
||||||
void callbackIQ(const float* buf, qint32 len);
|
void callbackIQ(const float* buf, qint32 len);
|
||||||
void callbackQI(const float* buf, qint32 len);
|
void callbackQI(const float* buf, qint32 len);
|
||||||
static int rx_callback(airspyhf_transfer_t* transfer);
|
static int rx_callback(airspyhf_transfer_t* transfer);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // INCLUDE_AIRSPYHFTHREAD_H
|
#endif // INCLUDE_AIRSPYHFWORKER_H
|
Loading…
x
Reference in New Issue
Block a user