1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-09-21 12:26:34 -04:00

Removed SyncMessenger from DSPDeviceSourceEngine. Part of #2159

This commit is contained in:
f4exb 2024-08-14 17:24:21 +02:00 committed by Edouard Griffiths
parent 6b2573d955
commit 9fa1974ba3
4 changed files with 153 additions and 164 deletions

View File

@ -47,7 +47,6 @@ DSPDeviceSourceEngine::DSPDeviceSourceEngine(uint uid, QObject* parent) :
m_imbalance(65536)
{
connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()), Qt::QueuedConnection);
connect(&m_syncMessenger, SIGNAL(messageSent()), this, SLOT(handleSynchronousMessages()), Qt::QueuedConnection);
moveToThread(this);
}
@ -69,61 +68,55 @@ void DSPDeviceSourceEngine::setState(State state)
void DSPDeviceSourceEngine::run()
{
qDebug() << "DSPDeviceSourceEngine::run";
qDebug("DSPDeviceSourceEngine::run");
setState(StIdle);
exec();
}
void DSPDeviceSourceEngine::start()
{
qDebug() << "DSPDeviceSourceEngine::start";
qDebug("DSPDeviceSourceEngine::start");
QThread::start();
}
void DSPDeviceSourceEngine::stop()
{
qDebug() << "DSPDeviceSourceEngine::stop";
qDebug("DSPDeviceSourceEngine::stop");
gotoIdle();
setState(StNotStarted);
QThread::exit();
// DSPExit cmd;
// m_syncMessenger.sendWait(cmd);
}
bool DSPDeviceSourceEngine::initAcquisition()
{
qDebug() << "DSPDeviceSourceEngine::initAcquisition";
DSPAcquisitionInit cmd;
return m_syncMessenger.sendWait(cmd) == StReady;
qDebug("DSPDeviceSourceEngine::initAcquisition (dummy)");
return true;
}
bool DSPDeviceSourceEngine::startAcquisition()
{
qDebug() << "DSPDeviceSourceEngine::startAcquisition";
DSPAcquisitionStart cmd;
return m_syncMessenger.sendWait(cmd) == StRunning;
qDebug("DSPDeviceSourceEngine::startAcquisition");
auto *cmd = new DSPAcquisitionStart();
getInputMessageQueue()->push(cmd);
return true;
}
void DSPDeviceSourceEngine::stopAcquistion()
{
qDebug() << "DSPDeviceSourceEngine::stopAcquistion";
DSPAcquisitionStop cmd;
m_syncMessenger.storeMessage(cmd);
handleSynchronousMessages();
qDebug("DSPDeviceSourceEngine::stopAcquistion");
auto *cmd = new DSPAcquisitionStop();
getInputMessageQueue()->push(cmd);
if(m_dcOffsetCorrection)
{
if (m_dcOffsetCorrection) {
qDebug("DC offset:%f,%f", m_iOffset, m_qOffset);
}
}
void DSPDeviceSourceEngine::setSource(DeviceSampleSource* source)
{
qDebug() << "DSPDeviceSourceEngine::setSource";
DSPSetSource cmd(source);
m_syncMessenger.sendWait(cmd);
qDebug("DSPDeviceSourceEngine::setSource");
auto *cmd = new DSPSetSource(source);
getInputMessageQueue()->push(cmd);
}
void DSPDeviceSourceEngine::setSourceSequence(int sequence)
@ -135,38 +128,34 @@ void DSPDeviceSourceEngine::setSourceSequence(int sequence)
void DSPDeviceSourceEngine::addSink(BasebandSampleSink* sink)
{
qDebug() << "DSPDeviceSourceEngine::addSink: " << sink->getSinkName().toStdString().c_str();
DSPAddBasebandSampleSink cmd(sink);
m_syncMessenger.sendWait(cmd);
auto *cmd = new DSPAddBasebandSampleSink(sink);
getInputMessageQueue()->push(cmd);
}
void DSPDeviceSourceEngine::removeSink(BasebandSampleSink* sink)
{
qDebug() << "DSPDeviceSourceEngine::removeSink: " << sink->getSinkName().toStdString().c_str();
DSPRemoveBasebandSampleSink cmd(sink);
m_syncMessenger.sendWait(cmd);
auto *cmd = new DSPRemoveBasebandSampleSink(sink);
getInputMessageQueue()->push(cmd);
}
void DSPDeviceSourceEngine::configureCorrections(bool dcOffsetCorrection, bool iqImbalanceCorrection)
{
qDebug() << "DSPDeviceSourceEngine::configureCorrections";
DSPConfigureCorrection* cmd = new DSPConfigureCorrection(dcOffsetCorrection, iqImbalanceCorrection);
m_inputMessageQueue.push(cmd);
qDebug("DSPDeviceSourceEngine::configureCorrections");
auto *cmd = new DSPConfigureCorrection(dcOffsetCorrection, iqImbalanceCorrection);
getInputMessageQueue()->push(cmd);
}
QString DSPDeviceSourceEngine::errorMessage()
QString DSPDeviceSourceEngine::errorMessage() const
{
qDebug() << "DSPDeviceSourceEngine::errorMessage";
DSPGetErrorMessage cmd;
m_syncMessenger.sendWait(cmd);
return cmd.getErrorMessage();
qDebug("DSPDeviceSourceEngine::errorMessage");
return m_errorMessage;
}
QString DSPDeviceSourceEngine::sourceDeviceDescription()
QString DSPDeviceSourceEngine::sourceDeviceDescription() const
{
qDebug() << "DSPDeviceSourceEngine::sourceDeviceDescription";
DSPGetSourceDeviceDescription cmd;
m_syncMessenger.sendWait(cmd);
return cmd.getDeviceDescription();
qDebug("DSPDeviceSourceEngine::sourceDeviceDescription");
return m_deviceDescription;
}
void DSPDeviceSourceEngine::iqCorrections(SampleVector::iterator begin, SampleVector::iterator end, bool imbalanceCorrection)
@ -217,8 +206,8 @@ void DSPDeviceSourceEngine::iqCorrections(SampleVector::iterator begin, SampleVe
#else
// DC correction and conversion
float xi = (it->m_real - (int32_t) m_iBeta) / SDR_RX_SCALEF;
float xq = (it->m_imag - (int32_t) m_qBeta) / SDR_RX_SCALEF;
float xi = (float) (it->m_real - (int32_t) m_iBeta) / SDR_RX_SCALEF;
float xq = (float) (it->m_imag - (int32_t) m_qBeta) / SDR_RX_SCALEF;
// phase imbalance
m_avgII(xi*xi); // <I", I">
@ -376,7 +365,7 @@ void DSPDeviceSourceEngine::work()
DSPDeviceSourceEngine::State DSPDeviceSourceEngine::gotoIdle()
{
qDebug() << "DSPDeviceSourceEngine::gotoIdle";
qDebug("DSPDeviceSourceEngine::gotoIdle");
switch(m_state) {
case StNotStarted:
@ -449,7 +438,7 @@ DSPDeviceSourceEngine::State DSPDeviceSourceEngine::gotoInit()
for (BasebandSampleSinks::const_iterator it = m_basebandSampleSinks.begin(); it != m_basebandSampleSinks.end(); ++it)
{
DSPSignalNotification *notif = new DSPSignalNotification(m_sampleRate, m_centerFrequency);
auto *notif = new DSPSignalNotification(m_sampleRate, m_centerFrequency);
qDebug() << "DSPDeviceSourceEngine::gotoInit: initializing " << (*it)->getSinkName().toStdString().c_str();
(*it)->pushMessage(notif);
}
@ -457,7 +446,7 @@ DSPDeviceSourceEngine::State DSPDeviceSourceEngine::gotoInit()
// pass data to listeners
if (m_deviceSampleSource->getMessageQueueToGUI())
{
DSPSignalNotification* rep = new DSPSignalNotification(m_sampleRate, m_centerFrequency);
auto *rep = new DSPSignalNotification(m_sampleRate, m_centerFrequency);
m_deviceSampleSource->getMessageQueueToGUI()->push(rep);
}
@ -466,7 +455,7 @@ DSPDeviceSourceEngine::State DSPDeviceSourceEngine::gotoInit()
DSPDeviceSourceEngine::State DSPDeviceSourceEngine::gotoRunning()
{
qDebug() << "DSPDeviceSourceEngine::gotoRunning";
qDebug("DSPDeviceSourceEngine::gotoRunning");
switch(m_state)
{
@ -521,11 +510,6 @@ void DSPDeviceSourceEngine::handleSetSource(DeviceSampleSource* source)
{
gotoIdle();
// if(m_sampleSource != 0)
// {
// disconnect(m_sampleSource->getSampleFifo(), SIGNAL(dataReady()), this, SLOT(handleData()));
// }
m_deviceSampleSource = source;
if (m_deviceSampleSource)
@ -547,89 +531,23 @@ void DSPDeviceSourceEngine::handleData()
}
}
void DSPDeviceSourceEngine::handleSynchronousMessages()
bool DSPDeviceSourceEngine::handleMessage(const Message& message)
{
Message *message = m_syncMessenger.getMessage();
qDebug() << "DSPDeviceSourceEngine::handleSynchronousMessages: " << message->getIdentifier();
if (DSPConfigureCorrection::match(message))
{
auto& conf = (const DSPConfigureCorrection&) message;
m_iqImbalanceCorrection = conf.getIQImbalanceCorrection();
if (DSPAcquisitionInit::match(*message))
if (m_dcOffsetCorrection != conf.getDCOffsetCorrection())
{
setState(gotoIdle());
if(m_state == StIdle) {
setState(gotoInit()); // State goes ready if init is performed
}
}
else if (DSPAcquisitionStart::match(*message))
{
if(m_state == StReady) {
setState(gotoRunning());
}
}
else if (DSPAcquisitionStop::match(*message))
{
setState(gotoIdle());
}
else if (DSPGetSourceDeviceDescription::match(*message))
{
((DSPGetSourceDeviceDescription*) message)->setDeviceDescription(m_deviceDescription);
}
else if (DSPGetErrorMessage::match(*message))
{
((DSPGetErrorMessage*) message)->setErrorMessage(m_errorMessage);
}
else if (DSPSetSource::match(*message)) {
handleSetSource(((DSPSetSource*) message)->getSampleSource());
}
else if (DSPAddBasebandSampleSink::match(*message))
{
BasebandSampleSink* sink = ((DSPAddBasebandSampleSink*) message)->getSampleSink();
m_basebandSampleSinks.push_back(sink);
// initialize sample rate and center frequency in the sink:
DSPSignalNotification *msg = new DSPSignalNotification(m_sampleRate, m_centerFrequency);
sink->pushMessage(msg);
// start the sink:
if(m_state == StRunning) {
sink->start();
}
}
else if (DSPRemoveBasebandSampleSink::match(*message))
{
BasebandSampleSink* sink = ((DSPRemoveBasebandSampleSink*) message)->getSampleSink();
if(m_state == StRunning) {
sink->stop();
}
m_basebandSampleSinks.remove(sink);
}
m_syncMessenger.done(m_state);
}
void DSPDeviceSourceEngine::handleInputMessages()
{
Message* message;
while ((message = m_inputMessageQueue.pop()) != 0)
{
qDebug("DSPDeviceSourceEngine::handleInputMessages: message: %s", message->getIdentifier());
if (DSPConfigureCorrection::match(*message))
{
DSPConfigureCorrection* conf = (DSPConfigureCorrection*) message;
m_iqImbalanceCorrection = conf->getIQImbalanceCorrection();
if(m_dcOffsetCorrection != conf->getDCOffsetCorrection())
{
m_dcOffsetCorrection = conf->getDCOffsetCorrection();
m_dcOffsetCorrection = conf.getDCOffsetCorrection();
m_iOffset = 0;
m_qOffset = 0;
}
if(m_iqImbalanceCorrection != conf->getIQImbalanceCorrection())
if (m_iqImbalanceCorrection != conf.getIQImbalanceCorrection())
{
m_iqImbalanceCorrection = conf->getIQImbalanceCorrection();
m_iqImbalanceCorrection = conf.getIQImbalanceCorrection();
m_iRange = 1 << 16;
m_qRange = 1 << 16;
m_imbalance = 65536;
@ -644,17 +562,17 @@ void DSPDeviceSourceEngine::handleInputMessages()
m_iBeta.reset();
m_qBeta.reset();
delete message;
return true;
}
else if (DSPSignalNotification::match(*message))
else if (DSPSignalNotification::match(message))
{
DSPSignalNotification *notif = (DSPSignalNotification *) message;
auto& notif = (const DSPSignalNotification&) message;
// update DSP values
m_sampleRate = notif->getSampleRate();
m_centerFrequency = notif->getCenterFrequency();
m_realElseComplex = notif->getRealElseComplex();
m_sampleRate = notif.getSampleRate();
m_centerFrequency = notif.getCenterFrequency();
m_realElseComplex = notif.getRealElseComplex();
qDebug() << "DSPDeviceSourceEngine::handleInputMessages: DSPSignalNotification:"
<< " m_sampleRate: " << m_sampleRate
@ -664,7 +582,7 @@ void DSPDeviceSourceEngine::handleInputMessages()
for(BasebandSampleSinks::const_iterator it = m_basebandSampleSinks.begin(); it != m_basebandSampleSinks.end(); it++)
{
DSPSignalNotification* rep = new DSPSignalNotification(*notif); // make a copy
auto* rep = new DSPSignalNotification(notif); // make a copy
qDebug() << "DSPDeviceSourceEngine::handleInputMessages: forward message to " << (*it)->getSinkName().toStdString().c_str();
(*it)->pushMessage(rep);
}
@ -677,11 +595,79 @@ void DSPDeviceSourceEngine::handleInputMessages()
if (guiMessageQueue)
{
DSPSignalNotification* rep = new DSPSignalNotification(*notif); // make a copy for the source GUI
auto* rep = new DSPSignalNotification(notif); // make a copy for the source GUI
guiMessageQueue->push(rep);
}
}
return true;
}
// was in handleSynchronousMessages:
else if (DSPAcquisitionInit::match(message))
{
return true; // discard
}
else if (DSPAcquisitionStart::match(message))
{
setState(gotoIdle());
if(m_state == StIdle) {
setState(gotoInit()); // State goes ready if init is performed
}
if(m_state == StReady) {
setState(gotoRunning());
}
return true;
}
else if (DSPAcquisitionStop::match(message))
{
setState(gotoIdle());
return true;
}
else if (DSPSetSource::match(message))
{
auto cmd = (const DSPSetSource&) message;
handleSetSource(cmd.getSampleSource());
}
else if (DSPAddBasebandSampleSink::match(message))
{
auto cmd = (const DSPAddBasebandSampleSink&) message;
BasebandSampleSink* sink = cmd.getSampleSink();
m_basebandSampleSinks.push_back(sink);
// initialize sample rate and center frequency in the sink:
auto *msg = new DSPSignalNotification(m_sampleRate, m_centerFrequency);
sink->pushMessage(msg);
// start the sink:
if(m_state == StRunning) {
sink->start();
}
}
else if (DSPRemoveBasebandSampleSink::match(message))
{
auto cmd = (const DSPRemoveBasebandSampleSink&) message;
BasebandSampleSink* sink = cmd.getSampleSink();
if(m_state == StRunning) {
sink->stop();
}
m_basebandSampleSinks.remove(sink);
}
return false;
}
void DSPDeviceSourceEngine::handleInputMessages()
{
Message* message;
while ((message = m_inputMessageQueue.pop()) != nullptr)
{
qDebug("DSPDeviceSourceEngine::handleInputMessages: message: %s", message->getIdentifier());
if (handleMessage(*message)) {
delete message;
}
}

View File

@ -28,7 +28,6 @@
#include <QWaitCondition>
#include "dsp/dsptypes.h"
#include "util/messagequeue.h"
#include "util/syncmessenger.h"
#include "export.h"
#include "util/movingaverage.h"
@ -47,7 +46,7 @@ public:
StError //!< engine is in error
};
DSPDeviceSourceEngine(uint uid, QObject* parent = NULL);
DSPDeviceSourceEngine(uint uid, QObject* parent = nullptr);
~DSPDeviceSourceEngine();
uint getUID() const { return m_uid; }
@ -72,14 +71,13 @@ public:
State state() const { return m_state; } //!< Return DSP engine current state
QString errorMessage(); //!< Return the current error message
QString sourceDeviceDescription(); //!< Return the source device description
QString errorMessage() const; //!< Return the current error message
QString sourceDeviceDescription() const; //!< Return the source device description
private:
uint m_uid; //!< unique ID
MessageQueue m_inputMessageQueue; //<! Input message queue. Post here.
SyncMessenger m_syncMessenger; //!< Used to process messages synchronously with the thread
State m_state;
@ -89,7 +87,7 @@ private:
DeviceSampleSource* m_deviceSampleSource;
int m_sampleSourceSequence;
typedef std::list<BasebandSampleSink*> BasebandSampleSinks;
using BasebandSampleSinks = std::list<BasebandSampleSink *>;
BasebandSampleSinks m_basebandSampleSinks; //!< sample sinks within main thread (usually spectrum, file output)
uint m_sampleRate;
@ -98,7 +96,8 @@ private:
bool m_dcOffsetCorrection;
bool m_iqImbalanceCorrection;
double m_iOffset, m_qOffset;
double m_iOffset;
double m_qOffset;
MovingAverageUtil<int32_t, int64_t, 1024> m_iBeta;
MovingAverageUtil<int32_t, int64_t, 1024> m_qBeta;
@ -140,11 +139,11 @@ private:
void setState(State state);
void handleSetSource(DeviceSampleSource* source); //!< Manage source setting
bool handleMessage(const Message& cmd);
private slots:
void handleData(); //!< Handle data when samples from source FIFO are ready to be processed
void handleInputMessages(); //!< Handle input message queue
void handleSynchronousMessages(); //!< Handle synchronous messages with the thread
signals:
void stateChanged();

View File

@ -63,10 +63,12 @@ DSPEngine *DSPEngine::instance()
DSPDeviceSourceEngine *DSPEngine::addDeviceSourceEngine()
{
m_deviceSourceEngines.push_back(new DSPDeviceSourceEngine(m_deviceSourceEnginesUIDSequence));
auto *deviceSourceEngine = new DSPDeviceSourceEngine(m_deviceSourceEnginesUIDSequence);
// auto *deviceThread = new QThread(); TBD
m_deviceSourceEnginesUIDSequence++;
m_deviceEngineReferences.push_back(DeviceEngineReference{0, m_deviceSourceEngines.back(), nullptr, nullptr});
return m_deviceSourceEngines.back();
m_deviceSourceEngines.push_back(deviceSourceEngine);
m_deviceEngineReferences.push_back(DeviceEngineReference{0, m_deviceSourceEngines.back(), nullptr, nullptr, nullptr});
return deviceSourceEngine;
}
void DSPEngine::removeLastDeviceSourceEngine()
@ -92,7 +94,7 @@ DSPDeviceSinkEngine *DSPEngine::addDeviceSinkEngine()
{
m_deviceSinkEngines.push_back(new DSPDeviceSinkEngine(m_deviceSinkEnginesUIDSequence));
m_deviceSinkEnginesUIDSequence++;
m_deviceEngineReferences.push_back(DeviceEngineReference{1, nullptr, m_deviceSinkEngines.back(), nullptr});
m_deviceEngineReferences.push_back(DeviceEngineReference{1, nullptr, m_deviceSinkEngines.back(), nullptr, nullptr});
return m_deviceSinkEngines.back();
}
@ -119,7 +121,7 @@ DSPDeviceMIMOEngine *DSPEngine::addDeviceMIMOEngine()
{
m_deviceMIMOEngines.push_back(new DSPDeviceMIMOEngine(m_deviceMIMOEnginesUIDSequence));
m_deviceMIMOEnginesUIDSequence++;
m_deviceEngineReferences.push_back(DeviceEngineReference{2, nullptr, nullptr, m_deviceMIMOEngines.back()});
m_deviceEngineReferences.push_back(DeviceEngineReference{2, nullptr, nullptr, m_deviceMIMOEngines.back(), nullptr});
return m_deviceMIMOEngines.back();
}

View File

@ -32,6 +32,7 @@ class DSPDeviceSourceEngine;
class DSPDeviceSinkEngine;
class DSPDeviceMIMOEngine;
class FFTFactory;
class QThread;
class SDRBASE_API DSPEngine : public QObject {
Q_OBJECT
@ -79,6 +80,7 @@ private:
DSPDeviceSourceEngine *m_deviceSourceEngine;
DSPDeviceSinkEngine *m_deviceSinkEngine;
DSPDeviceMIMOEngine *m_deviceMIMOEngine;
QThread *m_thread;
};
QList<DSPDeviceSourceEngine*> m_deviceSourceEngines;