2018-06-21 18:15:23 -04:00
|
|
|
|
2018-01-10 20:21:29 -05:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Copyright (C) 2018 Edouard Griffiths, F4EXB //
|
|
|
|
// //
|
|
|
|
// 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 //
|
2019-04-11 00:57:41 -04:00
|
|
|
// (at your option) any later version. //
|
2018-01-10 20:21:29 -05:00
|
|
|
// //
|
|
|
|
// 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 <stdio.h>
|
|
|
|
#include <errno.h>
|
2020-08-16 04:21:03 -04:00
|
|
|
#include <algorithm>
|
2018-01-10 20:21:29 -05:00
|
|
|
|
|
|
|
#include "dsp/samplesinkfifo.h"
|
2020-07-11 20:39:14 -04:00
|
|
|
#include "airspyhfworker.h"
|
2018-01-10 20:21:29 -05:00
|
|
|
|
2020-07-11 20:39:14 -04:00
|
|
|
AirspyHFWorker::AirspyHFWorker(airspyhf_device_t* dev, SampleSinkFifo* sampleFifo, QObject* parent) :
|
|
|
|
QObject(parent),
|
2018-01-10 20:21:29 -05:00
|
|
|
m_dev(dev),
|
|
|
|
m_convertBuffer(AIRSPYHF_BLOCKSIZE),
|
|
|
|
m_sampleFifo(sampleFifo),
|
|
|
|
m_samplerate(10),
|
2020-06-21 05:46:08 -04:00
|
|
|
m_log2Decim(0),
|
|
|
|
m_iqOrder(true)
|
2018-01-10 20:21:29 -05:00
|
|
|
{
|
2020-08-16 04:21:03 -04:00
|
|
|
std::fill(m_buf, m_buf + 2*AIRSPYHF_BLOCKSIZE, 0);
|
2018-01-10 20:21:29 -05:00
|
|
|
}
|
|
|
|
|
2020-07-11 20:39:14 -04:00
|
|
|
AirspyHFWorker::~AirspyHFWorker()
|
2018-01-10 20:21:29 -05:00
|
|
|
{
|
|
|
|
stopWork();
|
|
|
|
}
|
|
|
|
|
2022-09-21 16:06:35 -04:00
|
|
|
void AirspyHFWorker::startWork()
|
2018-01-10 20:21:29 -05:00
|
|
|
{
|
2020-08-16 04:21:03 -04:00
|
|
|
qDebug("AirspyHFWorker::startWork");
|
|
|
|
airspyhf_error rc = (airspyhf_error) airspyhf_start(m_dev, rx_callback, this);
|
2018-01-10 20:21:29 -05:00
|
|
|
|
2022-09-21 16:06:35 -04:00
|
|
|
if (rc != AIRSPYHF_SUCCESS) {
|
2020-08-16 04:21:03 -04:00
|
|
|
qCritical("AirspyHFWorker::run: failed to start Airspy HF Rx");
|
2018-01-10 20:21:29 -05:00
|
|
|
}
|
2020-07-11 20:39:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void AirspyHFWorker::stopWork()
|
|
|
|
{
|
2020-08-16 04:21:03 -04:00
|
|
|
qDebug("AirspyHFWorker::stopWork");
|
2020-07-11 20:39:14 -04:00
|
|
|
airspyhf_error rc = (airspyhf_error) airspyhf_stop(m_dev);
|
2018-01-10 20:21:29 -05:00
|
|
|
|
|
|
|
if (rc == AIRSPYHF_SUCCESS) {
|
2020-08-16 04:21:03 -04:00
|
|
|
qDebug("AirspyHFWorker::run: stopped Airspy HF Rx");
|
2018-01-10 20:21:29 -05:00
|
|
|
} else {
|
2020-08-16 04:21:03 -04:00
|
|
|
qDebug("AirspyHFWorker::run: failed to stop Airspy HF Rx");
|
2018-01-10 20:21:29 -05:00
|
|
|
}
|
2020-08-16 04:21:03 -04:00
|
|
|
}
|
2020-07-11 20:39:14 -04:00
|
|
|
|
|
|
|
void AirspyHFWorker::setSamplerate(uint32_t samplerate)
|
|
|
|
{
|
|
|
|
m_samplerate = samplerate;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AirspyHFWorker::setLog2Decimation(unsigned int log2_decim)
|
|
|
|
{
|
|
|
|
m_log2Decim = log2_decim;
|
2018-01-10 20:21:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Decimate according to specified log2 (ex: log2=4 => decim=16)
|
2020-07-11 20:39:14 -04:00
|
|
|
void AirspyHFWorker::callbackIQ(const float* buf, qint32 len)
|
2018-01-10 20:21:29 -05:00
|
|
|
{
|
|
|
|
SampleVector::iterator it = m_convertBuffer.begin();
|
|
|
|
|
2018-01-14 15:37:49 -05:00
|
|
|
switch (m_log2Decim)
|
|
|
|
{
|
|
|
|
case 0:
|
2020-06-21 05:46:08 -04:00
|
|
|
m_decimatorsIQ.decimate1(&it, buf, len);
|
2018-01-14 15:37:49 -05:00
|
|
|
break;
|
|
|
|
case 1:
|
2020-06-21 05:46:08 -04:00
|
|
|
m_decimatorsIQ.decimate2_cen(&it, buf, len);
|
2018-01-14 15:37:49 -05:00
|
|
|
break;
|
|
|
|
case 2:
|
2020-06-21 05:46:08 -04:00
|
|
|
m_decimatorsIQ.decimate4_cen(&it, buf, len);
|
2018-01-14 15:37:49 -05:00
|
|
|
break;
|
|
|
|
case 3:
|
2020-06-21 05:46:08 -04:00
|
|
|
m_decimatorsIQ.decimate8_cen(&it, buf, len);
|
2018-01-14 15:37:49 -05:00
|
|
|
break;
|
|
|
|
case 4:
|
2020-06-21 05:46:08 -04:00
|
|
|
m_decimatorsIQ.decimate16_cen(&it, buf, len);
|
2018-01-14 15:37:49 -05:00
|
|
|
break;
|
|
|
|
case 5:
|
2020-06-21 05:46:08 -04:00
|
|
|
m_decimatorsIQ.decimate32_cen(&it, buf, len);
|
2018-01-14 15:37:49 -05:00
|
|
|
break;
|
|
|
|
case 6:
|
2020-06-21 05:46:08 -04:00
|
|
|
m_decimatorsIQ.decimate64_cen(&it, buf, len);
|
2018-01-14 15:37:49 -05:00
|
|
|
break;
|
2021-02-01 11:40:23 -05:00
|
|
|
case 7:
|
|
|
|
m_decimatorsIQ.decimate128_cen(&it, buf, len);
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
m_decimatorsIQ.decimate256_cen(&it, buf, len);
|
|
|
|
break;
|
2018-01-14 15:37:49 -05:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2018-01-10 20:21:29 -05:00
|
|
|
|
|
|
|
m_sampleFifo->write(m_convertBuffer.begin(), it);
|
|
|
|
}
|
|
|
|
|
2020-07-11 20:39:14 -04:00
|
|
|
void AirspyHFWorker::callbackQI(const float* buf, qint32 len)
|
2020-06-21 05:46:08 -04:00
|
|
|
{
|
|
|
|
SampleVector::iterator it = m_convertBuffer.begin();
|
|
|
|
|
|
|
|
switch (m_log2Decim)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
m_decimatorsQI.decimate1(&it, buf, len);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
m_decimatorsQI.decimate2_cen(&it, buf, len);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
m_decimatorsQI.decimate4_cen(&it, buf, len);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
m_decimatorsQI.decimate8_cen(&it, buf, len);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
m_decimatorsQI.decimate16_cen(&it, buf, len);
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
m_decimatorsQI.decimate32_cen(&it, buf, len);
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
m_decimatorsQI.decimate64_cen(&it, buf, len);
|
|
|
|
break;
|
2021-02-01 11:40:23 -05:00
|
|
|
case 7:
|
|
|
|
m_decimatorsQI.decimate128_cen(&it, buf, len);
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
m_decimatorsQI.decimate256_cen(&it, buf, len);
|
|
|
|
break;
|
2020-06-21 05:46:08 -04:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_sampleFifo->write(m_convertBuffer.begin(), it);
|
|
|
|
}
|
2018-01-10 20:21:29 -05:00
|
|
|
|
2020-07-11 20:39:14 -04:00
|
|
|
int AirspyHFWorker::rx_callback(airspyhf_transfer_t* transfer)
|
2018-01-10 20:21:29 -05:00
|
|
|
{
|
2020-08-16 04:21:03 -04:00
|
|
|
//qDebug("AirspyHFWorker::rx_callback");
|
|
|
|
AirspyHFWorker *worker = (AirspyHFWorker*) transfer->ctx;
|
2018-02-05 02:38:47 -05:00
|
|
|
qint32 nbIAndQ = transfer->sample_count * 2;
|
2020-06-21 05:46:08 -04:00
|
|
|
|
2020-08-16 04:21:03 -04:00
|
|
|
if (worker->m_iqOrder) {
|
|
|
|
worker->callbackIQ((float *) transfer->samples, nbIAndQ);
|
2020-06-21 05:46:08 -04:00
|
|
|
} else {
|
2020-08-16 04:21:03 -04:00
|
|
|
worker->callbackQI((float *) transfer->samples, nbIAndQ);
|
2020-06-21 05:46:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2018-01-10 20:21:29 -05:00
|
|
|
}
|