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

#include <xtrxinputthread.h>

+ Inheritance diagram for XTRXInputThread:
+ Collaboration diagram for XTRXInputThread:

Classes

struct  Channel
 

Public Member Functions

 XTRXInputThread (struct xtrx_dev *dev, unsigned int nbChannels, unsigned int uniqueChannelIndex=0, QObject *parent=0)
 
 ~XTRXInputThread ()
 
virtual void startWork ()
 
virtual void stopWork ()
 
virtual bool isRunning ()
 
unsigned int getNbChannels () const
 
void setLog2Decimation (unsigned int channel, unsigned int log2_decim)
 
unsigned int getLog2Decimation (unsigned int channel) const
 
void setFifo (unsigned int channel, SampleSinkFifo *sampleFifo)
 
SampleSinkFifogetFifo (unsigned int channel)
 

Private Member Functions

void run ()
 
unsigned int getNbFifos ()
 
void callbackSI (const qint16 *buf, qint32 len)
 
void callbackMI (const qint16 *buf0, const qint16 *buf1, qint32 len)
 

Private Attributes

QMutex m_startWaitMutex
 
QWaitCondition m_startWaiter
 
bool m_running
 
struct xtrx_dev * m_dev
 
Channelm_channels
 Array of channels dynamically allocated for the given number of Rx channels. More...
 
unsigned int m_nbChannels
 
unsigned int m_uniqueChannelIndex
 

Detailed Description

Definition at line 34 of file xtrxinputthread.h.

Constructor & Destructor Documentation

◆ XTRXInputThread()

XTRXInputThread::XTRXInputThread ( struct xtrx_dev *  dev,
unsigned int  nbChannels,
unsigned int  uniqueChannelIndex = 0,
QObject *  parent = 0 
)

Definition at line 27 of file xtrxinputthread.cpp.

References DeviceXTRX::blockSize, i, m_channels, and XTRXInputThread::Channel::m_convertBuffer.

27  :
28  QThread(parent),
29  m_running(false),
30  m_dev(dev),
31  m_nbChannels(nbChannels),
32  m_uniqueChannelIndex(uniqueChannelIndex)
33 {
34  qDebug("XTRXInputThread::XTRXInputThread: nbChannels: %u uniqueChannelIndex: %u", nbChannels, uniqueChannelIndex);
35  m_channels = new Channel[2];
36 
37  for (unsigned int i = 0; i < 2; i++) {
39  }
40 }
Channel * m_channels
Array of channels dynamically allocated for the given number of Rx channels.
unsigned int m_uniqueChannelIndex
int32_t i
Definition: decimators.h:244
static const unsigned int blockSize
Definition: devicextrx.h:44
struct xtrx_dev * m_dev
unsigned int m_nbChannels

◆ ~XTRXInputThread()

XTRXInputThread::~XTRXInputThread ( )

Definition at line 42 of file xtrxinputthread.cpp.

References m_channels, m_running, and stopWork().

43 {
44  qDebug("XTRXInputThread::~XTRXInputThread");
45 
46  if (m_running) {
47  stopWork();
48  }
49 
50  delete[] m_channels;
51 }
Channel * m_channels
Array of channels dynamically allocated for the given number of Rx channels.
virtual void stopWork()
+ Here is the call graph for this function:

Member Function Documentation

◆ callbackMI()

void XTRXInputThread::callbackMI ( const qint16 *  buf0,
const qint16 *  buf1,
qint32  len 
)
private

Definition at line 264 of file xtrxinputthread.cpp.

References callbackSI(), and m_uniqueChannelIndex.

Referenced by run().

265 {
266  unsigned int uniqueChannelIndex = m_uniqueChannelIndex;
267 
268  // channel 0
270  callbackSI(buf0, len);
271  // channel 1
273  callbackSI(buf1, len);
274 
275  m_uniqueChannelIndex = uniqueChannelIndex;
276 }
unsigned int m_uniqueChannelIndex
void callbackSI(const qint16 *buf, qint32 len)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ callbackSI()

void XTRXInputThread::callbackSI ( const qint16 *  buf,
qint32  len 
)
private

Definition at line 226 of file xtrxinputthread.cpp.

