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.
Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
HackRFInputThread Class Reference

#include <hackrfinputthread.h>

Inherits QThread.

+ Collaboration diagram for HackRFInputThread:

Public Member Functions

 HackRFInputThread (hackrf_device *dev, SampleSinkFifo *sampleFifo, QObject *parent=NULL)
 
 ~HackRFInputThread ()
 
void startWork ()
 
void stopWork ()
 
void setSamplerate (uint32_t samplerate)
 
void setLog2Decimation (unsigned int log2_decim)
 
void setFcPos (int fcPos)
 

Private Member Functions

void run ()
 
void callback (const qint8 *buf, qint32 len)
 

Static Private Member Functions

static int rx_callback (hackrf_transfer *transfer)
 

Private Attributes

QMutex m_startWaitMutex
 
QWaitCondition m_startWaiter
 
bool m_running
 
hackrf_device * m_dev
 
qint16 m_buf [2 *HACKRF_BLOCKSIZE]
 
SampleVector m_convertBuffer
 
SampleSinkFifom_sampleFifo
 
int m_samplerate
 
unsigned int m_log2Decim
 
int m_fcPos
 
Decimators< qint32, qint8, SDR_RX_SAMP_SZ, 8 > m_decimators
 

Detailed Description

Definition at line 31 of file hackrfinputthread.h.

Constructor & Destructor Documentation

◆ HackRFInputThread()

HackRFInputThread::HackRFInputThread ( hackrf_device *  dev,
SampleSinkFifo sampleFifo,
QObject *  parent = NULL 
)

Definition at line 26 of file hackrfinputthread.cpp.

References HACKRF_BLOCKSIZE, and m_buf.

26  :
27  QThread(parent),
28  m_running(false),
29  m_dev(dev),
31  m_sampleFifo(sampleFifo),
32  m_samplerate(10),
33  m_log2Decim(0),
34  m_fcPos(0)
35 {
36  std::fill(m_buf, m_buf + 2*HACKRF_BLOCKSIZE, 0);
37 }
unsigned int m_log2Decim
SampleSinkFifo * m_sampleFifo
hackrf_device * m_dev
#define HACKRF_BLOCKSIZE
qint16 m_buf[2 *HACKRF_BLOCKSIZE]
SampleVector m_convertBuffer

◆ ~HackRFInputThread()

HackRFInputThread::~HackRFInputThread ( )

Definition at line 39 of file hackrfinputthread.cpp.

References stopWork().

40 {
41  stopWork();
42 }
+ Here is the call graph for this function:

Member Function Documentation

◆ callback()

void HackRFInputThread::callback ( const qint8 *  buf,
qint32  len 
)
private

Definition at line 125 of file hackrfinputthread.cpp.

References Decimators< StorageType, T, SdrBits, InputBits >::decimate1(), Decimators< StorageType, T, SdrBits, InputBits >::decimate16_cen(), Decimators< StorageType, T, SdrBits, InputBits >::decimate16_inf_txsync(), Decimators< StorageType, T, SdrBits, InputBits >::decimate16_sup_txsync(), Decimators< StorageType, T, SdrBits, InputBits >::decimate2_cen(), Decimators< StorageType, T, SdrBits, InputBits >::decimate2_inf(), Decimators< StorageType, T, SdrBits, InputBits >::decimate2_sup(), Decimators< StorageType, T, SdrBits, InputBits >::decimate32_cen(), Decimators< StorageType, T, SdrBits, InputBits >::decimate32_inf_txsync(), Decimators< StorageType, T, SdrBits, InputBits >::decimate32_sup_txsync(), Decimators< StorageType, T, SdrBits, InputBits >::decimate4_cen(), Decimators< StorageType, T, SdrBits, InputBits >::decimate4_inf_txsync(), Decimators< StorageType, T, SdrBits, InputBits >::decimate4_sup_txsync(), Decimators< StorageType, T, SdrBits, InputBits >::decimate64_cen(), Decimators< StorageType, T, SdrBits, InputBits >::decimate64_inf_txsync(), Decimators< StorageType, T, SdrBits, InputBits >::decimate64_sup_txsync(), Decimators< StorageType, T, SdrBits, InputBits >::decimate8_cen(), Decimators< StorageType, T, SdrBits, InputBits >::decimate8_inf_txsync(), Decimators< StorageType, T, SdrBits, InputBits >::decimate8_sup_txsync(), m_convertBuffer, m_decimators, m_fcPos, m_log2Decim, m_sampleFifo, and SampleSinkFifo::write().

Referenced by rx_callback().

