mirror of
https://github.com/f4exb/sdrangel.git
synced 2025-09-02 21:27:48 -04:00
SDRdaemon: write UDP socket
This commit is contained in:
parent
75b505d012
commit
4697b13e60
@ -20,6 +20,7 @@
|
|||||||
// 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 "channel/sdrdaemondataqueue.h"
|
#include "channel/sdrdaemondataqueue.h"
|
||||||
#include "channel/sdrdaemondatablock.h"
|
#include "channel/sdrdaemondatablock.h"
|
||||||
@ -31,14 +32,18 @@ SDRDaemonChannelSinkThread::SDRDaemonChannelSinkThread(SDRDaemonDataQueue *dataQ
|
|||||||
QThread(parent),
|
QThread(parent),
|
||||||
m_running(false),
|
m_running(false),
|
||||||
m_dataQueue(dataQueue),
|
m_dataQueue(dataQueue),
|
||||||
m_cm256(cm256)
|
m_cm256(cm256),
|
||||||
|
m_address(QHostAddress::LocalHost),
|
||||||
|
m_port(9090)
|
||||||
{
|
{
|
||||||
|
m_socket = new QUdpSocket(this);
|
||||||
connect(m_dataQueue, SIGNAL(dataBlockEnqueued()), this, SLOT(handleData()));
|
connect(m_dataQueue, SIGNAL(dataBlockEnqueued()), this, SLOT(handleData()));
|
||||||
}
|
}
|
||||||
|
|
||||||
SDRDaemonChannelSinkThread::~SDRDaemonChannelSinkThread()
|
SDRDaemonChannelSinkThread::~SDRDaemonChannelSinkThread()
|
||||||
{
|
{
|
||||||
stopWork();
|
stopWork();
|
||||||
|
delete m_socket;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDRDaemonChannelSinkThread::startWork()
|
void SDRDaemonChannelSinkThread::startWork()
|
||||||
@ -69,7 +74,7 @@ void SDRDaemonChannelSinkThread::run()
|
|||||||
sleep(1); // Do nothing as everything is in the data handler (dequeuer)
|
sleep(1); // Do nothing as everything is in the data handler (dequeuer)
|
||||||
}
|
}
|
||||||
|
|
||||||
m_running = false;
|
m_running = false;
|
||||||
qDebug("SDRDaemonChannelSinkThread::run: end");
|
qDebug("SDRDaemonChannelSinkThread::run: end");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,7 +93,8 @@ bool SDRDaemonChannelSinkThread::handleDataBlock(SDRDaemonDataBlock& dataBlock)
|
|||||||
{
|
{
|
||||||
for (int i = 0; i < SDRDaemonNbOrginalBlocks; i++)
|
for (int i = 0; i < SDRDaemonNbOrginalBlocks; i++)
|
||||||
{
|
{
|
||||||
// TODO: send block via UDP here
|
// send block via UDP
|
||||||
|
m_socket->writeDatagram((const char*)&txBlockx[i], (qint64 ) SDRDaemonUdpSize, m_address, m_port);
|
||||||
usleep(txDelay);
|
usleep(txDelay);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -109,7 +115,7 @@ bool SDRDaemonChannelSinkThread::handleDataBlock(SDRDaemonDataBlock& dataBlock)
|
|||||||
txBlockx[i].m_header.m_blockIndex = i;
|
txBlockx[i].m_header.m_blockIndex = i;
|
||||||
descriptorBlocks[i].Block = (void *) &(txBlockx[i].m_protectedBlock);
|
descriptorBlocks[i].Block = (void *) &(txBlockx[i].m_protectedBlock);
|
||||||
descriptorBlocks[i].Index = txBlockx[i].m_header.m_blockIndex;
|
descriptorBlocks[i].Index = txBlockx[i].m_header.m_blockIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Encode FEC blocks
|
// Encode FEC blocks
|
||||||
if (m_cm256->cm256_encode(cm256Params, descriptorBlocks, fecBlocks))
|
if (m_cm256->cm256_encode(cm256Params, descriptorBlocks, fecBlocks))
|
||||||
@ -117,7 +123,7 @@ bool SDRDaemonChannelSinkThread::handleDataBlock(SDRDaemonDataBlock& dataBlock)
|
|||||||
qWarning("SDRDaemonChannelSinkThread::handleDataBlock: CM256 encode failed. No transmission.");
|
qWarning("SDRDaemonChannelSinkThread::handleDataBlock: CM256 encode failed. No transmission.");
|
||||||
// TODO: send without FEC changing meta data to set indication of no FEC
|
// TODO: send without FEC changing meta data to set indication of no FEC
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Merge FEC with data to transmit
|
// Merge FEC with data to transmit
|
||||||
for (int i = 0; i < cm256Params.RecoveryCount; i++)
|
for (int i = 0; i < cm256Params.RecoveryCount; i++)
|
||||||
@ -128,7 +134,8 @@ bool SDRDaemonChannelSinkThread::handleDataBlock(SDRDaemonDataBlock& dataBlock)
|
|||||||
// Transmit all blocks
|
// Transmit all blocks
|
||||||
for (int i = 0; i < cm256Params.OriginalCount + cm256Params.RecoveryCount; i++)
|
for (int i = 0; i < cm256Params.OriginalCount + cm256Params.RecoveryCount; i++)
|
||||||
{
|
{
|
||||||
// TODO: send block via UDP here
|
// send block via UDP
|
||||||
|
m_socket->writeDatagram((const char*)&txBlockx[i], (qint64 ) SDRDaemonUdpSize, m_address, m_port);
|
||||||
usleep(txDelay);
|
usleep(txDelay);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -147,5 +154,5 @@ void SDRDaemonChannelSinkThread::handleData()
|
|||||||
{
|
{
|
||||||
delete dataBlock;
|
delete dataBlock;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,10 +23,12 @@
|
|||||||
#include <QThread>
|
#include <QThread>
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
#include <QWaitCondition>
|
#include <QWaitCondition>
|
||||||
|
#include <QHostAddress>
|
||||||
|
|
||||||
class SDRDaemonDataQueue;
|
class SDRDaemonDataQueue;
|
||||||
class SDRDaemonDataBlock;
|
class SDRDaemonDataBlock;
|
||||||
class CM256;
|
class CM256;
|
||||||
|
class QUdpSocket;
|
||||||
|
|
||||||
class SDRDaemonChannelSinkThread : public QThread {
|
class SDRDaemonChannelSinkThread : public QThread {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -38,18 +40,24 @@ public:
|
|||||||
void startWork();
|
void startWork();
|
||||||
void stopWork();
|
void stopWork();
|
||||||
|
|
||||||
|
void setAddress(QString& address) { m_address.setAddress(address); }
|
||||||
|
void setPort(unsigned int port) { m_port = port; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QMutex m_startWaitMutex;
|
QMutex m_startWaitMutex;
|
||||||
QWaitCondition m_startWaiter;
|
QWaitCondition m_startWaiter;
|
||||||
bool m_running;
|
bool m_running;
|
||||||
|
|
||||||
SDRDaemonDataQueue *m_dataQueue;
|
SDRDaemonDataQueue *m_dataQueue;
|
||||||
|
|
||||||
CM256 *m_cm256; //!< CM256 library object
|
CM256 *m_cm256; //!< CM256 library object
|
||||||
|
|
||||||
|
QHostAddress m_address;
|
||||||
|
unsigned int m_port;
|
||||||
|
QUdpSocket *m_socket;
|
||||||
|
|
||||||
void run();
|
void run();
|
||||||
bool handleDataBlock(SDRDaemonDataBlock& dataBlock);
|
bool handleDataBlock(SDRDaemonDataBlock& dataBlock);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void handleData();
|
void handleData();
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user