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

#include <rtlsdrthread.h>

Inherits QThread.

+ Collaboration diagram for RTLSDRThread:

Public Member Functions

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

Private Member Functions

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

Static Private Member Functions

static void callbackHelper (unsigned char *buf, uint32_t len, void *ctx)
 

Private Attributes

QMutex m_startWaitMutex
 
QWaitCondition m_startWaiter
 
bool m_running
 
rtlsdr_dev_t * m_dev
 
SampleVector m_convertBuffer
 
SampleSinkFifom_sampleFifo
 
int m_samplerate
 
unsigned int m_log2Decim
 
int m_fcPos
 
DecimatorsU< qint32, quint8, SDR_RX_SAMP_SZ, 8, 127 > m_decimators
 

Detailed Description

Definition at line 30 of file rtlsdrthread.h.

Constructor & Destructor Documentation

◆ RTLSDRThread()

RTLSDRThread::RTLSDRThread ( rtlsdr_dev_t *  dev,
SampleSinkFifo sampleFifo,
QObject *  parent = NULL 
)

Definition at line 27 of file rtlsdrthread.cpp.

27  :
28  QThread(parent),
29  m_running(false),
30  m_dev(dev),
32  m_sampleFifo(sampleFifo),
33  m_samplerate(288000),
34  m_log2Decim(4),
35  m_fcPos(0)
36 {
37 }
#define FCD_BLOCKSIZE
rtlsdr_dev_t * m_dev
Definition: rtlsdrthread.h:48
unsigned int m_log2Decim
Definition: rtlsdrthread.h:53
SampleSinkFifo * m_sampleFifo
Definition: rtlsdrthread.h:50
SampleVector m_convertBuffer
Definition: rtlsdrthread.h:49

◆ ~RTLSDRThread()

RTLSDRThread::~RTLSDRThread ( )

Definition at line 39 of file rtlsdrthread.cpp.

References stopWork().

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

Member Function Documentation

◆ callback()

void RTLSDRThread::callback ( const quint8 *  buf,
qint32  len 
)
private

Definition at line 92 of file rtlsdrthread.cpp.

References DecimatorsU< StorageType, T, SdrBits, InputBits, Shift >::decimate1(), DecimatorsU< StorageType, T, SdrBits, InputBits, Shift >::decimate16_cen(), DecimatorsU< StorageType, T, SdrBits, InputBits, Shift >::decimate16_inf(), DecimatorsU< StorageType, T, SdrBits, InputBits, Shift >::decimate16_sup(), DecimatorsU< StorageType, T, SdrBits, InputBits, Shift >::decimate2_cen(), DecimatorsU< StorageType, T, SdrBits, InputBits, Shift >::decimate2_inf(), DecimatorsU< StorageType, T, SdrBits, InputBits, Shift >::decimate2_sup(), DecimatorsU< StorageType, T, SdrBits, InputBits, Shift >::decimate32_cen(), DecimatorsU< StorageType, T, SdrBits, InputBits, Shift >::decimate32_inf(), DecimatorsU< StorageType, T, SdrBits, InputBits, Shift >::decimate32_sup(), DecimatorsU< StorageType, T, SdrBits, InputBits, Shift >::decimate4_cen(), DecimatorsU< StorageType, T, SdrBits, InputBits, Shift >::decimate4_inf(), DecimatorsU< StorageType, T, SdrBits, InputBits, Shift >::decimate4_sup(), DecimatorsU< StorageType, T, SdrBits, InputBits, Shift >::decimate64_cen(), DecimatorsU< StorageType, T, SdrBits, InputBits, Shift >::decimate64_inf(), DecimatorsU< StorageType, T, SdrBits, InputBits, Shift >::decimate64_sup(), DecimatorsU< StorageType, T, SdrBits, InputBits, Shift >::decimate8_cen(), DecimatorsU< StorageType, T, SdrBits, InputBits, Shift >::decimate8_inf(), DecimatorsU< StorageType, T, SdrBits, InputBits, Shift >::decimate8_sup(), m_convertBuffer, m_decimators, m_dev, m_fcPos, m_log2Decim, m_running, m_sampleFifo, and SampleSinkFifo::write().

Referenced by callbackHelper().

