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.
bladerf1inputthread.cpp
Go to the documentation of this file.
1 // Copyright (C) 2015 Edouard Griffiths, F4EXB //
3 // //
4 // This program is free software; you can redistribute it and/or modify //
5 // it under the terms of the GNU General Public License as published by //
6 // the Free Software Foundation as version 3 of the License, or //
7 // (at your option) any later version. //
8 // //
9 // This program is distributed in the hope that it will be useful, //
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
12 // GNU General Public License V3 for more details. //
13 // //
14 // You should have received a copy of the GNU General Public License //
15 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
17 
18 #include "bladerf1inputthread.h"
19 
20 #include <stdio.h>
21 #include <errno.h>
22 #include <algorithm>
23 #include "dsp/samplesinkfifo.h"
24 
25 
26 
27 Bladerf1InputThread::Bladerf1InputThread(struct bladerf* dev, SampleSinkFifo* sampleFifo, QObject* parent) :
28  QThread(parent),
29  m_running(false),
30  m_dev(dev),
31  m_convertBuffer(BLADERF_BLOCKSIZE),
32  m_sampleFifo(sampleFifo),
33  m_log2Decim(0),
34  m_fcPos(0)
35 {
36  std::fill(m_buf, m_buf + 2*BLADERF_BLOCKSIZE, 0);
37 }
38 
40 {
41  stopWork();
42 }
43 
45 {
46  m_startWaitMutex.lock();
47  start();
48  while(!m_running)
49  m_startWaiter.wait(&m_startWaitMutex, 100);
50  m_startWaitMutex.unlock();
51 }
52 
54 {
55  m_running = false;
56  wait();
57 }
58 
59 void Bladerf1InputThread::setLog2Decimation(unsigned int log2_decim)
60 {
61  m_log2Decim = log2_decim;
62 }
63 
65 {
66  m_fcPos = fcPos;
67 }
68 
70 {
71  int res;
72 
73  m_running = true;
74  m_startWaiter.wakeAll();
75 
76  while(m_running) {
77  if((res = bladerf_sync_rx(m_dev, m_buf, BLADERF_BLOCKSIZE, NULL, 10000)) < 0) {
78  qCritical("BladerfThread: sync error: %s", strerror(errno));
79  break;
80  }
81 
83  }
84 
85  m_running = false;
86 }
87 
88 // Decimate according to specified log2 (ex: log2=4 => decim=16)
89 void Bladerf1InputThread::callback(const qint16* buf, qint32 len)
90 {
91  SampleVector::iterator it = m_convertBuffer.begin();
92 
93  if (m_log2Decim == 0)
94  {
95  m_decimators.decimate1(&it, buf, len);
96  }
97  else
98  {
99  if (m_fcPos == 0) // Infra
100  {
101  switch (m_log2Decim)
102  {
103  case 1:
104  m_decimators.decimate2_inf(&it, buf, len);
105  break;
106  case 2:
107  m_decimators.decimate4_inf(&it, buf, len);
108  break;
109  case 3:
110  m_decimators.decimate8_inf(&it, buf, len);
111  break;
112  case 4:
113  m_decimators.decimate16_inf(&it, buf, len);
114  break;
115  case 5:
116  m_decimators.decimate32_inf(&it, buf, len);
117  break;
118  case 6:
119  m_decimators.decimate64_inf(&it, buf, len);
120  break;
121  default:
122  break;
123  }
124  }
125  else if (m_fcPos == 1) // Supra
126  {
127  switch (m_log2Decim)
128  {
129  case 1:
130  m_decimators.decimate2_sup(&it, buf, len);
131  break;
132  case 2:
133  m_decimators.decimate4_sup(&it, buf, len);
134  break;
135  case 3:
136  m_decimators.decimate8_sup(&it, buf, len);
137  break;
138  case 4:
139  m_decimators.decimate16_sup(&it, buf, len);
140  break;
141  case 5:
142  m_decimators.decimate32_sup(&it, buf, len);
143  break;
144  case 6:
145  m_decimators.decimate64_sup(&it, buf, len);
146  break;
147  default:
148  break;
149  }
150  }
151  else if (m_fcPos == 2) // Center
152  {
153  switch (m_log2Decim)
154  {
155  case 1:
156  m_decimators.decimate2_cen(&it, buf, len);
157  break;
158  case 2:
159  m_decimators.decimate4_cen(&it, buf, len);
160  break;
161  case 3:
162  m_decimators.decimate8_cen(&it, buf, len);
163  break;
164  case 4:
165  m_decimators.decimate16_cen(&it, buf, len);
166  break;
167  case 5:
168  m_decimators.decimate32_cen(&it, buf, len);
169  break;
170  case 6:
171  m_decimators.decimate64_cen(&it, buf, len);
172  break;
173  default:
174  break;
175  }
176  }
177  }
178 
179 
180  m_sampleFifo->write(m_convertBuffer.begin(), it);
181 }
void callback(const qint16 *buf, qint32 len)
SampleSinkFifo * m_sampleFifo
void decimate2_inf(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:498
void decimate64_sup(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:2975
QWaitCondition m_startWaiter
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 decimate2_cen(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:554
void setLog2Decimation(unsigned int log2_decim)
uint write(const quint8 *data, uint count)
void decimate8_sup(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:941
Bladerf1InputThread(struct bladerf *dev, SampleSinkFifo *sampleFifo, QObject *parent=NULL)
struct bladerf * m_dev
void decimate64_inf(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:2418
void decimate32_inf(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:1592
void decimate32_sup(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:1902
#define BLADERF_BLOCKSIZE
void decimate4_sup(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:682
void decimate8_cen(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:1057
void decimate8_inf(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:825
void decimate16_sup(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:1300
void decimate4_cen(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:782
Decimators< qint32, qint16, SDR_RX_SAMP_SZ, 12 > m_decimators
void decimate4_inf(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:582
qint16 m_buf[2 *BLADERF_BLOCKSIZE]
void decimate16_inf(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:1117
SampleVector m_convertBuffer
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