SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
airspyhfthread.cpp
Go to the documentation of this file.
1 
3 // Copyright (C) 2018 Edouard Griffiths, F4EXB //
4 // //
5 // This program is free software; you can redistribute it and/or modify //
6 // it under the terms of the GNU General Public License as published by //
7 // the Free Software Foundation as version 3 of the License, or //
8 // (at your option) any later version. //
9 // //
10 // This program is distributed in the hope that it will be useful, //
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
13 // GNU General Public License V3 for more details. //
14 // //
15 // You should have received a copy of the GNU General Public License //
16 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
18 
19 #include <stdio.h>
20 #include <errno.h>
21 
22 #include "dsp/samplesinkfifo.h"
23 #include "airspyhfthread.h"
24 
26 
27 AirspyHFThread::AirspyHFThread(airspyhf_device_t* dev, SampleSinkFifo* sampleFifo, QObject* parent) :
28  QThread(parent),
29  m_running(false),
30  m_dev(dev),
31  m_convertBuffer(AIRSPYHF_BLOCKSIZE),
32  m_sampleFifo(sampleFifo),
33  m_samplerate(10),
34  m_log2Decim(0)
35 {
36  memset((char*) m_buf, 0, 2*AIRSPYHF_BLOCKSIZE*sizeof(qint16));
37  m_this = this;
38 }
39 
41 {
42  stopWork();
43  m_this = 0;
44 }
45 
47 {
48  m_startWaitMutex.lock();
49  start();
50  while(!m_running)
51  m_startWaiter.wait(&m_startWaitMutex, 100);
52  m_startWaitMutex.unlock();
53 }
54 
56 {
57  qDebug("AirspyThread::stopWork");
58  m_running = false;
59  wait();
60 }
61 
63 {
64  m_samplerate = samplerate;
65 }
66 
67 void AirspyHFThread::setLog2Decimation(unsigned int log2_decim)
68 {
69  m_log2Decim = log2_decim;
70 }
71 
73 {
74  airspyhf_error rc;
75 
76  m_running = true;
77  m_startWaiter.wakeAll();
78 
79  rc = (airspyhf_error) airspyhf_start(m_dev, rx_callback, 0);
80 
81  if (rc != AIRSPYHF_SUCCESS)
82  {
83  qCritical("AirspyHFFThread::run: failed to start Airspy HF Rx");
84  }
85  else
86  {
87  while ((m_running) && (airspyhf_is_streaming(m_dev) != 0))
88  {
89  sleep(1);
90  }
91  }
92 
93  rc = (airspyhf_error) airspyhf_stop(m_dev);
94 
95  if (rc == AIRSPYHF_SUCCESS) {
96  qDebug("AirspyHFFThread::run: stopped Airspy HF Rx");
97  } else {
98  qDebug("AirspyHFFThread::run: failed to stop Airspy HF Rx");
99  }
100 
101  m_running = false;
102 }
103 
104 // Decimate according to specified log2 (ex: log2=4 => decim=16)
105 void AirspyHFThread::callback(const float* buf, qint32 len)
106 {
107  SampleVector::iterator it = m_convertBuffer.begin();
108 
109  switch (m_log2Decim)
110  {
111  case 0:
112  m_decimators.decimate1(&it, buf, len);
113  break;
114  case 1:
115  m_decimators.decimate2_cen(&it, buf, len);
116  break;
117  case 2:
118  m_decimators.decimate4_cen(&it, buf, len);
119  break;
120  case 3:
121  m_decimators.decimate8_cen(&it, buf, len);
122  break;
123  case 4:
124  m_decimators.decimate16_cen(&it, buf, len);
125  break;
126  case 5:
127  m_decimators.decimate32_cen(&it, buf, len);
128  break;
129  case 6:
130  m_decimators.decimate64_cen(&it, buf, len);
131  break;
132  default:
133  break;
134  }
135 
136  m_sampleFifo->write(m_convertBuffer.begin(), it);
137 }
138 
139 
140 int AirspyHFThread::rx_callback(airspyhf_transfer_t* transfer)
141 {
142  qint32 nbIAndQ = transfer->sample_count * 2;
143  m_this->callback((float *) transfer->samples, nbIAndQ);
144  return 0;
145 }
#define AIRSPYHF_BLOCKSIZE
void decimate32_cen(SampleVector::iterator *it, const float *buf, qint32 nbIAndQ)
void setLog2Decimation(unsigned int log2_decim)
uint write(const quint8 *data, uint count)
QWaitCondition m_startWaiter
qint16 m_buf[2 *AIRSPYHF_BLOCKSIZE]
void setSamplerate(uint32_t samplerate)
QMutex m_startWaitMutex
unsigned int uint32_t
Definition: rtptypes_win.h:46
void decimate16_cen(SampleVector::iterator *it, const float *buf, qint32 nbIAndQ)
void decimate2_cen(SampleVector::iterator *it, const float *buf, qint32 nbIAndQ)
void decimate4_cen(SampleVector::iterator *it, const float *buf, qint32 nbIAndQ)
unsigned int m_log2Decim
void callback(const float *buf, qint32 len)
void decimate8_cen(SampleVector::iterator *it, const float *buf, qint32 nbIAndQ)
DecimatorsFI m_decimators
static int rx_callback(airspyhf_transfer_t *transfer)
SampleVector m_convertBuffer
static AirspyHFThread * m_this
SampleSinkFifo * m_sampleFifo
AirspyHFThread(airspyhf_device_t *dev, SampleSinkFifo *sampleFifo, QObject *parent=0)
airspyhf_device_t * m_dev
void decimate64_cen(SampleVector::iterator *it, const float *buf, qint32 nbIAndQ)
void decimate1(SampleVector::iterator *it, const float *buf, qint32 nbIAndQ)