126 {
127  SampleVector::iterator it = m_convertBuffer.begin();
128 
129  if (m_log2Decim == 0)
130  {
131  m_decimators.decimate1(&it, buf, len);
132  }
133  else
134  {
135  if (m_fcPos == 0) // Infra
136  {
137  switch (m_log2Decim)
138  {
139  case 1:
140  m_decimators.decimate2_inf(&it, buf, len);
141  break;
142  case 2:
143  m_decimators.decimate4_inf_txsync(&it, buf, len);
144  break;
145  case 3:
146  m_decimators.decimate8_inf_txsync(&it, buf, len);
147  break;
148  case 4:
149  m_decimators.decimate16_inf_txsync(&it, buf, len);
150  break;
151  case 5:
152  m_decimators.decimate32_inf_txsync(&it, buf, len);
153  break;
154  case 6:
155  m_decimators.decimate64_inf_txsync(&it, buf, len);
156  break;
157  default:
158  break;
159  }
160  }
161  else if (m_fcPos == 1) // Supra
162  {
163  switch (m_log2Decim)
164  {
165  case 1:
166  m_decimators.decimate2_sup(&it, buf, len);
167  break;
168  case 2:
169  m_decimators.decimate4_sup_txsync(&it, buf, len);
170  break;
171  case 3:
172  m_decimators.decimate8_sup_txsync(&it, buf, len);
173  break;
174  case 4:
175  m_decimators.decimate16_sup_txsync(&it, buf, len);
176  break;
177  case 5:
178  m_decimators.decimate32_sup_txsync(&it, buf, len);
179  break;
180  case 6:
181  m_decimators.decimate64_sup_txsync(&it, buf, len);
182  break;
183  default:
184  break;
185  }
186  }
187  else if (m_fcPos == 2) // Center
188  {
189  switch (m_log2Decim)
190  {
191  case 1:
192  m_decimators.decimate2_cen(&it, buf, len);
193  break;
194  case 2:
195  m_decimators.decimate4_cen(&it, buf, len);
196  break;
197  case 3:
198  m_decimators.decimate8_cen(&it, buf, len);
199  break;
200  case 4:
201  m_decimators.decimate16_cen(&it, buf, len);
202  break;
203  case 5:
204  m_decimators.decimate32_cen(&it, buf, len);
205  break;
206  case 6:
207  m_decimators.decimate64_cen(&it, buf, len);
208  break;
209  default:
210  break;
211  }
212  }
213  }
214 
215  m_sampleFifo->write(m_convertBuffer.begin(), it);
216 }
void decimate2_inf(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:498
void decimate4_sup_txsync(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:732
void decimate64_cen(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:3040
void decimate2_sup(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:526
void decimate64_inf_txsync(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:2911
void decimate2_cen(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:554
uint write(const quint8 *data, uint count)
void decimate8_inf_txsync(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:898
unsigned int m_log2Decim
void decimate8_cen(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:1057
void decimate8_sup_txsync(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:1014
void decimate64_sup_txsync(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:3440
void decimate16_inf_txsync(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:1250
void decimate4_cen(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:782
SampleSinkFifo * m_sampleFifo
void decimate32_sup_txsync(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:2155
void decimate16_sup_txsync(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:1433
void decimate16_cen(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:1483
void decimate32_cen(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:2212
void decimate1(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:462
Decimators< qint32, qint8, SDR_RX_SAMP_SZ, 8 > m_decimators
SampleVector m_convertBuffer
void decimate32_inf_txsync(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:1845
void decimate4_inf_txsync(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:632
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ run()

void HackRFInputThread::run ( )
private

Definition at line 75 of file hackrfinputthread.cpp.

References m_dev, m_running, m_startWaiter, and rx_callback().

76 {
77  hackrf_error rc;
78 
79  m_running = true;
80  m_startWaiter.wakeAll();
81 
82  if (hackrf_is_streaming(m_dev) == HACKRF_TRUE)
83  {
84  qDebug("HackRFInputThread::run: HackRF is streaming already");
85  }
86  else
87  {
88  qDebug("HackRFInputThread::run: HackRF is not streaming");
89 
90  rc = (hackrf_error) hackrf_start_rx(m_dev, rx_callback, this);
91 
92  if (rc == HACKRF_SUCCESS)
93  {
94  qDebug("HackRFInputThread::run: started HackRF Rx");
95  }
96  else
97  {
98  qDebug("HackRFInputThread::run: failed to start HackRF Rx: %s", hackrf_error_name(rc));
99  }
100  }
101 
102  while ((m_running) && (hackrf_is_streaming(m_dev) == HACKRF_TRUE))
103  {
104  usleep(200000);
105  }
106 
107  if (hackrf_is_streaming(m_dev) == HACKRF_TRUE)
108  {
109  rc = (hackrf_error) hackrf_stop_rx(m_dev);
110 
111  if (rc == HACKRF_SUCCESS)
112  {
113  qDebug("HackRFInputThread::run: stopped HackRF Rx");
114  }
115  else
116  {
117  qDebug("HackRFInputThread::run: failed to stop HackRF Rx: %s", hackrf_error_name(rc));
118  }
119  }
120 
121  m_running = false;
122 }
static int rx_callback(hackrf_transfer *transfer)
QWaitCondition m_startWaiter
hackrf_device * m_dev
+ Here is the call graph for this function:

◆ rx_callback()

int HackRFInputThread::rx_callback ( hackrf_transfer *  transfer)
staticprivate

Definition at line 219 of file hackrfinputthread.cpp.

References callback().

Referenced by run().

220 {
221  HackRFInputThread *thread = (HackRFInputThread *) transfer->rx_ctx;
222  qint32 bytes_to_write = transfer->valid_length;
223  thread->callback((qint8 *) transfer->buffer, bytes_to_write);
224  return 0;
225 }
void callback(const qint8 *buf, qint32 len)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setFcPos()

void HackRFInputThread::setFcPos ( int  fcPos)

Definition at line 70 of file hackrfinputthread.cpp.

References m_fcPos.

Referenced by HackRFInput::applySettings(), and HackRFInput::start().

71 {
72  m_fcPos = fcPos;
73 }
+ Here is the caller graph for this function:

◆ setLog2Decimation()

void HackRFInputThread::setLog2Decimation ( unsigned int  log2_decim)

Definition at line 65 of file hackrfinputthread.cpp.

References m_log2Decim.

Referenced by HackRFInput::applySettings(), and HackRFInput::start().

66 {
67  m_log2Decim = log2_decim;
68 }
unsigned int m_log2Decim
+ Here is the caller graph for this function:

◆ setSamplerate()

void HackRFInputThread::setSamplerate ( uint32_t  samplerate)

Definition at line 60 of file hackrfinputthread.cpp.

References m_samplerate.

Referenced by HackRFInput::applySettings(), and HackRFInput::start().

61 {
62  m_samplerate = samplerate;
63 }
+ Here is the caller graph for this function:

◆ startWork()

void HackRFInputThread::startWork ( )

Definition at line 44 of file hackrfinputthread.cpp.

References m_running, m_startWaiter, and m_startWaitMutex.

Referenced by HackRFInput::start().

45 {
46  m_startWaitMutex.lock();
47  start();
48  while(!m_running)
49  m_startWaiter.wait(&m_startWaitMutex, 100);
50  m_startWaitMutex.unlock();
51 }
QWaitCondition m_startWaiter
+ Here is the caller graph for this function:

◆ stopWork()

void HackRFInputThread::stopWork ( )

Definition at line 53 of file hackrfinputthread.cpp.

References m_running.

Referenced by HackRFInput::stop(), and ~HackRFInputThread().

54 {
55  qDebug("HackRFThread::stopWork");
56  m_running = false;
57  wait();
58 }
+ Here is the caller graph for this function:

Member Data Documentation

◆ m_buf

qint16 HackRFInputThread::m_buf[2 *HACKRF_BLOCKSIZE]
private

Definition at line 50 of file hackrfinputthread.h.

Referenced by HackRFInputThread().

◆ m_convertBuffer

SampleVector HackRFInputThread::m_convertBuffer
private

Definition at line 51 of file hackrfinputthread.h.

Referenced by callback().

◆ m_decimators

Decimators<qint32, qint8, SDR_RX_SAMP_SZ, 8> HackRFInputThread::m_decimators
private

Definition at line 58 of file hackrfinputthread.h.

Referenced by callback().

◆ m_dev

hackrf_device* HackRFInputThread::m_dev
private

Definition at line 49 of file hackrfinputthread.h.

Referenced by run().

◆ m_fcPos

int HackRFInputThread::m_fcPos
private

Definition at line 56 of file hackrfinputthread.h.

Referenced by callback(), and setFcPos().

◆ m_log2Decim

unsigned int HackRFInputThread::m_log2Decim
private

Definition at line 55 of file hackrfinputthread.h.

Referenced by callback(), and setLog2Decimation().

◆ m_running

bool HackRFInputThread::m_running
private

Definition at line 47 of file hackrfinputthread.h.

Referenced by run(), startWork(), and stopWork().

◆ m_sampleFifo

SampleSinkFifo* HackRFInputThread::m_sampleFifo
private

Definition at line 52 of file hackrfinputthread.h.

Referenced by callback().

◆ m_samplerate

int HackRFInputThread::m_samplerate
private

Definition at line 54 of file hackrfinputthread.h.

Referenced by setSamplerate().

◆ m_startWaiter

QWaitCondition HackRFInputThread::m_startWaiter
private

Definition at line 46 of file hackrfinputthread.h.

Referenced by run(), and startWork().

◆ m_startWaitMutex

QMutex HackRFInputThread::m_startWaitMutex
private

Definition at line 45 of file hackrfinputthread.h.

Referenced by startWork().


The documentation for this class was generated from the following files: