mirror of
https://github.com/f4exb/sdrangel.git
synced 2025-06-25 05:25:27 -04:00
Chirpchat demod: updated threading model. Part of #1346
This commit is contained in:
parent
c9dad59438
commit
aab8b0f15d
@ -52,6 +52,9 @@ const char* const ChirpChatDemod::m_channelId = "ChirpChatDemod";
|
|||||||
ChirpChatDemod::ChirpChatDemod(DeviceAPI* deviceAPI) :
|
ChirpChatDemod::ChirpChatDemod(DeviceAPI* deviceAPI) :
|
||||||
ChannelAPI(m_channelIdURI, ChannelAPI::StreamSingleSink),
|
ChannelAPI(m_channelIdURI, ChannelAPI::StreamSingleSink),
|
||||||
m_deviceAPI(deviceAPI),
|
m_deviceAPI(deviceAPI),
|
||||||
|
m_thread(nullptr),
|
||||||
|
m_basebandSink(nullptr),
|
||||||
|
m_running(false),
|
||||||
m_spectrumVis(SDR_RX_SCALEF),
|
m_spectrumVis(SDR_RX_SCALEF),
|
||||||
m_basebandSampleRate(0),
|
m_basebandSampleRate(0),
|
||||||
m_lastMsgSignalDb(0.0),
|
m_lastMsgSignalDb(0.0),
|
||||||
@ -70,13 +73,6 @@ ChirpChatDemod::ChirpChatDemod(DeviceAPI* deviceAPI) :
|
|||||||
m_udpSink(this, 256)
|
m_udpSink(this, 256)
|
||||||
{
|
{
|
||||||
setObjectName(m_channelId);
|
setObjectName(m_channelId);
|
||||||
|
|
||||||
m_thread = new QThread(this);
|
|
||||||
m_basebandSink = new ChirpChatDemodBaseband();
|
|
||||||
m_basebandSink->setSpectrumSink(&m_spectrumVis);
|
|
||||||
m_basebandSink->setDecoderMessageQueue(getInputMessageQueue()); // Decoder held on the main thread
|
|
||||||
m_basebandSink->moveToThread(m_thread);
|
|
||||||
|
|
||||||
applySettings(m_settings, true);
|
applySettings(m_settings, true);
|
||||||
|
|
||||||
m_deviceAPI->addChannelSink(this);
|
m_deviceAPI->addChannelSink(this);
|
||||||
@ -88,14 +84,15 @@ ChirpChatDemod::ChirpChatDemod(DeviceAPI* deviceAPI) :
|
|||||||
this,
|
this,
|
||||||
&ChirpChatDemod::handleIndexInDeviceSetChanged
|
&ChirpChatDemod::handleIndexInDeviceSetChanged
|
||||||
);
|
);
|
||||||
|
|
||||||
|
start();
|
||||||
}
|
}
|
||||||
|
|
||||||
ChirpChatDemod::~ChirpChatDemod()
|
ChirpChatDemod::~ChirpChatDemod()
|
||||||
{
|
{
|
||||||
m_deviceAPI->removeChannelSinkAPI(this);
|
m_deviceAPI->removeChannelSinkAPI(this);
|
||||||
m_deviceAPI->removeChannelSink(this);
|
m_deviceAPI->removeChannelSink(this);
|
||||||
delete m_basebandSink;
|
stop();
|
||||||
delete m_thread;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChirpChatDemod::setDeviceAPI(DeviceAPI *deviceAPI)
|
void ChirpChatDemod::setDeviceAPI(DeviceAPI *deviceAPI)
|
||||||
@ -118,12 +115,27 @@ uint32_t ChirpChatDemod::getNumberOfDeviceStreams() const
|
|||||||
void ChirpChatDemod::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool pO)
|
void ChirpChatDemod::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool pO)
|
||||||
{
|
{
|
||||||
(void) pO;
|
(void) pO;
|
||||||
|
|
||||||
|
if (m_running) {
|
||||||
m_basebandSink->feed(begin, end);
|
m_basebandSink->feed(begin, end);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChirpChatDemod::start()
|
void ChirpChatDemod::start()
|
||||||
{
|
{
|
||||||
|
if (m_running) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
qDebug() << "ChirpChatDemod::start";
|
qDebug() << "ChirpChatDemod::start";
|
||||||
|
m_thread = new QThread(this);
|
||||||
|
m_basebandSink = new ChirpChatDemodBaseband();
|
||||||
|
m_basebandSink->setSpectrumSink(&m_spectrumVis);
|
||||||
|
m_basebandSink->setDecoderMessageQueue(getInputMessageQueue()); // Decoder held on the main thread
|
||||||
|
m_basebandSink->moveToThread(m_thread);
|
||||||
|
|
||||||
|
QObject::connect(m_thread, &QThread::finished, m_basebandSink, &QObject::deleteLater);
|
||||||
|
QObject::connect(m_thread, &QThread::finished, m_thread, &QThread::deleteLater);
|
||||||
|
|
||||||
if (m_basebandSampleRate != 0) {
|
if (m_basebandSampleRate != 0) {
|
||||||
m_basebandSink->setBasebandSampleRate(m_basebandSampleRate);
|
m_basebandSink->setBasebandSampleRate(m_basebandSampleRate);
|
||||||
@ -135,11 +147,19 @@ void ChirpChatDemod::start()
|
|||||||
SpectrumSettings spectrumSettings = m_spectrumVis.getSettings();
|
SpectrumSettings spectrumSettings = m_spectrumVis.getSettings();
|
||||||
spectrumSettings.m_ssb = true;
|
spectrumSettings.m_ssb = true;
|
||||||
SpectrumVis::MsgConfigureSpectrumVis *msg = SpectrumVis::MsgConfigureSpectrumVis::create(spectrumSettings, false);
|
SpectrumVis::MsgConfigureSpectrumVis *msg = SpectrumVis::MsgConfigureSpectrumVis::create(spectrumSettings, false);
|
||||||
m_spectrumVis.getInputMessageQueue()->push(msg);}
|
m_spectrumVis.getInputMessageQueue()->push(msg);
|
||||||
|
|
||||||
|
m_running = true;
|
||||||
|
}
|
||||||
|
|
||||||
void ChirpChatDemod::stop()
|
void ChirpChatDemod::stop()
|
||||||
{
|
{
|
||||||
|
if (!m_running) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
qDebug() << "ChirpChatDemod::stop";
|
qDebug() << "ChirpChatDemod::stop";
|
||||||
|
m_running = false;
|
||||||
m_thread->exit();
|
m_thread->exit();
|
||||||
m_thread->wait();
|
m_thread->wait();
|
||||||
}
|
}
|
||||||
@ -293,10 +313,14 @@ bool ChirpChatDemod::handleMessage(const Message& cmd)
|
|||||||
{
|
{
|
||||||
DSPSignalNotification& notif = (DSPSignalNotification&) cmd;
|
DSPSignalNotification& notif = (DSPSignalNotification&) cmd;
|
||||||
m_basebandSampleRate = notif.getSampleRate();
|
m_basebandSampleRate = notif.getSampleRate();
|
||||||
// Forward to the sink
|
|
||||||
DSPSignalNotification* rep = new DSPSignalNotification(notif); // make a copy
|
|
||||||
qDebug() << "ChirpChatDemod::handleMessage: DSPSignalNotification: m_basebandSampleRate: " << m_basebandSampleRate;
|
qDebug() << "ChirpChatDemod::handleMessage: DSPSignalNotification: m_basebandSampleRate: " << m_basebandSampleRate;
|
||||||
|
|
||||||
|
// Forward to the sink
|
||||||
|
if (m_running)
|
||||||
|
{
|
||||||
|
DSPSignalNotification* rep = new DSPSignalNotification(notif); // make a copy
|
||||||
m_basebandSink->getInputMessageQueue()->push(rep);
|
m_basebandSink->getInputMessageQueue()->push(rep);
|
||||||
|
}
|
||||||
|
|
||||||
if (getMessageQueueToGUI()) {
|
if (getMessageQueueToGUI()) {
|
||||||
getMessageQueueToGUI()->push(new DSPSignalNotification(notif)); // make a copy
|
getMessageQueueToGUI()->push(new DSPSignalNotification(notif)); // make a copy
|
||||||
@ -475,9 +499,12 @@ void ChirpChatDemod::applySettings(const ChirpChatDemodSettings& settings, bool
|
|||||||
reverseAPIKeys.append("streamIndex");
|
reverseAPIKeys.append("streamIndex");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m_running)
|
||||||
|
{
|
||||||
ChirpChatDemodBaseband::MsgConfigureChirpChatDemodBaseband *msg =
|
ChirpChatDemodBaseband::MsgConfigureChirpChatDemodBaseband *msg =
|
||||||
ChirpChatDemodBaseband::MsgConfigureChirpChatDemodBaseband::create(settings, force);
|
ChirpChatDemodBaseband::MsgConfigureChirpChatDemodBaseband::create(settings, force);
|
||||||
m_basebandSink->getInputMessageQueue()->push(msg);
|
m_basebandSink->getInputMessageQueue()->push(msg);
|
||||||
|
}
|
||||||
|
|
||||||
if (settings.m_useReverseAPI)
|
if (settings.m_useReverseAPI)
|
||||||
{
|
{
|
||||||
@ -741,11 +768,14 @@ void ChirpChatDemod::webapiFormatChannelSettings(SWGSDRangel::SWGChannelSettings
|
|||||||
|
|
||||||
void ChirpChatDemod::webapiFormatChannelReport(SWGSDRangel::SWGChannelReport& response)
|
void ChirpChatDemod::webapiFormatChannelReport(SWGSDRangel::SWGChannelReport& response)
|
||||||
{
|
{
|
||||||
|
if (m_running) {
|
||||||
|
response.getChirpChatDemodReport()->setChannelSampleRate(m_basebandSink->getChannelSampleRate());
|
||||||
|
}
|
||||||
|
|
||||||
response.getChirpChatDemodReport()->setChannelPowerDb(CalcDb::dbPower(getTotalPower()));
|
response.getChirpChatDemodReport()->setChannelPowerDb(CalcDb::dbPower(getTotalPower()));
|
||||||
response.getChirpChatDemodReport()->setSignalPowerDb(m_lastMsgSignalDb);
|
response.getChirpChatDemodReport()->setSignalPowerDb(m_lastMsgSignalDb);
|
||||||
response.getChirpChatDemodReport()->setNoisePowerDb(CalcDb::dbPower(getCurrentNoiseLevel()));
|
response.getChirpChatDemodReport()->setNoisePowerDb(CalcDb::dbPower(getCurrentNoiseLevel()));
|
||||||
response.getChirpChatDemodReport()->setSnrPowerDb(m_lastMsgSignalDb - m_lastMsgNoiseDb);
|
response.getChirpChatDemodReport()->setSnrPowerDb(m_lastMsgSignalDb - m_lastMsgNoiseDb);
|
||||||
response.getChirpChatDemodReport()->setChannelSampleRate(m_basebandSink->getChannelSampleRate());
|
|
||||||
response.getChirpChatDemodReport()->setHasCrc(m_lastMsgHasCRC);
|
response.getChirpChatDemodReport()->setHasCrc(m_lastMsgHasCRC);
|
||||||
response.getChirpChatDemodReport()->setNbParityBits(m_lastMsgNbParityBits);
|
response.getChirpChatDemodReport()->setNbParityBits(m_lastMsgNbParityBits);
|
||||||
response.getChirpChatDemodReport()->setPacketLength(m_lastMsgPacketLength);
|
response.getChirpChatDemodReport()->setPacketLength(m_lastMsgPacketLength);
|
||||||
@ -938,22 +968,22 @@ void ChirpChatDemod::networkManagerFinished(QNetworkReply *reply)
|
|||||||
|
|
||||||
bool ChirpChatDemod::getDemodActive() const
|
bool ChirpChatDemod::getDemodActive() const
|
||||||
{
|
{
|
||||||
return m_basebandSink->getDemodActive();
|
return m_running ? m_basebandSink->getDemodActive() : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
double ChirpChatDemod::getCurrentNoiseLevel() const
|
double ChirpChatDemod::getCurrentNoiseLevel() const
|
||||||
{
|
{
|
||||||
return m_basebandSink->getCurrentNoiseLevel();
|
return m_running ? m_basebandSink->getCurrentNoiseLevel(): 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
double ChirpChatDemod::getTotalPower() const
|
double ChirpChatDemod::getTotalPower() const
|
||||||
{
|
{
|
||||||
return m_basebandSink->getTotalPower();
|
return m_running ? m_basebandSink->getTotalPower() : 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChirpChatDemod::handleIndexInDeviceSetChanged(int index)
|
void ChirpChatDemod::handleIndexInDeviceSetChanged(int index)
|
||||||
{
|
{
|
||||||
if (index < 0) {
|
if (!m_running || (index < 0)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -271,7 +271,8 @@ public:
|
|||||||
private:
|
private:
|
||||||
DeviceAPI *m_deviceAPI;
|
DeviceAPI *m_deviceAPI;
|
||||||
QThread *m_thread;
|
QThread *m_thread;
|
||||||
ChirpChatDemodBaseband* m_basebandSink;
|
ChirpChatDemodBaseband *m_basebandSink;
|
||||||
|
bool m_running;
|
||||||
ChirpChatDemodDecoder m_decoder;
|
ChirpChatDemodDecoder m_decoder;
|
||||||
ChirpChatDemodSettings m_settings;
|
ChirpChatDemodSettings m_settings;
|
||||||
SpectrumVis m_spectrumVis;
|
SpectrumVis m_spectrumVis;
|
||||||
|
@ -25,10 +25,10 @@
|
|||||||
|
|
||||||
MESSAGE_CLASS_DEFINITION(ChirpChatDemodBaseband::MsgConfigureChirpChatDemodBaseband, Message)
|
MESSAGE_CLASS_DEFINITION(ChirpChatDemodBaseband::MsgConfigureChirpChatDemodBaseband, Message)
|
||||||
|
|
||||||
ChirpChatDemodBaseband::ChirpChatDemodBaseband()
|
ChirpChatDemodBaseband::ChirpChatDemodBaseband() :
|
||||||
|
m_channelizer(&m_sink)
|
||||||
{
|
{
|
||||||
m_sampleFifo.setSize(SampleSinkFifo::getSizePolicy(48000));
|
m_sampleFifo.setSize(SampleSinkFifo::getSizePolicy(48000));
|
||||||
m_channelizer = new DownChannelizer(&m_sink);
|
|
||||||
|
|
||||||
qDebug("ChirpChatDemodBaseband::ChirpChatDemodBaseband");
|
qDebug("ChirpChatDemodBaseband::ChirpChatDemodBaseband");
|
||||||
QObject::connect(
|
QObject::connect(
|
||||||
@ -44,7 +44,6 @@ ChirpChatDemodBaseband::ChirpChatDemodBaseband()
|
|||||||
|
|
||||||
ChirpChatDemodBaseband::~ChirpChatDemodBaseband()
|
ChirpChatDemodBaseband::~ChirpChatDemodBaseband()
|
||||||
{
|
{
|
||||||
delete m_channelizer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChirpChatDemodBaseband::reset()
|
void ChirpChatDemodBaseband::reset()
|
||||||
@ -73,12 +72,12 @@ void ChirpChatDemodBaseband::handleData()
|
|||||||
|
|
||||||
// first part of FIFO data
|
// first part of FIFO data
|
||||||
if (part1begin != part1end) {
|
if (part1begin != part1end) {
|
||||||
m_channelizer->feed(part1begin, part1end);
|
m_channelizer.feed(part1begin, part1end);
|
||||||
}
|
}
|
||||||
|
|
||||||
// second part of FIFO data (used when block wraps around)
|
// second part of FIFO data (used when block wraps around)
|
||||||
if(part2begin != part2end) {
|
if(part2begin != part2end) {
|
||||||
m_channelizer->feed(part2begin, part2end);
|
m_channelizer.feed(part2begin, part2end);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_sampleFifo.readCommit((unsigned int) count);
|
m_sampleFifo.readCommit((unsigned int) count);
|
||||||
@ -115,11 +114,11 @@ bool ChirpChatDemodBaseband::handleMessage(const Message& cmd)
|
|||||||
DSPSignalNotification& notif = (DSPSignalNotification&) cmd;
|
DSPSignalNotification& notif = (DSPSignalNotification&) cmd;
|
||||||
qDebug() << "ChirpChatDemodBaseband::handleMessage: DSPSignalNotification: basebandSampleRate: " << notif.getSampleRate();
|
qDebug() << "ChirpChatDemodBaseband::handleMessage: DSPSignalNotification: basebandSampleRate: " << notif.getSampleRate();
|
||||||
m_sampleFifo.setSize(SampleSinkFifo::getSizePolicy(notif.getSampleRate()));
|
m_sampleFifo.setSize(SampleSinkFifo::getSizePolicy(notif.getSampleRate()));
|
||||||
m_channelizer->setBasebandSampleRate(notif.getSampleRate());
|
m_channelizer.setBasebandSampleRate(notif.getSampleRate());
|
||||||
m_sink.applyChannelSettings(
|
m_sink.applyChannelSettings(
|
||||||
m_channelizer->getChannelSampleRate(),
|
m_channelizer.getChannelSampleRate(),
|
||||||
ChirpChatDemodSettings::bandwidths[m_settings.m_bandwidthIndex],
|
ChirpChatDemodSettings::bandwidths[m_settings.m_bandwidthIndex],
|
||||||
m_channelizer->getChannelFrequencyOffset()
|
m_channelizer.getChannelFrequencyOffset()
|
||||||
);
|
);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -135,14 +134,14 @@ void ChirpChatDemodBaseband::applySettings(const ChirpChatDemodSettings& setting
|
|||||||
if ((settings.m_bandwidthIndex != m_settings.m_bandwidthIndex)
|
if ((settings.m_bandwidthIndex != m_settings.m_bandwidthIndex)
|
||||||
|| (settings.m_inputFrequencyOffset != m_settings.m_inputFrequencyOffset) || force)
|
|| (settings.m_inputFrequencyOffset != m_settings.m_inputFrequencyOffset) || force)
|
||||||
{
|
{
|
||||||
m_channelizer->setChannelization(
|
m_channelizer.setChannelization(
|
||||||
ChirpChatDemodSettings::bandwidths[settings.m_bandwidthIndex]*ChirpChatDemodSettings::oversampling,
|
ChirpChatDemodSettings::bandwidths[settings.m_bandwidthIndex]*ChirpChatDemodSettings::oversampling,
|
||||||
settings.m_inputFrequencyOffset
|
settings.m_inputFrequencyOffset
|
||||||
);
|
);
|
||||||
m_sink.applyChannelSettings(
|
m_sink.applyChannelSettings(
|
||||||
m_channelizer->getChannelSampleRate(),
|
m_channelizer.getChannelSampleRate(),
|
||||||
ChirpChatDemodSettings::bandwidths[settings.m_bandwidthIndex],
|
ChirpChatDemodSettings::bandwidths[settings.m_bandwidthIndex],
|
||||||
m_channelizer->getChannelFrequencyOffset()
|
m_channelizer.getChannelFrequencyOffset()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,16 +152,16 @@ void ChirpChatDemodBaseband::applySettings(const ChirpChatDemodSettings& setting
|
|||||||
|
|
||||||
int ChirpChatDemodBaseband::getChannelSampleRate() const
|
int ChirpChatDemodBaseband::getChannelSampleRate() const
|
||||||
{
|
{
|
||||||
return m_channelizer->getChannelSampleRate();
|
return m_channelizer.getChannelSampleRate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ChirpChatDemodBaseband::setBasebandSampleRate(int sampleRate)
|
void ChirpChatDemodBaseband::setBasebandSampleRate(int sampleRate)
|
||||||
{
|
{
|
||||||
m_channelizer->setBasebandSampleRate(sampleRate);
|
m_channelizer.setBasebandSampleRate(sampleRate);
|
||||||
m_sink.applyChannelSettings(
|
m_sink.applyChannelSettings(
|
||||||
m_channelizer->getChannelSampleRate(),
|
m_channelizer.getChannelSampleRate(),
|
||||||
ChirpChatDemodSettings::bandwidths[m_settings.m_bandwidthIndex],
|
ChirpChatDemodSettings::bandwidths[m_settings.m_bandwidthIndex],
|
||||||
m_channelizer->getChannelFrequencyOffset()
|
m_channelizer.getChannelFrequencyOffset()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -22,13 +22,12 @@
|
|||||||
#include <QRecursiveMutex>
|
#include <QRecursiveMutex>
|
||||||
|
|
||||||
#include "dsp/samplesinkfifo.h"
|
#include "dsp/samplesinkfifo.h"
|
||||||
|
#include "dsp/downchannelizer.h"
|
||||||
#include "util/message.h"
|
#include "util/message.h"
|
||||||
#include "util/messagequeue.h"
|
#include "util/messagequeue.h"
|
||||||
|
|
||||||
#include "chirpchatdemodsink.h"
|
#include "chirpchatdemodsink.h"
|
||||||
|
|
||||||
class DownChannelizer;
|
|
||||||
|
|
||||||
class ChirpChatDemodBaseband : public QObject
|
class ChirpChatDemodBaseband : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -72,7 +71,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
SampleSinkFifo m_sampleFifo;
|
SampleSinkFifo m_sampleFifo;
|
||||||
DownChannelizer *m_channelizer;
|
DownChannelizer m_channelizer;
|
||||||
ChirpChatDemodSink m_sink;
|
ChirpChatDemodSink m_sink;
|
||||||
MessageQueue m_inputMessageQueue; //!< Queue for asynchronous inbound communication
|
MessageQueue m_inputMessageQueue; //!< Queue for asynchronous inbound communication
|
||||||
ChirpChatDemodSettings m_settings;
|
ChirpChatDemodSettings m_settings;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user