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

#include <udpsinkfecworker.h>

Inherits QThread.

+ Collaboration diagram for UDPSinkFECWorker:

Classes

class  MsgConfigureRemoteAddress
 
class  MsgStartStop
 
class  MsgUDPFECEncodeAndSend
 

Public Member Functions

 UDPSinkFECWorker ()
 
 ~UDPSinkFECWorker ()
 
void startStop (bool start)
 
void pushTxFrame (RemoteSuperBlock *txBlocks, uint32_t nbBlocksFEC, uint32_t txDelay, uint16_t frameIndex)
 
void setRemoteAddress (const QString &address, uint16_t port)
 

Public Attributes

MessageQueue m_inputMessageQueue
 Queue for asynchronous inbound communication. More...
 

Private Slots

void handleInputMessages ()
 

Private Member Functions

void startWork ()
 
void stopWork ()
 
void run ()
 
void encodeAndTransmit (RemoteSuperBlock *txBlockx, uint16_t frameIndex, uint32_t nbBlocksFEC, uint32_t txDelay)
 

Private Attributes

QMutex m_startWaitMutex
 
QWaitCondition m_startWaiter
 
volatile bool m_running
 
CM256 m_cm256
 CM256 library object. More...
 
bool m_cm256Valid
 true if CM256 library is initialized correctly More...
 
QUdpSocket * m_udpSocket
 
QString m_remoteAddress
 
uint16_t m_remotePort
 
QHostAddress m_remoteHostAddress
 

Detailed Description

Definition at line 34 of file udpsinkfecworker.h.

Constructor & Destructor Documentation

◆ UDPSinkFECWorker()

UDPSinkFECWorker::UDPSinkFECWorker ( )

Definition at line 27 of file udpsinkfecworker.cpp.

Referenced by UDPSinkFECWorker::MsgStartStop::MsgStartStop().

27  :
28  m_running(false),
29  m_udpSocket(0),
30  m_remotePort(9090)
31 {
32  m_cm256Valid = m_cm256.isInitialized();
33  connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()), Qt::QueuedConnection);
34 }
QUdpSocket * m_udpSocket
MessageQueue m_inputMessageQueue
Queue for asynchronous inbound communication.
CM256 m_cm256
CM256 library object.
bool m_cm256Valid
true if CM256 library is initialized correctly
volatile bool m_running
+ Here is the caller graph for this function:

◆ ~UDPSinkFECWorker()

UDPSinkFECWorker::~UDPSinkFECWorker ( )

Definition at line 36 of file udpsinkfecworker.cpp.

Referenced by UDPSinkFECWorker::MsgStartStop::MsgStartStop().

37 {
38 }
+ Here is the caller graph for this function:

Member Function Documentation

◆ encodeAndTransmit()

void UDPSinkFECWorker::encodeAndTransmit ( RemoteSuperBlock txBlockx,
uint16_t  frameIndex,
uint32_t  nbBlocksFEC,
uint32_t  txDelay 
)
private

< Main interface with CM256 encoder

< Pointers to data for CM256 encoder

< FEC data

Definition at line 135 of file udpsinkfecworker.cpp.

References i, m_cm256Valid, and m_udpSocket.

Referenced by handleInputMessages().

