diff --git a/sdrdaemon/channel/sdrdaemonchannelsink.cpp b/sdrdaemon/channel/sdrdaemonchannelsink.cpp index 9a656db67..9b4a270fc 100644 --- a/sdrdaemon/channel/sdrdaemonchannelsink.cpp +++ b/sdrdaemon/channel/sdrdaemonchannelsink.cpp @@ -49,7 +49,9 @@ SDRDaemonChannelSink::SDRDaemonChannelSink(DeviceSourceAPI *deviceAPI) : m_sampleRate(48000), m_sampleBytes(SDR_RX_SAMP_SZ == 24 ? 4 : 2), m_nbBlocksFEC(0), - m_txDelay(100) + m_txDelay(100), + m_dataAddress("127.0.0.1"), + m_dataPort(9090) { setObjectName(m_channelId); @@ -170,6 +172,8 @@ void SDRDaemonChannelSink::feed(const SampleVector::const_iterator& begin, const m_dataBlock->m_controlBlock.m_complete = true; m_dataBlock->m_controlBlock.m_nbBlocksFEC = m_nbBlocksFEC; m_dataBlock->m_controlBlock.m_txDelay = m_txDelay; + m_dataBlock->m_controlBlock.m_dataAddress = m_dataAddress; + m_dataBlock->m_controlBlock.m_dataPort = m_dataPort; m_dataQueue.push(m_dataBlock); m_dataBlock = new SDRDaemonDataBlock(); // create a new one immediately diff --git a/sdrdaemon/channel/sdrdaemonchannelsink.h b/sdrdaemon/channel/sdrdaemonchannelsink.h index 810954cbb..11c7a7841 100644 --- a/sdrdaemon/channel/sdrdaemonchannelsink.h +++ b/sdrdaemon/channel/sdrdaemonchannelsink.h @@ -64,6 +64,8 @@ public: void setNbBlocksFEC(int nbBlocksFEC); void setTxDelay(int txDelay); + void setDataAddress(const QString& address) { m_dataAddress = address; } + void setDataPort(uint16_t port) { m_dataPort = port; } static const QString m_channelIdURI; static const QString m_channelId; @@ -92,6 +94,8 @@ private: uint8_t m_sampleBytes; int m_nbBlocksFEC; int m_txDelay; + QString m_dataAddress; + uint16_t m_dataPort; }; #endif /* SDRDAEMON_CHANNEL_SDRDAEMONCHANNELSINK_H_ */ diff --git a/sdrdaemon/channel/sdrdaemonchannelsinkthread.cpp b/sdrdaemon/channel/sdrdaemonchannelsinkthread.cpp index 4333cd96b..e975dddcb 100644 --- a/sdrdaemon/channel/sdrdaemonchannelsinkthread.cpp +++ b/sdrdaemon/channel/sdrdaemonchannelsinkthread.cpp @@ -36,7 +36,7 @@ SDRDaemonChannelSinkThread::SDRDaemonChannelSinkThread(SDRDaemonDataQueue *dataQ m_dataQueue(dataQueue), m_cm256(cm256), m_address(QHostAddress::LocalHost), - m_port(9090) + m_socket(0) { connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()), Qt::QueuedConnection); connect(m_dataQueue, SIGNAL(dataBlockEnqueued()), this, SLOT(handleData()), Qt::QueuedConnection); @@ -68,6 +68,7 @@ void SDRDaemonChannelSinkThread::stopWork() { qDebug("SDRDaemonChannelSinkThread::stopWork"); delete m_socket; + m_socket = 0; m_running = false; wait(); } @@ -96,15 +97,20 @@ bool SDRDaemonChannelSinkThread::handleDataBlock(SDRDaemonDataBlock& dataBlock) uint16_t frameIndex = dataBlock.m_controlBlock.m_frameIndex; int nbBlocksFEC = dataBlock.m_controlBlock.m_nbBlocksFEC; int txDelay = dataBlock.m_controlBlock.m_txDelay; + m_address.setAddress(dataBlock.m_controlBlock.m_dataAddress); + uint16_t dataPort = dataBlock.m_controlBlock.m_dataPort; SDRDaemonSuperBlock *txBlockx = dataBlock.m_superBlocks; if ((nbBlocksFEC == 0) || !m_cm256) // Do not FEC encode { - for (int i = 0; i < SDRDaemonNbOrginalBlocks; i++) + if (m_socket) { - // send block via UDP - m_socket->writeDatagram((const char*)&txBlockx[i], (qint64 ) SDRDaemonUdpSize, m_address, m_port); - usleep(txDelay); + for (int i = 0; i < SDRDaemonNbOrginalBlocks; i++) + { + // send block via UDP + m_socket->writeDatagram((const char*)&txBlockx[i], (qint64 ) SDRDaemonUdpSize, m_address, dataPort); + usleep(txDelay); + } } } else @@ -141,11 +147,14 @@ bool SDRDaemonChannelSinkThread::handleDataBlock(SDRDaemonDataBlock& dataBlock) } // Transmit all blocks - for (int i = 0; i < cm256Params.OriginalCount + cm256Params.RecoveryCount; i++) + if (m_socket) { - // send block via UDP - m_socket->writeDatagram((const char*)&txBlockx[i], (qint64 ) SDRDaemonUdpSize, m_address, m_port); - usleep(txDelay); + for (int i = 0; i < cm256Params.OriginalCount + cm256Params.RecoveryCount; i++) + { + // send block via UDP + m_socket->writeDatagram((const char*)&txBlockx[i], (qint64 ) SDRDaemonUdpSize, m_address, dataPort); + usleep(txDelay); + } } } diff --git a/sdrdaemon/channel/sdrdaemonchannelsinkthread.h b/sdrdaemon/channel/sdrdaemonchannelsinkthread.h index 375dda954..1f4e655e5 100644 --- a/sdrdaemon/channel/sdrdaemonchannelsinkthread.h +++ b/sdrdaemon/channel/sdrdaemonchannelsinkthread.h @@ -61,9 +61,6 @@ public: void startStop(bool start); - void setAddress(QString& address) { m_address.setAddress(address); } - void setPort(unsigned int port) { m_port = port; } - private: QMutex m_startWaitMutex; QWaitCondition m_startWaiter; @@ -73,7 +70,6 @@ private: CM256 *m_cm256; //!< CM256 library object QHostAddress m_address; - unsigned int m_port; QUdpSocket *m_socket; MessageQueue m_inputMessageQueue; diff --git a/sdrdaemon/channel/sdrdaemondatablock.h b/sdrdaemon/channel/sdrdaemondatablock.h index 2bb9f28f4..b8aec1a71 100644 --- a/sdrdaemon/channel/sdrdaemondatablock.h +++ b/sdrdaemon/channel/sdrdaemondatablock.h @@ -70,12 +70,12 @@ struct SDRDaemonHeader uint8_t m_blockIndex; uint8_t m_filler; - void init() + void init() { m_frameIndex = 0; m_blockIndex = 0; m_filler = 0; - } + } }; static const int SDRDaemonUdpSize = UDPSINKFEC_UDPSIZE; @@ -111,6 +111,8 @@ struct SDRDaemonTxControlBlock uint16_t m_frameIndex; int m_nbBlocksFEC; int m_txDelay; + QString m_dataAddress; + uint16_t m_dataPort; SDRDaemonTxControlBlock() { m_complete = false; @@ -118,6 +120,8 @@ struct SDRDaemonTxControlBlock m_frameIndex = 0; m_nbBlocksFEC = 0; m_txDelay = 100; + m_dataAddress = "127.0.0.1"; + m_dataPort = 9090; } }; diff --git a/sdrdaemon/sdrdaemonmain.cpp b/sdrdaemon/sdrdaemonmain.cpp index 486ba0efb..963388adf 100644 --- a/sdrdaemon/sdrdaemonmain.cpp +++ b/sdrdaemon/sdrdaemonmain.cpp @@ -132,6 +132,8 @@ SDRDaemonMain::SDRDaemonMain(qtwebapp::LoggerWithFile *logger, const SDRDaemonPa m_channelSink = new SDRDaemonChannelSink(m_deviceSourceAPI); m_channelSink->setNbBlocksFEC(parser.getNbBlocksFEC()); m_channelSink->setTxDelay(parser.getTxDelay()); + m_channelSink->setDataAddress(parser.getDataAddress()); + m_channelSink->setDataPort(parser.getDataPort()); } else {