AirspyHF: use transfer->ctx to pass this object address

This commit is contained in:
f4exb 2020-08-16 10:21:03 +02:00
parent 17afe4fa65
commit 7eb5b762b0
2 changed files with 15 additions and 16 deletions

View File

@ -18,12 +18,11 @@
#include <stdio.h> #include <stdio.h>
#include <errno.h> #include <errno.h>
#include <algorithm>
#include "dsp/samplesinkfifo.h" #include "dsp/samplesinkfifo.h"
#include "airspyhfworker.h" #include "airspyhfworker.h"
AirspyHFWorker *AirspyHFWorker::m_this = 0;
AirspyHFWorker::AirspyHFWorker(airspyhf_device_t* dev, SampleSinkFifo* sampleFifo, QObject* parent) : AirspyHFWorker::AirspyHFWorker(airspyhf_device_t* dev, SampleSinkFifo* sampleFifo, QObject* parent) :
QObject(parent), QObject(parent),
m_running(false), m_running(false),
@ -34,20 +33,18 @@ AirspyHFWorker::AirspyHFWorker(airspyhf_device_t* dev, SampleSinkFifo* sampleFif
m_log2Decim(0), m_log2Decim(0),
m_iqOrder(true) m_iqOrder(true)
{ {
memset((char*) m_buf, 0, 2*AIRSPYHF_BLOCKSIZE*sizeof(qint16)); std::fill(m_buf, m_buf + 2*AIRSPYHF_BLOCKSIZE, 0);
m_this = this;
} }
AirspyHFWorker::~AirspyHFWorker() AirspyHFWorker::~AirspyHFWorker()
{ {
stopWork(); stopWork();
m_this = 0;
} }
bool AirspyHFWorker::startWork() bool AirspyHFWorker::startWork()
{ {
qDebug("AirspyThread::startWork"); qDebug("AirspyHFWorker::startWork");
airspyhf_error rc = (airspyhf_error) airspyhf_start(m_dev, rx_callback, 0); airspyhf_error rc = (airspyhf_error) airspyhf_start(m_dev, rx_callback, this);
if (rc == AIRSPYHF_SUCCESS) if (rc == AIRSPYHF_SUCCESS)
{ {
@ -55,7 +52,7 @@ bool AirspyHFWorker::startWork()
} }
else else
{ {
qCritical("AirspyHFFThread::run: failed to start Airspy HF Rx"); qCritical("AirspyHFWorker::run: failed to start Airspy HF Rx");
m_running = false; m_running = false;
} }
@ -64,16 +61,17 @@ bool AirspyHFWorker::startWork()
void AirspyHFWorker::stopWork() void AirspyHFWorker::stopWork()
{ {
qDebug("AirspyThread::stopWork"); qDebug("AirspyHFWorker::stopWork");
airspyhf_error rc = (airspyhf_error) airspyhf_stop(m_dev); 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("AirspyHFWorker::run: stopped Airspy HF Rx");
} else { } else {
qDebug("AirspyHFFThread::run: failed to stop Airspy HF Rx"); qDebug("AirspyHFWorker::run: failed to stop Airspy HF Rx");
} }
m_running = false;} m_running = false;
}
void AirspyHFWorker::setSamplerate(uint32_t samplerate) void AirspyHFWorker::setSamplerate(uint32_t samplerate)
{ {
@ -156,12 +154,14 @@ void AirspyHFWorker::callbackQI(const float* buf, qint32 len)
int AirspyHFWorker::rx_callback(airspyhf_transfer_t* transfer) int AirspyHFWorker::rx_callback(airspyhf_transfer_t* transfer)
{ {
//qDebug("AirspyHFWorker::rx_callback");
AirspyHFWorker *worker = (AirspyHFWorker*) transfer->ctx;
qint32 nbIAndQ = transfer->sample_count * 2; qint32 nbIAndQ = transfer->sample_count * 2;
if (m_this->m_iqOrder) { if (worker->m_iqOrder) {
m_this->callbackIQ((float *) transfer->samples, nbIAndQ); worker->callbackIQ((float *) transfer->samples, nbIAndQ);
} else { } else {
m_this->callbackQI((float *) transfer->samples, nbIAndQ); worker->callbackQI((float *) transfer->samples, nbIAndQ);
} }
return 0; return 0;

View File

@ -50,7 +50,6 @@ private:
int m_samplerate; int m_samplerate;
unsigned int m_log2Decim; unsigned int m_log2Decim;
bool m_iqOrder; bool m_iqOrder;
static AirspyHFWorker *m_this;
DecimatorsFI<true> m_decimatorsIQ; DecimatorsFI<true> m_decimatorsIQ;
DecimatorsFI<false> m_decimatorsQI; DecimatorsFI<false> m_decimatorsQI;