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 Slots | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
RemoteSourceThread Class Reference

#include <remotesourcethread.h>

Inherits QThread.

+ Collaboration diagram for RemoteSourceThread:

Classes

class  MsgDataBind
 
class  MsgStartStop
 

Public Member Functions

 RemoteSourceThread (RemoteDataQueue *dataQueue, QObject *parent=0)
 
 ~RemoteSourceThread ()
 
void startStop (bool start)
 
void dataBind (const QString &address, uint16_t port)
 

Private Slots

void handleInputMessages ()
 
void readPendingDatagrams ()
 

Private Member Functions

void startWork ()
 
void stopWork ()
 
void run ()
 

Private Attributes

QMutex m_startWaitMutex
 
QWaitCondition m_startWaiter
 
volatile bool m_running
 
MessageQueue m_inputMessageQueue
 
RemoteDataQueuem_dataQueue
 
QHostAddress m_address
 
QUdpSocket * m_socket
 
RemoteDataBlockm_dataBlocks [m_nbDataBlocks]
 ring buffer of data blocks indexed by frame affinity More...
 

Static Private Attributes

static const uint32_t m_nbDataBlocks = 4
 number of data blocks in the ring buffer More...
 

Detailed Description

Definition at line 33 of file remotesourcethread.h.

Constructor & Destructor Documentation

◆ RemoteSourceThread()

RemoteSourceThread::RemoteSourceThread ( RemoteDataQueue dataQueue,
QObject *  parent = 0 
)

Definition at line 32 of file remotesourcethread.cpp.

Referenced by RemoteSourceThread::MsgDataBind::MsgDataBind().

32  :
33  QThread(parent),
34  m_running(false),
35  m_dataQueue(dataQueue),
36  m_address(QHostAddress::LocalHost),
37  m_socket(0)
38 {
39  std::fill(m_dataBlocks, m_dataBlocks+4, (RemoteDataBlock *) 0);
40  connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()), Qt::QueuedConnection);
41 }
RemoteDataQueue * m_dataQueue
volatile bool m_running
MessageQueue m_inputMessageQueue
RemoteDataBlock * m_dataBlocks[m_nbDataBlocks]
ring buffer of data blocks indexed by frame affinity
+ Here is the caller graph for this function:

◆ ~RemoteSourceThread()

RemoteSourceThread::~RemoteSourceThread ( )

Definition at line 43 of file remotesourcethread.cpp.

Referenced by RemoteSourceThread::MsgDataBind::MsgDataBind().

44 {
45  qDebug("RemoteSourceThread::~RemoteSourceThread");
46 }
+ Here is the caller graph for this function:

Member Function Documentation

◆ dataBind()

void RemoteSourceThread::dataBind ( const QString &  address,
uint16_t  port 
)

Definition at line 54 of file remotesourcethread.cpp.

References RemoteSourceThread::MsgDataBind::create(), m_inputMessageQueue, and MessageQueue::push().

Referenced by RemoteSource::applySettings(), RemoteSourceThread::MsgDataBind::MsgDataBind(), and RemoteSource::start().

55 {
56  MsgDataBind *msg = MsgDataBind::create(address, port);
58 }
void push(Message *message, bool emitSignal=true)
Push message onto queue.
static MsgDataBind * create(const QString &address, uint16_t port)
MessageQueue m_inputMessageQueue
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ handleInputMessages

void RemoteSourceThread::handleInputMessages ( )
privateslot

Definition at line 96 of file remotesourcethread.cpp.

References RemoteSourceThread::MsgDataBind::getAddress(), RemoteSourceThread::MsgDataBind::getPort(), RemoteSourceThread::MsgStartStop::getStartStop(), m_inputMessageQueue, m_socket, Message::match(), MessageQueue::pop(), readPendingDatagrams(), startWork(), and stopWork().

