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
HackRFOutputThread Class Reference

#include <hackrfoutputthread.h>

Inherits QThread.

+ Collaboration diagram for HackRFOutputThread:

Public Member Functions

 HackRFOutputThread (hackrf_device *dev, SampleSourceFifo *sampleFifo, QObject *parent=NULL)
 
 ~HackRFOutputThread ()
 
void startWork ()
 
void stopWork ()
 
void setLog2Interpolation (unsigned int log2_interp)
 
void setFcPos (int fcPos)
 

Private Member Functions

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

Static Private Member Functions

static int tx_callback (hackrf_transfer *transfer)
 

Private Attributes

QMutex m_startWaitMutex
 
QWaitCondition m_startWaiter
 
bool m_running
 
hackrf_device * m_dev
 
qint8 m_buf [2 *HACKRF_BLOCKSIZE]
 
SampleSourceFifom_sampleFifo
 
unsigned int m_log2Interp
 
int m_fcPos
 
Interpolators< qint8, SDR_TX_SAMP_SZ, 8 > m_interpolators
 

Detailed Description

Definition at line 31 of file hackrfoutputthread.h.

Constructor & Destructor Documentation

◆ HackRFOutputThread()

HackRFOutputThread::HackRFOutputThread ( hackrf_device *  dev,
SampleSourceFifo sampleFifo,
QObject *  parent = NULL 
)

Definition at line 25 of file hackrfoutputthread.cpp.

References HACKRF_BLOCKSIZE, and m_buf.

25  :
26  QThread(parent),
27  m_running(false),
28  m_dev(dev),
29  m_sampleFifo(sampleFifo),
30  m_log2Interp(0),
31  m_fcPos(2)
32 {
33  std::fill(m_buf, m_buf + 2*HACKRF_BLOCKSIZE, 0);
34 }
unsigned int m_log2Interp
hackrf_device * m_dev
SampleSourceFifo * m_sampleFifo
#define HACKRF_BLOCKSIZE
qint8 m_buf[2 *HACKRF_BLOCKSIZE]

◆ ~HackRFOutputThread()

HackRFOutputThread::~HackRFOutputThread ( )

Definition at line 36 of file hackrfoutputthread.cpp.

References stopWork().

37 {
38  stopWork();
39 }
+ Here is the call graph for this function:

Member Function Documentation

◆ callback()

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

Definition at line 119 of file hackrfoutputthread.cpp.

References Interpolators< T, SdrBits, OutputBits >::interpolate1(), Interpolators< T, SdrBits, OutputBits >::interpolate16_cen(), Interpolators< T, SdrBits, OutputBits >::interpolate16_inf(), Interpolators< T, SdrBits, OutputBits >::interpolate16_sup(), Interpolators< T, SdrBits, OutputBits >::interpolate2_cen(), Interpolators< T, SdrBits, OutputBits >::interpolate2_inf(), Interpolators< T, SdrBits, OutputBits >::interpolate2_sup(), Interpolators< T, SdrBits, OutputBits >::interpolate32_cen(), Interpolators< T, SdrBits, OutputBits >::interpolate32_inf(), Interpolators< T, SdrBits, OutputBits >::interpolate32_sup(), Interpolators< T, SdrBits, OutputBits >::interpolate4_cen(), Interpolators< T, SdrBits, OutputBits >::interpolate4_inf(), Interpolators< T, SdrBits, OutputBits >::interpolate4_sup(), Interpolators< T, SdrBits, OutputBits >::interpolate64_cen(), Interpolators< T, SdrBits, OutputBits >::interpolate64_inf(), Interpolators< T, SdrBits, OutputBits >::interpolate64_sup(), Interpolators< T, SdrBits, OutputBits >::interpolate8_cen(), Interpolators< T, SdrBits, OutputBits >::interpolate8_inf(), Interpolators< T, SdrBits, OutputBits >::interpolate8_sup(), m_fcPos, m_interpolators, m_log2Interp, m_sampleFifo, and SampleSourceFifo::readAdvance().

Referenced by tx_callback().