References Decimators< StorageType, T, SdrBits, InputBits >::decimate1(), Decimators< StorageType, T, SdrBits, InputBits >::decimate16_cen(), Decimators< StorageType, T, SdrBits, InputBits >::decimate2_cen(), Decimators< StorageType, T, SdrBits, InputBits >::decimate32_cen(), Decimators< StorageType, T, SdrBits, InputBits >::decimate4_cen(), Decimators< StorageType, T, SdrBits, InputBits >::decimate64_cen(), Decimators< StorageType, T, SdrBits, InputBits >::decimate8_cen(), m_channels, XTRXInputThread::Channel::m_convertBuffer, XTRXInputThread::Channel::m_decimators, XTRXInputThread::Channel::m_sampleFifo, m_uniqueChannelIndex, and SampleSinkFifo::write().

Referenced by callbackMI(), and run().

227 {
228  SampleVector::iterator it = m_channels[m_uniqueChannelIndex].m_convertBuffer.begin();
229 
230  if (m_channels[m_uniqueChannelIndex].m_log2Decim == 0)
231  {
233  }
234  else
235  {
236  switch (m_channels[m_uniqueChannelIndex].m_log2Decim)
237  {
238  case 1:
240  break;
241  case 2:
243  break;
244  case 3:
246  break;
247  case 4:
249  break;
250  case 5:
252  break;
253  case 6:
255  break;
256  default:
257  break;
258  }
259  }
260 
262 }
void decimate64_cen(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:3040
void decimate2_cen(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:554
uint write(const quint8 *data, uint count)
Channel * m_channels
Array of channels dynamically allocated for the given number of Rx channels.
unsigned int m_uniqueChannelIndex
void decimate8_cen(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:1057
SampleSinkFifo * m_sampleFifo
Decimators< qint32, qint16, SDR_RX_SAMP_SZ, 12 > m_decimators
void decimate4_cen(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:782
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
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getFifo()

SampleSinkFifo * XTRXInputThread::getFifo ( unsigned int  channel)

Definition at line 217 of file xtrxinputthread.cpp.

References m_channels, and XTRXInputThread::Channel::m_sampleFifo.

Referenced by getNbChannels(), and XTRXInput::start().

218 {
219  if (channel < 2) {
220  return m_channels[channel].m_sampleFifo;
221  } else {
222  return 0;
223  }
224 }
Channel * m_channels
Array of channels dynamically allocated for the given number of Rx channels.
SampleSinkFifo * m_sampleFifo
+ Here is the caller graph for this function:

◆ getLog2Decimation()

unsigned int XTRXInputThread::getLog2Decimation ( unsigned int  channel) const

Definition at line 201 of file xtrxinputthread.cpp.

References m_channels, and XTRXInputThread::Channel::m_log2Decim.

Referenced by getNbChannels(), and XTRXInput::start().

202 {
203  if (channel < 2) {
204  return m_channels[channel].m_log2Decim;
205  } else {
206  return 0;
207  }
208 }
Channel * m_channels
Array of channels dynamically allocated for the given number of Rx channels.
+ Here is the caller graph for this function:

◆ getNbChannels()

unsigned int XTRXInputThread::getNbChannels ( ) const
inline

Definition at line 45 of file xtrxinputthread.h.

References getFifo(), getLog2Decimation(), m_nbChannels, setFifo(), and setLog2Decimation().

Referenced by XTRXInput::start(), and XTRXInput::stop().

45 { return m_nbChannels; }
unsigned int m_nbChannels
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getNbFifos()

unsigned int XTRXInputThread::getNbFifos ( )
private

Definition at line 180 of file xtrxinputthread.cpp.

References i, and m_channels.

Referenced by run().

181 {
182  unsigned int fifoCount = 0;
183 
184  for (unsigned int i = 0; i < 2; i++)
185  {
186  if (m_channels[i].m_sampleFifo) {
187  fifoCount++;
188  }
189  }
190 
191  return fifoCount;
192 }
Channel * m_channels
Array of channels dynamically allocated for the given number of Rx channels.
int32_t i
Definition: decimators.h:244
+ Here is the caller graph for this function:

◆ isRunning()

virtual bool XTRXInputThread::isRunning ( )
inlinevirtual

Implements DeviceXTRXShared::ThreadInterface.

Definition at line 44 of file xtrxinputthread.h.

References m_running.

Referenced by XTRXInput::applySettings().

44 { return m_running; }
+ Here is the caller graph for this function:

◆ run()

void XTRXInputThread::run ( )
private

Definition at line 80 of file xtrxinputthread.cpp.

References DeviceXTRX::blockSize, callbackMI(), callbackSI(), getNbFifos(), i, m_dev, m_nbChannels, m_running, m_startWaiter, and m_uniqueChannelIndex.

81 {
82  int res;
83 
84  m_running = true;
85  m_startWaiter.wakeAll();
86 
87  unsigned int nbFifos = getNbFifos();
88 
89  if ((m_nbChannels != 0) && (nbFifos != 0))
90  {
91  xtrx_run_params params;
92  xtrx_run_params_init(&params);
93 
94  params.dir = XTRX_RX;
95  params.rx.chs = XTRX_CH_AB;
96  params.rx.wfmt = XTRX_WF_16;
97  params.rx.hfmt = XTRX_IQ_INT16;
98  params.rx_stream_start = 2*DeviceXTRX::blockSize; // was 2*8192
99  params.rx.paketsize = 2*DeviceXTRX::blockSize;
100 
101  if (m_nbChannels == 1)
102  {
103  qDebug("XTRXInputThread::run: SI mode for channel #%u", m_uniqueChannelIndex);
104  params.rx.flags |= XTRX_RSP_SISO_MODE;
105 
106  if (m_uniqueChannelIndex == 1) {
107  params.rx.flags |= XTRX_RSP_SWAP_AB;
108  }
109  }
110 
111  res = xtrx_run_ex(m_dev, &params);
112 
113  if (res != 0)
114  {
115  qCritical("XTRXInputThread::run: could not start stream err:%d", res);
116  m_running = false;
117  }
118  else
119  {
120  std::this_thread::sleep_for(std::chrono::milliseconds(50));
121  qDebug("XTRXInputThread::run: stream started");
122  }
123 
124  const unsigned int elemSize = 4; // XTRX uses 4 byte I+Q samples
125  std::vector<std::vector<char>> buffMem(m_nbChannels, std::vector<char>(elemSize*DeviceXTRX::blockSize));
126  std::vector<void *> buffs(m_nbChannels);
127 
128  for (std::size_t i = 0; i < m_nbChannels; i++) {
129  buffs[i] = buffMem[i].data();
130  }
131 
132  xtrx_recv_ex_info_t nfo;
133  nfo.samples = DeviceXTRX::blockSize;
134  nfo.buffer_count = m_nbChannels;
135  nfo.buffers = (void* const*) buffs.data();
136  nfo.flags = RCVEX_DONT_INSER_ZEROS | RCVEX_DROP_OLD_ON_OVERFLOW;
137 
138  while (m_running)
139  {
140  res = xtrx_recv_sync_ex(m_dev, &nfo);
141 
142  if (res < 0)
143  {
144  qCritical("XTRXInputThread::run read error: %d", res);
145  qDebug("XTRXInputThread::run: out_samples: %u out_events: %u", nfo.out_samples, nfo.out_events);
146  break;
147  }
148 
149  if (nfo.out_events & RCVEX_EVENT_OVERFLOW) {
150  qDebug("XTRXInputThread::run: overflow");
151  }
152 
153  if (m_nbChannels > 1) {
154  callbackMI((const qint16*) buffs[0], (const qint16*) buffs[1], 2 * nfo.out_samples);
155  } else {
156  callbackSI((const qint16*) buffs[0], 2 * nfo.out_samples);
157  }
158  }
159 
160  res = xtrx_stop(m_dev, XTRX_RX);
161 
162  if (res != 0)
163  {
164  qCritical("XTRXInputThread::run: could not stop stream");
165  }
166  else
167  {
168  std::this_thread::sleep_for(std::chrono::milliseconds(50));
169  qDebug("XTRXInputThread::run: stream stopped");
170  }
171  }
172  else
173  {
174  qWarning("XTRXInputThread::run: no channels or FIFO allocated. Aborting");
175  }
176 
177  m_running = false;
178 }
QWaitCondition m_startWaiter
unsigned int getNbFifos()
unsigned int m_uniqueChannelIndex
int32_t i
Definition: decimators.h:244
static const unsigned int blockSize
Definition: devicextrx.h:44
struct xtrx_dev * m_dev
unsigned int m_nbChannels
void callbackMI(const qint16 *buf0, const qint16 *buf1, qint32 len)
void callbackSI(const qint16 *buf, qint32 len)
+ Here is the call graph for this function:

◆ setFifo()

void XTRXInputThread::setFifo ( unsigned int  channel,
SampleSinkFifo sampleFifo 
)

Definition at line 210 of file xtrxinputthread.cpp.

References m_channels, and XTRXInputThread::Channel::m_sampleFifo.

Referenced by getNbChannels(), XTRXInput::start(), and XTRXInput::stop().

211 {
212  if (channel < 2) {
213  m_channels[channel].m_sampleFifo = sampleFifo;
214  }
215 }
Channel * m_channels
Array of channels dynamically allocated for the given number of Rx channels.
SampleSinkFifo * m_sampleFifo
+ Here is the caller graph for this function:

◆ setLog2Decimation()

void XTRXInputThread::setLog2Decimation ( unsigned int  channel,
unsigned int  log2_decim 
)

Definition at line 194 of file xtrxinputthread.cpp.

References m_channels, and XTRXInputThread::Channel::m_log2Decim.

Referenced by XTRXInput::applySettings(), getNbChannels(), XTRXInput::start(), and XTRXInput::stop().

195 {
196  if (channel < 2) {
197  m_channels[channel].m_log2Decim = log2_decim;
198  }
199 }
Channel * m_channels
Array of channels dynamically allocated for the given number of Rx channels.
+ Here is the caller graph for this function:

◆ startWork()

void XTRXInputThread::startWork ( )
virtual

Implements DeviceXTRXShared::ThreadInterface.

Definition at line 53 of file xtrxinputthread.cpp.

References m_running, m_startWaiter, and m_startWaitMutex.

Referenced by XTRXInput::applySettings(), XTRXInput::start(), and XTRXInput::stop().

54 {
55  if (m_running) {
56  return; // return if running already
57  }
58 
59  m_startWaitMutex.lock();
60  start();
61 
62  while (!m_running) {
63  m_startWaiter.wait(&m_startWaitMutex, 100);
64  }
65 
66  m_startWaitMutex.unlock();
67 }
QWaitCondition m_startWaiter
+ Here is the caller graph for this function:

◆ stopWork()

void XTRXInputThread::stopWork ( )
virtual

Implements DeviceXTRXShared::ThreadInterface.

Definition at line 69 of file xtrxinputthread.cpp.

References m_running.

Referenced by XTRXInput::applySettings(), XTRXInput::start(), XTRXInput::stop(), and ~XTRXInputThread().

70 {
71  if (!m_running) {
72  return; // return if not running
73  }
74 
75  m_running = false;
76  wait();
77 }
+ Here is the caller graph for this function:

Member Data Documentation

◆ m_channels

Channel* XTRXInputThread::m_channels
private

Array of channels dynamically allocated for the given number of Rx channels.

Definition at line 73 of file xtrxinputthread.h.

Referenced by callbackSI(), getFifo(), getLog2Decimation(), getNbFifos(), setFifo(), setLog2Decimation(), XTRXInputThread(), and ~XTRXInputThread().

◆ m_dev

struct xtrx_dev* XTRXInputThread::m_dev
private

Definition at line 71 of file xtrxinputthread.h.

Referenced by run().

◆ m_nbChannels

unsigned int XTRXInputThread::m_nbChannels
private

Definition at line 74 of file xtrxinputthread.h.

Referenced by getNbChannels(), and run().

◆ m_running

bool XTRXInputThread::m_running
private

Definition at line 70 of file xtrxinputthread.h.

Referenced by isRunning(), run(), startWork(), stopWork(), and ~XTRXInputThread().

◆ m_startWaiter

QWaitCondition XTRXInputThread::m_startWaiter
private

Definition at line 69 of file xtrxinputthread.h.

Referenced by run(), and startWork().

◆ m_startWaitMutex

QMutex XTRXInputThread::m_startWaitMutex
private

Definition at line 68 of file xtrxinputthread.h.

Referenced by startWork().

◆ m_uniqueChannelIndex

unsigned int XTRXInputThread::m_uniqueChannelIndex
private

Definition at line 75 of file xtrxinputthread.h.

Referenced by callbackMI(), callbackSI(), and run().


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