1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2026-06-02 06:04:39 -04:00

SDRdaemon input: refactored plugin with nanomsg handling in core plugin

This commit is contained in:
f4exb
2017-12-26 02:18:30 +01:00
parent 9213b3c0b2
commit 6d70a644dd
8 changed files with 385 additions and 426 deletions
@@ -26,15 +26,17 @@
#include "sdrdaemonsourceinput.h"
#include "sdrdaemonsourceudphandler.h"
SDRdaemonSourceUDPHandler::SDRdaemonSourceUDPHandler(SampleSinkFifo *sampleFifo, DeviceSourceAPI *devieAPI) :
m_deviceAPI(devieAPI),
SDRdaemonSourceUDPHandler::SDRdaemonSourceUDPHandler(SampleSinkFifo *sampleFifo, DeviceSourceAPI *deviceAPI) :
m_deviceAPI(deviceAPI),
m_masterTimer(deviceAPI->getMasterTimer()),
m_masterTimerConnected(false),
m_running(false),
m_sdrDaemonBuffer(m_rateDivider),
m_dataSocket(0),
m_dataAddress(QHostAddress::LocalHost),
m_remoteAddress(QHostAddress::LocalHost),
m_dataPort(9090),
m_dataConnected(false),
m_startInit(true),
m_udpBuf(0),
m_udpReadBytes(0),
m_sampleFifo(sampleFifo),
@@ -54,6 +56,16 @@ SDRdaemonSourceUDPHandler::SDRdaemonSourceUDPHandler(SampleSinkFifo *sampleFifo,
m_autoCorrBuffer(true)
{
m_udpBuf = new char[SDRdaemonSourceBuffer::m_udpPayloadSize];
#ifdef USE_INTERNAL_TIMER
#warning "Uses internal timer"
m_timer = new QTimer();
m_timer->start(50);
m_throttlems = m_timer->interval();
#else
m_throttlems = m_masterTimer.interval();
#endif
m_rateDivider = 1000 / m_throttlems;
}
SDRdaemonSourceUDPHandler::~SDRdaemonSourceUDPHandler()
@@ -71,6 +83,10 @@ void SDRdaemonSourceUDPHandler::start()
{
qDebug("SDRdaemonSourceUDPHandler::start");
if (m_running) {
return;
}
if (!m_dataSocket)
{
m_dataSocket = new QUdpSocket(this);
@@ -93,16 +109,20 @@ void SDRdaemonSourceUDPHandler::start()
}
}
// Need to notify the DSP engine to actually start FIXME: may cause transient confusion because at this point sample rate and frequency are unknown
DSPSignalNotification *notif = new DSPSignalNotification(128000, 435000 * 1000); // Frequency in Hz for the DSP engine
m_deviceAPI->getDeviceEngineInputMessageQueue()->push(notif);
m_elapsedTimer.start();
m_running = true;
}
void SDRdaemonSourceUDPHandler::stop()
{
qDebug("SDRdaemonSourceUDPHandler::stop");
if (!m_running) {
return;
}
disconnectTimer();
if (m_dataConnected)
{
m_dataConnected = false;
@@ -115,7 +135,9 @@ void SDRdaemonSourceUDPHandler::stop()
m_dataSocket = 0;
}
m_startInit = true;
m_centerFrequency = 0;
m_samplerate = 0;
m_running = false;
}
void SDRdaemonSourceUDPHandler::configureUDPLink(const QString& address, quint16 port)
@@ -129,8 +151,8 @@ void SDRdaemonSourceUDPHandler::configureUDPLink(const QString& address, quint16
m_dataAddress = QHostAddress::LocalHost;
}
stop();
m_dataPort = port;
stop();
start();
}
@@ -154,10 +176,8 @@ void SDRdaemonSourceUDPHandler::processData()
{
m_sdrDaemonBuffer.writeData(m_udpBuf);
const SDRdaemonSourceBuffer::MetaDataFEC& metaData = m_sdrDaemonBuffer.getCurrentMeta();
bool change = false;
// m_tv_sec = metaData.m_tv_sec;
// m_tv_usec = metaData.m_tv_usec;
m_tv_sec = m_sdrDaemonBuffer.getTVOutSec();
m_tv_usec = m_sdrDaemonBuffer.getTVOutUsec();
@@ -173,14 +193,15 @@ void SDRdaemonSourceUDPHandler::processData()
change = true;
}
if (change || m_startInit)
if (change && (m_samplerate != 0) && (m_centerFrequency != 0))
{
qDebug("SDRdaemonSourceUDPHandler::processData: m_samplerate: %u m_centerFrequency: %u kHz", m_samplerate, m_centerFrequency);
if (m_samplerate != 0)
DSPSignalNotification *notif = new DSPSignalNotification(m_samplerate, m_centerFrequency * 1000); // Frequency in Hz for the DSP engine
m_deviceAPI->getDeviceEngineInputMessageQueue()->push(notif);
if (m_outputMessageQueueToGUI)
{
DSPSignalNotification *notif = new DSPSignalNotification(m_samplerate, m_centerFrequency * 1000); // Frequency in Hz for the DSP engine
m_deviceAPI->getDeviceEngineInputMessageQueue()->push(notif);
SDRdaemonSourceInput::MsgReportSDRdaemonSourceStreamData *report = SDRdaemonSourceInput::MsgReportSDRdaemonSourceStreamData::create(
m_samplerate,
m_centerFrequency * 1000, // Frequency in Hz for the GUI
@@ -188,25 +209,40 @@ void SDRdaemonSourceUDPHandler::processData()
m_tv_usec);
m_outputMessageQueueToGUI->push(report);
m_startInit = false;
}
connectTimer();
}
}
void SDRdaemonSourceUDPHandler::connectTimer(const QTimer* timer)
void SDRdaemonSourceUDPHandler::connectTimer()
{
qDebug() << "SDRdaemonSourceUDPHandler::connectTimer";
if (!m_masterTimerConnected)
{
qDebug() << "SDRdaemonSourceUDPHandler::connectTimer";
#ifdef USE_INTERNAL_TIMER
#warning "Uses internal timer"
m_timer = new QTimer();
m_timer->start(50);
m_throttlems = m_timer->interval();
connect(m_timer, SIGNAL(timeout()), this, SLOT(tick()));
connect(m_timer, SIGNAL(timeout()), this, SLOT(tick()));
#else
m_throttlems = timer->interval();
connect(timer, SIGNAL(timeout()), this, SLOT(tick()));
connect(&m_masterTimer, SIGNAL(timeout()), this, SLOT(tick()));
#endif
m_rateDivider = 1000 / m_throttlems;
m_masterTimerConnected = true;
}
}
void SDRdaemonSourceUDPHandler::disconnectTimer()
{
if (m_masterTimerConnected)
{
qDebug() << "SDRdaemonSourceUDPHandler::disconnectTimer";
#ifdef USE_INTERNAL_TIMER
#warning "Uses internal timer"
disconnect(m_timer, SIGNAL(timeout()), this, SLOT(tick()));
#else
disconnect(&m_masterTimer, SIGNAL(timeout()), this, SLOT(tick()));
#endif
m_masterTimerConnected = false;
}
}
void SDRdaemonSourceUDPHandler::tick()
@@ -237,24 +273,25 @@ void SDRdaemonSourceUDPHandler::tick()
}
else
{
int framesDecodingStatus;
int minNbBlocks = m_sdrDaemonBuffer.getMinNbBlocks();
int minNbOriginalBlocks = m_sdrDaemonBuffer.getMinOriginalBlocks();
int nbOriginalBlocks = m_sdrDaemonBuffer.getCurrentMeta().m_nbOriginalBlocks;
int nbFECblocks = m_sdrDaemonBuffer.getCurrentMeta().m_nbFECBlocks;
m_tickCount = 0;
//framesDecodingStatus = (minNbOriginalBlocks == nbOriginalBlocks ? 2 : (minNbOriginalBlocks < nbOriginalBlocks - nbFECblocks ? 0 : 1));
if (minNbBlocks < nbOriginalBlocks) {
framesDecodingStatus = 0;
} else if (minNbBlocks < nbOriginalBlocks + nbFECblocks) {
framesDecodingStatus = 1;
} else {
framesDecodingStatus = 2;
}
if (m_outputMessageQueueToGUI)
{
int framesDecodingStatus;
int minNbBlocks = m_sdrDaemonBuffer.getMinNbBlocks();
int minNbOriginalBlocks = m_sdrDaemonBuffer.getMinOriginalBlocks();
int nbOriginalBlocks = m_sdrDaemonBuffer.getCurrentMeta().m_nbOriginalBlocks;
int nbFECblocks = m_sdrDaemonBuffer.getCurrentMeta().m_nbFECBlocks;
//framesDecodingStatus = (minNbOriginalBlocks == nbOriginalBlocks ? 2 : (minNbOriginalBlocks < nbOriginalBlocks - nbFECblocks ? 0 : 1));
if (minNbBlocks < nbOriginalBlocks) {
framesDecodingStatus = 0;
} else if (minNbBlocks < nbOriginalBlocks + nbFECblocks) {
framesDecodingStatus = 1;
} else {
framesDecodingStatus = 2;
}
SDRdaemonSourceInput::MsgReportSDRdaemonSourceStreamTiming *report = SDRdaemonSourceInput::MsgReportSDRdaemonSourceStreamTiming::create(
m_tv_sec,
m_tv_usec,