97 {
98  Message* message;
99 
100  while ((message = m_inputMessageQueue.pop()) != 0)
101  {
102  if (MsgStartStop::match(*message))
103  {
104  MsgStartStop* notif = (MsgStartStop*) message;
105  qDebug("RemoteSourceThread::handleInputMessages: MsgStartStop: %s", notif->getStartStop() ? "start" : "stop");
106 
107  if (notif->getStartStop()) {
108  startWork();
109  } else {
110  stopWork();
111  }
112 
113  delete message;
114  }
115  else if (MsgDataBind::match(*message))
116  {
117  MsgDataBind* notif = (MsgDataBind*) message;
118  qDebug("RemoteSourceThread::handleInputMessages: MsgDataBind: %s:%d", qPrintable(notif->getAddress().toString()), notif->getPort());
119 
120  if (m_socket)
121  {
122  disconnect(m_socket, SIGNAL(readyRead()), this, SLOT(readPendingDatagrams()));
123  m_socket->bind(notif->getAddress(), notif->getPort());
124  connect(m_socket, SIGNAL(readyRead()), this, SLOT(readPendingDatagrams()));
125  }
126  }
127  }
128 }
Message * pop()
Pop message from queue.
MessageQueue m_inputMessageQueue
static bool match(const Message *message)
Definition: message.cpp:45
+ Here is the call graph for this function:

◆ readPendingDatagrams

void RemoteSourceThread::readPendingDatagrams ( )
privateslot

Definition at line 130 of file remotesourcethread.cpp.

References m_dataBlocks, m_dataQueue, RemoteRxControlBlock::m_frameIndex, RemoteRxControlBlock::m_metaRetrieved, m_nbDataBlocks, RemoteDataBlock::m_rxControlBlock, m_socket, RemoteDataBlock::m_superBlocks, and RemoteDataQueue::push().

Referenced by handleInputMessages().

131 {
132  RemoteSuperBlock superBlock;
133  qint64 size;
134 
135  while (m_socket->hasPendingDatagrams())
136  {
137  QHostAddress sender;
138  quint16 senderPort = 0;
139  //qint64 pendingDataSize = m_socket->pendingDatagramSize();
140  size = m_socket->readDatagram((char *) &superBlock, (long long int) sizeof(RemoteSuperBlock), &sender, &senderPort);
141 
142  if (size == sizeof(RemoteSuperBlock))
143  {
144  unsigned int dataBlockIndex = superBlock.m_header.m_frameIndex % m_nbDataBlocks;
145 
146  // create the first block for this index
147  if (m_dataBlocks[dataBlockIndex] == 0) {
148  m_dataBlocks[dataBlockIndex] = new RemoteDataBlock();
149  }
150 
151  if (m_dataBlocks[dataBlockIndex]->m_rxControlBlock.m_frameIndex < 0)
152  {
153  // initialize virgin block with the frame index
154  m_dataBlocks[dataBlockIndex]->m_rxControlBlock.m_frameIndex = superBlock.m_header.m_frameIndex;
155  }
156  else
157  {
158  // if the frame index is not the same for the same slot it means we are starting a new frame
159  uint32_t frameIndex = m_dataBlocks[dataBlockIndex]->m_rxControlBlock.m_frameIndex;
160 
161  if (superBlock.m_header.m_frameIndex != frameIndex)
162  {
163  //qDebug("RemoteSourceThread::readPendingDatagrams: push frame %u", frameIndex);
164  m_dataQueue->push(m_dataBlocks[dataBlockIndex]);
165  m_dataBlocks[dataBlockIndex] = new RemoteDataBlock();
166  m_dataBlocks[dataBlockIndex]->m_rxControlBlock.m_frameIndex = superBlock.m_header.m_frameIndex;
167  }
168  }
169 
170  m_dataBlocks[dataBlockIndex]->m_superBlocks[superBlock.m_header.m_blockIndex] = superBlock;
171 
172  if (superBlock.m_header.m_blockIndex == 0) {
173  m_dataBlocks[dataBlockIndex]->m_rxControlBlock.m_metaRetrieved = true;
174  }
175 
176  if (superBlock.m_header.m_blockIndex < RemoteNbOrginalBlocks) {
177  m_dataBlocks[dataBlockIndex]->m_rxControlBlock.m_originalCount++;
178  } else {
179  m_dataBlocks[dataBlockIndex]->m_rxControlBlock.m_recoveryCount++;
180  }
181 
182  m_dataBlocks[dataBlockIndex]->m_rxControlBlock.m_blockCount++;
183  }
184  else
185  {
186  qWarning("RemoteSourceThread::readPendingDatagrams: wrong super block size not processing");
187  }
188  }
189 }
RemoteSuperBlock * m_superBlocks
RemoteDataQueue * m_dataQueue
void push(RemoteDataBlock *dataBlock, bool emitSignal=true)
Push daa block onto queue.
int m_recoveryCount
number of recovery blocks received
static const uint32_t m_nbDataBlocks
number of data blocks in the ring buffer
unsigned int uint32_t
Definition: rtptypes_win.h:46
RemoteRxControlBlock m_rxControlBlock
int m_originalCount
number of original blocks received
RemoteDataBlock * m_dataBlocks[m_nbDataBlocks]
ring buffer of data blocks indexed by frame affinity
int m_frameIndex
this frame index or -1 if unset
int m_blockCount
number of blocks received for this frame
bool m_metaRetrieved
true if meta data (block zero) was retrieved
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ run()