136 {
137  CM256::cm256_encoder_params cm256Params;
138  CM256::cm256_block descriptorBlocks[256];
139  RemoteProtectedBlock fecBlocks[256];
140 
141  if ((nbBlocksFEC == 0) || !m_cm256Valid)
142  {
143  if (m_udpSocket)
144  {
145  for (unsigned int i = 0; i < RemoteNbOrginalBlocks; i++)
146  {
147  m_udpSocket->writeDatagram((const char *) &txBlockx[i], RemoteUdpSize, m_remoteHostAddress, m_remotePort);
148  usleep(txDelay);
149  }
150  }
151  }
152  else
153  {
154  cm256Params.BlockBytes = sizeof(RemoteProtectedBlock);
155  cm256Params.OriginalCount = RemoteNbOrginalBlocks;
156  cm256Params.RecoveryCount = nbBlocksFEC;
157 
158 
159  // Fill pointers to data
160  for (int i = 0; i < cm256Params.OriginalCount + cm256Params.RecoveryCount; ++i)
161  {
162  if (i >= cm256Params.OriginalCount) {
163  memset((char *) &txBlockx[i].m_protectedBlock, 0, sizeof(RemoteProtectedBlock));
164  }
165 
166  txBlockx[i].m_header.m_frameIndex = frameIndex;
167  txBlockx[i].m_header.m_blockIndex = i;
168  txBlockx[i].m_header.m_sampleBytes = (SDR_RX_SAMP_SZ <= 16 ? 2 : 4);
170  descriptorBlocks[i].Block = (void *) &(txBlockx[i].m_protectedBlock);
171  descriptorBlocks[i].Index = txBlockx[i].m_header.m_blockIndex;
172  }
173 
174  // Encode FEC blocks
175  if (m_cm256.cm256_encode(cm256Params, descriptorBlocks, fecBlocks))
176  {
177  qDebug("UDPSinkFECWorker::encodeAndTransmit: CM256 encode failed. No transmission.");
178  return;
179  }
180 
181  // Merge FEC with data to transmit
182  for (int i = 0; i < cm256Params.RecoveryCount; i++)
183  {
184  txBlockx[i + cm256Params.OriginalCount].m_protectedBlock = fecBlocks[i];
185  }
186 
187  // Transmit all blocks
188  if (m_udpSocket)
189  {
190  for (int i = 0; i < cm256Params.OriginalCount + cm256Params.RecoveryCount; i++)
191  {
192  #ifdef REMOTE_PUNCTURE
193  if (i == REMOTE_PUNCTURE) {
194  continue;
195  }
196  #endif
197 
198  m_udpSocket->writeDatagram((const char *) &txBlockx[i], RemoteUdpSize, m_remoteHostAddress, m_remotePort);
199  usleep(txDelay);
200  }
201  }
202  }
203 }
QHostAddress m_remoteHostAddress
QUdpSocket * m_udpSocket
RemoteProtectedBlock m_protectedBlock
#define SDR_RX_SAMP_SZ
Definition: dsptypes.h:32
uint8_t m_sampleBytes
number of bytes per sample (2 or 4) for this block
int32_t i
Definition: decimators.h:244
uint8_t m_blockIndex
RemoteHeader m_header
CM256 m_cm256
CM256 library object.
uint16_t m_frameIndex
bool m_cm256Valid
true if CM256 library is initialized correctly
uint8_t m_sampleBits
number of bits per sample
+ Here is the caller graph for this function:

◆ handleInputMessages

void UDPSinkFECWorker::handleInputMessages ( )
privateslot

Definition at line 100 of file udpsinkfecworker.cpp.

References encodeAndTransmit(), UDPSinkFECWorker::MsgUDPFECEncodeAndSend::getFrameIndex(), Message::getIdentifier(), UDPSinkFECWorker::MsgUDPFECEncodeAndSend::getNbBlocsFEC(), UDPSinkFECWorker::MsgStartStop::getStartStop(), UDPSinkFECWorker::MsgUDPFECEncodeAndSend::getTxBlocks(), UDPSinkFECWorker::MsgUDPFECEncodeAndSend::getTxDelay(), m_inputMessageQueue, m_remoteAddress, m_remoteHostAddress, m_remotePort, Message::match(), MessageQueue::pop(), startWork(), and stopWork().

