1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-10 10:33:29 -05:00

SDRDaemonSink: use QUdpSocket

This commit is contained in:
f4exb 2018-09-17 03:42:08 +02:00
parent 1e02b85702
commit aac6d09622
2 changed files with 16 additions and 4 deletions

View File

@ -14,6 +14,8 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>. // // along with this program. If not, see <http://www.gnu.org/licenses/>. //
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
#include <QUdpSocket>
#include "udpsinkfecworker.h" #include "udpsinkfecworker.h"
MESSAGE_CLASS_DEFINITION(UDPSinkFECWorker::MsgUDPFECEncodeAndSend, Message) MESSAGE_CLASS_DEFINITION(UDPSinkFECWorker::MsgUDPFECEncodeAndSend, Message)
@ -25,7 +27,7 @@ UDPSinkFECWorker::UDPSinkFECWorker() :
m_remotePort(9090) m_remotePort(9090)
{ {
m_cm256Valid = m_cm256.isInitialized(); m_cm256Valid = m_cm256.isInitialized();
connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()), Qt::DirectConnection); connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()), Qt::QueuedConnection);
} }
UDPSinkFECWorker::~UDPSinkFECWorker() UDPSinkFECWorker::~UDPSinkFECWorker()
@ -42,6 +44,7 @@ void UDPSinkFECWorker::startWork()
{ {
qDebug("UDPSinkFECWorker::startWork"); qDebug("UDPSinkFECWorker::startWork");
m_startWaitMutex.lock(); m_startWaitMutex.lock();
m_udpSocket = new QUdpSocket(this);
start(); start();
while(!m_running) while(!m_running)
m_startWaiter.wait(&m_startWaitMutex, 100); m_startWaiter.wait(&m_startWaitMutex, 100);
@ -51,6 +54,8 @@ void UDPSinkFECWorker::startWork()
void UDPSinkFECWorker::stopWork() void UDPSinkFECWorker::stopWork()
{ {
qDebug("UDPSinkFECWorker::stopWork"); qDebug("UDPSinkFECWorker::stopWork");
delete m_udpSocket;
m_udpSocket = 0;
m_running = false; m_running = false;
wait(); wait();
} }
@ -102,6 +107,7 @@ void UDPSinkFECWorker::handleInputMessages()
MsgConfigureRemoteAddress *addressMsg = (MsgConfigureRemoteAddress *) message; MsgConfigureRemoteAddress *addressMsg = (MsgConfigureRemoteAddress *) message;
m_remoteAddress = addressMsg->getAddress(); m_remoteAddress = addressMsg->getAddress();
m_remotePort = addressMsg->getPort(); m_remotePort = addressMsg->getPort();
m_remoteHostAddress.setAddress(addressMsg->getAddress());
} }
else if (MsgStartStop::match(*message)) else if (MsgStartStop::match(*message))
{ {
@ -129,8 +135,8 @@ void UDPSinkFECWorker::encodeAndTransmit(SDRDaemonSuperBlock *txBlockx, uint16_t
{ {
for (unsigned int i = 0; i < SDRDaemonNbOrginalBlocks; i++) for (unsigned int i = 0; i < SDRDaemonNbOrginalBlocks; i++)
{ {
m_socket.SendDataGram((const void *) &txBlockx[i], (int) SDRDaemonUdpSize, m_remoteAddress.toStdString(), (uint32_t) m_remotePort); //m_socket.SendDataGram((const void *) &txBlockx[i], SDRDaemonUdpSize, m_remoteAddress.toStdString(), (uint32_t) m_remotePort);
//m_udpSocket->writeDatagram((const char *) &txBlockx[i], (int) UDPSinkFEC::m_udpSize, m_remoteAddress, m_remotePort); m_udpSocket->writeDatagram((const char *) &txBlockx[i], SDRDaemonUdpSize, m_remoteHostAddress, m_remotePort);
usleep(txDelay); usleep(txDelay);
} }
} }
@ -179,7 +185,8 @@ void UDPSinkFECWorker::encodeAndTransmit(SDRDaemonSuperBlock *txBlockx, uint16_t
} }
#endif #endif
m_socket.SendDataGram((const void *) &txBlockx[i], (int) SDRDaemonUdpSize, m_remoteAddress.toStdString(), (uint32_t) m_remotePort); //m_socket.SendDataGram((const void *) &txBlockx[i], SDRDaemonUdpSize, m_remoteAddress.toStdString(), (uint32_t) m_remotePort);
m_udpSocket->writeDatagram((const char *) &txBlockx[i], SDRDaemonUdpSize, m_remoteHostAddress, m_remotePort);
usleep(txDelay); usleep(txDelay);
} }
} }

View File

@ -20,6 +20,7 @@
#include <QThread> #include <QThread>
#include <QMutex> #include <QMutex>
#include <QWaitCondition> #include <QWaitCondition>
#include <QHostAddress>
#include "cm256.h" #include "cm256.h"
@ -29,6 +30,8 @@
#include "UDPSocket.h" #include "UDPSocket.h"
class QUdpSocket;
class UDPSinkFECWorker : public QThread class UDPSinkFECWorker : public QThread
{ {
Q_OBJECT Q_OBJECT
@ -138,8 +141,10 @@ private:
CM256 m_cm256; //!< CM256 library object CM256 m_cm256; //!< CM256 library object
bool m_cm256Valid; //!< true if CM256 library is initialized correctly bool m_cm256Valid; //!< true if CM256 library is initialized correctly
UDPSocket m_socket; UDPSocket m_socket;
QUdpSocket *m_udpSocket;
QString m_remoteAddress; QString m_remoteAddress;
uint16_t m_remotePort; uint16_t m_remotePort;
QHostAddress m_remoteHostAddress;
}; };
#endif /* PLUGINS_SAMPLESINK_SDRDAEMONSINK_UDPSINKFECWORKER_H_ */ #endif /* PLUGINS_SAMPLESINK_SDRDAEMONSINK_UDPSINKFECWORKER_H_ */