void RemoteSourceThread::run ( )
private

Definition at line 80 of file remotesourcethread.cpp.

References m_running, and m_startWaiter.

81 {
82  qDebug("RemoteSourceThread::run: begin");
83  m_running = true;
84  m_startWaiter.wakeAll();
85 
86  while (m_running)
87  {
88  sleep(1); // Do nothing as everything is in the data handler (dequeuer)
89  }
90 
91  m_running = false;
92  qDebug("RemoteSourceThread::run: end");
93 }
QWaitCondition m_startWaiter
volatile bool m_running

◆ startStop()

void RemoteSourceThread::startStop ( bool  start)

Definition at line 48 of file remotesourcethread.cpp.

References RemoteSourceThread::MsgStartStop::create(), m_inputMessageQueue, and MessageQueue::push().

Referenced by RemoteSourceThread::MsgDataBind::MsgDataBind(), RemoteSource::start(), and RemoteSource::stop().

49 {
50  MsgStartStop *msg = MsgStartStop::create(start);
52 }
void push(Message *message, bool emitSignal=true)
Push message onto queue.
MessageQueue m_inputMessageQueue
static MsgStartStop * create(bool startStop)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ startWork()

void RemoteSourceThread::startWork ( )
private

Definition at line 60 of file remotesourcethread.cpp.

References m_running, m_socket, m_startWaiter, and m_startWaitMutex.

Referenced by handleInputMessages().

61 {
62  qDebug("RemoteSourceThread::startWork");
63  m_startWaitMutex.lock();
64  m_socket = new QUdpSocket(this);
65  start();
66  while(!m_running)
67  m_startWaiter.wait(&m_startWaitMutex, 100);
68  m_startWaitMutex.unlock();
69 }
QWaitCondition m_startWaiter
volatile bool m_running
+ Here is the caller graph for this function:

◆ stopWork()

void RemoteSourceThread::stopWork ( )
private

Definition at line 71 of file remotesourcethread.cpp.

References m_running, and m_socket.

Referenced by handleInputMessages().

72 {
73  qDebug("RemoteSourceThread::stopWork");
74  delete m_socket;
75  m_socket = 0;
76  m_running = false;
77  wait();
78 }
volatile bool m_running
+ Here is the caller graph for this function:

Member Data Documentation

◆ m_address

QHostAddress RemoteSourceThread::m_address
private

Definition at line 92 of file remotesourcethread.h.

Referenced by RemoteSourceThread::MsgDataBind::getAddress().

◆ m_dataBlocks

RemoteDataBlock* RemoteSourceThread::m_dataBlocks[m_nbDataBlocks]
private

ring buffer of data blocks indexed by frame affinity

Definition at line 96 of file remotesourcethread.h.

Referenced by readPendingDatagrams().

◆ m_dataQueue

RemoteDataQueue* RemoteSourceThread::m_dataQueue
private

Definition at line 90 of file remotesourcethread.h.

Referenced by readPendingDatagrams().

◆ m_inputMessageQueue

MessageQueue RemoteSourceThread::m_inputMessageQueue
private

Definition at line 89 of file remotesourcethread.h.

Referenced by dataBind(), handleInputMessages(), and startStop().

◆ m_nbDataBlocks

const uint32_t RemoteSourceThread::m_nbDataBlocks = 4
staticprivate

number of data blocks in the ring buffer

Definition at line 95 of file remotesourcethread.h.

Referenced by readPendingDatagrams().

◆ m_running

volatile bool RemoteSourceThread::m_running
private

Definition at line 87 of file remotesourcethread.h.

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

◆ m_socket

QUdpSocket* RemoteSourceThread::m_socket
private

◆ m_startWaiter

QWaitCondition RemoteSourceThread::m_startWaiter
private

Definition at line 86 of file remotesourcethread.h.

Referenced by run(), and startWork().

◆ m_startWaitMutex

QMutex RemoteSourceThread::m_startWaitMutex
private

Definition at line 85 of file remotesourcethread.h.

Referenced by startWork().


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