101 {
102  Message* message;
103 
104  while ((message = m_inputMessageQueue.pop()) != 0)
105  {
106  if (MsgUDPFECEncodeAndSend::match(*message))
107  {
108  MsgUDPFECEncodeAndSend *sendMsg = (MsgUDPFECEncodeAndSend *) message;
109  encodeAndTransmit(sendMsg->getTxBlocks(), sendMsg->getFrameIndex(), sendMsg->getNbBlocsFEC(), sendMsg->getTxDelay());
110  }
111  else if (MsgConfigureRemoteAddress::match(*message))
112  {
113  qDebug("UDPSinkFECWorker::handleInputMessages: %s", message->getIdentifier());
114  MsgConfigureRemoteAddress *addressMsg = (MsgConfigureRemoteAddress *) message;
115  m_remoteAddress = addressMsg->getAddress();
116  m_remotePort = addressMsg->getPort();
117  m_remoteHostAddress.setAddress(addressMsg->getAddress());
118  }
119  else if (MsgStartStop::match(*message))
120  {
121  MsgStartStop* notif = (MsgStartStop*) message;
122  qDebug("UDPSinkFECWorker::handleInputMessages: MsgStartStop: %s", notif->getStartStop() ? "start" : "stop");
123 
124  if (notif->getStartStop()) {
125  startWork();
126  } else {
127  stopWork();
128  }
129  }
130 
131  delete message;
132  }
133 }
Message * pop()
Pop message from queue.
QHostAddress m_remoteHostAddress
void encodeAndTransmit(RemoteSuperBlock *txBlockx, uint16_t frameIndex, uint32_t nbBlocksFEC, uint32_t txDelay)
MessageQueue m_inputMessageQueue
Queue for asynchronous inbound communication.
static bool match(const Message *message)
Definition: message.cpp:45
virtual const char * getIdentifier() const
Definition: message.cpp:35
+ Here is the call graph for this function:

◆ pushTxFrame()

void UDPSinkFECWorker::pushTxFrame ( RemoteSuperBlock txBlocks,
uint32_t  nbBlocksFEC,
uint32_t  txDelay,
uint16_t  frameIndex 
)

Definition at line 86 of file udpsinkfecworker.cpp.

References UDPSinkFECWorker::MsgUDPFECEncodeAndSend::create(), m_inputMessageQueue, and MessageQueue::push().

Referenced by UDPSinkFECWorker::MsgStartStop::MsgStartStop().

90 {
91  //qDebug("UDPSinkFECWorker::pushTxFrame. %d", m_inputMessageQueue.size());
92  m_inputMessageQueue.push(MsgUDPFECEncodeAndSend::create(txBlocks, nbBlocksFEC, txDelay, frameIndex));
93 }
void push(Message *message, bool emitSignal=true)
Push message onto queue.
static MsgUDPFECEncodeAndSend * create(RemoteSuperBlock *txBlocks, uint32_t nbBlocksFEC, uint32_t txDelay, uint16_t frameIndex)
MessageQueue m_inputMessageQueue
Queue for asynchronous inbound communication.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ run()

void UDPSinkFECWorker::run ( )
private

Definition at line 70 of file udpsinkfecworker.cpp.

References m_running, and m_startWaiter.

71 {
72  m_running = true;
73  m_startWaiter.wakeAll();
74 
75  qDebug("UDPSinkFECWorker::process: started");
76 
77  while (m_running)
78  {
79  sleep(1);
80  }
81  m_running = false;
82 
83  qDebug("UDPSinkFECWorker::process: stopped");
84 }
QWaitCondition m_startWaiter
volatile bool m_running

◆ setRemoteAddress()

void UDPSinkFECWorker::setRemoteAddress ( const QString &  address,
uint16_t  port 
)

Definition at line 95 of file udpsinkfecworker.cpp.

References UDPSinkFECWorker::MsgConfigureRemoteAddress::create(), m_inputMessageQueue, and MessageQueue::push().

Referenced by UDPSinkFECWorker::MsgStartStop::MsgStartStop(), UDPSinkFEC::setRemoteAddress(), and UDPSinkFEC::start().

96 {
98 }
void push(Message *message, bool emitSignal=true)
Push message onto queue.
MessageQueue m_inputMessageQueue
Queue for asynchronous inbound communication.
static MsgConfigureRemoteAddress * create(const QString &address, uint16_t port)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ startStop()