120 {
121  SampleVector::iterator beginRead;
122  m_sampleFifo->readAdvance(beginRead, len/(2*(1<<m_log2Interp)));
123  beginRead -= len/2;
124 
125  if (m_log2Interp == 0)
126  {
127  m_interpolators.interpolate1(&beginRead, buf, len);
128  }
129  else
130  {
131  if (m_fcPos == 0) // Infra
132  {
133  switch (m_log2Interp)
134  {
135  case 1:
136  m_interpolators.interpolate2_inf(&beginRead, buf, len);
137  break;
138  case 2:
139  m_interpolators.interpolate4_inf(&beginRead, buf, len);
140  break;
141  case 3:
142  m_interpolators.interpolate8_inf(&beginRead, buf, len);
143  break;
144  case 4:
145  m_interpolators.interpolate16_inf(&beginRead, buf, len);
146  break;
147  case 5:
148  m_interpolators.interpolate32_inf(&beginRead, buf, len);
149  break;
150  case 6:
151  m_interpolators.interpolate64_inf(&beginRead, buf, len);
152  break;
153  default:
154  break;
155  }
156  }
157  else if (m_fcPos == 1) // Supra
158  {
159  switch (m_log2Interp)
160  {
161  case 1:
162  m_interpolators.interpolate2_sup(&beginRead, buf, len);
163  break;
164  case 2:
165  m_interpolators.interpolate4_sup(&beginRead, buf, len);
166  break;
167  case 3:
168  m_interpolators.interpolate8_sup(&beginRead, buf, len);
169  break;
170  case 4:
171  m_interpolators.interpolate16_sup(&beginRead, buf, len);
172  break;
173  case 5:
174  m_interpolators.interpolate32_sup(&beginRead, buf, len);
175  break;
176  case 6:
177  m_interpolators.interpolate64_sup(&beginRead, buf, len);
178  break;
179  default:
180  break;
181  }
182  }
183  else if (m_fcPos == 2) // Center
184  {
185  switch (m_log2Interp)
186  {
187  case 1:
188  m_interpolators.interpolate2_cen(&beginRead, buf, len);
189  break;
190  case 2:
191  m_interpolators.interpolate4_cen(&beginRead, buf, len);
192  break;
193  case 3:
194  m_interpolators.interpolate8_cen(&beginRead, buf, len);
195  break;
196  case 4:
197  m_interpolators.interpolate16_cen(&beginRead, buf, len);
198  break;
199  case 5:
200  m_interpolators.interpolate32_cen(&beginRead, buf, len);
201  break;
202  case 6:
203  m_interpolators.interpolate64_cen(&beginRead, buf, len);
204  break;
205  default:
206  break;
207  }
208  }
209  }
210 }
Interpolators< qint8, SDR_TX_SAMP_SZ, 8 > m_interpolators
void interpolate64_sup(SampleVector::iterator *it, T *buf, qint32 len, bool invertIQ=false)
void interpolate64_cen(SampleVector::iterator *it, T *buf, qint32 len, bool invertIQ=false)
unsigned int m_log2Interp
void interpolate8_inf(SampleVector::iterator *it, T *buf, qint32 len, bool invertIQ=false)
void interpolate32_inf(SampleVector::iterator *it, T *buf, qint32 len, bool invertIQ=false)
void interpolate32_cen(SampleVector::iterator *it, T *buf, qint32 len, bool invertIQ=false)
void interpolate4_inf(SampleVector::iterator *it, T *buf, qint32 len, bool invertIQ=false)
void interpolate8_cen(SampleVector::iterator *it, T *buf, qint32 len, bool invertIQ=false)
void interpolate2_cen(SampleVector::iterator *it, T *buf, qint32 len, bool invertIQ=false)
void readAdvance(SampleVector::iterator &readUntil, unsigned int nbSamples)
SampleSourceFifo * m_sampleFifo
void interpolate16_inf(SampleVector::iterator *it, T *buf, qint32 len, bool invertIQ=false)
void interpolate2_sup(SampleVector::iterator *it, T *buf, qint32 len, bool invertIQ=false)
void interpolate2_inf(SampleVector::iterator *it, T *buf, qint32 len, bool invertIQ=false)
void interpolate1(SampleVector::iterator *it, T *buf, qint32 len, bool invertIQ=false)
void interpolate16_sup(SampleVector::iterator *it, T *buf, qint32 len, bool invertIQ=false)
void interpolate32_sup(SampleVector::iterator *it, T *buf, qint32 len, bool invertIQ=false)
void interpolate8_sup(SampleVector::iterator *it, T *buf, qint32 len, bool invertIQ=false)
void interpolate16_cen(SampleVector::iterator *it, T *buf, qint32 len, bool invertIQ=false)
void interpolate4_cen(SampleVector::iterator *it, T *buf, qint32 len, bool invertIQ=false)
void interpolate64_inf(SampleVector::iterator *it, T *buf, qint32 len, bool invertIQ=false)
void interpolate4_sup(SampleVector::iterator *it, T *buf, qint32 len, bool invertIQ=false)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ run()

