mirror of
https://github.com/f4exb/sdrangel.git
synced 2025-07-31 05:02:24 -04:00
SDRdaemon: channel sink thread: handle socket life cycle appropriately
This commit is contained in:
parent
a8f53ec70b
commit
716a77eeb2
@ -113,7 +113,7 @@ void SDRDaemonChannelSink::feed(const SampleVector::const_iterator& begin, const
|
|||||||
if (!m_dataBlock) { // on the very first cycle there is no data block allocated
|
if (!m_dataBlock) { // on the very first cycle there is no data block allocated
|
||||||
m_dataBlock = new SDRDaemonDataBlock();
|
m_dataBlock = new SDRDaemonDataBlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::crc_32_type crc32;
|
boost::crc_32_type crc32;
|
||||||
crc32.process_bytes(&metaData, 20);
|
crc32.process_bytes(&metaData, 20);
|
||||||
metaData.m_crc32 = crc32.checksum();
|
metaData.m_crc32 = crc32.checksum();
|
||||||
@ -182,7 +182,7 @@ void SDRDaemonChannelSink::feed(const SampleVector::const_iterator& begin, const
|
|||||||
{
|
{
|
||||||
m_txBlockIndex++;
|
m_txBlockIndex++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,27 +191,27 @@ void SDRDaemonChannelSink::start()
|
|||||||
qDebug("SDRDaemonChannelSink::start");
|
qDebug("SDRDaemonChannelSink::start");
|
||||||
|
|
||||||
memset((void *) &m_currentMetaFEC, 0, sizeof(SDRDaemonMetaDataFEC));
|
memset((void *) &m_currentMetaFEC, 0, sizeof(SDRDaemonMetaDataFEC));
|
||||||
|
|
||||||
if (m_running) {
|
if (m_running) {
|
||||||
stop();
|
stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_sinkThread = new SDRDaemonChannelSinkThread(&m_dataQueue, m_cm256p);
|
m_sinkThread = new SDRDaemonChannelSinkThread(&m_dataQueue, m_cm256p);
|
||||||
m_sinkThread->startWork();
|
m_sinkThread->startStop(true);
|
||||||
m_running = true;
|
m_running = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDRDaemonChannelSink::stop()
|
void SDRDaemonChannelSink::stop()
|
||||||
{
|
{
|
||||||
qDebug("SDRDaemonChannelSink::stop");
|
qDebug("SDRDaemonChannelSink::stop");
|
||||||
|
|
||||||
if (m_sinkThread != 0)
|
if (m_sinkThread != 0)
|
||||||
{
|
{
|
||||||
m_sinkThread->stopWork();
|
m_sinkThread->startStop(false);
|
||||||
delete m_sinkThread;
|
m_sinkThread->deleteLater();
|
||||||
m_sinkThread = 0;
|
m_sinkThread = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_running = false;
|
m_running = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -224,7 +224,7 @@ bool SDRDaemonChannelSink::handleMessage(const Message& cmd __attribute__((unuse
|
|||||||
qDebug() << "SDRDaemonChannelSink::handleMessage: MsgChannelizerNotification:"
|
qDebug() << "SDRDaemonChannelSink::handleMessage: MsgChannelizerNotification:"
|
||||||
<< " channelSampleRate: " << notif.getSampleRate()
|
<< " channelSampleRate: " << notif.getSampleRate()
|
||||||
<< " offsetFrequency: " << notif.getFrequencyOffset();
|
<< " offsetFrequency: " << notif.getFrequencyOffset();
|
||||||
|
|
||||||
if (notif.getSampleRate() > 0) {
|
if (notif.getSampleRate() > 0) {
|
||||||
setSampleRate(notif.getSampleRate());
|
setSampleRate(notif.getSampleRate());
|
||||||
}
|
}
|
||||||
@ -238,7 +238,7 @@ bool SDRDaemonChannelSink::handleMessage(const Message& cmd __attribute__((unuse
|
|||||||
qDebug() << "SDRDaemonChannelSink::handleMessage: DSPSignalNotification:"
|
qDebug() << "SDRDaemonChannelSink::handleMessage: DSPSignalNotification:"
|
||||||
<< " inputSampleRate: " << notif.getSampleRate()
|
<< " inputSampleRate: " << notif.getSampleRate()
|
||||||
<< " centerFrequency: " << notif.getCenterFrequency();
|
<< " centerFrequency: " << notif.getCenterFrequency();
|
||||||
|
|
||||||
setCenterFrequency(notif.getCenterFrequency());
|
setCenterFrequency(notif.getCenterFrequency());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -246,7 +246,7 @@ bool SDRDaemonChannelSink::handleMessage(const Message& cmd __attribute__((unuse
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray SDRDaemonChannelSink::serialize() const
|
QByteArray SDRDaemonChannelSink::serialize() const
|
||||||
|
@ -28,6 +28,8 @@
|
|||||||
|
|
||||||
#include "cm256.h"
|
#include "cm256.h"
|
||||||
|
|
||||||
|
MESSAGE_CLASS_DEFINITION(SDRDaemonChannelSinkThread::MsgStartStop, Message)
|
||||||
|
|
||||||
SDRDaemonChannelSinkThread::SDRDaemonChannelSinkThread(SDRDaemonDataQueue *dataQueue, CM256 *cm256, QObject* parent) :
|
SDRDaemonChannelSinkThread::SDRDaemonChannelSinkThread(SDRDaemonDataQueue *dataQueue, CM256 *cm256, QObject* parent) :
|
||||||
QThread(parent),
|
QThread(parent),
|
||||||
m_running(false),
|
m_running(false),
|
||||||
@ -36,20 +38,26 @@ SDRDaemonChannelSinkThread::SDRDaemonChannelSinkThread(SDRDaemonDataQueue *dataQ
|
|||||||
m_address(QHostAddress::LocalHost),
|
m_address(QHostAddress::LocalHost),
|
||||||
m_port(9090)
|
m_port(9090)
|
||||||
{
|
{
|
||||||
m_socket = new QUdpSocket(this);
|
connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()), Qt::QueuedConnection);
|
||||||
connect(m_dataQueue, SIGNAL(dataBlockEnqueued()), this, SLOT(handleData()), Qt::QueuedConnection);
|
connect(m_dataQueue, SIGNAL(dataBlockEnqueued()), this, SLOT(handleData()), Qt::QueuedConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
SDRDaemonChannelSinkThread::~SDRDaemonChannelSinkThread()
|
SDRDaemonChannelSinkThread::~SDRDaemonChannelSinkThread()
|
||||||
{
|
{
|
||||||
stopWork();
|
qDebug("SDRDaemonChannelSinkThread::~SDRDaemonChannelSinkThread");
|
||||||
delete m_socket;
|
}
|
||||||
|
|
||||||
|
void SDRDaemonChannelSinkThread::startStop(bool start)
|
||||||
|
{
|
||||||
|
MsgStartStop *msg = MsgStartStop::create(start);
|
||||||
|
m_inputMessageQueue.push(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDRDaemonChannelSinkThread::startWork()
|
void SDRDaemonChannelSinkThread::startWork()
|
||||||
{
|
{
|
||||||
qDebug("SDRDaemonChannelSinkThread::startWork");
|
qDebug("SDRDaemonChannelSinkThread::startWork");
|
||||||
m_startWaitMutex.lock();
|
m_startWaitMutex.lock();
|
||||||
|
m_socket = new QUdpSocket(this);
|
||||||
start();
|
start();
|
||||||
while(!m_running)
|
while(!m_running)
|
||||||
m_startWaiter.wait(&m_startWaitMutex, 100);
|
m_startWaiter.wait(&m_startWaitMutex, 100);
|
||||||
@ -59,6 +67,7 @@ void SDRDaemonChannelSinkThread::startWork()
|
|||||||
void SDRDaemonChannelSinkThread::stopWork()
|
void SDRDaemonChannelSinkThread::stopWork()
|
||||||
{
|
{
|
||||||
qDebug("SDRDaemonChannelSinkThread::stopWork");
|
qDebug("SDRDaemonChannelSinkThread::stopWork");
|
||||||
|
delete m_socket;
|
||||||
m_running = false;
|
m_running = false;
|
||||||
wait();
|
wait();
|
||||||
}
|
}
|
||||||
@ -156,3 +165,25 @@ void SDRDaemonChannelSinkThread::handleData()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SDRDaemonChannelSinkThread::handleInputMessages()
|
||||||
|
{
|
||||||
|
Message* message;
|
||||||
|
|
||||||
|
while ((message = m_inputMessageQueue.pop()) != 0)
|
||||||
|
{
|
||||||
|
if (MsgStartStop::match(*message))
|
||||||
|
{
|
||||||
|
MsgStartStop* notif = (MsgStartStop*) message;
|
||||||
|
qDebug("SDRDaemonChannelSinkThread::handleInputMessages: MsgStartStop: %s", notif->getStartStop() ? "start" : "stop");
|
||||||
|
|
||||||
|
if (notif->getStartStop()) {
|
||||||
|
startWork();
|
||||||
|
} else {
|
||||||
|
stopWork();
|
||||||
|
}
|
||||||
|
|
||||||
|
delete message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -25,6 +25,9 @@
|
|||||||
#include <QWaitCondition>
|
#include <QWaitCondition>
|
||||||
#include <QHostAddress>
|
#include <QHostAddress>
|
||||||
|
|
||||||
|
#include "util/message.h"
|
||||||
|
#include "util/messagequeue.h"
|
||||||
|
|
||||||
class SDRDaemonDataQueue;
|
class SDRDaemonDataQueue;
|
||||||
class SDRDaemonDataBlock;
|
class SDRDaemonDataBlock;
|
||||||
class CM256;
|
class CM256;
|
||||||
@ -34,11 +37,29 @@ class SDRDaemonChannelSinkThread : public QThread {
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
class MsgStartStop : public Message {
|
||||||
|
MESSAGE_CLASS_DECLARATION
|
||||||
|
|
||||||
|
public:
|
||||||
|
bool getStartStop() const { return m_startStop; }
|
||||||
|
|
||||||
|
static MsgStartStop* create(bool startStop) {
|
||||||
|
return new MsgStartStop(startStop);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool m_startStop;
|
||||||
|
|
||||||
|
MsgStartStop(bool startStop) :
|
||||||
|
Message(),
|
||||||
|
m_startStop(startStop)
|
||||||
|
{ }
|
||||||
|
};
|
||||||
|
|
||||||
SDRDaemonChannelSinkThread(SDRDaemonDataQueue *dataQueue, CM256 *cm256, QObject* parent = 0);
|
SDRDaemonChannelSinkThread(SDRDaemonDataQueue *dataQueue, CM256 *cm256, QObject* parent = 0);
|
||||||
~SDRDaemonChannelSinkThread();
|
~SDRDaemonChannelSinkThread();
|
||||||
|
|
||||||
void startWork();
|
void startStop(bool start);
|
||||||
void stopWork();
|
|
||||||
|
|
||||||
void setAddress(QString& address) { m_address.setAddress(address); }
|
void setAddress(QString& address) { m_address.setAddress(address); }
|
||||||
void setPort(unsigned int port) { m_port = port; }
|
void setPort(unsigned int port) { m_port = port; }
|
||||||
@ -55,9 +76,15 @@ private:
|
|||||||
unsigned int m_port;
|
unsigned int m_port;
|
||||||
QUdpSocket *m_socket;
|
QUdpSocket *m_socket;
|
||||||
|
|
||||||
|
MessageQueue m_inputMessageQueue;
|
||||||
|
|
||||||
|
void startWork();
|
||||||
|
void stopWork();
|
||||||
|
|
||||||
void run();
|
void run();
|
||||||
bool handleDataBlock(SDRDaemonDataBlock& dataBlock);
|
bool handleDataBlock(SDRDaemonDataBlock& dataBlock);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void handleData();
|
void handleData();
|
||||||
|
void handleInputMessages();
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user