void UDPSinkFECWorker::startStop ( bool  start)

Definition at line 40 of file udpsinkfecworker.cpp.

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

Referenced by UDPSinkFECWorker::MsgStartStop::MsgStartStop(), UDPSinkFEC::start(), and UDPSinkFEC::stop().

41 {
42  MsgStartStop *msg = MsgStartStop::create(start);
44 }
void push(Message *message, bool emitSignal=true)
Push message onto queue.
static MsgStartStop * create(bool startStop)
MessageQueue m_inputMessageQueue
Queue for asynchronous inbound communication.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ startWork()

void UDPSinkFECWorker::startWork ( )
private

Definition at line 46 of file udpsinkfecworker.cpp.

References m_running, m_startWaiter, m_startWaitMutex, and m_udpSocket.

Referenced by handleInputMessages().

47 {
48  qDebug("UDPSinkFECWorker::startWork");
49  m_startWaitMutex.lock();
50  m_udpSocket = new QUdpSocket(this);
51 
52  start();
53 
54  while(!m_running) {
55  m_startWaiter.wait(&m_startWaitMutex, 100);
56  }
57 
58  m_startWaitMutex.unlock();
59 }
QWaitCondition m_startWaiter
QUdpSocket * m_udpSocket
volatile bool m_running
+ Here is the caller graph for this function:

◆ stopWork()

void UDPSinkFECWorker::stopWork ( )
private

Definition at line 61 of file udpsinkfecworker.cpp.

References m_running, and m_udpSocket.

Referenced by handleInputMessages().

62 {
63  qDebug("UDPSinkFECWorker::stopWork");
64  delete m_udpSocket;
65  m_udpSocket = 0;
66  m_running = false;
67  wait();
68 }
QUdpSocket * m_udpSocket
volatile bool m_running
+ Here is the caller graph for this function:

Member Data Documentation

◆ m_cm256

CM256 UDPSinkFECWorker::m_cm256
private

CM256 library object.

Definition at line 140 of file udpsinkfecworker.h.

◆ m_cm256Valid

bool UDPSinkFECWorker::m_cm256Valid
private

true if CM256 library is initialized correctly

Definition at line 141 of file udpsinkfecworker.h.

Referenced by encodeAndTransmit().

◆ m_inputMessageQueue

MessageQueue UDPSinkFECWorker::m_inputMessageQueue

Queue for asynchronous inbound communication.

Definition at line 126 of file udpsinkfecworker.h.

Referenced by handleInputMessages(), pushTxFrame(), setRemoteAddress(), and startStop().

◆ m_remoteAddress

QString UDPSinkFECWorker::m_remoteAddress
private

Definition at line 143 of file udpsinkfecworker.h.

Referenced by handleInputMessages().

◆ m_remoteHostAddress

QHostAddress UDPSinkFECWorker::m_remoteHostAddress
private

Definition at line 145 of file udpsinkfecworker.h.

Referenced by handleInputMessages().

◆ m_remotePort

uint16_t UDPSinkFECWorker::m_remotePort
private

Definition at line 144 of file udpsinkfecworker.h.

Referenced by handleInputMessages().

◆ m_running

volatile bool UDPSinkFECWorker::m_running
private

Definition at line 139 of file udpsinkfecworker.h.

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

◆ m_startWaiter

QWaitCondition UDPSinkFECWorker::m_startWaiter
private

Definition at line 138 of file udpsinkfecworker.h.

Referenced by run(), and startWork().

◆ m_startWaitMutex

QMutex UDPSinkFECWorker::m_startWaitMutex
private

Definition at line 137 of file udpsinkfecworker.h.

Referenced by startWork().

◆ m_udpSocket

QUdpSocket* UDPSinkFECWorker::m_udpSocket
private

Definition at line 142 of file udpsinkfecworker.h.

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


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