93 {
94  SampleVector::iterator it = m_convertBuffer.begin();
95 
96  if (m_log2Decim == 0)
97  {
98  m_decimators.decimate1(&it, buf, len);
99  }
100  else
101  {
102  if (m_fcPos == 0) // Infradyne
103  {
104  switch (m_log2Decim)
105  {
106  case 1:
107  m_decimators.decimate2_inf(&it, buf, len);
108  break;
109  case 2:
110  m_decimators.decimate4_inf(&it, buf, len);
111  break;
112  case 3:
113  m_decimators.decimate8_inf(&it, buf, len);
114  break;
115  case 4:
116  m_decimators.decimate16_inf(&it, buf, len);
117  break;
118  case 5:
119  m_decimators.decimate32_inf(&it, buf, len);
120  break;
121  case 6:
122  m_decimators.decimate64_inf(&it, buf, len);
123  break;
124  default:
125  break;
126  }
127  }
128  else if (m_fcPos == 1) // Supradyne
129  {
130  switch (m_log2Decim)
131  {
132  case 1:
133  m_decimators.decimate2_sup(&it, buf, len);
134  break;
135  case 2:
136  m_decimators.decimate4_sup(&it, buf, len);
137  break;
138  case 3:
139  m_decimators.decimate8_sup(&it, buf, len);
140  break;
141  case 4:
142  m_decimators.decimate16_sup(&it, buf, len);
143  break;
144  case 5:
145  m_decimators.decimate32_sup(&it, buf, len);
146  break;
147  case 6:
148  m_decimators.decimate64_sup(&it, buf, len);
149  break;
150  default:
151  break;
152  }
153  }
154  else // Centered
155  {
156  switch (m_log2Decim)
157  {
158  case 1:
159  m_decimators.decimate2_cen(&it, buf, len);
160  break;
161  case 2:
162  m_decimators.decimate4_cen(&it, buf, len);
163  break;
164  case 3:
165  m_decimators.decimate8_cen(&it, buf, len);
166  break;
167  case 4:
168  m_decimators.decimate16_cen(&it, buf, len);
169  break;
170  case 5:
171  m_decimators.decimate32_cen(&it, buf, len);
172  break;
173  case 6:
174  m_decimators.decimate64_cen(&it, buf, len);
175  break;
176  default:
177  break;
178  }
179  }
180  }
181 
182  m_sampleFifo->write(m_convertBuffer.begin(), it);
183 
184  if(!m_running)
185  rtlsdr_cancel_async(m_dev);
186 }
void decimate4_sup(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimatorsu.h:341
void decimate2_sup(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimatorsu.h:263
void decimate8_inf(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimatorsu.h:391
void decimate16_inf(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimatorsu.h:543
uint write(const quint8 *data, uint count)
void decimate16_cen(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimatorsu.h:2538
void decimate2_inf(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimatorsu.h:235
void decimate8_cen(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimatorsu.h:2478
void decimate4_cen(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimatorsu.h:2435
void decimate4_inf(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimatorsu.h:291
void decimate32_inf(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimatorsu.h:823
void decimate32_cen(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimatorsu.h:2647
void decimate32_sup(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimatorsu.h:1091
void decimate64_inf(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimatorsu.h:1359
void decimate64_cen(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimatorsu.h:2853
void decimate16_sup(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimatorsu.h:683
rtlsdr_dev_t * m_dev
Definition: rtlsdrthread.h:48
unsigned int m_log2Decim
Definition: rtlsdrthread.h:53
void decimate1(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimatorsu.h:220
DecimatorsU< qint32, quint8, SDR_RX_SAMP_SZ, 8, 127 > m_decimators
Definition: rtlsdrthread.h:56
SampleSinkFifo * m_sampleFifo
Definition: rtlsdrthread.h:50
void decimate2_cen(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimatorsu.h:2407
SampleVector m_convertBuffer
Definition: rtlsdrthread.h:49
void decimate64_sup(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimatorsu.h:1883
void decimate8_sup(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimatorsu.h:467
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ callbackHelper()

void RTLSDRThread::callbackHelper ( unsigned char *  buf,
uint32_t  len,
void *  ctx 
)
staticprivate

Definition at line 188 of file rtlsdrthread.cpp.

References callback().

Referenced by run().

189 {
190  RTLSDRThread* thread = (RTLSDRThread*)ctx;
191  thread->callback(buf, len);
192 }
void callback(const quint8 *buf, qint32 len)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ run()

void RTLSDRThread::run ( )
private

Definition at line 74 of file rtlsdrthread.cpp.

References callbackHelper(), FCD_BLOCKSIZE, m_dev, m_running, and m_startWaiter.

75 {
76  int res;
77 
78  m_running = true;
79  m_startWaiter.wakeAll();
80 
81  while(m_running) {
82  if((res = rtlsdr_read_async(m_dev, &RTLSDRThread::callbackHelper, this, 32, FCD_BLOCKSIZE)) < 0) {
83  qCritical("RTLSDRThread: async error: %s", strerror(errno));
84  break;
85  }
86  }
87 
88  m_running = false;
89 }
static void callbackHelper(unsigned char *buf, uint32_t len, void *ctx)
#define FCD_BLOCKSIZE
QWaitCondition m_startWaiter
Definition: rtlsdrthread.h:45
rtlsdr_dev_t * m_dev
Definition: rtlsdrthread.h:48
+ Here is the call graph for this function:

◆ setFcPos()

void RTLSDRThread::setFcPos ( int  fcPos)

Definition at line 69 of file rtlsdrthread.cpp.

References m_fcPos.

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

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

◆ setLog2Decimation()

void RTLSDRThread::setLog2Decimation ( unsigned int  log2_decim)

Definition at line 64 of file rtlsdrthread.cpp.

References m_log2Decim.

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

65 {
66  m_log2Decim = log2_decim;
67 }
unsigned int m_log2Decim
Definition: rtlsdrthread.h:53
+ Here is the caller graph for this function:

◆ setSamplerate()

void RTLSDRThread::setSamplerate ( int  samplerate)

Definition at line 59 of file rtlsdrthread.cpp.

References m_samplerate.

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

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

◆ startWork()

void RTLSDRThread::startWork ( )

Definition at line 44 of file rtlsdrthread.cpp.

References m_running, m_startWaiter, and m_startWaitMutex.

Referenced by RTLSDRInput::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
Definition: rtlsdrthread.h:45
QMutex m_startWaitMutex
Definition: rtlsdrthread.h:44
+ Here is the caller graph for this function:

◆ stopWork()

void RTLSDRThread::stopWork ( )

Definition at line 53 of file rtlsdrthread.cpp.

References m_running.

Referenced by RTLSDRInput::stop(), and ~RTLSDRThread().

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

Member Data Documentation

◆ m_convertBuffer

SampleVector RTLSDRThread::m_convertBuffer
private

Definition at line 49 of file rtlsdrthread.h.

Referenced by callback().

◆ m_decimators

DecimatorsU<qint32, quint8, SDR_RX_SAMP_SZ, 8, 127> RTLSDRThread::m_decimators
private

Definition at line 56 of file rtlsdrthread.h.

Referenced by callback().

◆ m_dev

rtlsdr_dev_t* RTLSDRThread::m_dev
private

Definition at line 48 of file rtlsdrthread.h.

Referenced by callback(), and run().

◆ m_fcPos

int RTLSDRThread::m_fcPos
private

Definition at line 54 of file rtlsdrthread.h.

Referenced by callback(), and setFcPos().

◆ m_log2Decim

unsigned int RTLSDRThread::m_log2Decim
private

Definition at line 53 of file rtlsdrthread.h.

Referenced by callback(), and setLog2Decimation().

◆ m_running

bool RTLSDRThread::m_running
private

Definition at line 46 of file rtlsdrthread.h.

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

◆ m_sampleFifo

SampleSinkFifo* RTLSDRThread::m_sampleFifo
private

Definition at line 50 of file rtlsdrthread.h.

Referenced by callback().

◆ m_samplerate

int RTLSDRThread::m_samplerate
private

Definition at line 52 of file rtlsdrthread.h.

Referenced by setSamplerate().

◆ m_startWaiter

QWaitCondition RTLSDRThread::m_startWaiter
private

Definition at line 45 of file rtlsdrthread.h.

Referenced by run(), and startWork().

◆ m_startWaitMutex

QMutex RTLSDRThread::m_startWaitMutex
private

Definition at line 44 of file rtlsdrthread.h.

Referenced by startWork().


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