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.
perseusthread.cpp
Go to the documentation of this file.
1 // Copyright (C) 2018 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 <QtGlobal>
19 #include <algorithm>
20 #include "perseusthread.h"
21 
23 
24 PerseusThread::PerseusThread(perseus_descr* dev, SampleSinkFifo* sampleFifo, QObject* parent) :
25  QThread(parent),
26  m_running(false),
27  m_dev(dev),
28  m_convertBuffer(PERSEUS_NBSAMPLES),
29  m_sampleFifo(sampleFifo),
30  m_log2Decim(0)
31 {
32  m_this = this;
33  std::fill(m_buf, m_buf + 2*PERSEUS_NBSAMPLES, 0);
34 }
35 
37 {
38  stopWork();
39  m_this = 0;
40 }
41 
43 {
44  qDebug("PerseusThread::startWork");
45  m_startWaitMutex.lock();
46  start();
47  while(!m_running)
48  m_startWaiter.wait(&m_startWaitMutex, 100);
49  m_startWaitMutex.unlock();
50 }
51 
53 {
54  qDebug("PerseusThread::stopWork");
55  m_running = false;
56  wait();
57 }
58 
59 void PerseusThread::setLog2Decimation(unsigned int log2_decim)
60 {
61  m_log2Decim = log2_decim;
62 }
63 
65 {
66  m_running = true;
67  m_startWaiter.wakeAll();
68 
69  int rc = perseus_start_async_input(m_dev, PERSEUS_BLOCKSIZE, rx_callback, 0);
70 
71  if (rc < 0) {
72  qCritical("PerseusThread::run: failed to start Perseus Rx: %s", perseus_errorstr());
73  }
74  else
75  {
76  qDebug("PerseusThread::run: start Perseus Rx");
77  while (m_running) {
78  sleep(1);
79  }
80  }
81 
82  rc = perseus_stop_async_input(m_dev);
83 
84  if (rc < 0) {
85  qCritical("PerseusThread::run: failed to stop Perseus Rx: %s", perseus_errorstr());
86  } else {
87  qDebug("PerseusThread::run: stopped Perseus Rx");
88  }
89 
90  m_running = false;
91 }
92 
93 void PerseusThread::callback(const uint8_t* buf, qint32 len)
94 {
95  SampleVector::iterator it = m_convertBuffer.begin();
96 
97  switch (m_log2Decim)
98  {
99  case 0:
101  break;
102  case 1:
104  break;
105  case 2:
107  break;
108  default:
109  break;
110  }
111 
112  m_sampleFifo->write(m_convertBuffer.begin(), it);
113 }
114 
115 int PerseusThread::rx_callback(void *buf, int buf_size, void *extra)
116 {
117  (void) extra;
118  qint32 nbIAndQ = buf_size / 3; // 3 bytes per I or Q
119  m_this->callback((uint8_t*) buf, nbIAndQ);
120  return 0;
121 }
122 
volatile bool m_running
Definition: perseusthread.h:46
#define PERSEUS_BLOCKSIZE
Definition: perseusthread.h:30
Decimators< qint32, TripleByteLE< qint64 >, SDR_RX_SAMP_SZ, 24 > m_decimators64
Definition: perseusthread.h:57
void decimate2_cen(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:554
uint write(const quint8 *data, uint count)
QWaitCondition m_startWaiter
Definition: perseusthread.h:45
static PerseusThread * m_this
Definition: perseusthread.h:54
perseus_descr * m_dev
Definition: perseusthread.h:48
void setLog2Decimation(unsigned int log2_decim)
unsigned int m_log2Decim
Definition: perseusthread.h:53
PerseusThread(perseus_descr *dev, SampleSinkFifo *sampleFifo, QObject *parent=0)
unsigned char uint8_t
Definition: rtptypes_win.h:42
void callback(const uint8_t *buf, qint32 len)
void decimate4_cen(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:782
Decimators< qint32, TripleByteLE< qint32 >, SDR_RX_SAMP_SZ, 24 > m_decimators32
Definition: perseusthread.h:56
QMutex m_startWaitMutex
Definition: perseusthread.h:44
static int rx_callback(void *buf, int buf_size, void *extra)
SampleSinkFifo * m_sampleFifo
Definition: perseusthread.h:51
#define PERSEUS_NBSAMPLES
Definition: perseusthread.h:29
qint32 m_buf[2 *PERSEUS_NBSAMPLES]
Definition: perseusthread.h:49
void decimate1(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:462
SampleVector m_convertBuffer
Definition: perseusthread.h:50