void HackRFOutputThread::run ( )
private

Definition at line 68 of file hackrfoutputthread.cpp.

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

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

◆ setFcPos()

void HackRFOutputThread::setFcPos ( int  fcPos)

Definition at line 63 of file hackrfoutputthread.cpp.

References m_fcPos.

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

64 {
65  m_fcPos = fcPos;
66 }
+ Here is the caller graph for this function:

◆ setLog2Interpolation()

void HackRFOutputThread::setLog2Interpolation ( unsigned int  log2_interp)

Definition at line 58 of file hackrfoutputthread.cpp.

References m_log2Interp.

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

59 {
60  m_log2Interp = log2Interp;
61 }
unsigned int m_log2Interp
+ Here is the caller graph for this function:

◆ startWork()

void HackRFOutputThread::startWork ( )

Definition at line 41 of file hackrfoutputthread.cpp.

References m_running, m_startWaiter, and m_startWaitMutex.

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

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

◆ stopWork()

void HackRFOutputThread::stopWork ( )

Definition at line 50 of file hackrfoutputthread.cpp.

References m_running.

Referenced by HackRFOutput::applySettings(), HackRFOutput::stop(), and ~HackRFOutputThread().

51 {
52  if (!m_running) return;
53  qDebug("HackRFOutputThread::stopWork");
54  m_running = false;
55  wait();
56 }
+ Here is the caller graph for this function:

◆ tx_callback()

int HackRFOutputThread::tx_callback ( hackrf_transfer *  transfer)
staticprivate

Definition at line 212 of file hackrfoutputthread.cpp.

References callback().

Referenced by run().

213 {
214  HackRFOutputThread *thread = (HackRFOutputThread *) transfer->tx_ctx;
215  qint32 bytes_to_write = transfer->valid_length;
216  thread->callback((qint8 *) transfer->buffer, bytes_to_write);
217  return 0;
218 }
void callback(qint8 *buf, qint32 len)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ m_buf

qint8 HackRFOutputThread::m_buf[2 *HACKRF_BLOCKSIZE]
private

Definition at line 49 of file hackrfoutputthread.h.

Referenced by HackRFOutputThread().

◆ m_dev

hackrf_device* HackRFOutputThread::m_dev
private

Definition at line 48 of file hackrfoutputthread.h.

Referenced by run().

◆ m_fcPos

int HackRFOutputThread::m_fcPos
private

Definition at line 53 of file hackrfoutputthread.h.

Referenced by callback(), and setFcPos().

◆ m_interpolators

Interpolators<qint8, SDR_TX_SAMP_SZ, 8> HackRFOutputThread::m_interpolators
private

Definition at line 55 of file hackrfoutputthread.h.

Referenced by callback().

◆ m_log2Interp

unsigned int HackRFOutputThread::m_log2Interp
private

Definition at line 52 of file hackrfoutputthread.h.

Referenced by callback(), and setLog2Interpolation().

◆ m_running

bool HackRFOutputThread::m_running
private

Definition at line 46 of file hackrfoutputthread.h.

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

◆ m_sampleFifo

SampleSourceFifo* HackRFOutputThread::m_sampleFifo
private

Definition at line 50 of file hackrfoutputthread.h.

Referenced by callback().

◆ m_startWaiter

QWaitCondition HackRFOutputThread::m_startWaiter
private

Definition at line 45 of file hackrfoutputthread.h.

Referenced by run(), and startWork().

◆ m_startWaitMutex

QMutex HackRFOutputThread::m_startWaitMutex
private

Definition at line 44 of file hackrfoutputthread.h.

Referenced by startWork().


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