From 4a6943b4d9d02e0fe9618e19a25691f2fdb54768 Mon Sep 17 00:00:00 2001 From: f4exb Date: Wed, 14 Aug 2024 17:24:21 +0200 Subject: [PATCH 01/16] Removed SyncMessenger from DSPDeviceSourceEngine. Part of #2159 --- sdrbase/dsp/dspdevicesourceengine.cpp | 288 ++++++++++++-------------- sdrbase/dsp/dspdevicesourceengine.h | 15 +- sdrbase/dsp/dspengine.cpp | 12 +- sdrbase/dsp/dspengine.h | 2 + 4 files changed, 153 insertions(+), 164 deletions(-) diff --git a/sdrbase/dsp/dspdevicesourceengine.cpp b/sdrbase/dsp/dspdevicesourceengine.cpp index 7ac7b0019..5403baf77 100644 --- a/sdrbase/dsp/dspdevicesourceengine.cpp +++ b/sdrbase/dsp/dspdevicesourceengine.cpp @@ -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); // @@ -263,10 +252,10 @@ void DSPDeviceSourceEngine::dcOffset(SampleVector::iterator begin, SampleVector: // sum and correct in one pass for(SampleVector::iterator it = begin; it < end; it++) { - m_iBeta(it->real()); - m_qBeta(it->imag()); - it->m_real -= (int32_t) m_iBeta; - it->m_imag -= (int32_t) m_qBeta; + m_iBeta(it->real()); + m_qBeta(it->imag()); + it->m_real -= (int32_t) m_iBeta; + it->m_imag -= (int32_t) m_qBeta; } } @@ -376,7 +365,7 @@ void DSPDeviceSourceEngine::work() DSPDeviceSourceEngine::State DSPDeviceSourceEngine::gotoIdle() { - qDebug() << "DSPDeviceSourceEngine::gotoIdle"; + qDebug("DSPDeviceSourceEngine::gotoIdle"); switch(m_state) { case StNotStarted: @@ -442,14 +431,14 @@ DSPDeviceSourceEngine::State DSPDeviceSourceEngine::gotoInit() m_sampleRate = m_deviceSampleSource->getSampleRate(); qDebug() << "DSPDeviceSourceEngine::gotoInit: " - << " m_deviceDescription: " << m_deviceDescription.toStdString().c_str() + << " m_deviceDescription: " << m_deviceDescription.toStdString().c_str() << " sampleRate: " << m_sampleRate << " centerFrequency: " << m_centerFrequency; 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,55 +531,123 @@ 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()) + { + m_dcOffsetCorrection = conf.getDCOffsetCorrection(); + m_iOffset = 0; + m_qOffset = 0; + } + + if (m_iqImbalanceCorrection != conf.getIQImbalanceCorrection()) + { + m_iqImbalanceCorrection = conf.getIQImbalanceCorrection(); + m_iRange = 1 << 16; + m_qRange = 1 << 16; + m_imbalance = 65536; + } + + m_avgAmp.reset(); + m_avgII.reset(); + m_avgII2.reset(); + m_avgIQ.reset(); + m_avgPhi.reset(); + m_avgQQ2.reset(); + m_iBeta.reset(); + m_qBeta.reset(); + + return true; + } + else if (DSPSignalNotification::match(message)) + { + auto& notif = (const DSPSignalNotification&) message; + + // update DSP values + + m_sampleRate = notif.getSampleRate(); + m_centerFrequency = notif.getCenterFrequency(); + m_realElseComplex = notif.getRealElseComplex(); + + qDebug() << "DSPDeviceSourceEngine::handleInputMessages: DSPSignalNotification:" + << " m_sampleRate: " << m_sampleRate + << " m_centerFrequency: " << m_centerFrequency; + + // forward source changes to channel sinks with immediate execution (no queuing) + + for(BasebandSampleSinks::const_iterator it = m_basebandSampleSinks.begin(); it != m_basebandSampleSinks.end(); it++) + { + auto* rep = new DSPSignalNotification(notif); // make a copy + qDebug() << "DSPDeviceSourceEngine::handleInputMessages: forward message to " << (*it)->getSinkName().toStdString().c_str(); + (*it)->pushMessage(rep); + } + + // forward changes to source GUI input queue + if (m_deviceSampleSource) + { + MessageQueue *guiMessageQueue = m_deviceSampleSource->getMessageQueueToGUI(); + qDebug("DSPDeviceSourceEngine::handleInputMessages: DSPSignalNotification: guiMessageQueue: %p", guiMessageQueue); + + if (guiMessageQueue) + { + 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 } - } - else if (DSPAcquisitionStart::match(*message)) - { + if(m_state == StReady) { setState(gotoRunning()); } + + return true; } - else if (DSPAcquisitionStop::match(*message)) + else if (DSPAcquisitionStop::match(message)) { setState(gotoIdle()); + return true; } - else if (DSPGetSourceDeviceDescription::match(*message)) + else if (DSPSetSource::match(message)) + { + auto cmd = (const DSPSetSource&) message; + handleSetSource(cmd.getSampleSource()); + } + else if (DSPAddBasebandSampleSink::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(); + auto cmd = (const DSPAddBasebandSampleSink&) message; + BasebandSampleSink* sink = cmd.getSampleSink(); m_basebandSampleSinks.push_back(sink); // initialize sample rate and center frequency in the sink: - DSPSignalNotification *msg = new DSPSignalNotification(m_sampleRate, m_centerFrequency); + 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)) + else if (DSPRemoveBasebandSampleSink::match(message)) { - BasebandSampleSink* sink = ((DSPRemoveBasebandSampleSink*) message)->getSampleSink(); + auto cmd = (const DSPRemoveBasebandSampleSink&) message; + BasebandSampleSink* sink = cmd.getSampleSink(); if(m_state == StRunning) { sink->stop(); @@ -604,85 +656,19 @@ void DSPDeviceSourceEngine::handleSynchronousMessages() m_basebandSampleSinks.remove(sink); } - m_syncMessenger.done(m_state); + return false; } void DSPDeviceSourceEngine::handleInputMessages() { Message* message; - while ((message = m_inputMessageQueue.pop()) != 0) + while ((message = m_inputMessageQueue.pop()) != nullptr) { 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_iOffset = 0; - m_qOffset = 0; - } - - if(m_iqImbalanceCorrection != conf->getIQImbalanceCorrection()) - { - m_iqImbalanceCorrection = conf->getIQImbalanceCorrection(); - m_iRange = 1 << 16; - m_qRange = 1 << 16; - m_imbalance = 65536; - } - - m_avgAmp.reset(); - m_avgII.reset(); - m_avgII2.reset(); - m_avgIQ.reset(); - m_avgPhi.reset(); - m_avgQQ2.reset(); - m_iBeta.reset(); - m_qBeta.reset(); - - delete message; - } - else if (DSPSignalNotification::match(*message)) - { - DSPSignalNotification *notif = (DSPSignalNotification *) message; - - // update DSP values - - m_sampleRate = notif->getSampleRate(); - m_centerFrequency = notif->getCenterFrequency(); - m_realElseComplex = notif->getRealElseComplex(); - - qDebug() << "DSPDeviceSourceEngine::handleInputMessages: DSPSignalNotification:" - << " m_sampleRate: " << m_sampleRate - << " m_centerFrequency: " << m_centerFrequency; - - // forward source changes to channel sinks with immediate execution (no queuing) - - for(BasebandSampleSinks::const_iterator it = m_basebandSampleSinks.begin(); it != m_basebandSampleSinks.end(); it++) - { - DSPSignalNotification* rep = new DSPSignalNotification(*notif); // make a copy - qDebug() << "DSPDeviceSourceEngine::handleInputMessages: forward message to " << (*it)->getSinkName().toStdString().c_str(); - (*it)->pushMessage(rep); - } - - // forward changes to source GUI input queue - if (m_deviceSampleSource) - { - MessageQueue *guiMessageQueue = m_deviceSampleSource->getMessageQueueToGUI(); - qDebug("DSPDeviceSourceEngine::handleInputMessages: DSPSignalNotification: guiMessageQueue: %p", guiMessageQueue); - - if (guiMessageQueue) - { - DSPSignalNotification* rep = new DSPSignalNotification(*notif); // make a copy for the source GUI - guiMessageQueue->push(rep); - } - } - - delete message; - } + if (handleMessage(*message)) { + delete message; + } } } diff --git a/sdrbase/dsp/dspdevicesourceengine.h b/sdrbase/dsp/dspdevicesourceengine.h index fa0731bd4..0b10490d7 100644 --- a/sdrbase/dsp/dspdevicesourceengine.h +++ b/sdrbase/dsp/dspdevicesourceengine.h @@ -28,7 +28,6 @@ #include #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; // BasebandSampleSinks; + using BasebandSampleSinks = std::list; 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 m_iBeta; MovingAverageUtil 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(); diff --git a/sdrbase/dsp/dspengine.cpp b/sdrbase/dsp/dspengine.cpp index 76ec86a3f..96dc47fcb 100644 --- a/sdrbase/dsp/dspengine.cpp +++ b/sdrbase/dsp/dspengine.cpp @@ -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(); } diff --git a/sdrbase/dsp/dspengine.h b/sdrbase/dsp/dspengine.h index 0a518e1ec..a8cad782d 100644 --- a/sdrbase/dsp/dspengine.h +++ b/sdrbase/dsp/dspengine.h @@ -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 m_deviceSourceEngines; From 580fbda09cab415ff2bc326baeece7384e0b39ab Mon Sep 17 00:00:00 2001 From: f4exb Date: Wed, 14 Aug 2024 22:08:49 +0200 Subject: [PATCH 02/16] Fixed threading model for DSPDeviceSourceEngine. Part of #2159 --- sdrbase/dsp/dspdevicesourceengine.cpp | 28 ++------------------- sdrbase/dsp/dspdevicesourceengine.h | 9 ++----- sdrbase/dsp/dspengine.cpp | 35 +++++++++++++++++++++------ sdrgui/mainwindow.cpp | 3 --- sdrsrv/mainserver.cpp | 2 -- 5 files changed, 32 insertions(+), 45 deletions(-) diff --git a/sdrbase/dsp/dspdevicesourceengine.cpp b/sdrbase/dsp/dspdevicesourceengine.cpp index 5403baf77..27869762a 100644 --- a/sdrbase/dsp/dspdevicesourceengine.cpp +++ b/sdrbase/dsp/dspdevicesourceengine.cpp @@ -29,7 +29,7 @@ #include "samplesinkfifo.h" DSPDeviceSourceEngine::DSPDeviceSourceEngine(uint uid, QObject* parent) : - QThread(parent), + QObject(parent), m_uid(uid), m_state(StNotStarted), m_deviceSampleSource(nullptr), @@ -46,15 +46,12 @@ DSPDeviceSourceEngine::DSPDeviceSourceEngine(uint uid, QObject* parent) : m_qRange(1 << 16), m_imbalance(65536) { + setState(StIdle); connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()), Qt::QueuedConnection); - - moveToThread(this); } DSPDeviceSourceEngine::~DSPDeviceSourceEngine() { - stop(); - wait(); } void DSPDeviceSourceEngine::setState(State state) @@ -66,27 +63,6 @@ void DSPDeviceSourceEngine::setState(State state) } } -void DSPDeviceSourceEngine::run() -{ - qDebug("DSPDeviceSourceEngine::run"); - setState(StIdle); - exec(); -} - -void DSPDeviceSourceEngine::start() -{ - qDebug("DSPDeviceSourceEngine::start"); - QThread::start(); -} - -void DSPDeviceSourceEngine::stop() -{ - qDebug("DSPDeviceSourceEngine::stop"); - gotoIdle(); - setState(StNotStarted); - QThread::exit(); -} - bool DSPDeviceSourceEngine::initAcquisition() { qDebug("DSPDeviceSourceEngine::initAcquisition (dummy)"); diff --git a/sdrbase/dsp/dspdevicesourceengine.h b/sdrbase/dsp/dspdevicesourceengine.h index 0b10490d7..ba5b839ac 100644 --- a/sdrbase/dsp/dspdevicesourceengine.h +++ b/sdrbase/dsp/dspdevicesourceengine.h @@ -22,7 +22,7 @@ #ifndef INCLUDE_DSPDEVICEENGINE_H #define INCLUDE_DSPDEVICEENGINE_H -#include +#include #include #include #include @@ -34,7 +34,7 @@ class DeviceSampleSource; class BasebandSampleSink; -class SDRBASE_API DSPDeviceSourceEngine : public QThread { +class SDRBASE_API DSPDeviceSourceEngine : public QObject { Q_OBJECT public: @@ -53,9 +53,6 @@ public: MessageQueue* getInputMessageQueue() { return &m_inputMessageQueue; } - void start(); //!< This thread start - void stop(); //!< This thread stop - bool initAcquisition(); //!< Initialize acquisition sequence bool startAcquisition(); //!< Start acquisition sequence void stopAcquistion(); //!< Stop acquisition sequence @@ -125,8 +122,6 @@ private: qint32 m_qRange; qint32 m_imbalance; - void run(); - void iqCorrections(SampleVector::iterator begin, SampleVector::iterator end, bool imbalanceCorrection); void dcOffset(SampleVector::iterator begin, SampleVector::iterator end); void imbalance(SampleVector::iterator begin, SampleVector::iterator end); diff --git a/sdrbase/dsp/dspengine.cpp b/sdrbase/dsp/dspengine.cpp index 96dc47fcb..b6d688ba7 100644 --- a/sdrbase/dsp/dspengine.cpp +++ b/sdrbase/dsp/dspengine.cpp @@ -42,7 +42,7 @@ DSPEngine::DSPEngine() : DSPEngine::~DSPEngine() { - QList::iterator it = m_deviceSourceEngines.begin(); + auto it = m_deviceSourceEngines.begin(); while (it != m_deviceSourceEngines.end()) { @@ -64,25 +64,44 @@ DSPEngine *DSPEngine::instance() DSPDeviceSourceEngine *DSPEngine::addDeviceSourceEngine() { auto *deviceSourceEngine = new DSPDeviceSourceEngine(m_deviceSourceEnginesUIDSequence); - // auto *deviceThread = new QThread(); TBD + auto *deviceThread = new QThread(); m_deviceSourceEnginesUIDSequence++; m_deviceSourceEngines.push_back(deviceSourceEngine); - m_deviceEngineReferences.push_back(DeviceEngineReference{0, m_deviceSourceEngines.back(), nullptr, nullptr, nullptr}); + m_deviceEngineReferences.push_back(DeviceEngineReference{0, m_deviceSourceEngines.back(), nullptr, nullptr, deviceThread}); + deviceSourceEngine->moveToThread(deviceThread); + + QObject::connect( + deviceThread, + &QThread::finished, + deviceSourceEngine, + &QObject::deleteLater + ); + QObject::connect( + deviceThread, + &QThread::finished, + deviceThread, + &QThread::deleteLater + ); + + deviceThread->start(); + return deviceSourceEngine; } void DSPEngine::removeLastDeviceSourceEngine() { - if (m_deviceSourceEngines.size() > 0) + if (!m_deviceSourceEngines.empty()) { - DSPDeviceSourceEngine *lastDeviceEngine = m_deviceSourceEngines.back(); - delete lastDeviceEngine; + const DSPDeviceSourceEngine *lastDeviceEngine = m_deviceSourceEngines.back(); m_deviceSourceEngines.pop_back(); for (int i = 0; i < m_deviceEngineReferences.size(); i++) { if (m_deviceEngineReferences[i].m_deviceSourceEngine == lastDeviceEngine) { + QThread* deviceThread = m_deviceEngineReferences[i].m_thread; + deviceThread->exit(); + deviceThread->wait(); m_deviceEngineReferences.removeAt(i); break; } @@ -153,7 +172,9 @@ void DSPEngine::removeDeviceEngineAt(int deviceIndex) if (m_deviceEngineReferences[deviceIndex].m_deviceEngineType == 0) // source { DSPDeviceSourceEngine *deviceEngine = m_deviceEngineReferences[deviceIndex].m_deviceSourceEngine; - delete deviceEngine; + QThread *deviceThread = m_deviceEngineReferences[deviceIndex].m_thread; + deviceThread->exit(); + deviceThread->wait(); m_deviceSourceEngines.removeAll(deviceEngine); } else if (m_deviceEngineReferences[deviceIndex].m_deviceEngineType == 1) // sink diff --git a/sdrgui/mainwindow.cpp b/sdrgui/mainwindow.cpp index 3b905a7dd..3c3cef816 100644 --- a/sdrgui/mainwindow.cpp +++ b/sdrgui/mainwindow.cpp @@ -343,7 +343,6 @@ MainWindow::~MainWindow() void MainWindow::sampleSourceAdd(Workspace *deviceWorkspace, Workspace *spectrumWorkspace, int deviceIndex) { DSPDeviceSourceEngine *dspDeviceSourceEngine = m_dspEngine->addDeviceSourceEngine(); - dspDeviceSourceEngine->start(); uint dspDeviceSourceEngineUID = dspDeviceSourceEngine->getUID(); char uidCStr[16]; @@ -1010,7 +1009,6 @@ void MainWindow::removeDeviceSet(int deviceSetIndex) DeviceAPI *sourceAPI = deviceUISet->m_deviceAPI; delete deviceUISet; - deviceEngine->stop(); m_dspEngine->removeDeviceEngineAt(deviceSetIndex); DeviceEnumerator::instance()->removeRxSelection(deviceSetIndex); @@ -1116,7 +1114,6 @@ void MainWindow::removeLastDeviceSet() DeviceAPI *sourceAPI = m_deviceUIs.back()->m_deviceAPI; delete m_deviceUIs.back(); - lastDeviceEngine->stop(); m_dspEngine->removeLastDeviceSourceEngine(); delete sourceAPI; diff --git a/sdrsrv/mainserver.cpp b/sdrsrv/mainserver.cpp index 27ae511b0..7f66b948e 100644 --- a/sdrsrv/mainserver.cpp +++ b/sdrsrv/mainserver.cpp @@ -315,7 +315,6 @@ void MainServer::addSinkDevice() void MainServer::addSourceDevice() { DSPDeviceSourceEngine *dspDeviceSourceEngine = m_dspEngine->addDeviceSourceEngine(); - dspDeviceSourceEngine->start(); uint dspDeviceSourceEngineUID = dspDeviceSourceEngine->getUID(); char uidCStr[16]; @@ -423,7 +422,6 @@ void MainServer::removeLastDevice() DeviceAPI *sourceAPI = m_mainCore->m_deviceSets.back()->m_deviceAPI; delete m_mainCore->m_deviceSets.back(); - lastDeviceEngine->stop(); m_dspEngine->removeLastDeviceSourceEngine(); delete sourceAPI; From 0ff75e1538bf8f48f5ec5bd8f455db4750fee50b Mon Sep 17 00:00:00 2001 From: f4exb Date: Thu, 15 Aug 2024 03:08:28 +0200 Subject: [PATCH 03/16] Removed SyncMessenger from DSPDeviceMIMOEngine. Part of #2159 --- sdrbase/dsp/dspdevicemimoengine.cpp | 523 ++++++++++++++-------------- sdrbase/dsp/dspdevicemimoengine.h | 10 +- 2 files changed, 270 insertions(+), 263 deletions(-) diff --git a/sdrbase/dsp/dspdevicemimoengine.cpp b/sdrbase/dsp/dspdevicemimoengine.cpp index a6cd6f6f4..386c234b8 100644 --- a/sdrbase/dsp/dspdevicemimoengine.cpp +++ b/sdrbase/dsp/dspdevicemimoengine.cpp @@ -50,7 +50,6 @@ DSPDeviceMIMOEngine::DSPDeviceMIMOEngine(uint32_t uid, QObject* parent) : m_spectrumInputIndex(0) { connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()), Qt::QueuedConnection); - connect(&m_syncMessenger, SIGNAL(messageSent()), this, SLOT(handleSynchronousMessages()), Qt::QueuedConnection); moveToThread(this); } @@ -109,13 +108,15 @@ bool DSPDeviceMIMOEngine::initProcess(int subsystemIndex) if (subsystemIndex == 0) // Rx side { - DSPAcquisitionInit cmd; - return m_syncMessenger.sendWait(cmd) == StReady; + auto *cmd = new DSPAcquisitionInit(); + getInputMessageQueue()->push(cmd); + return true; } else if (subsystemIndex == 1) // Tx side { - DSPGenerationInit cmd; - return m_syncMessenger.sendWait(cmd) == StReady; + auto *cmd = new DSPGenerationInit(); + getInputMessageQueue()->push(cmd); + return true; } return false; @@ -126,13 +127,15 @@ bool DSPDeviceMIMOEngine::startProcess(int subsystemIndex) qDebug() << "DSPDeviceMIMOEngine::startProcess: subsystemIndex: " << subsystemIndex; if (subsystemIndex == 0) // Rx side { - DSPAcquisitionStart cmd; - return m_syncMessenger.sendWait(cmd) == StRunning; + auto *cmd = new DSPAcquisitionStart(); + getInputMessageQueue()->push(cmd); + return true; } else if (subsystemIndex == 1) // Tx side { - DSPGenerationStart cmd; - return m_syncMessenger.sendWait(cmd) == StRunning; + auto *cmd = new DSPGenerationStart(); + getInputMessageQueue()->push(cmd); + return true; } return false; @@ -144,21 +147,21 @@ void DSPDeviceMIMOEngine::stopProcess(int subsystemIndex) if (subsystemIndex == 0) // Rx side { - DSPAcquisitionStop cmd; - m_syncMessenger.sendWait(cmd); + auto *cmd = new DSPAcquisitionStop(); + getInputMessageQueue()->push(cmd); } else if (subsystemIndex == 1) // Tx side { - DSPGenerationStop cmd; - m_syncMessenger.sendWait(cmd); + DSPGenerationStop *cmd = new DSPGenerationStop(); + getInputMessageQueue()->push(cmd); } } void DSPDeviceMIMOEngine::setMIMO(DeviceSampleMIMO* mimo) { qDebug() << "DSPDeviceMIMOEngine::setMIMO"; - SetSampleMIMO cmd(mimo); - m_syncMessenger.sendWait(cmd); + auto *cmd = new SetSampleMIMO(mimo); + getInputMessageQueue()->push(cmd); } void DSPDeviceMIMOEngine::setMIMOSequence(int sequence) @@ -173,8 +176,8 @@ void DSPDeviceMIMOEngine::addChannelSource(BasebandSampleSource* source, int ind << source->getSourceName().toStdString().c_str() << " at: " << index; - AddBasebandSampleSource cmd(source, index); - m_syncMessenger.sendWait(cmd); + auto *cmd = new AddBasebandSampleSource(source, index); + getInputMessageQueue()->push(cmd); } void DSPDeviceMIMOEngine::removeChannelSource(BasebandSampleSource* source, int index) @@ -183,8 +186,8 @@ void DSPDeviceMIMOEngine::removeChannelSource(BasebandSampleSource* source, int << source->getSourceName().toStdString().c_str() << " at: " << index; - RemoveBasebandSampleSource cmd(source, index); - m_syncMessenger.sendWait(cmd); + auto *cmd = new RemoveBasebandSampleSource(source, index); + getInputMessageQueue()->push(cmd); } void DSPDeviceMIMOEngine::addChannelSink(BasebandSampleSink* sink, int index) @@ -193,8 +196,8 @@ void DSPDeviceMIMOEngine::addChannelSink(BasebandSampleSink* sink, int index) << sink->getSinkName().toStdString().c_str() << " at: " << index; - AddBasebandSampleSink cmd(sink, index); - m_syncMessenger.sendWait(cmd); + auto *cmd = new AddBasebandSampleSink(sink, index); + getInputMessageQueue()->push(cmd); } void DSPDeviceMIMOEngine::removeChannelSink(BasebandSampleSink* sink, int index) @@ -203,38 +206,38 @@ void DSPDeviceMIMOEngine::removeChannelSink(BasebandSampleSink* sink, int index) << sink->getSinkName().toStdString().c_str() << " at: " << index; - RemoveBasebandSampleSink cmd(sink, index); - m_syncMessenger.sendWait(cmd); + auto *cmd = new RemoveBasebandSampleSink(sink, index); + getInputMessageQueue()->push(cmd); } void DSPDeviceMIMOEngine::addMIMOChannel(MIMOChannel *channel) { qDebug() << "DSPDeviceMIMOEngine::addMIMOChannel: " << channel->getMIMOName().toStdString().c_str(); - AddMIMOChannel cmd(channel); - m_syncMessenger.sendWait(cmd); + auto *cmd = new AddMIMOChannel(channel); + getInputMessageQueue()->push(cmd); } void DSPDeviceMIMOEngine::removeMIMOChannel(MIMOChannel *channel) { qDebug() << "DSPDeviceMIMOEngine::removeMIMOChannel: " << channel->getMIMOName().toStdString().c_str(); - RemoveMIMOChannel cmd(channel); - m_syncMessenger.sendWait(cmd); + auto *cmd = new RemoveMIMOChannel(channel); + getInputMessageQueue()->push(cmd); } void DSPDeviceMIMOEngine::addSpectrumSink(BasebandSampleSink* spectrumSink) { qDebug() << "DSPDeviceMIMOEngine::addSpectrumSink: " << spectrumSink->getSinkName().toStdString().c_str(); - AddSpectrumSink cmd(spectrumSink); - m_syncMessenger.sendWait(cmd); + auto *cmd = new AddSpectrumSink(spectrumSink); + getInputMessageQueue()->push(cmd); } void DSPDeviceMIMOEngine::removeSpectrumSink(BasebandSampleSink* spectrumSink) { qDebug() << "DSPDeviceSinkEngine::removeSpectrumSink: " << spectrumSink->getSinkName().toStdString().c_str(); - DSPRemoveSpectrumSink cmd(spectrumSink); - m_syncMessenger.sendWait(cmd); + auto *cmd = new RemoveSpectrumSink(spectrumSink); + getInputMessageQueue()->push(cmd); } void DSPDeviceMIMOEngine::setSpectrumSinkInput(bool sourceElseSink, int index) @@ -242,24 +245,26 @@ void DSPDeviceMIMOEngine::setSpectrumSinkInput(bool sourceElseSink, int index) qDebug() << "DSPDeviceSinkEngine::setSpectrumSinkInput: " << " sourceElseSink: " << sourceElseSink << " index: " << index; - SetSpectrumSinkInput cmd(sourceElseSink, index); - m_syncMessenger.sendWait(cmd); + auto *cmd = new SetSpectrumSinkInput(sourceElseSink, index); + getInputMessageQueue()->push(cmd); } -QString DSPDeviceMIMOEngine::errorMessage(int subsystemIndex) +QString DSPDeviceMIMOEngine::errorMessage(int subsystemIndex) const { qDebug() << "DSPDeviceMIMOEngine::errorMessage: subsystemIndex:" << subsystemIndex; - GetErrorMessage cmd(subsystemIndex); - m_syncMessenger.sendWait(cmd); - return cmd.getErrorMessage(); + if (subsystemIndex == 0) { + return m_errorMessageRx; + } else if (subsystemIndex == 1) { + return m_errorMessageTx; + } else { + return "Not implemented"; + } } -QString DSPDeviceMIMOEngine::deviceDescription() +QString DSPDeviceMIMOEngine::deviceDescription() const { qDebug() << "DSPDeviceMIMOEngine::deviceDescription"; - GetMIMODeviceDescription cmd; - m_syncMessenger.sendWait(cmd); - return cmd.getDeviceDescription(); + return m_deviceDescription; } void DSPDeviceMIMOEngine::workSampleSinkFifos() @@ -896,13 +901,150 @@ void DSPDeviceMIMOEngine::handleSetMIMO(DeviceSampleMIMO* mimo) } } -void DSPDeviceMIMOEngine::handleSynchronousMessages() +bool DSPDeviceMIMOEngine::handleMessage(const Message& message) { - Message *message = m_syncMessenger.getMessage(); - qDebug() << "DSPDeviceMIMOEngine::handleSynchronousMessages: " << message->getIdentifier(); - State returnState = StNotStarted; + if (ConfigureCorrection::match(message)) + { + const auto& conf = (const ConfigureCorrection&) message; + unsigned int isource = conf.getIndex(); - if (DSPAcquisitionInit::match(*message)) + if (isource < m_sourcesCorrections.size()) + { + m_sourcesCorrections[isource].m_iqImbalanceCorrection = conf.getIQImbalanceCorrection(); + + if (m_sourcesCorrections[isource].m_dcOffsetCorrection != conf.getDCOffsetCorrection()) + { + m_sourcesCorrections[isource].m_dcOffsetCorrection = conf.getDCOffsetCorrection(); + m_sourcesCorrections[isource].m_iOffset = 0; + m_sourcesCorrections[isource].m_qOffset = 0; + + if (m_sourcesCorrections[isource].m_iqImbalanceCorrection != conf.getIQImbalanceCorrection()) + { + m_sourcesCorrections[isource].m_iqImbalanceCorrection = conf.getIQImbalanceCorrection(); + m_sourcesCorrections[isource].m_iRange = 1 << 16; + m_sourcesCorrections[isource].m_qRange = 1 << 16; + m_sourcesCorrections[isource].m_imbalance = 65536; + } + } + m_sourcesCorrections[isource].m_iBeta.reset(); + m_sourcesCorrections[isource].m_qBeta.reset(); + m_sourcesCorrections[isource].m_avgAmp.reset(); + m_sourcesCorrections[isource].m_avgII.reset(); + m_sourcesCorrections[isource].m_avgII2.reset(); + m_sourcesCorrections[isource].m_avgIQ.reset(); + m_sourcesCorrections[isource].m_avgPhi.reset(); + m_sourcesCorrections[isource].m_avgQQ2.reset(); + m_sourcesCorrections[isource].m_iBeta.reset(); + m_sourcesCorrections[isource].m_qBeta.reset(); + } + + return true; + } + else if (DSPMIMOSignalNotification::match(message)) + { + const auto& notif = (const DSPMIMOSignalNotification&) message; + + // update DSP values + + bool sourceElseSink = notif.getSourceOrSink(); + unsigned int istream = notif.getIndex(); + int sampleRate = notif.getSampleRate(); + qint64 centerFrequency = notif.getCenterFrequency(); + bool realElseComplex = notif.getRealElseComplex(); + + qDebug() << "DeviceMIMOEngine::handleInputMessages: DSPMIMOSignalNotification:" + << " sourceElseSink: " << sourceElseSink + << " istream: " << istream + << " sampleRate: " << sampleRate + << " centerFrequency: " << centerFrequency + << " realElseComplex" << realElseComplex; + + if (sourceElseSink) { + m_rxRealElseComplex[istream] = realElseComplex; + } else { + m_txRealElseComplex[istream] = realElseComplex; + } + + for (MIMOChannels::const_iterator it = m_mimoChannels.begin(); it != m_mimoChannels.end(); ++it) + { + auto *msg = new DSPMIMOSignalNotification(notif); + (*it)->pushMessage(msg); + } + + if (m_deviceSampleMIMO) + { + if (sourceElseSink) + { + if ((istream < m_deviceSampleMIMO->getNbSourceStreams())) + { + + // forward source changes to ancillary sinks + if (istream < m_basebandSampleSinks.size()) + { + for (BasebandSampleSinks::const_iterator it = m_basebandSampleSinks[istream].begin(); it != m_basebandSampleSinks[istream].end(); ++it) + { + auto *msg = new DSPSignalNotification(sampleRate, centerFrequency); + qDebug() << "DSPDeviceMIMOEngine::handleInputMessages: starting " << (*it)->getSinkName().toStdString().c_str(); + (*it)->pushMessage(msg); + } + } + + // forward changes to MIMO GUI input queue + MessageQueue *guiMessageQueue = m_deviceSampleMIMO->getMessageQueueToGUI(); + qDebug("DeviceMIMOEngine::handleInputMessages: DSPMIMOSignalNotification: guiMessageQueue: %p", guiMessageQueue); + + if (guiMessageQueue) { + auto* rep = new DSPMIMOSignalNotification(notif); // make a copy for the MIMO GUI + guiMessageQueue->push(rep); + } + + // forward changes to spectrum sink if currently active + if (m_spectrumSink && m_spectrumInputSourceElseSink && (m_spectrumInputIndex == istream)) + { + auto *spectrumNotif = new DSPSignalNotification(sampleRate, centerFrequency); + m_spectrumSink->pushMessage(spectrumNotif); + } + } + } + else + { + if ((istream < m_deviceSampleMIMO->getNbSinkStreams())) + { + + // forward source changes to channel sources with immediate execution (no queuing) + if (istream < m_basebandSampleSources.size()) + { + for (BasebandSampleSources::const_iterator it = m_basebandSampleSources[istream].begin(); it != m_basebandSampleSources[istream].end(); ++it) + { + auto *msg = new DSPSignalNotification(sampleRate, centerFrequency); + qDebug() << "DSPDeviceMIMOEngine::handleSinkMessages: forward message to BasebandSampleSource(" << (*it)->getSourceName().toStdString().c_str() << ")"; + (*it)->pushMessage(msg); + } + } + + // forward changes to MIMO GUI input queue + MessageQueue *guiMessageQueue = m_deviceSampleMIMO->getMessageQueueToGUI(); + qDebug("DSPDeviceMIMOEngine::handleInputMessages: DSPSignalNotification: guiMessageQueue: %p", guiMessageQueue); + + if (guiMessageQueue) { + auto* rep = new DSPMIMOSignalNotification(notif); // make a copy for the source GUI + guiMessageQueue->push(rep); + } + + // forward changes to spectrum sink if currently active + if (m_spectrumSink && !m_spectrumInputSourceElseSink && (m_spectrumInputIndex == istream)) + { + auto *spectrumNotif = new DSPSignalNotification(sampleRate, centerFrequency); + m_spectrumSink->pushMessage(spectrumNotif); + } + } + } + } + + return true; + } + // was in handleSynchronousMessages + else if (DSPAcquisitionInit::match(message)) { setStateRx(gotoIdle(0)); @@ -910,22 +1052,22 @@ void DSPDeviceMIMOEngine::handleSynchronousMessages() setStateRx(gotoInit(0)); // State goes ready if init is performed } - returnState = m_stateRx; + return true; } - else if (DSPAcquisitionStart::match(*message)) + else if (DSPAcquisitionStart::match(message)) { if (m_stateRx == StReady) { setStateRx(gotoRunning(0)); } - returnState = m_stateRx; + return true; } - else if (DSPAcquisitionStop::match(*message)) + else if (DSPAcquisitionStop::match(message)) { setStateRx(gotoIdle(0)); - returnState = m_stateRx; + return true; } - else if (DSPGenerationInit::match(*message)) + else if (DSPGenerationInit::match(message)) { setStateTx(gotoIdle(1)); @@ -933,45 +1075,31 @@ void DSPDeviceMIMOEngine::handleSynchronousMessages() setStateTx(gotoInit(1)); // State goes ready if init is performed } - returnState = m_stateTx; + return true; } - else if (DSPGenerationStart::match(*message)) + else if (DSPGenerationStart::match(message)) { if (m_stateTx == StReady) { setStateTx(gotoRunning(1)); } - returnState = m_stateTx; + return true; } - else if (DSPGenerationStop::match(*message)) + else if (DSPGenerationStop::match(message)) { setStateTx(gotoIdle(1)); - returnState = m_stateTx; + return true; } - else if (GetMIMODeviceDescription::match(*message)) + else if (SetSampleMIMO::match(message)) { + const auto& cmd = (const SetSampleMIMO&) message; + handleSetMIMO(cmd.getSampleMIMO()); + return true; + } + else if (AddBasebandSampleSink::match(message)) { - ((GetMIMODeviceDescription*) message)->setDeviceDescription(m_deviceDescription); - } - else if (GetErrorMessage::match(*message)) - { - GetErrorMessage *cmd = (GetErrorMessage *) message; - int subsystemIndex = cmd->getSubsystemIndex(); - if (subsystemIndex == 0) { - cmd->setErrorMessage(m_errorMessageRx); - } else if (subsystemIndex == 1) { - cmd->setErrorMessage(m_errorMessageTx); - } else { - cmd->setErrorMessage("Not implemented"); - } - } - else if (SetSampleMIMO::match(*message)) { - handleSetMIMO(((SetSampleMIMO*) message)->getSampleMIMO()); - } - else if (AddBasebandSampleSink::match(*message)) - { - const AddBasebandSampleSink *msg = (AddBasebandSampleSink *) message; - BasebandSampleSink* sink = msg->getSampleSink(); - unsigned int isource = msg->getIndex(); + const auto& msg = (const AddBasebandSampleSink&) message; + BasebandSampleSink* sink = msg.getSampleSink(); + unsigned int isource = msg.getIndex(); if (isource < m_basebandSampleSinks.size()) { @@ -979,19 +1107,21 @@ void DSPDeviceMIMOEngine::handleSynchronousMessages() // initialize sample rate and center frequency in the sink: int sourceStreamSampleRate = m_deviceSampleMIMO->getSourceSampleRate(isource); quint64 sourceCenterFrequency = m_deviceSampleMIMO->getSourceCenterFrequency(isource); - DSPSignalNotification *msg = new DSPSignalNotification(sourceStreamSampleRate, sourceCenterFrequency); - sink->pushMessage(msg); + auto *msgToSink = new DSPSignalNotification(sourceStreamSampleRate, sourceCenterFrequency); + sink->pushMessage(msgToSink); // start the sink: if (m_stateRx == StRunning) { sink->start(); } } + + return true; } - else if (RemoveBasebandSampleSink::match(*message)) + else if (RemoveBasebandSampleSink::match(message)) { - const RemoveBasebandSampleSink *msg = (RemoveBasebandSampleSink *) message; - BasebandSampleSink* sink = ((DSPRemoveBasebandSampleSink*) message)->getSampleSink(); - unsigned int isource = msg->getIndex(); + const auto& msg = (const RemoveBasebandSampleSink&) message; + BasebandSampleSink* sink = msg.getSampleSink(); + unsigned int isource = msg.getIndex(); if (isource < m_basebandSampleSinks.size()) { @@ -999,50 +1129,56 @@ void DSPDeviceMIMOEngine::handleSynchronousMessages() sink->stop(); } - m_basebandSampleSinks[isource].remove(sink); + m_basebandSampleSinks[isource].remove(sink); } + + return true; } - else if (AddBasebandSampleSource::match(*message)) + else if (AddBasebandSampleSource::match(message)) { - const AddBasebandSampleSource *msg = (AddBasebandSampleSource *) message; - BasebandSampleSource *sampleSource = msg->getSampleSource(); - unsigned int isink = msg->getIndex(); + const auto& msg = (const AddBasebandSampleSource&) message; + BasebandSampleSource *sampleSource = msg.getSampleSource(); + unsigned int isink = msg.getIndex(); if (isink < m_basebandSampleSources.size()) { - m_basebandSampleSources[isink].push_back(sampleSource); + m_basebandSampleSources[isink].push_back(sampleSource); // initialize sample rate and center frequency in the sink: int sinkStreamSampleRate = m_deviceSampleMIMO->getSinkSampleRate(isink); quint64 sinkCenterFrequency = m_deviceSampleMIMO->getSinkCenterFrequency(isink); - DSPSignalNotification *msg = new DSPSignalNotification(sinkStreamSampleRate, sinkCenterFrequency); - sampleSource->pushMessage(msg); + auto *msgToSource = new DSPSignalNotification(sinkStreamSampleRate, sinkCenterFrequency); + sampleSource->pushMessage(msgToSource); // start the sink: if (m_stateTx == StRunning) { sampleSource->start(); } } + + return true; } - else if (RemoveBasebandSampleSource::match(*message)) + else if (RemoveBasebandSampleSource::match(message)) { - const RemoveBasebandSampleSource *msg = (RemoveBasebandSampleSource *) message; - BasebandSampleSource* sampleSource = msg->getSampleSource(); - unsigned int isink = msg->getIndex(); + const auto& msg = (const RemoveBasebandSampleSource&) message; + BasebandSampleSource* sampleSource = msg.getSampleSource(); + unsigned int isink = msg.getIndex(); if (isink < m_basebandSampleSources.size()) { sampleSource->stop(); m_basebandSampleSources[isink].remove(sampleSource); } + + return true; } - else if (AddMIMOChannel::match(*message)) + else if (AddMIMOChannel::match(message)) { - const AddMIMOChannel *msg = (AddMIMOChannel *) message; - MIMOChannel *channel = msg->getChannel(); + const auto& msg = (const AddMIMOChannel&) message; + MIMOChannel *channel = msg.getChannel(); m_mimoChannels.push_back(channel); for (unsigned int isource = 0; isource < m_deviceSampleMIMO->getNbSourceStreams(); isource++) { - DSPMIMOSignalNotification *notif = new DSPMIMOSignalNotification( + auto *notif = new DSPMIMOSignalNotification( m_deviceSampleMIMO->getSourceSampleRate(isource), m_deviceSampleMIMO->getSourceCenterFrequency(isource), true, @@ -1053,7 +1189,7 @@ void DSPDeviceMIMOEngine::handleSynchronousMessages() for (unsigned int isink = 0; isink < m_deviceSampleMIMO->getNbSinkStreams(); isink++) { - DSPMIMOSignalNotification *notif = new DSPMIMOSignalNotification( + auto *notif = new DSPMIMOSignalNotification( m_deviceSampleMIMO->getSinkSampleRate(isink), m_deviceSampleMIMO->getSinkCenterFrequency(isink), false, @@ -1069,30 +1205,37 @@ void DSPDeviceMIMOEngine::handleSynchronousMessages() if (m_stateTx == StRunning) { channel->startSources(); } + + return true; } - else if (RemoveMIMOChannel::match(*message)) + else if (RemoveMIMOChannel::match(message)) { - const RemoveMIMOChannel *msg = (RemoveMIMOChannel *) message; - MIMOChannel *channel = msg->getChannel(); + const auto& msg = (const RemoveMIMOChannel&) message; + MIMOChannel *channel = msg.getChannel(); channel->stopSinks(); channel->stopSources(); m_mimoChannels.remove(channel); + return true; } - else if (AddSpectrumSink::match(*message)) + else if (AddSpectrumSink::match(message)) { - m_spectrumSink = ((AddSpectrumSink*) message)->getSampleSink(); + const auto& msg = (const AddSpectrumSink&) message; + m_spectrumSink = msg.getSampleSink(); + return true; } - else if (RemoveSpectrumSink::match(*message)) + else if (RemoveSpectrumSink::match(message)) { - BasebandSampleSink* spectrumSink = ((DSPRemoveSpectrumSink*) message)->getSampleSink(); + const auto& msg = (const RemoveSpectrumSink&) message; + BasebandSampleSink* spectrumSink = msg.getSampleSink(); spectrumSink->stop(); m_spectrumSink = nullptr; + return true; } - else if (SetSpectrumSinkInput::match(*message)) + else if (SetSpectrumSinkInput::match(message)) { - const SetSpectrumSinkInput *msg = (SetSpectrumSinkInput *) message; - bool spectrumInputSourceElseSink = msg->getSourceElseSink(); - unsigned int spectrumInputIndex = msg->getIndex(); + const auto& msg = (const SetSpectrumSinkInput&) message; + bool spectrumInputSourceElseSink = msg.getSourceElseSink(); + unsigned int spectrumInputIndex = msg.getIndex(); if ((spectrumInputSourceElseSink != m_spectrumInputSourceElseSink) || (spectrumInputIndex != m_spectrumInputIndex)) { @@ -1100,16 +1243,16 @@ void DSPDeviceMIMOEngine::handleSynchronousMessages() { if (m_spectrumSink) { - DSPSignalNotification *notif = new DSPSignalNotification( + auto *notif = new DSPSignalNotification( m_deviceSampleMIMO->getSinkSampleRate(spectrumInputIndex), m_deviceSampleMIMO->getSinkCenterFrequency(spectrumInputIndex)); m_spectrumSink->pushMessage(notif); } } - if (m_spectrumSink && (spectrumInputSourceElseSink) && (spectrumInputIndex < m_deviceSampleMIMO->getNbSinkFifos())) + if (m_spectrumSink && spectrumInputSourceElseSink && (spectrumInputIndex < m_deviceSampleMIMO->getNbSinkFifos())) { - DSPSignalNotification *notif = new DSPSignalNotification( + auto *notif = new DSPSignalNotification( m_deviceSampleMIMO->getSourceSampleRate(spectrumInputIndex), m_deviceSampleMIMO->getSourceCenterFrequency(spectrumInputIndex)); m_spectrumSink->pushMessage(notif); @@ -1118,9 +1261,12 @@ void DSPDeviceMIMOEngine::handleSynchronousMessages() m_spectrumInputSourceElseSink = spectrumInputSourceElseSink; m_spectrumInputIndex = spectrumInputIndex; } + + return true; } - m_syncMessenger.done(returnState); + + return false; } void DSPDeviceMIMOEngine::handleInputMessages() @@ -1131,146 +1277,9 @@ void DSPDeviceMIMOEngine::handleInputMessages() { qDebug("DSPDeviceMIMOEngine::handleInputMessages: message: %s", message->getIdentifier()); - if (ConfigureCorrection::match(*message)) - { - ConfigureCorrection* conf = (ConfigureCorrection*) message; - unsigned int isource = conf->getIndex(); - - if (isource < m_sourcesCorrections.size()) - { - m_sourcesCorrections[isource].m_iqImbalanceCorrection = conf->getIQImbalanceCorrection(); - - if (m_sourcesCorrections[isource].m_dcOffsetCorrection != conf->getDCOffsetCorrection()) - { - m_sourcesCorrections[isource].m_dcOffsetCorrection = conf->getDCOffsetCorrection(); - m_sourcesCorrections[isource].m_iOffset = 0; - m_sourcesCorrections[isource].m_qOffset = 0; - - if (m_sourcesCorrections[isource].m_iqImbalanceCorrection != conf->getIQImbalanceCorrection()) - { - m_sourcesCorrections[isource].m_iqImbalanceCorrection = conf->getIQImbalanceCorrection(); - m_sourcesCorrections[isource].m_iRange = 1 << 16; - m_sourcesCorrections[isource].m_qRange = 1 << 16; - m_sourcesCorrections[isource].m_imbalance = 65536; - } - } - m_sourcesCorrections[isource].m_iBeta.reset(); - m_sourcesCorrections[isource].m_qBeta.reset(); - m_sourcesCorrections[isource].m_avgAmp.reset(); - m_sourcesCorrections[isource].m_avgII.reset(); - m_sourcesCorrections[isource].m_avgII2.reset(); - m_sourcesCorrections[isource].m_avgIQ.reset(); - m_sourcesCorrections[isource].m_avgPhi.reset(); - m_sourcesCorrections[isource].m_avgQQ2.reset(); - m_sourcesCorrections[isource].m_iBeta.reset(); - m_sourcesCorrections[isource].m_qBeta.reset(); - } - - delete message; - } - else if (DSPMIMOSignalNotification::match(*message)) - { - DSPMIMOSignalNotification *notif = (DSPMIMOSignalNotification *) message; - - // update DSP values - - bool sourceElseSink = notif->getSourceOrSink(); - unsigned int istream = notif->getIndex(); - int sampleRate = notif->getSampleRate(); - qint64 centerFrequency = notif->getCenterFrequency(); - bool realElseComplex = notif->getRealElseComplex(); - - qDebug() << "DeviceMIMOEngine::handleInputMessages: DSPMIMOSignalNotification:" - << " sourceElseSink: " << sourceElseSink - << " istream: " << istream - << " sampleRate: " << sampleRate - << " centerFrequency: " << centerFrequency - << " realElseComplex" << realElseComplex; - - if (sourceElseSink) { - m_rxRealElseComplex[istream] = realElseComplex; - } else { - m_txRealElseComplex[istream] = realElseComplex; - } - - for (MIMOChannels::const_iterator it = m_mimoChannels.begin(); it != m_mimoChannels.end(); ++it) - { - DSPMIMOSignalNotification *message = new DSPMIMOSignalNotification(*notif); - (*it)->pushMessage(message); - } - - if (m_deviceSampleMIMO) - { - if (sourceElseSink) - { - if ((istream < m_deviceSampleMIMO->getNbSourceStreams())) - { - - // forward source changes to ancillary sinks - if (istream < m_basebandSampleSinks.size()) - { - for (BasebandSampleSinks::const_iterator it = m_basebandSampleSinks[istream].begin(); it != m_basebandSampleSinks[istream].end(); ++it) - { - DSPSignalNotification *message = new DSPSignalNotification(sampleRate, centerFrequency); - qDebug() << "DSPDeviceMIMOEngine::handleInputMessages: starting " << (*it)->getSinkName().toStdString().c_str(); - (*it)->pushMessage(message); - } - } - - // forward changes to MIMO GUI input queue - MessageQueue *guiMessageQueue = m_deviceSampleMIMO->getMessageQueueToGUI(); - qDebug("DeviceMIMOEngine::handleInputMessages: DSPMIMOSignalNotification: guiMessageQueue: %p", guiMessageQueue); - - if (guiMessageQueue) { - DSPMIMOSignalNotification* rep = new DSPMIMOSignalNotification(*notif); // make a copy for the MIMO GUI - guiMessageQueue->push(rep); - } - - // forward changes to spectrum sink if currently active - if (m_spectrumSink && m_spectrumInputSourceElseSink && (m_spectrumInputIndex == istream)) - { - DSPSignalNotification *spectrumNotif = new DSPSignalNotification(sampleRate, centerFrequency); - m_spectrumSink->pushMessage(spectrumNotif); - } - } - } - else - { - if ((istream < m_deviceSampleMIMO->getNbSinkStreams())) - { - - // forward source changes to channel sources with immediate execution (no queuing) - if (istream < m_basebandSampleSources.size()) - { - for (BasebandSampleSources::const_iterator it = m_basebandSampleSources[istream].begin(); it != m_basebandSampleSources[istream].end(); ++it) - { - DSPSignalNotification *message = new DSPSignalNotification(sampleRate, centerFrequency); - qDebug() << "DSPDeviceMIMOEngine::handleSinkMessages: forward message to BasebandSampleSource(" << (*it)->getSourceName().toStdString().c_str() << ")"; - (*it)->pushMessage(message); - } - } - - // forward changes to MIMO GUI input queue - MessageQueue *guiMessageQueue = m_deviceSampleMIMO->getMessageQueueToGUI(); - qDebug("DSPDeviceMIMOEngine::handleInputMessages: DSPSignalNotification: guiMessageQueue: %p", guiMessageQueue); - - if (guiMessageQueue) { - DSPMIMOSignalNotification* rep = new DSPMIMOSignalNotification(*notif); // make a copy for the source GUI - guiMessageQueue->push(rep); - } - - // forward changes to spectrum sink if currently active - if (m_spectrumSink && !m_spectrumInputSourceElseSink && (m_spectrumInputIndex == istream)) - { - DSPSignalNotification *spectrumNotif = new DSPSignalNotification(sampleRate, centerFrequency); - m_spectrumSink->pushMessage(spectrumNotif); - } - } - } - } - + if (handleMessage(*message)) { delete message; - } + } } } diff --git a/sdrbase/dsp/dspdevicemimoengine.h b/sdrbase/dsp/dspdevicemimoengine.h index 00e24f44f..b765aecb7 100644 --- a/sdrbase/dsp/dspdevicemimoengine.h +++ b/sdrbase/dsp/dspdevicemimoengine.h @@ -24,7 +24,6 @@ #include "dsp/dsptypes.h" #include "util/message.h" #include "util/messagequeue.h" -#include "util/syncmessenger.h" #include "util/movingaverage.h" #include "util/incrementalvector.h" #include "export.h" @@ -252,8 +251,8 @@ public: } } - QString errorMessage(int subsystemIndex); //!< Return the current error message - QString deviceDescription(); //!< Return the device description + QString errorMessage(int subsystemIndex) const; //!< Return the current error message + QString deviceDescription() const; //!< Return the device description void configureCorrections(bool dcOffsetCorrection, bool iqImbalanceCorrection, int isource); //!< Configure source DSP corrections @@ -320,7 +319,6 @@ private: int m_sampleMIMOSequence; MessageQueue m_inputMessageQueue; // BasebandSampleSinks; std::vector m_basebandSampleSinks; //!< ancillary sample sinks on main thread (per input stream) @@ -357,14 +355,14 @@ private: void setStateTx(State state); void handleSetMIMO(DeviceSampleMIMO* mimo); //!< Manage MIMO device setting - void iqCorrections(SampleVector::iterator begin, SampleVector::iterator end, int isource, bool imbalanceCorrection); + void iqCorrections(SampleVector::iterator begin, SampleVector::iterator end, int isource, bool imbalanceCorrection); + bool handleMessage(const Message& cmd); private slots: void handleDataRxSync(); //!< Handle data when Rx samples have to be processed synchronously void handleDataRxAsync(int streamIndex); //!< Handle data when Rx samples have to be processed asynchronously void handleDataTxSync(); //!< Handle data when Tx samples have to be processed synchronously void handleDataTxAsync(int streamIndex); //!< Handle data when Tx samples have to be processed asynchronously - void handleSynchronousMessages(); //!< Handle synchronous messages with the thread void handleInputMessages(); //!< Handle input message queue signals: From f5e770861274d6f8c93c8956765944c70196d4db Mon Sep 17 00:00:00 2001 From: f4exb Date: Sat, 17 Aug 2024 11:22:09 +0200 Subject: [PATCH 04/16] RTLSDR: make sure start and stop are effective once only. PArt of #2159 --- plugins/samplesource/rtlsdr/rtlsdrinput.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/plugins/samplesource/rtlsdr/rtlsdrinput.cpp b/plugins/samplesource/rtlsdr/rtlsdrinput.cpp index 20cf56e01..d98509fee 100644 --- a/plugins/samplesource/rtlsdr/rtlsdrinput.cpp +++ b/plugins/samplesource/rtlsdr/rtlsdrinput.cpp @@ -78,6 +78,7 @@ RTLSDRInput::RTLSDRInput(DeviceAPI *deviceAPI) : RTLSDRInput::~RTLSDRInput() { + qDebug("RTLSDRInput::~RTLSDRInput"); QObject::disconnect( m_networkManager, &QNetworkAccessManager::finished, @@ -91,6 +92,7 @@ RTLSDRInput::~RTLSDRInput() } closeDevice(); + qDebug("RTLSDRInput::~RTLSDRInput: end"); } void RTLSDRInput::destroy() @@ -231,11 +233,15 @@ bool RTLSDRInput::start() { QMutexLocker mutexLocker(&m_mutex); + if (m_running) { + return true; + } + if (!m_dev) { - return false; + return false; } - if (m_running) stop(); + qDebug("RTLSDRInput::start"); m_rtlSDRThread = new RTLSDRThread(m_dev, &m_sampleFifo, &m_replayBuffer); m_rtlSDRThread->setSamplerate(m_settings.m_devSampleRate); @@ -243,11 +249,11 @@ bool RTLSDRInput::start() m_rtlSDRThread->setFcPos((int) m_settings.m_fcPos); m_rtlSDRThread->setIQOrder(m_settings.m_iqOrder); m_rtlSDRThread->startWork(); + m_running = true; mutexLocker.unlock(); applySettings(m_settings, QList(), true); - m_running = true; return true; } @@ -267,6 +273,12 @@ void RTLSDRInput::stop() { QMutexLocker mutexLocker(&m_mutex); + if (!m_running) { + return; + } + + qDebug("RTLSDRInput::stop"); + if (m_rtlSDRThread) { m_rtlSDRThread->stopWork(); From 436d1665eae2b5fc9d4597aa7711a66f86ae165c Mon Sep 17 00:00:00 2001 From: f4exb Date: Sat, 17 Aug 2024 11:24:19 +0200 Subject: [PATCH 05/16] Fixed threading model for DSPDeviceMIMOEngine plus other fixes. Part of #2159 --- plugins/samplemimo/metismiso/metismiso.cpp | 3 + sdrbase/dsp/dspdevicemimoengine.cpp | 33 +------- sdrbase/dsp/dspdevicemimoengine.h | 10 +-- sdrbase/dsp/dspdevicesourceengine.cpp | 1 + sdrbase/dsp/dspengine.cpp | 37 ++++++-- sdrgui/mainwindow.cpp | 99 ++++++++++------------ sdrsrv/mainserver.cpp | 42 ++++----- 7 files changed, 109 insertions(+), 116 deletions(-) diff --git a/plugins/samplemimo/metismiso/metismiso.cpp b/plugins/samplemimo/metismiso/metismiso.cpp index 8844a349e..3ad802c5d 100644 --- a/plugins/samplemimo/metismiso/metismiso.cpp +++ b/plugins/samplemimo/metismiso/metismiso.cpp @@ -66,6 +66,7 @@ MetisMISO::MetisMISO(DeviceAPI *deviceAPI) : MetisMISO::~MetisMISO() { + qDebug("MetisMISO::~MetisMISO"); QObject::disconnect( m_networkManager, &QNetworkAccessManager::finished, @@ -77,6 +78,7 @@ MetisMISO::~MetisMISO() if (m_running) { stopRx(); } + qDebug("MetisMISO::~MetisMISO: end"); } void MetisMISO::destroy() @@ -155,6 +157,7 @@ void MetisMISO::startMetis() void MetisMISO::stopMetis() { + qDebug("MetisMISO::stopMetis"); MetisMISOUDPHandler::MsgStartStop *message = MetisMISOUDPHandler::MsgStartStop::create(false); m_udpHandler.getInputMessageQueue()->push(message); } diff --git a/sdrbase/dsp/dspdevicemimoengine.cpp b/sdrbase/dsp/dspdevicemimoengine.cpp index 386c234b8..7fd4997ae 100644 --- a/sdrbase/dsp/dspdevicemimoengine.cpp +++ b/sdrbase/dsp/dspdevicemimoengine.cpp @@ -41,7 +41,7 @@ MESSAGE_CLASS_DEFINITION(DSPDeviceMIMOEngine::ConfigureCorrection, Message) MESSAGE_CLASS_DEFINITION(DSPDeviceMIMOEngine::SetSpectrumSinkInput, Message) DSPDeviceMIMOEngine::DSPDeviceMIMOEngine(uint32_t uid, QObject* parent) : - QThread(parent), + QObject(parent), m_uid(uid), m_stateRx(StNotStarted), m_stateTx(StNotStarted), @@ -49,15 +49,14 @@ DSPDeviceMIMOEngine::DSPDeviceMIMOEngine(uint32_t uid, QObject* parent) : m_spectrumInputSourceElseSink(true), m_spectrumInputIndex(0) { + setStateRx(StIdle); + setStateTx(StIdle); connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()), Qt::QueuedConnection); - - moveToThread(this); } DSPDeviceMIMOEngine::~DSPDeviceMIMOEngine() { - stop(); - wait(); + qDebug("DSPDeviceMIMOEngine::~DSPDeviceMIMOEngine"); } void DSPDeviceMIMOEngine::setStateRx(State state) @@ -78,30 +77,6 @@ void DSPDeviceMIMOEngine::setStateTx(State state) } } -void DSPDeviceMIMOEngine::run() -{ - qDebug() << "DSPDeviceMIMOEngine::run"; - setStateRx(StIdle); - setStateTx(StIdle); - exec(); -} - -void DSPDeviceMIMOEngine::start() -{ - qDebug() << "DSPDeviceMIMOEngine::start"; - QThread::start(); -} - -void DSPDeviceMIMOEngine::stop() -{ - qDebug() << "DSPDeviceMIMOEngine::stop"; - gotoIdle(0); // Rx - gotoIdle(1); // Tx - setStateRx(StNotStarted); - setStateTx(StNotStarted); - QThread::exit(); -} - bool DSPDeviceMIMOEngine::initProcess(int subsystemIndex) { qDebug() << "DSPDeviceMIMOEngine::initProcess: subsystemIndex: " << subsystemIndex; diff --git a/sdrbase/dsp/dspdevicemimoengine.h b/sdrbase/dsp/dspdevicemimoengine.h index b765aecb7..57968680c 100644 --- a/sdrbase/dsp/dspdevicemimoengine.h +++ b/sdrbase/dsp/dspdevicemimoengine.h @@ -19,7 +19,7 @@ #ifndef SDRBASE_DSP_DSPDEVICEMIMOENGINE_H_ #define SDRBASE_DSP_DSPDEVICEMIMOENGINE_H_ -#include +#include #include "dsp/dsptypes.h" #include "util/message.h" @@ -33,7 +33,7 @@ class BasebandSampleSink; class BasebandSampleSource; class MIMOChannel; -class SDRBASE_API DSPDeviceMIMOEngine : public QThread { +class SDRBASE_API DSPDeviceMIMOEngine : public QObject { Q_OBJECT public: @@ -213,13 +213,10 @@ public: }; DSPDeviceMIMOEngine(uint32_t uid, QObject* parent = nullptr); - ~DSPDeviceMIMOEngine(); + ~DSPDeviceMIMOEngine() override; MessageQueue* getInputMessageQueue() { return &m_inputMessageQueue; } - void start(); //!< This thread start - void stop(); //!< This thread stop - bool initProcess(int subsystemIndex); //!< Initialize process sequence bool startProcess(int subsystemIndex); //!< Start process sequence void stopProcess(int subsystemIndex); //!< Stop process sequence @@ -339,7 +336,6 @@ private: bool m_spectrumInputSourceElseSink; //!< Source else sink stream to be used as spectrum sink input unsigned int m_spectrumInputIndex; //!< Index of the stream to be used as spectrum sink input - void run(); void workSampleSinkFifos(); //!< transfer samples of all sink streams (sync mode) void workSampleSinkFifo(unsigned int streamIndex); //!< transfer samples of one sink stream (async mode) void workSamplesSink(const SampleVector::const_iterator& vbegin, const SampleVector::const_iterator& vend, unsigned int streamIndex); diff --git a/sdrbase/dsp/dspdevicesourceengine.cpp b/sdrbase/dsp/dspdevicesourceengine.cpp index 27869762a..afaf18ee7 100644 --- a/sdrbase/dsp/dspdevicesourceengine.cpp +++ b/sdrbase/dsp/dspdevicesourceengine.cpp @@ -52,6 +52,7 @@ DSPDeviceSourceEngine::DSPDeviceSourceEngine(uint uid, QObject* parent) : DSPDeviceSourceEngine::~DSPDeviceSourceEngine() { + qDebug("DSPDeviceSourceEngine::~DSPDeviceSourceEngine"); } void DSPDeviceSourceEngine::setState(State state) diff --git a/sdrbase/dsp/dspengine.cpp b/sdrbase/dsp/dspengine.cpp index b6d688ba7..43e7be763 100644 --- a/sdrbase/dsp/dspengine.cpp +++ b/sdrbase/dsp/dspengine.cpp @@ -138,24 +138,45 @@ void DSPEngine::removeLastDeviceSinkEngine() DSPDeviceMIMOEngine *DSPEngine::addDeviceMIMOEngine() { - m_deviceMIMOEngines.push_back(new DSPDeviceMIMOEngine(m_deviceMIMOEnginesUIDSequence)); + auto *deviceMIMOEngine = new DSPDeviceMIMOEngine(m_deviceMIMOEnginesUIDSequence); + auto *deviceThread = new QThread(); m_deviceMIMOEnginesUIDSequence++; - m_deviceEngineReferences.push_back(DeviceEngineReference{2, nullptr, nullptr, m_deviceMIMOEngines.back(), nullptr}); - return m_deviceMIMOEngines.back(); + m_deviceMIMOEngines.push_back(deviceMIMOEngine); + m_deviceEngineReferences.push_back(DeviceEngineReference{2, nullptr, nullptr, m_deviceMIMOEngines.back(), deviceThread}); + deviceMIMOEngine->moveToThread(deviceThread); + + QObject::connect( + deviceThread, + &QThread::finished, + deviceMIMOEngine, + &QObject::deleteLater + ); + QObject::connect( + deviceThread, + &QThread::finished, + deviceThread, + &QThread::deleteLater + ); + + deviceThread->start(); + + return deviceMIMOEngine; } void DSPEngine::removeLastDeviceMIMOEngine() { - if (m_deviceMIMOEngines.size() > 0) + if (!m_deviceMIMOEngines.empty()) { - DSPDeviceMIMOEngine *lastDeviceEngine = m_deviceMIMOEngines.back(); - delete lastDeviceEngine; + const DSPDeviceMIMOEngine *lastDeviceEngine = m_deviceMIMOEngines.back(); m_deviceMIMOEngines.pop_back(); for (int i = 0; i < m_deviceEngineReferences.size(); i++) { if (m_deviceEngineReferences[i].m_deviceMIMOEngine == lastDeviceEngine) { + QThread* deviceThread = m_deviceEngineReferences[i].m_thread; + deviceThread->exit(); + deviceThread->wait(); m_deviceEngineReferences.removeAt(i); break; } @@ -186,7 +207,9 @@ void DSPEngine::removeDeviceEngineAt(int deviceIndex) else if (m_deviceEngineReferences[deviceIndex].m_deviceEngineType == 2) // MIMO { DSPDeviceMIMOEngine *deviceEngine = m_deviceEngineReferences[deviceIndex].m_deviceMIMOEngine; - delete deviceEngine; + QThread *deviceThread = m_deviceEngineReferences[deviceIndex].m_thread; + deviceThread->exit(); + deviceThread->wait(); m_deviceMIMOEngines.removeAll(deviceEngine); } diff --git a/sdrgui/mainwindow.cpp b/sdrgui/mainwindow.cpp index 3c3cef816..5d29360ad 100644 --- a/sdrgui/mainwindow.cpp +++ b/sdrgui/mainwindow.cpp @@ -783,7 +783,6 @@ void MainWindow::sampleSinkCreate( void MainWindow::sampleMIMOAdd(Workspace *deviceWorkspace, Workspace *spectrumWorkspace, int deviceIndex) { DSPDeviceMIMOEngine *dspDeviceMIMOEngine = m_dspEngine->addDeviceMIMOEngine(); - dspDeviceMIMOEngine->start(); uint dspDeviceMIMOEngineUID = dspDeviceMIMOEngine->getUID(); char uidCStr[16]; @@ -1002,65 +1001,62 @@ void MainWindow::removeDeviceSet(int deviceSetIndex) deviceUISet->m_deviceAPI->getSampleSource()->setMessageQueueToGUI(nullptr); // have source stop sending messages to the GUI deviceUISet->m_deviceGUI->destroy(); deviceUISet->m_deviceAPI->resetSamplingDeviceId(); - deviceUISet->m_deviceAPI->getPluginInterface()->deleteSampleSourcePluginInstanceInput( - deviceUISet->m_deviceAPI->getSampleSource()); deviceUISet->m_deviceAPI->clearBuddiesLists(); // clear old API buddies lists - DeviceAPI *sourceAPI = deviceUISet->m_deviceAPI; - delete deviceUISet; - m_dspEngine->removeDeviceEngineAt(deviceSetIndex); + m_dspEngine->removeDeviceEngineAt(deviceSetIndex); DeviceEnumerator::instance()->removeRxSelection(deviceSetIndex); - delete sourceAPI; + DeviceAPI *sourceAPI = deviceUISet->m_deviceAPI; + delete deviceUISet; + delete sourceAPI->getSampleSource(); + delete sourceAPI; } else if (deviceUISet->m_deviceSinkEngine) // sink device { DSPDeviceSinkEngine *deviceEngine = deviceUISet->m_deviceSinkEngine; - deviceEngine->stopGeneration(); - deviceEngine->removeSpectrumSink(deviceUISet->m_spectrumVis); + deviceEngine->stopGeneration(); + deviceEngine->removeSpectrumSink(deviceUISet->m_spectrumVis); // deletes old UI and output object deviceUISet->freeChannels(); deviceUISet->m_deviceAPI->getSampleSink()->setMessageQueueToGUI(nullptr); // have sink stop sending messages to the GUI deviceUISet->m_deviceGUI->destroy(); - deviceUISet->m_deviceAPI->resetSamplingDeviceId(); - deviceUISet->m_deviceAPI->getPluginInterface()->deleteSampleSinkPluginInstanceOutput( - deviceUISet->m_deviceAPI->getSampleSink()); + deviceUISet->m_deviceAPI->resetSamplingDeviceId(); + deviceUISet->m_deviceAPI->getPluginInterface()->deleteSampleSinkPluginInstanceOutput( + deviceUISet->m_deviceAPI->getSampleSink()); deviceUISet->m_deviceAPI->clearBuddiesLists(); // clear old API buddies lists DeviceAPI *sinkAPI = deviceUISet->m_deviceAPI; - delete deviceUISet; + delete deviceUISet; - deviceEngine->stop(); - m_dspEngine->removeDeviceEngineAt(deviceSetIndex); + deviceEngine->stop(); + m_dspEngine->removeDeviceEngineAt(deviceSetIndex); DeviceEnumerator::instance()->removeTxSelection(deviceSetIndex); - delete sinkAPI; + delete sinkAPI; } else if (deviceUISet->m_deviceMIMOEngine) // MIMO device { DSPDeviceMIMOEngine *deviceEngine = deviceUISet->m_deviceMIMOEngine; deviceEngine->stopProcess(1); // Tx side deviceEngine->stopProcess(0); // Rx side - deviceEngine->removeSpectrumSink(deviceUISet->m_spectrumVis); + deviceEngine->removeSpectrumSink(deviceUISet->m_spectrumVis); // deletes old UI and output object deviceUISet->freeChannels(); deviceUISet->m_deviceAPI->getSampleMIMO()->setMessageQueueToGUI(nullptr); // have sink stop sending messages to the GUI deviceUISet->m_deviceGUI->destroy(); - deviceUISet->m_deviceAPI->resetSamplingDeviceId(); - deviceUISet->m_deviceAPI->getPluginInterface()->deleteSampleMIMOPluginInstanceMIMO( - deviceUISet->m_deviceAPI->getSampleMIMO()); + deviceUISet->m_deviceAPI->resetSamplingDeviceId(); - DeviceAPI *mimoAPI = deviceUISet->m_deviceAPI; - delete deviceUISet; - deviceEngine->stop(); - m_dspEngine->removeDeviceEngineAt(deviceSetIndex); + m_dspEngine->removeDeviceEngineAt(deviceSetIndex); DeviceEnumerator::instance()->removeMIMOSelection(deviceSetIndex); - delete mimoAPI; + DeviceAPI *mimoAPI = deviceUISet->m_deviceAPI; + delete deviceUISet; + delete mimoAPI->getSampleMIMO(); + delete mimoAPI; } m_deviceUIs.erase(m_deviceUIs.begin() + deviceSetIndex); @@ -1094,75 +1090,72 @@ void MainWindow::removeDeviceSet(int deviceSetIndex) void MainWindow::removeLastDeviceSet() { + qDebug("MainWindow::removeLastDeviceSet: %s", qPrintable(m_deviceUIs.back()->m_deviceAPI->getHardwareId())); int removedDeviceSetIndex = m_deviceUIs.size() - 1; if (m_deviceUIs.back()->m_deviceSourceEngine) // source tab { DSPDeviceSourceEngine *lastDeviceEngine = m_deviceUIs.back()->m_deviceSourceEngine; - lastDeviceEngine->stopAcquistion(); - lastDeviceEngine->removeSink(m_deviceUIs.back()->m_spectrumVis); + lastDeviceEngine->stopAcquistion(); + lastDeviceEngine->removeSink(m_deviceUIs.back()->m_spectrumVis); // deletes old UI and input object m_deviceUIs.back()->freeChannels(); // destroys the channel instances m_deviceUIs.back()->m_deviceAPI->getSampleSource()->setMessageQueueToGUI(nullptr); // have source stop sending messages to the GUI m_deviceUIs.back()->m_deviceGUI->destroy(); m_deviceUIs.back()->m_deviceAPI->resetSamplingDeviceId(); - m_deviceUIs.back()->m_deviceAPI->getPluginInterface()->deleteSampleSourcePluginInstanceInput( - m_deviceUIs.back()->m_deviceAPI->getSampleSource()); m_deviceUIs.back()->m_deviceAPI->clearBuddiesLists(); // clear old API buddies lists + + m_dspEngine->removeLastDeviceSourceEngine(); + DeviceAPI *sourceAPI = m_deviceUIs.back()->m_deviceAPI; - delete m_deviceUIs.back(); - - m_dspEngine->removeLastDeviceSourceEngine(); - - delete sourceAPI; + delete m_deviceUIs.back(); + delete sourceAPI->getSampleSource(); + delete sourceAPI; } else if (m_deviceUIs.back()->m_deviceSinkEngine) // sink tab { DSPDeviceSinkEngine *lastDeviceEngine = m_deviceUIs.back()->m_deviceSinkEngine; - lastDeviceEngine->stopGeneration(); - lastDeviceEngine->removeSpectrumSink(m_deviceUIs.back()->m_spectrumVis); + lastDeviceEngine->stopGeneration(); + lastDeviceEngine->removeSpectrumSink(m_deviceUIs.back()->m_spectrumVis); // deletes old UI and output object m_deviceUIs.back()->freeChannels(); m_deviceUIs.back()->m_deviceAPI->getSampleSink()->setMessageQueueToGUI(nullptr); // have sink stop sending messages to the GUI m_deviceUIs.back()->m_deviceGUI->destroy(); - m_deviceUIs.back()->m_deviceAPI->resetSamplingDeviceId(); - m_deviceUIs.back()->m_deviceAPI->getPluginInterface()->deleteSampleSinkPluginInstanceOutput( - m_deviceUIs.back()->m_deviceAPI->getSampleSink()); + m_deviceUIs.back()->m_deviceAPI->resetSamplingDeviceId(); + m_deviceUIs.back()->m_deviceAPI->getPluginInterface()->deleteSampleSinkPluginInstanceOutput( + m_deviceUIs.back()->m_deviceAPI->getSampleSink()); m_deviceUIs.back()->m_deviceAPI->clearBuddiesLists(); // clear old API buddies lists DeviceAPI *sinkAPI = m_deviceUIs.back()->m_deviceAPI; - delete m_deviceUIs.back(); + delete m_deviceUIs.back(); - lastDeviceEngine->stop(); - m_dspEngine->removeLastDeviceSinkEngine(); + lastDeviceEngine->stop(); + m_dspEngine->removeLastDeviceSinkEngine(); - delete sinkAPI; + delete sinkAPI; } else if (m_deviceUIs.back()->m_deviceMIMOEngine) // MIMO tab { DSPDeviceMIMOEngine *lastDeviceEngine = m_deviceUIs.back()->m_deviceMIMOEngine; lastDeviceEngine->stopProcess(1); // Tx side lastDeviceEngine->stopProcess(0); // Rx side - lastDeviceEngine->removeSpectrumSink(m_deviceUIs.back()->m_spectrumVis); + lastDeviceEngine->removeSpectrumSink(m_deviceUIs.back()->m_spectrumVis); // deletes old UI and output object m_deviceUIs.back()->freeChannels(); m_deviceUIs.back()->m_deviceAPI->getSampleMIMO()->setMessageQueueToGUI(nullptr); // have sink stop sending messages to the GUI m_deviceUIs.back()->m_deviceGUI->destroy(); - m_deviceUIs.back()->m_deviceAPI->resetSamplingDeviceId(); - m_deviceUIs.back()->m_deviceAPI->getPluginInterface()->deleteSampleMIMOPluginInstanceMIMO( - m_deviceUIs.back()->m_deviceAPI->getSampleMIMO()); + m_deviceUIs.back()->m_deviceAPI->resetSamplingDeviceId(); + + m_dspEngine->removeLastDeviceMIMOEngine(); DeviceAPI *mimoAPI = m_deviceUIs.back()->m_deviceAPI; - delete m_deviceUIs.back(); - - lastDeviceEngine->stop(); - m_dspEngine->removeLastDeviceMIMOEngine(); - - delete mimoAPI; + delete m_deviceUIs.back(); + delete mimoAPI->getSampleMIMO(); + delete mimoAPI; } m_deviceUIs.pop_back(); diff --git a/sdrsrv/mainserver.cpp b/sdrsrv/mainserver.cpp index 7f66b948e..c98f5decd 100644 --- a/sdrsrv/mainserver.cpp +++ b/sdrsrv/mainserver.cpp @@ -27,6 +27,9 @@ #include "dsp/dspdevicesourceengine.h" #include "dsp/dspdevicesinkengine.h" #include "dsp/dspdevicemimoengine.h" +#include "dsp/devicesamplesource.h" +#include "dsp/devicesamplesink.h" +#include "dsp/devicesamplemimo.h" #include "dsp/spectrumvis.h" #include "device/deviceapi.h" #include "device/deviceset.h" @@ -316,10 +319,6 @@ void MainServer::addSourceDevice() { DSPDeviceSourceEngine *dspDeviceSourceEngine = m_dspEngine->addDeviceSourceEngine(); - uint dspDeviceSourceEngineUID = dspDeviceSourceEngine->getUID(); - char uidCStr[16]; - sprintf(uidCStr, "UID:%d", dspDeviceSourceEngineUID); - int deviceTabIndex = m_mainCore->m_deviceSets.size(); m_mainCore->m_deviceSets.push_back(new DeviceSet(deviceTabIndex, 0)); m_mainCore->m_deviceSets.back()->m_deviceSourceEngine = dspDeviceSourceEngine; @@ -327,9 +326,6 @@ void MainServer::addSourceDevice() m_mainCore->m_deviceSets.back()->m_deviceMIMOEngine = nullptr; dspDeviceSourceEngine->addSink(m_mainCore->m_deviceSets.back()->m_spectrumVis); - char tabNameCStr[16]; - sprintf(tabNameCStr, "R%d", deviceTabIndex); - DeviceAPI *deviceAPI = new DeviceAPI(DeviceAPI::StreamSingleRx, deviceTabIndex, dspDeviceSourceEngine, nullptr, nullptr); m_mainCore->m_deviceSets.back()->m_deviceAPI = deviceAPI; @@ -361,11 +357,6 @@ void MainServer::addSourceDevice() void MainServer::addMIMODevice() { DSPDeviceMIMOEngine *dspDeviceMIMOEngine = m_dspEngine->addDeviceMIMOEngine(); - dspDeviceMIMOEngine->start(); - - uint dspDeviceMIMOEngineUID = dspDeviceMIMOEngine->getUID(); - char uidCStr[16]; - sprintf(uidCStr, "UID:%d", dspDeviceMIMOEngineUID); int deviceTabIndex = m_mainCore->m_deviceSets.size(); m_mainCore->m_deviceSets.push_back(new DeviceSet(deviceTabIndex, 2)); @@ -374,9 +365,6 @@ void MainServer::addMIMODevice() m_mainCore->m_deviceSets.back()->m_deviceMIMOEngine = dspDeviceMIMOEngine; dspDeviceMIMOEngine->addSpectrumSink(m_mainCore->m_deviceSets.back()->m_spectrumVis); - char tabNameCStr[16]; - sprintf(tabNameCStr, "M%d", deviceTabIndex); - DeviceAPI *deviceAPI = new DeviceAPI(DeviceAPI::StreamMIMO, deviceTabIndex, nullptr, nullptr, dspDeviceMIMOEngine); // create a test MIMO by default @@ -415,15 +403,13 @@ void MainServer::removeLastDevice() // deletes old UI and input object m_mainCore->m_deviceSets.back()->freeChannels(); // destroys the channel instances m_mainCore->m_deviceSets.back()->m_deviceAPI->resetSamplingDeviceId(); - m_mainCore->m_deviceSets.back()->m_deviceAPI->getPluginInterface()->deleteSampleSourcePluginInstanceInput( - m_mainCore->m_deviceSets.back()->m_deviceAPI->getSampleSource()); m_mainCore->m_deviceSets.back()->m_deviceAPI->clearBuddiesLists(); // clear old API buddies lists - DeviceAPI *sourceAPI = m_mainCore->m_deviceSets.back()->m_deviceAPI; - delete m_mainCore->m_deviceSets.back(); - m_dspEngine->removeLastDeviceSourceEngine(); + DeviceAPI *sourceAPI = m_mainCore->m_deviceSets.back()->m_deviceAPI; + delete m_mainCore->m_deviceSets.back(); + delete sourceAPI->getSampleSource(); delete sourceAPI; } else if (m_mainCore->m_deviceSets.back()->m_deviceSinkEngine) // sink set @@ -446,6 +432,22 @@ void MainServer::removeLastDevice() delete sinkAPI; } + else if (m_mainCore->m_deviceSets.back()->m_deviceMIMOEngine) // MIMO set + { + DSPDeviceMIMOEngine *lastDeviceEngine = m_mainCore->m_deviceSets.back()->m_deviceMIMOEngine; + lastDeviceEngine->stopProcess(1); // Tx side + lastDeviceEngine->stopProcess(0); // Rx side + + m_mainCore->m_deviceSets.back()->freeChannels(); + m_mainCore->m_deviceSets.back()->m_deviceAPI->resetSamplingDeviceId(); + + m_dspEngine->removeLastDeviceSourceEngine(); + + DeviceAPI *mimoAPI = m_mainCore->m_deviceSets.back()->m_deviceAPI; + delete m_mainCore->m_deviceSets.back(); + delete mimoAPI->getSampleMIMO(); + delete mimoAPI; + } m_mainCore->m_deviceSets.pop_back(); emit m_mainCore->deviceSetRemoved(removedTabIndex); From 4a2032a26ab9af634cbee1aaa37b77d59f3fcad0 Mon Sep 17 00:00:00 2001 From: f4exb Date: Sat, 17 Aug 2024 22:33:30 +0200 Subject: [PATCH 06/16] NFMMod: revised thread processing --- plugins/channeltx/modnfm/nfmmod.cpp | 128 ++++++++++++++------ plugins/channeltx/modnfm/nfmmod.h | 9 +- plugins/channeltx/modnfm/nfmmodbaseband.cpp | 5 +- plugins/channeltx/modnfm/nfmmodbaseband.h | 2 +- plugins/channeltx/modnfm/nfmmodsource.cpp | 23 +++- plugins/channeltx/modnfm/nfmmodsource.h | 7 +- 6 files changed, 120 insertions(+), 54 deletions(-) diff --git a/plugins/channeltx/modnfm/nfmmod.cpp b/plugins/channeltx/modnfm/nfmmod.cpp index 78940acd3..dc4b0d549 100644 --- a/plugins/channeltx/modnfm/nfmmod.cpp +++ b/plugins/channeltx/modnfm/nfmmod.cpp @@ -57,18 +57,14 @@ const char* const NFMMod::m_channelId = "NFMMod"; NFMMod::NFMMod(DeviceAPI *deviceAPI) : ChannelAPI(m_channelIdURI, ChannelAPI::StreamSingleSource), m_deviceAPI(deviceAPI), + m_running(false), m_fileSize(0), m_recordLength(0), - m_sampleRate(48000) + m_sampleRate(48000), + m_levelMeter(nullptr) { setObjectName(m_channelId); - m_thread = new QThread(this); - m_basebandSource = new NFMModBaseband(); - m_basebandSource->setInputFileStream(&m_ifstream); - m_basebandSource->setChannel(this); - m_basebandSource->moveToThread(m_thread); - applySettings(m_settings, true); m_deviceAPI->addChannelSource(this); @@ -94,8 +90,8 @@ NFMMod::~NFMMod() delete m_networkManager; m_deviceAPI->removeChannelSourceAPI(this); m_deviceAPI->removeChannelSource(this); - delete m_basebandSource; - delete m_thread; + + stop(); } void NFMMod::setDeviceAPI(DeviceAPI *deviceAPI) @@ -112,21 +108,61 @@ void NFMMod::setDeviceAPI(DeviceAPI *deviceAPI) void NFMMod::start() { + if (m_running) { + return; + } + qDebug("NFMMod::start"); + m_thread = new QThread(this); + m_basebandSource = new NFMModBaseband(); + m_basebandSource->setInputFileStream(&m_ifstream); + m_basebandSource->setChannel(this); m_basebandSource->reset(); + m_basebandSource->setCWKeyer(&m_cwKeyer); + m_basebandSource->moveToThread(m_thread); + + QObject::connect( + m_thread, + &QThread::finished, + m_basebandSource, + &QObject::deleteLater + ); + QObject::connect( + m_thread, + &QThread::finished, + m_thread, + &QThread::deleteLater + ); + m_thread->start(); + + if (m_levelMeter) { + connect(m_basebandSource, SIGNAL(levelChanged(qreal, qreal, int)), m_levelMeter, SLOT(levelChanged(qreal, qreal, int))); + } + + NFMModBaseband::MsgConfigureNFMModBaseband *msg = NFMModBaseband::MsgConfigureNFMModBaseband::create(m_settings, true); + m_basebandSource->getInputMessageQueue()->push(msg); + + m_running = true; } void NFMMod::stop() { + if (!m_running) { + return; + } + qDebug("NFMMod::stop"); - m_thread->exit(); + m_running = false; + m_thread->quit(); m_thread->wait(); } void NFMMod::pull(SampleVector::iterator& begin, unsigned int nbSamples) { - m_basebandSource->pull(begin, nbSamples); + if (m_running) { + m_basebandSource->pull(begin, nbSamples); + } } void NFMMod::setCenterFrequency(qint64 frequency) @@ -236,13 +272,16 @@ bool NFMMod::handleMessage(const Message& cmd) else if (DSPSignalNotification::match(cmd)) { // Forward to the source - DSPSignalNotification& notif = (DSPSignalNotification&) cmd; - DSPSignalNotification* rep = new DSPSignalNotification(notif); // make a copy - qDebug() << "NFMMod::handleMessage: DSPSignalNotification"; - m_basebandSource->getInputMessageQueue()->push(rep); - // Forward to GUI if any - if (getMessageQueueToGUI()) { - getMessageQueueToGUI()->push(new DSPSignalNotification(notif)); + if (m_running) + { + DSPSignalNotification& notif = (DSPSignalNotification&) cmd; + DSPSignalNotification* rep = new DSPSignalNotification(notif); // make a copy + qDebug() << "NFMMod::handleMessage: DSPSignalNotification"; + m_basebandSource->getInputMessageQueue()->push(rep); + // Forward to GUI if any + if (getMessageQueueToGUI()) { + getMessageQueueToGUI()->push(new DSPSignalNotification(notif)); + } } return true; @@ -386,8 +425,11 @@ void NFMMod::applySettings(const NFMModSettings& settings, bool force) reverseAPIKeys.append("streamIndex"); } - NFMModBaseband::MsgConfigureNFMModBaseband *msg = NFMModBaseband::MsgConfigureNFMModBaseband::create(settings, force); - m_basebandSource->getInputMessageQueue()->push(msg); + if (m_running) + { + NFMModBaseband::MsgConfigureNFMModBaseband *msg = NFMModBaseband::MsgConfigureNFMModBaseband::create(settings, force); + m_basebandSource->getInputMessageQueue()->push(msg); + } if (settings.m_useReverseAPI) { @@ -459,7 +501,7 @@ int NFMMod::webapiSettingsGet( webapiFormatChannelSettings(response, m_settings); SWGSDRangel::SWGCWKeyerSettings *apiCwKeyerSettings = response.getNfmModSettings()->getCwKeyer(); - const CWKeyerSettings& cwKeyerSettings = m_basebandSource->getCWKeyer().getSettings(); + const CWKeyerSettings& cwKeyerSettings = getCWKeyer()->getSettings(); CWKeyer::webapiFormatChannelSettings(apiCwKeyerSettings, cwKeyerSettings); return 200; @@ -487,11 +529,11 @@ int NFMMod::webapiSettingsPutPatch( if (channelSettingsKeys.contains("cwKeyer")) { SWGSDRangel::SWGCWKeyerSettings *apiCwKeyerSettings = response.getNfmModSettings()->getCwKeyer(); - CWKeyerSettings cwKeyerSettings = m_basebandSource->getCWKeyer().getSettings(); + CWKeyerSettings cwKeyerSettings = getCWKeyer()->getSettings(); CWKeyer::webapiSettingsPutPatch(channelSettingsKeys, cwKeyerSettings, apiCwKeyerSettings); CWKeyer::MsgConfigureCWKeyer *msgCwKeyer = CWKeyer::MsgConfigureCWKeyer::create(cwKeyerSettings, force); - m_basebandSource->getCWKeyer().getInputMessageQueue()->push(msgCwKeyer); + getCWKeyer()->getInputMessageQueue()->push(msgCwKeyer); if (m_guiMessageQueue) // forward to GUI if any { @@ -691,8 +733,12 @@ void NFMMod::webapiFormatChannelSettings(SWGSDRangel::SWGChannelSettings& respon void NFMMod::webapiFormatChannelReport(SWGSDRangel::SWGChannelReport& response) { response.getNfmModReport()->setChannelPowerDb(CalcDb::dbPower(getMagSq())); - response.getNfmModReport()->setAudioSampleRate(m_basebandSource->getAudioSampleRate()); - response.getNfmModReport()->setChannelSampleRate(m_basebandSource->getChannelSampleRate()); + + if (m_running) + { + response.getNfmModReport()->setAudioSampleRate(m_basebandSource->getAudioSampleRate()); + response.getNfmModReport()->setChannelSampleRate(m_basebandSource->getChannelSampleRate()); + } } void NFMMod::webapiReverseSendSettings(QList& channelSettingsKeys, const NFMModSettings& settings, bool force) @@ -730,7 +776,7 @@ void NFMMod::webapiReverseSendCWSettings(const CWKeyerSettings& cwKeyerSettings) swgNFModSettings->setCwKeyer(new SWGSDRangel::SWGCWKeyerSettings()); SWGSDRangel::SWGCWKeyerSettings *apiCwKeyerSettings = swgNFModSettings->getCwKeyer(); - m_basebandSource->getCWKeyer().webapiFormatChannelSettings(apiCwKeyerSettings, cwKeyerSettings); + getCWKeyer()->webapiFormatChannelSettings(apiCwKeyerSettings, cwKeyerSettings); QString channelSettingsURL = QString("http://%1:%2/sdrangel/deviceset/%3/channel/%4/settings") .arg(m_settings.m_reverseAPIAddress) @@ -870,10 +916,10 @@ void NFMMod::webapiFormatChannelSettings( if (force) { - const CWKeyerSettings& cwKeyerSettings = m_basebandSource->getCWKeyer().getSettings(); + const CWKeyerSettings& cwKeyerSettings = getCWKeyer()->getSettings(); swgNFMModSettings->setCwKeyer(new SWGSDRangel::SWGCWKeyerSettings()); SWGSDRangel::SWGCWKeyerSettings *apiCwKeyerSettings = swgNFMModSettings->getCwKeyer(); - m_basebandSource->getCWKeyer().webapiFormatChannelSettings(apiCwKeyerSettings, cwKeyerSettings); + getCWKeyer()->webapiFormatChannelSettings(apiCwKeyerSettings, cwKeyerSettings); } } @@ -900,17 +946,11 @@ void NFMMod::networkManagerFinished(QNetworkReply *reply) double NFMMod::getMagSq() const { - return m_basebandSource->getMagSq(); -} + if (m_running) { + return m_basebandSource->getMagSq(); + } -CWKeyer *NFMMod::getCWKeyer() -{ - return &m_basebandSource->getCWKeyer(); -} - -void NFMMod::setLevelMeter(QObject *levelMeter) -{ - connect(m_basebandSource, SIGNAL(levelChanged(qreal, qreal, int)), levelMeter, SLOT(levelChanged(qreal, qreal, int))); + return 0; } uint32_t NFMMod::getNumberOfDeviceStreams() const @@ -920,10 +960,18 @@ uint32_t NFMMod::getNumberOfDeviceStreams() const int NFMMod::getAudioSampleRate() const { - return m_basebandSource->getAudioSampleRate(); + if (m_running) { + return m_basebandSource->getAudioSampleRate(); + } + + return 0; } int NFMMod::getFeedbackAudioSampleRate() const { - return m_basebandSource->getFeedbackAudioSampleRate(); + if (m_running) { + return m_basebandSource->getFeedbackAudioSampleRate(); + } + + return 0; } diff --git a/plugins/channeltx/modnfm/nfmmod.h b/plugins/channeltx/modnfm/nfmmod.h index 36478dbac..de0ad0c8b 100644 --- a/plugins/channeltx/modnfm/nfmmod.h +++ b/plugins/channeltx/modnfm/nfmmod.h @@ -28,6 +28,7 @@ #include #include "dsp/basebandsamplesource.h" +#include "dsp/cwkeyer.h" #include "channel/channelapi.h" #include "util/message.h" @@ -233,8 +234,8 @@ public: SWGSDRangel::SWGChannelSettings& response); double getMagSq() const; - CWKeyer *getCWKeyer(); - void setLevelMeter(QObject *levelMeter); + CWKeyer *getCWKeyer() { return &m_cwKeyer; } + void setLevelMeter(QObject *levelMeter) { m_levelMeter = levelMeter; } uint32_t getNumberOfDeviceStreams() const; int getAudioSampleRate() const; int getFeedbackAudioSampleRate() const; @@ -250,6 +251,7 @@ private: DeviceAPI* m_deviceAPI; QThread *m_thread; + bool m_running; NFMModBaseband* m_basebandSource; NFMModSettings m_settings; @@ -265,6 +267,9 @@ private: QNetworkAccessManager *m_networkManager; QNetworkRequest m_networkRequest; + CWKeyer m_cwKeyer; + QObject *m_levelMeter; + virtual bool handleMessage(const Message& cmd); void applySettings(const NFMModSettings& settings, bool force = false); void sendSampleRateToDemodAnalyzer(); diff --git a/plugins/channeltx/modnfm/nfmmodbaseband.cpp b/plugins/channeltx/modnfm/nfmmodbaseband.cpp index 8bfbc0833..ca7d35def 100644 --- a/plugins/channeltx/modnfm/nfmmodbaseband.cpp +++ b/plugins/channeltx/modnfm/nfmmodbaseband.cpp @@ -21,6 +21,7 @@ #include "dsp/upchannelizer.h" #include "dsp/dspengine.h" #include "dsp/dspcommands.h" +#include "dsp/cwkeyer.h" #include "nfmmodbaseband.h" @@ -170,8 +171,8 @@ bool NFMModBaseband::handleMessage(const Message& cmd) QMutexLocker mutexLocker(&m_mutex); const CWKeyer::MsgConfigureCWKeyer& cfg = (CWKeyer::MsgConfigureCWKeyer&) cmd; CWKeyer::MsgConfigureCWKeyer *notif = new CWKeyer::MsgConfigureCWKeyer(cfg); - CWKeyer& cwKeyer = m_source.getCWKeyer(); - cwKeyer.getInputMessageQueue()->push(notif); + CWKeyer *cwKeyer = m_source.getCWKeyer(); + cwKeyer->getInputMessageQueue()->push(notif); return true; } diff --git a/plugins/channeltx/modnfm/nfmmodbaseband.h b/plugins/channeltx/modnfm/nfmmodbaseband.h index d37973d42..69a1480c4 100644 --- a/plugins/channeltx/modnfm/nfmmodbaseband.h +++ b/plugins/channeltx/modnfm/nfmmodbaseband.h @@ -63,7 +63,7 @@ public: void reset(); void pull(const SampleVector::iterator& begin, unsigned int nbSamples); MessageQueue *getInputMessageQueue() { return &m_inputMessageQueue; } //!< Get the queue for asynchronous inbound communication - CWKeyer& getCWKeyer() { return m_source.getCWKeyer(); } + void setCWKeyer(CWKeyer *cwKeyer) { m_source.setCWKeyer(cwKeyer); } double getMagSq() const { return m_source.getMagSq(); } int getAudioSampleRate() const { return m_source.getAudioSampleRate(); } int getFeedbackAudioSampleRate() const { return m_source.getFeedbackAudioSampleRate(); } diff --git a/plugins/channeltx/modnfm/nfmmodsource.cpp b/plugins/channeltx/modnfm/nfmmodsource.cpp index 5db3b2f52..39d758f1b 100644 --- a/plugins/channeltx/modnfm/nfmmodsource.cpp +++ b/plugins/channeltx/modnfm/nfmmodsource.cpp @@ -20,6 +20,7 @@ #include "dsp/datafifo.h" #include "dsp/misc.h" +#include "dsp/cwkeyer.h" #include "util/messagequeue.h" #include "maincore.h" @@ -39,7 +40,8 @@ NFMModSource::NFMModSource() : m_levelCalcCount(0), m_peakLevel(0.0f), m_levelSum(0.0f), - m_ifstream(nullptr) + m_ifstream(nullptr), + m_cwKeyer(nullptr) { m_audioFifo.setLabel("NFMModSource.m_audioFifo"); m_feedbackAudioFifo.setLabel("NFMModSource.m_feedbackAudioFifo"); @@ -276,14 +278,18 @@ void NFMModSource::pullAF(Real& sample) case NFMModSettings::NFMModInputCWTone: Real fadeFactor; - if (m_cwKeyer.getSample()) + if (!m_cwKeyer) { + break; + } + + if (m_cwKeyer->getSample()) { - m_cwKeyer.getCWSmoother().getFadeSample(true, fadeFactor); + m_cwKeyer->getCWSmoother().getFadeSample(true, fadeFactor); sample = m_toneNco.next() * fadeFactor; } else { - if (m_cwKeyer.getCWSmoother().getFadeSample(false, fadeFactor)) + if (m_cwKeyer->getCWSmoother().getFadeSample(false, fadeFactor)) { sample = m_toneNco.next() * fadeFactor; } @@ -382,8 +388,13 @@ void NFMModSource::applyAudioSampleRate(int sampleRate) m_toneNco.setFreq(m_settings.m_toneFrequency, sampleRate); m_ctcssNco.setFreq(NFMModSettings::getCTCSSFreq(m_settings.m_ctcssIndex), sampleRate); m_dcsMod.setSampleRate(sampleRate); - m_cwKeyer.setSampleRate(sampleRate); - m_cwKeyer.reset(); + + if (m_cwKeyer) + { + m_cwKeyer->setSampleRate(sampleRate); + m_cwKeyer->reset(); + } + m_preemphasisFilter.configure(m_preemphasis*sampleRate); m_audioCompressor.m_rate = sampleRate; m_audioCompressor.initState(); diff --git a/plugins/channeltx/modnfm/nfmmodsource.h b/plugins/channeltx/modnfm/nfmmodsource.h index ac15b5639..9a6d31ed9 100644 --- a/plugins/channeltx/modnfm/nfmmodsource.h +++ b/plugins/channeltx/modnfm/nfmmodsource.h @@ -33,7 +33,6 @@ #include "dsp/firfilter.h" #include "dsp/filterrc.h" #include "util/movingaverage.h" -#include "dsp/cwkeyer.h" #include "audio/audiofifo.h" #include "audio/audiocompressorsnd.h" @@ -41,6 +40,7 @@ #include "nfmmoddcs.h" class ChannelAPI; +class CWKeyer; class NFMModSource : public QObject, public ChannelSampleSource { @@ -61,7 +61,8 @@ public: int getAudioSampleRate() const { return m_audioSampleRate; } int getFeedbackAudioSampleRate() const { return m_feedbackAudioSampleRate; } void setChannel(ChannelAPI *channel) { m_channel = channel; } - CWKeyer& getCWKeyer() { return m_cwKeyer; } + void setCWKeyer(CWKeyer *cwKeyer) { m_cwKeyer = cwKeyer; } + CWKeyer *getCWKeyer() { return m_cwKeyer; } double getMagSq() const { return m_magsq; } void getLevels(qreal& rmsLevel, qreal& peakLevel, int& numSamples) const { @@ -124,7 +125,7 @@ private: Real m_levelSum; std::ifstream *m_ifstream; - CWKeyer m_cwKeyer; + CWKeyer *m_cwKeyer; AudioCompressorSnd m_audioCompressor; From 7739dfd46880aef276b6be5b4b6c028c55596af6 Mon Sep 17 00:00:00 2001 From: f4exb Date: Sat, 17 Aug 2024 22:33:55 +0200 Subject: [PATCH 07/16] AMMod: revised thread processing --- plugins/channeltx/modam/ammod.cpp | 117 ++++++++++++++++------ plugins/channeltx/modam/ammod.h | 6 +- plugins/channeltx/modam/ammodbaseband.cpp | 5 +- plugins/channeltx/modam/ammodbaseband.h | 2 +- plugins/channeltx/modam/ammodsource.cpp | 22 ++-- plugins/channeltx/modam/ammodsource.h | 7 +- 6 files changed, 113 insertions(+), 46 deletions(-) diff --git a/plugins/channeltx/modam/ammod.cpp b/plugins/channeltx/modam/ammod.cpp index b947d4f76..39430c63b 100644 --- a/plugins/channeltx/modam/ammod.cpp +++ b/plugins/channeltx/modam/ammod.cpp @@ -56,18 +56,13 @@ const char* const AMMod::m_channelId ="AMMod"; AMMod::AMMod(DeviceAPI *deviceAPI) : ChannelAPI(m_channelIdURI, ChannelAPI::StreamSingleSource), m_deviceAPI(deviceAPI), + m_running(false), m_fileSize(0), m_recordLength(0), - m_sampleRate(48000) + m_sampleRate(48000), + m_levelMeter(nullptr) { setObjectName(m_channelId); - - m_thread = new QThread(this); - m_basebandSource = new AMModBaseband(); - m_basebandSource->setInputFileStream(&m_ifstream); - m_basebandSource->setChannel(this); - m_basebandSource->moveToThread(m_thread); - applySettings(m_settings, true); m_deviceAPI->addChannelSource(this); @@ -93,8 +88,8 @@ AMMod::~AMMod() delete m_networkManager; m_deviceAPI->removeChannelSourceAPI(this); m_deviceAPI->removeChannelSource(this); - delete m_basebandSource; - delete m_thread; + + stop(); } void AMMod::setDeviceAPI(DeviceAPI *deviceAPI) @@ -116,21 +111,61 @@ uint32_t AMMod::getNumberOfDeviceStreams() const void AMMod::start() { + if (m_running) { + return; + } + qDebug("AMMod::start"); + m_thread = new QThread(this); + m_basebandSource = new AMModBaseband(); + m_basebandSource->setInputFileStream(&m_ifstream); + m_basebandSource->setChannel(this); m_basebandSource->reset(); + m_basebandSource->setCWKeyer(&m_cwKeyer); + m_basebandSource->moveToThread(m_thread); + + QObject::connect( + m_thread, + &QThread::finished, + m_basebandSource, + &QObject::deleteLater + ); + QObject::connect( + m_thread, + &QThread::finished, + m_thread, + &QThread::deleteLater + ); + m_thread->start(); + + AMModBaseband::MsgConfigureAMModBaseband *msg = AMModBaseband::MsgConfigureAMModBaseband::create(m_settings, true); + m_basebandSource->getInputMessageQueue()->push(msg); + + if (m_levelMeter) { + connect(m_basebandSource, SIGNAL(levelChanged(qreal, qreal, int)), m_levelMeter, SLOT(levelChanged(qreal, qreal, int))); + } + + m_running = true; } void AMMod::stop() { + if (!m_running) { + return; + } + qDebug("AMMod::stop"); + m_running = false; m_thread->exit(); m_thread->wait(); } void AMMod::pull(SampleVector::iterator& begin, unsigned int nbSamples) { - m_basebandSource->pull(begin, nbSamples); + if (m_running) { + m_basebandSource->pull(begin, nbSamples); + } } void AMMod::setCenterFrequency(qint64 frequency) @@ -203,11 +238,13 @@ bool AMMod::handleMessage(const Message& cmd) } else if (DSPSignalNotification::match(cmd)) { + qDebug() << "AMMod::handleMessage: DSPSignalNotification"; // Forward to the source DSPSignalNotification& notif = (DSPSignalNotification&) cmd; - DSPSignalNotification* rep = new DSPSignalNotification(notif); // make a copy - qDebug() << "AMMod::handleMessage: DSPSignalNotification"; - m_basebandSource->getInputMessageQueue()->push(rep); + + if (m_running) { + m_basebandSource->getInputMessageQueue()->push(new DSPSignalNotification(notif)); + } // Forward to GUI if any if (getMessageQueueToGUI()) { getMessageQueueToGUI()->push(new DSPSignalNotification(notif)); @@ -338,8 +375,11 @@ void AMMod::applySettings(const AMModSettings& settings, bool force) reverseAPIKeys.append("streamIndex"); } - AMModBaseband::MsgConfigureAMModBaseband *msg = AMModBaseband::MsgConfigureAMModBaseband::create(settings, force); - m_basebandSource->getInputMessageQueue()->push(msg); + if (m_running) + { + AMModBaseband::MsgConfigureAMModBaseband *msg = AMModBaseband::MsgConfigureAMModBaseband::create(settings, force); + m_basebandSource->getInputMessageQueue()->push(msg); + } if (settings.m_useReverseAPI) { @@ -412,7 +452,7 @@ int AMMod::webapiSettingsGet( webapiFormatChannelSettings(response, m_settings); SWGSDRangel::SWGCWKeyerSettings *apiCwKeyerSettings = response.getAmModSettings()->getCwKeyer(); - const CWKeyerSettings& cwKeyerSettings = m_basebandSource->getCWKeyer().getSettings(); + const CWKeyerSettings& cwKeyerSettings = getCWKeyer()->getSettings(); CWKeyer::webapiFormatChannelSettings(apiCwKeyerSettings, cwKeyerSettings); return 200; @@ -440,11 +480,11 @@ int AMMod::webapiSettingsPutPatch( if (channelSettingsKeys.contains("cwKeyer")) { SWGSDRangel::SWGCWKeyerSettings *apiCwKeyerSettings = response.getAmModSettings()->getCwKeyer(); - CWKeyerSettings cwKeyerSettings = m_basebandSource->getCWKeyer().getSettings(); + CWKeyerSettings cwKeyerSettings = getCWKeyer()->getSettings(); CWKeyer::webapiSettingsPutPatch(channelSettingsKeys, cwKeyerSettings, apiCwKeyerSettings); CWKeyer::MsgConfigureCWKeyer *msgCwKeyer = CWKeyer::MsgConfigureCWKeyer::create(cwKeyerSettings, force); - m_basebandSource->getCWKeyer().getInputMessageQueue()->push(msgCwKeyer); + getCWKeyer()->getInputMessageQueue()->push(msgCwKeyer); if (m_guiMessageQueue) // forward to GUI if any { @@ -615,8 +655,12 @@ void AMMod::webapiFormatChannelSettings(SWGSDRangel::SWGChannelSettings& respons void AMMod::webapiFormatChannelReport(SWGSDRangel::SWGChannelReport& response) { response.getAmModReport()->setChannelPowerDb(CalcDb::dbPower(getMagSq())); - response.getAmModReport()->setAudioSampleRate(m_basebandSource->getAudioSampleRate()); - response.getAmModReport()->setChannelSampleRate(m_basebandSource->getChannelSampleRate()); + + if (m_running) + { + response.getAmModReport()->setAudioSampleRate(m_basebandSource->getAudioSampleRate()); + response.getAmModReport()->setChannelSampleRate(m_basebandSource->getChannelSampleRate()); + } } void AMMod::webapiReverseSendSettings(QList& channelSettingsKeys, const AMModSettings& settings, bool force) @@ -654,7 +698,7 @@ void AMMod::webapiReverseSendCWSettings(const CWKeyerSettings& cwKeyerSettings) swgAMModSettings->setCwKeyer(new SWGSDRangel::SWGCWKeyerSettings()); SWGSDRangel::SWGCWKeyerSettings *apiCwKeyerSettings = swgAMModSettings->getCwKeyer(); - m_basebandSource->getCWKeyer().webapiFormatChannelSettings(apiCwKeyerSettings, cwKeyerSettings); + getCWKeyer()->webapiFormatChannelSettings(apiCwKeyerSettings, cwKeyerSettings); QString channelSettingsURL = QString("http://%1:%2/sdrangel/deviceset/%3/channel/%4/settings") .arg(m_settings.m_reverseAPIAddress) @@ -756,10 +800,10 @@ void AMMod::webapiFormatChannelSettings( if (force) { - const CWKeyerSettings& cwKeyerSettings = m_basebandSource->getCWKeyer().getSettings(); + const CWKeyerSettings& cwKeyerSettings = getCWKeyer()->getSettings(); swgAMModSettings->setCwKeyer(new SWGSDRangel::SWGCWKeyerSettings()); SWGSDRangel::SWGCWKeyerSettings *apiCwKeyerSettings = swgAMModSettings->getCwKeyer(); - m_basebandSource->getCWKeyer().webapiFormatChannelSettings(apiCwKeyerSettings, cwKeyerSettings); + getCWKeyer()->webapiFormatChannelSettings(apiCwKeyerSettings, cwKeyerSettings); } if (settings.m_channelMarker && (channelSettingsKeys.contains("channelMarker") || force)) @@ -800,25 +844,32 @@ void AMMod::networkManagerFinished(QNetworkReply *reply) double AMMod::getMagSq() const { - return m_basebandSource->getMagSq(); + if (m_running) { + return m_basebandSource->getMagSq(); + } + + return 0; } CWKeyer *AMMod::getCWKeyer() { - return &m_basebandSource->getCWKeyer(); -} - -void AMMod::setLevelMeter(QObject *levelMeter) -{ - connect(m_basebandSource, SIGNAL(levelChanged(qreal, qreal, int)), levelMeter, SLOT(levelChanged(qreal, qreal, int))); + return &m_cwKeyer; } int AMMod::getAudioSampleRate() const { - return m_basebandSource->getAudioSampleRate(); + if (m_running) { + return m_basebandSource->getAudioSampleRate(); + } + + return 0; } int AMMod::getFeedbackAudioSampleRate() const { - return m_basebandSource->getFeedbackAudioSampleRate(); + if (m_running) { + return m_basebandSource->getFeedbackAudioSampleRate(); + } + + return 0; } diff --git a/plugins/channeltx/modam/ammod.h b/plugins/channeltx/modam/ammod.h index 61f427a53..28fdc6553 100644 --- a/plugins/channeltx/modam/ammod.h +++ b/plugins/channeltx/modam/ammod.h @@ -28,6 +28,7 @@ #include #include "dsp/basebandsamplesource.h" +#include "dsp/cwkeyer.h" #include "channel/channelapi.h" #include "util/message.h" @@ -235,7 +236,7 @@ public: uint32_t getNumberOfDeviceStreams() const; double getMagSq() const; CWKeyer *getCWKeyer(); - void setLevelMeter(QObject *levelMeter); + void setLevelMeter(QObject *levelMeter) { m_levelMeter = levelMeter; } int getAudioSampleRate() const; int getFeedbackAudioSampleRate() const; @@ -250,6 +251,7 @@ private: DeviceAPI* m_deviceAPI; QThread *m_thread; + bool m_running; AMModBaseband* m_basebandSource; AMModSettings m_settings; @@ -264,6 +266,8 @@ private: QNetworkAccessManager *m_networkManager; QNetworkRequest m_networkRequest; + CWKeyer m_cwKeyer; + QObject *m_levelMeter; virtual bool handleMessage(const Message& cmd); void applySettings(const AMModSettings& settings, bool force = false); diff --git a/plugins/channeltx/modam/ammodbaseband.cpp b/plugins/channeltx/modam/ammodbaseband.cpp index 605b2f09e..df3726894 100644 --- a/plugins/channeltx/modam/ammodbaseband.cpp +++ b/plugins/channeltx/modam/ammodbaseband.cpp @@ -21,6 +21,7 @@ #include "dsp/upchannelizer.h" #include "dsp/dspengine.h" #include "dsp/dspcommands.h" +#include "dsp/cwkeyer.h" #include "ammodbaseband.h" @@ -171,8 +172,8 @@ bool AMModBaseband::handleMessage(const Message& cmd) qDebug() << "AMModBaseband::handleMessage: MsgConfigureCWKeyer"; const CWKeyer::MsgConfigureCWKeyer& cfg = (CWKeyer::MsgConfigureCWKeyer&) cmd; CWKeyer::MsgConfigureCWKeyer *notif = new CWKeyer::MsgConfigureCWKeyer(cfg); - CWKeyer& cwKeyer = m_source.getCWKeyer(); - cwKeyer.getInputMessageQueue()->push(notif); + CWKeyer *cwKeyer = m_source.getCWKeyer(); + cwKeyer->getInputMessageQueue()->push(notif); return true; } diff --git a/plugins/channeltx/modam/ammodbaseband.h b/plugins/channeltx/modam/ammodbaseband.h index ef2bde946..c0926c610 100644 --- a/plugins/channeltx/modam/ammodbaseband.h +++ b/plugins/channeltx/modam/ammodbaseband.h @@ -63,7 +63,7 @@ public: void reset(); void pull(const SampleVector::iterator& begin, unsigned int nbSamples); MessageQueue *getInputMessageQueue() { return &m_inputMessageQueue; } //!< Get the queue for asynchronous inbound communication - CWKeyer& getCWKeyer() { return m_source.getCWKeyer(); } + void setCWKeyer(CWKeyer *cwKeyer) { m_source.setCWKeyer(cwKeyer); } double getMagSq() const { return m_source.getMagSq(); } int getAudioSampleRate() const { return m_source.getAudioSampleRate(); } int getFeedbackAudioSampleRate() const { return m_source.getFeedbackAudioSampleRate(); } diff --git a/plugins/channeltx/modam/ammodsource.cpp b/plugins/channeltx/modam/ammodsource.cpp index b25e5e343..01921618c 100644 --- a/plugins/channeltx/modam/ammodsource.cpp +++ b/plugins/channeltx/modam/ammodsource.cpp @@ -19,6 +19,7 @@ #include #include "dsp/datafifo.h" +#include "dsp/cwkeyer.h" #include "util/messagequeue.h" #include "maincore.h" @@ -35,7 +36,8 @@ AMModSource::AMModSource() : m_levelCalcCount(0), m_peakLevel(0.0f), m_levelSum(0.0f), - m_ifstream(nullptr) + m_ifstream(nullptr), + m_cwKeyer(nullptr) { m_audioFifo.setLabel("AMModSource.m_audioFifo"); m_feedbackAudioFifo.setLabel("AMModSource.m_feedbackAudioFifo"); @@ -218,14 +220,18 @@ void AMModSource::pullAF(Real& sample) case AMModSettings::AMModInputCWTone: Real fadeFactor; - if (m_cwKeyer.getSample()) + if (!m_cwKeyer) { + break; + } + + if (m_cwKeyer->getSample()) { - m_cwKeyer.getCWSmoother().getFadeSample(true, fadeFactor); + m_cwKeyer->getCWSmoother().getFadeSample(true, fadeFactor); sample = m_toneNco.next() * fadeFactor; } else { - if (m_cwKeyer.getCWSmoother().getFadeSample(false, fadeFactor)) + if (m_cwKeyer->getCWSmoother().getFadeSample(false, fadeFactor)) { sample = m_toneNco.next() * fadeFactor; } @@ -320,8 +326,12 @@ void AMModSource::applyAudioSampleRate(int sampleRate) m_interpolatorDistance = (Real) sampleRate / (Real) m_channelSampleRate; m_interpolator.create(48, sampleRate, m_settings.m_rfBandwidth / 2.2, 3.0); m_toneNco.setFreq(m_settings.m_toneFrequency, sampleRate); - m_cwKeyer.setSampleRate(sampleRate); - m_cwKeyer.reset(); + + if (m_cwKeyer) + { + m_cwKeyer->setSampleRate(sampleRate); + m_cwKeyer->reset(); + } QList pipes; MainCore::instance()->getMessagePipes().getMessagePipes(m_channel, "reportdemod", pipes); diff --git a/plugins/channeltx/modam/ammodsource.h b/plugins/channeltx/modam/ammodsource.h index f10ef226e..a032ff774 100644 --- a/plugins/channeltx/modam/ammodsource.h +++ b/plugins/channeltx/modam/ammodsource.h @@ -31,12 +31,12 @@ #include "dsp/ncof.h" #include "dsp/interpolator.h" #include "util/movingaverage.h" -#include "dsp/cwkeyer.h" #include "audio/audiofifo.h" #include "ammodsettings.h" class ChannelAPI; +class CWKeyer; class AMModSource : public QObject, public ChannelSampleSource { @@ -57,7 +57,8 @@ public: void applyFeedbackAudioSampleRate(int sampleRate); int getAudioSampleRate() const { return m_audioSampleRate; } int getFeedbackAudioSampleRate() const { return m_feedbackAudioSampleRate; } - CWKeyer& getCWKeyer() { return m_cwKeyer; } + void setCWKeyer(CWKeyer *cwKeyer) { m_cwKeyer = cwKeyer; } + CWKeyer* getCWKeyer() { return m_cwKeyer; } double getMagSq() const { return m_magsq; } void getLevels(qreal& rmsLevel, qreal& peakLevel, int& numSamples) const { @@ -112,7 +113,7 @@ private: Real m_levelSum; std::ifstream *m_ifstream; - CWKeyer m_cwKeyer; + CWKeyer *m_cwKeyer; QRecursiveMutex m_mutex; From 7d1af5b24ff220adfb59f0a5f4bb62ef15777cf1 Mon Sep 17 00:00:00 2001 From: f4exb Date: Sat, 17 Aug 2024 22:34:30 +0200 Subject: [PATCH 08/16] Removed SyncMessenger from DSPDeviceSinkEngine. Part of #2159 --- sdrbase/dsp/dspdevicesinkengine.cpp | 203 ++++++++++++++-------------- sdrbase/dsp/dspdevicesinkengine.h | 4 +- sdrgui/mainwindow.cpp | 10 +- 3 files changed, 102 insertions(+), 115 deletions(-) diff --git a/sdrbase/dsp/dspdevicesinkengine.cpp b/sdrbase/dsp/dspdevicesinkengine.cpp index 80c37d258..210bd5780 100644 --- a/sdrbase/dsp/dspdevicesinkengine.cpp +++ b/sdrbase/dsp/dspdevicesinkengine.cpp @@ -39,16 +39,15 @@ DSPDeviceSinkEngine::DSPDeviceSinkEngine(uint32_t uid, QObject* parent) : m_centerFrequency(0), m_realElseComplex(false) { + setState(StIdle); connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()), Qt::QueuedConnection); - connect(&m_syncMessenger, SIGNAL(messageSent()), this, SLOT(handleSynchronousMessages()), Qt::QueuedConnection); moveToThread(this); } DSPDeviceSinkEngine::~DSPDeviceSinkEngine() { - stop(); - wait(); + qDebug("DSPDeviceSinkEngine::~DSPDeviceSinkEngine"); } void DSPDeviceSinkEngine::setState(State state) @@ -86,32 +85,32 @@ void DSPDeviceSinkEngine::stop() bool DSPDeviceSinkEngine::initGeneration() { qDebug() << "DSPDeviceSinkEngine::initGeneration"; - DSPGenerationInit cmd; - - return m_syncMessenger.sendWait(cmd) == StReady; + auto *cmd = new DSPGenerationInit(); + getInputMessageQueue()->push(cmd); + return true; } bool DSPDeviceSinkEngine::startGeneration() { qDebug() << "DSPDeviceSinkEngine::startGeneration"; - DSPGenerationStart cmd; - - return m_syncMessenger.sendWait(cmd) == StRunning; + auto *cmd = new DSPGenerationStart(); + getInputMessageQueue()->push(cmd); + return true; } void DSPDeviceSinkEngine::stopGeneration() { qDebug() << "DSPDeviceSinkEngine::stopGeneration"; - DSPGenerationStop cmd; - m_syncMessenger.storeMessage(cmd); - handleSynchronousMessages(); + DSPGenerationStop *cmd = new DSPGenerationStop(); + getInputMessageQueue()->push(cmd); } void DSPDeviceSinkEngine::setSink(DeviceSampleSink* sink) { qDebug() << "DSPDeviceSinkEngine::setSink"; - DSPSetSink cmd(sink); - m_syncMessenger.sendWait(cmd); + m_deviceSampleSink = sink; + auto *cmd = new DSPSetSink(sink); + getInputMessageQueue()->push(cmd); } void DSPDeviceSinkEngine::setSinkSequence(int sequence) @@ -123,45 +122,40 @@ void DSPDeviceSinkEngine::setSinkSequence(int sequence) void DSPDeviceSinkEngine::addChannelSource(BasebandSampleSource* source) { qDebug() << "DSPDeviceSinkEngine::addChannelSource: " << source->getSourceName().toStdString().c_str(); - DSPAddBasebandSampleSource cmd(source); - m_syncMessenger.sendWait(cmd); + DSPAddBasebandSampleSource *cmd = new DSPAddBasebandSampleSource(source); + getInputMessageQueue()->push(cmd); } void DSPDeviceSinkEngine::removeChannelSource(BasebandSampleSource* source) { qDebug() << "DSPDeviceSinkEngine::removeChannelSource: " << source->getSourceName().toStdString().c_str(); - DSPRemoveBasebandSampleSource cmd(source); - m_syncMessenger.sendWait(cmd); + auto *cmd = new DSPRemoveBasebandSampleSource(source); + getInputMessageQueue()->push(cmd); } void DSPDeviceSinkEngine::addSpectrumSink(BasebandSampleSink* spectrumSink) { qDebug() << "DSPDeviceSinkEngine::addSpectrumSink: " << spectrumSink->getSinkName().toStdString().c_str(); - DSPAddSpectrumSink cmd(spectrumSink); - m_syncMessenger.sendWait(cmd); + m_spectrumSink = spectrumSink; } void DSPDeviceSinkEngine::removeSpectrumSink(BasebandSampleSink* spectrumSink) { qDebug() << "DSPDeviceSinkEngine::removeSpectrumSink: " << spectrumSink->getSinkName().toStdString().c_str(); - DSPRemoveSpectrumSink cmd(spectrumSink); - m_syncMessenger.sendWait(cmd); + auto *cmd = new DSPRemoveSpectrumSink(spectrumSink); + getInputMessageQueue()->push(cmd); } QString DSPDeviceSinkEngine::errorMessage() { qDebug() << "DSPDeviceSinkEngine::errorMessage"; - DSPGetErrorMessage cmd; - m_syncMessenger.sendWait(cmd); - return cmd.getErrorMessage(); + return m_errorMessage; } QString DSPDeviceSinkEngine::sinkDeviceDescription() { qDebug() << "DSPDeviceSinkEngine::sinkDeviceDescription"; - DSPGetSinkDeviceDescription cmd; - m_syncMessenger.sendWait(cmd); - return cmd.getDeviceDescription(); + return m_deviceDescription; } void DSPDeviceSinkEngine::workSampleFifo() @@ -399,15 +393,13 @@ DSPDeviceSinkEngine::State DSPDeviceSinkEngine::gotoError(const QString& errorMe return StError; } -void DSPDeviceSinkEngine::handleSetSink(DeviceSampleSink* sink) +void DSPDeviceSinkEngine::handleSetSink(DeviceSampleSink*) { - m_deviceSampleSink = sink; - if (!m_deviceSampleSink) { // Early leave return; } - qDebug("DSPDeviceSinkEngine::handleSetSink: set %s", qPrintable(sink->getDeviceDescription())); + qDebug("DSPDeviceSinkEngine::handleSetSink: set %s", qPrintable(m_deviceSampleSink->getDeviceDescription())); QObject::connect( m_deviceSampleSink->getSampleFifo(), @@ -416,7 +408,6 @@ void DSPDeviceSinkEngine::handleSetSink(DeviceSampleSink* sink) &DSPDeviceSinkEngine::handleData, Qt::QueuedConnection ); - } void DSPDeviceSinkEngine::handleData() @@ -426,126 +417,128 @@ void DSPDeviceSinkEngine::handleData() } } -void DSPDeviceSinkEngine::handleSynchronousMessages() +bool DSPDeviceSinkEngine::handleMessage(const Message& message) { - Message *message = m_syncMessenger.getMessage(); - qDebug() << "DSPDeviceSinkEngine::handleSynchronousMessages: " << message->getIdentifier(); + if (DSPSignalNotification::match(message)) + { + const DSPSignalNotification& notif = (const DSPSignalNotification&) message; - if (DSPGenerationInit::match(*message)) + // update DSP values + + m_sampleRate = notif.getSampleRate(); + m_centerFrequency = notif.getCenterFrequency(); + m_realElseComplex = notif.getRealElseComplex(); + + qDebug() << "DSPDeviceSinkEngine::handleInputMessages: DSPSignalNotification:" + << " m_sampleRate: " << m_sampleRate + << " m_centerFrequency: " << m_centerFrequency + << " m_realElseComplex" << m_realElseComplex; + + // forward source changes to sources with immediate execution + + for(BasebandSampleSources::const_iterator it = m_basebandSampleSources.begin(); it != m_basebandSampleSources.end(); it++) + { + auto *rep = new DSPSignalNotification(notif); // make a copy + qDebug() << "DSPDeviceSinkEngine::handleInputMessages: forward message to " << (*it)->getSourceName().toStdString().c_str(); + (*it)->pushMessage(rep); + } + + // forward changes to listeners on DSP output queue + if (m_deviceSampleSink) + { + MessageQueue *guiMessageQueue = m_deviceSampleSink->getMessageQueueToGUI(); + qDebug("DSPDeviceSinkEngine::handleInputMessages: DSPSignalNotification: guiMessageQueue: %p", guiMessageQueue); + + if (guiMessageQueue) + { + auto *rep = new DSPSignalNotification(notif); // make a copy for the output queue + guiMessageQueue->push(rep); + } + } + + return true; + } + // From synchronous messages + if (DSPGenerationInit::match(message)) { setState(gotoIdle()); if(m_state == StIdle) { setState(gotoInit()); // State goes ready if init is performed } + + return true; } - else if (DSPGenerationStart::match(*message)) + else if (DSPGenerationStart::match(message)) { if(m_state == StReady) { setState(gotoRunning()); } + + return true; } - else if (DSPGenerationStop::match(*message)) + else if (DSPGenerationStop::match(message)) { setState(gotoIdle()); + return true; } - else if (DSPGetSinkDeviceDescription::match(*message)) + else if (DSPSetSink::match(message)) + { + const DSPSetSink& cmd = (const DSPSetSink&) message; + handleSetSink(cmd.getSampleSink()); + return true; + } + else if (DSPRemoveSpectrumSink::match(message)) { - ((DSPGetSinkDeviceDescription*) message)->setDeviceDescription(m_deviceDescription); - } - else if (DSPGetErrorMessage::match(*message)) - { - ((DSPGetErrorMessage*) message)->setErrorMessage(m_errorMessage); - } - else if (DSPSetSink::match(*message)) { - handleSetSink(((DSPSetSink*) message)->getSampleSink()); - } - else if (DSPAddSpectrumSink::match(*message)) - { - m_spectrumSink = ((DSPAddSpectrumSink*) message)->getSampleSink(); - } - else if (DSPRemoveSpectrumSink::match(*message)) - { - BasebandSampleSink* spectrumSink = ((DSPRemoveSpectrumSink*) message)->getSampleSink(); + auto& cmd = (const DSPRemoveSpectrumSink&) message; + BasebandSampleSink* spectrumSink = cmd.getSampleSink(); if(m_state == StRunning) { spectrumSink->stop(); } m_spectrumSink = nullptr; + return true; } - else if (DSPAddBasebandSampleSource::match(*message)) + else if (DSPAddBasebandSampleSource::match(message)) { - BasebandSampleSource* source = ((DSPAddBasebandSampleSource*) message)->getSampleSource(); + auto& cmd = (const DSPAddBasebandSampleSource&) message; + BasebandSampleSource* source = cmd.getSampleSource(); m_basebandSampleSources.push_back(source); - DSPSignalNotification *notif = new DSPSignalNotification(m_sampleRate, m_centerFrequency); + auto *notif = new DSPSignalNotification(m_sampleRate, m_centerFrequency); source->pushMessage(notif); - if (m_state == StRunning) - { + if (m_state == StRunning) { source->start(); } + + return true; } - else if (DSPRemoveBasebandSampleSource::match(*message)) + else if (DSPRemoveBasebandSampleSource::match(message)) { - BasebandSampleSource* source = ((DSPRemoveBasebandSampleSource*) message)->getSampleSource(); + auto& cmd = (const DSPRemoveBasebandSampleSource&) message; + BasebandSampleSource* source = cmd.getSampleSource(); if(m_state == StRunning) { source->stop(); } m_basebandSampleSources.remove(source); + return true; } - m_syncMessenger.done(m_state); + return false; } void DSPDeviceSinkEngine::handleInputMessages() { Message* message; - while ((message = m_inputMessageQueue.pop()) != 0) + while ((message = m_inputMessageQueue.pop()) != nullptr) { qDebug("DSPDeviceSinkEngine::handleInputMessages: message: %s", message->getIdentifier()); - - if (DSPSignalNotification::match(*message)) - { - DSPSignalNotification *notif = (DSPSignalNotification *) message; - - // update DSP values - - m_sampleRate = notif->getSampleRate(); - m_centerFrequency = notif->getCenterFrequency(); - m_realElseComplex = notif->getRealElseComplex(); - - qDebug() << "DSPDeviceSinkEngine::handleInputMessages: DSPSignalNotification:" - << " m_sampleRate: " << m_sampleRate - << " m_centerFrequency: " << m_centerFrequency - << " m_realElseComplex" << m_realElseComplex; - - // forward source changes to sources with immediate execution - - for(BasebandSampleSources::const_iterator it = m_basebandSampleSources.begin(); it != m_basebandSampleSources.end(); it++) - { - DSPSignalNotification* rep = new DSPSignalNotification(*notif); // make a copy - qDebug() << "DSPDeviceSinkEngine::handleInputMessages: forward message to " << (*it)->getSourceName().toStdString().c_str(); - (*it)->pushMessage(rep); - } - - // forward changes to listeners on DSP output queue - if (m_deviceSampleSink) - { - MessageQueue *guiMessageQueue = m_deviceSampleSink->getMessageQueueToGUI(); - qDebug("DSPDeviceSinkEngine::handleInputMessages: DSPSignalNotification: guiMessageQueue: %p", guiMessageQueue); - - if (guiMessageQueue) - { - DSPSignalNotification* rep = new DSPSignalNotification(*notif); // make a copy for the output queue - guiMessageQueue->push(rep); - } - } - - delete message; - } + if (handleMessage(*message)) { + delete message; + } } } diff --git a/sdrbase/dsp/dspdevicesinkengine.h b/sdrbase/dsp/dspdevicesinkengine.h index ed0757648..608028176 100644 --- a/sdrbase/dsp/dspdevicesinkengine.h +++ b/sdrbase/dsp/dspdevicesinkengine.h @@ -33,7 +33,6 @@ #include "dsp/dsptypes.h" #include "util/messagequeue.h" -#include "util/syncmessenger.h" #include "util/incrementalvector.h" #include "export.h" @@ -86,7 +85,6 @@ private: uint32_t m_uid; //!< unique ID MessageQueue m_inputMessageQueue; //m_deviceAPI->resetSamplingDeviceId(); m_deviceUIs.back()->m_deviceAPI->clearBuddiesLists(); // clear old API buddies lists - m_dspEngine->removeLastDeviceSourceEngine(); DeviceAPI *sourceAPI = m_deviceUIs.back()->m_deviceAPI; @@ -1125,16 +1124,13 @@ void MainWindow::removeLastDeviceSet() m_deviceUIs.back()->m_deviceAPI->getSampleSink()->setMessageQueueToGUI(nullptr); // have sink stop sending messages to the GUI m_deviceUIs.back()->m_deviceGUI->destroy(); m_deviceUIs.back()->m_deviceAPI->resetSamplingDeviceId(); - m_deviceUIs.back()->m_deviceAPI->getPluginInterface()->deleteSampleSinkPluginInstanceOutput( - m_deviceUIs.back()->m_deviceAPI->getSampleSink()); m_deviceUIs.back()->m_deviceAPI->clearBuddiesLists(); // clear old API buddies lists + m_dspEngine->removeLastDeviceSinkEngine(); + DeviceAPI *sinkAPI = m_deviceUIs.back()->m_deviceAPI; delete m_deviceUIs.back(); - - lastDeviceEngine->stop(); - m_dspEngine->removeLastDeviceSinkEngine(); - + delete sinkAPI->getSampleSink(); delete sinkAPI; } else if (m_deviceUIs.back()->m_deviceMIMOEngine) // MIMO tab From 0208d113766ebe529fd45c9b91b27b16fca0e182 Mon Sep 17 00:00:00 2001 From: f4exb Date: Sun, 18 Aug 2024 13:36:30 +0200 Subject: [PATCH 09/16] SSBMod: revised thread processing --- plugins/channeltx/modssb/ssbmod.cpp | 119 ++++++++++++++------ plugins/channeltx/modssb/ssbmod.h | 6 +- plugins/channeltx/modssb/ssbmodbaseband.cpp | 4 +- plugins/channeltx/modssb/ssbmodbaseband.h | 2 +- plugins/channeltx/modssb/ssbmodsource.cpp | 24 ++-- plugins/channeltx/modssb/ssbmodsource.h | 6 +- 6 files changed, 112 insertions(+), 49 deletions(-) diff --git a/plugins/channeltx/modssb/ssbmod.cpp b/plugins/channeltx/modssb/ssbmod.cpp index 67106ec72..9ae2b047a 100644 --- a/plugins/channeltx/modssb/ssbmod.cpp +++ b/plugins/channeltx/modssb/ssbmod.cpp @@ -57,20 +57,13 @@ const char* const SSBMod::m_channelId = "SSBMod"; SSBMod::SSBMod(DeviceAPI *deviceAPI) : ChannelAPI(m_channelIdURI, ChannelAPI::StreamSingleSource), m_deviceAPI(deviceAPI), + m_running(false), m_spectrumVis(SDR_TX_SCALEF), m_fileSize(0), m_recordLength(0), m_sampleRate(48000) { setObjectName(m_channelId); - - m_thread = new QThread(this); - m_basebandSource = new SSBModBaseband(); - m_basebandSource->setSpectrumSink(&m_spectrumVis); - m_basebandSource->setInputFileStream(&m_ifstream); - m_basebandSource->setChannel(this); - m_basebandSource->moveToThread(m_thread); - applySettings(m_settings, true); m_deviceAPI->addChannelSource(this); @@ -96,8 +89,8 @@ SSBMod::~SSBMod() delete m_networkManager; m_deviceAPI->removeChannelSourceAPI(this); m_deviceAPI->removeChannelSource(this); - delete m_basebandSource; - delete m_thread; + + stop(); } void SSBMod::setDeviceAPI(DeviceAPI *deviceAPI) @@ -114,21 +107,62 @@ void SSBMod::setDeviceAPI(DeviceAPI *deviceAPI) void SSBMod::start() { + if (m_running) { + return; + } + qDebug("SSBMod::start"); + m_thread = new QThread(this); + m_basebandSource = new SSBModBaseband(); + m_basebandSource->setSpectrumSink(&m_spectrumVis); + m_basebandSource->setInputFileStream(&m_ifstream); + m_basebandSource->setChannel(this); m_basebandSource->reset(); + m_basebandSource->setCWKeyer(&m_cwKeyer); + m_basebandSource->moveToThread(m_thread); + + QObject::connect( + m_thread, + &QThread::finished, + m_basebandSource, + &QObject::deleteLater + ); + QObject::connect( + m_thread, + &QThread::finished, + m_thread, + &QThread::deleteLater + ); + m_thread->start(); + + SSBModBaseband::MsgConfigureSSBModBaseband *msg = SSBModBaseband::MsgConfigureSSBModBaseband::create(m_settings, true); + m_basebandSource->getInputMessageQueue()->push(msg); + + if (m_levelMeter) { + connect(m_basebandSource, SIGNAL(levelChanged(qreal, qreal, int)), m_levelMeter, SLOT(levelChanged(qreal, qreal, int))); + } + + m_running = true; } void SSBMod::stop() { + if (!m_running) { + return; + } + qDebug("SSBMod::stop"); + m_running = false; m_thread->exit(); m_thread->wait(); } void SSBMod::pull(SampleVector::iterator& begin, unsigned int nbSamples) { - m_basebandSource->pull(begin, nbSamples); + if (m_running) { + m_basebandSource->pull(begin, nbSamples); + } } void SSBMod::setCenterFrequency(qint64 frequency) @@ -201,11 +235,14 @@ bool SSBMod::handleMessage(const Message& cmd) } else if (DSPSignalNotification::match(cmd)) { - // Forward to the source DSPSignalNotification& notif = (DSPSignalNotification&) cmd; - DSPSignalNotification* rep = new DSPSignalNotification(notif); // make a copy - qDebug() << "SSBMod::handleMessage: DSPSignalNotification"; - m_basebandSource->getInputMessageQueue()->push(rep); + // Forward to the source + if (m_running) + { + DSPSignalNotification* rep = new DSPSignalNotification(notif); // make a copy + qDebug() << "SSBMod::handleMessage: DSPSignalNotification"; + m_basebandSource->getInputMessageQueue()->push(rep); + } // Forward to GUI if any if (getMessageQueueToGUI()) { getMessageQueueToGUI()->push(new DSPSignalNotification(notif)); @@ -360,8 +397,11 @@ void SSBMod::applySettings(const SSBModSettings& settings, bool force) m_spectrumVis.getInputMessageQueue()->push(msg); } - SSBModBaseband::MsgConfigureSSBModBaseband *msg = SSBModBaseband::MsgConfigureSSBModBaseband::create(settings, force); - m_basebandSource->getInputMessageQueue()->push(msg); + if (m_running) + { + SSBModBaseband::MsgConfigureSSBModBaseband *msg = SSBModBaseband::MsgConfigureSSBModBaseband::create(settings, force); + m_basebandSource->getInputMessageQueue()->push(msg); + } if (settings.m_useReverseAPI) { @@ -437,7 +477,7 @@ int SSBMod::webapiSettingsGet( webapiFormatChannelSettings(response, m_settings); SWGSDRangel::SWGCWKeyerSettings *apiCwKeyerSettings = response.getSsbModSettings()->getCwKeyer(); - const CWKeyerSettings& cwKeyerSettings = m_basebandSource->getCWKeyer().getSettings(); + const CWKeyerSettings& cwKeyerSettings = m_cwKeyer.getSettings(); CWKeyer::webapiFormatChannelSettings(apiCwKeyerSettings, cwKeyerSettings); return 200; @@ -465,11 +505,11 @@ int SSBMod::webapiSettingsPutPatch( if (channelSettingsKeys.contains("cwKeyer")) { SWGSDRangel::SWGCWKeyerSettings *apiCwKeyerSettings = response.getSsbModSettings()->getCwKeyer(); - CWKeyerSettings cwKeyerSettings = m_basebandSource->getCWKeyer().getSettings(); + CWKeyerSettings cwKeyerSettings = m_cwKeyer.getSettings(); CWKeyer::webapiSettingsPutPatch(channelSettingsKeys, cwKeyerSettings, apiCwKeyerSettings); CWKeyer::MsgConfigureCWKeyer *msgCwKeyer = CWKeyer::MsgConfigureCWKeyer::create(cwKeyerSettings, force); - m_basebandSource->getCWKeyer().getInputMessageQueue()->push(msgCwKeyer); + m_cwKeyer.getInputMessageQueue()->push(msgCwKeyer); if (m_guiMessageQueue) // forward to GUI if any { @@ -689,8 +729,12 @@ void SSBMod::webapiFormatChannelSettings(SWGSDRangel::SWGChannelSettings& respon void SSBMod::webapiFormatChannelReport(SWGSDRangel::SWGChannelReport& response) { response.getSsbModReport()->setChannelPowerDb(CalcDb::dbPower(getMagSq())); - response.getSsbModReport()->setAudioSampleRate(m_basebandSource->getAudioSampleRate()); - response.getSsbModReport()->setChannelSampleRate(m_basebandSource->getChannelSampleRate()); + + if (m_running) + { + response.getSsbModReport()->setAudioSampleRate(m_basebandSource->getAudioSampleRate()); + response.getSsbModReport()->setChannelSampleRate(m_basebandSource->getChannelSampleRate()); + } } void SSBMod::webapiReverseSendSettings(QList& channelSettingsKeys, const SSBModSettings& settings, bool force) @@ -728,7 +772,7 @@ void SSBMod::webapiReverseSendCWSettings(const CWKeyerSettings& cwKeyerSettings) swgSSBModSettings->setCwKeyer(new SWGSDRangel::SWGCWKeyerSettings()); SWGSDRangel::SWGCWKeyerSettings *apiCwKeyerSettings = swgSSBModSettings->getCwKeyer(); - m_basebandSource->getCWKeyer().webapiFormatChannelSettings(apiCwKeyerSettings, cwKeyerSettings); + m_cwKeyer.webapiFormatChannelSettings(apiCwKeyerSettings, cwKeyerSettings); QString channelSettingsURL = QString("http://%1:%2/sdrangel/deviceset/%3/channel/%4/settings") .arg(m_settings.m_reverseAPIAddress) @@ -875,10 +919,10 @@ void SSBMod::webapiFormatChannelSettings( if (force) { - const CWKeyerSettings& cwKeyerSettings = m_basebandSource->getCWKeyer().getSettings(); + const CWKeyerSettings& cwKeyerSettings = m_cwKeyer.getSettings(); swgSSBModSettings->setCwKeyer(new SWGSDRangel::SWGCWKeyerSettings()); SWGSDRangel::SWGCWKeyerSettings *apiCwKeyerSettings = swgSSBModSettings->getCwKeyer(); - m_basebandSource->getCWKeyer().webapiFormatChannelSettings(apiCwKeyerSettings, cwKeyerSettings); + m_cwKeyer.webapiFormatChannelSettings(apiCwKeyerSettings, cwKeyerSettings); } } @@ -905,27 +949,34 @@ void SSBMod::networkManagerFinished(QNetworkReply *reply) double SSBMod::getMagSq() const { - return m_basebandSource->getMagSq(); + if (m_running) { + return m_basebandSource->getMagSq(); + } + + return 0; } CWKeyer *SSBMod::getCWKeyer() { - return &m_basebandSource->getCWKeyer(); -} - -void SSBMod::setLevelMeter(QObject *levelMeter) -{ - connect(m_basebandSource, SIGNAL(levelChanged(qreal, qreal, int)), levelMeter, SLOT(levelChanged(qreal, qreal, int))); + return &m_cwKeyer; } int SSBMod::getAudioSampleRate() const { - return m_basebandSource->getAudioSampleRate(); + if (m_running) { + return m_basebandSource->getAudioSampleRate(); + } + + return 0; } int SSBMod::getFeedbackAudioSampleRate() const { - return m_basebandSource->getFeedbackAudioSampleRate(); + if (m_running) { + return m_basebandSource->getFeedbackAudioSampleRate(); + } + + return 0; } uint32_t SSBMod::getNumberOfDeviceStreams() const diff --git a/plugins/channeltx/modssb/ssbmod.h b/plugins/channeltx/modssb/ssbmod.h index 549221c14..166086428 100644 --- a/plugins/channeltx/modssb/ssbmod.h +++ b/plugins/channeltx/modssb/ssbmod.h @@ -29,6 +29,7 @@ #include "dsp/basebandsamplesource.h" #include "dsp/spectrumvis.h" +#include "dsp/cwkeyer.h" #include "channel/channelapi.h" #include "util/message.h" @@ -236,7 +237,7 @@ public: SpectrumVis *getSpectrumVis() { return &m_spectrumVis; } double getMagSq() const; CWKeyer *getCWKeyer(); - void setLevelMeter(QObject *levelMeter); + void setLevelMeter(QObject *levelMeter) { m_levelMeter = levelMeter; } int getAudioSampleRate() const; int getFeedbackAudioSampleRate() const; uint32_t getNumberOfDeviceStreams() const; @@ -252,6 +253,7 @@ private: DeviceAPI* m_deviceAPI; QThread *m_thread; + bool m_running; SSBModBaseband* m_basebandSource; SSBModSettings m_settings; SpectrumVis m_spectrumVis; @@ -267,6 +269,8 @@ private: QNetworkAccessManager *m_networkManager; QNetworkRequest m_networkRequest; + CWKeyer m_cwKeyer; + QObject *m_levelMeter; virtual bool handleMessage(const Message& cmd); void applySettings(const SSBModSettings& settings, bool force = false); diff --git a/plugins/channeltx/modssb/ssbmodbaseband.cpp b/plugins/channeltx/modssb/ssbmodbaseband.cpp index d45b49699..c58d7f926 100644 --- a/plugins/channeltx/modssb/ssbmodbaseband.cpp +++ b/plugins/channeltx/modssb/ssbmodbaseband.cpp @@ -171,8 +171,8 @@ bool SSBModBaseband::handleMessage(const Message& cmd) QMutexLocker mutexLocker(&m_mutex); const CWKeyer::MsgConfigureCWKeyer& cfg = (CWKeyer::MsgConfigureCWKeyer&) cmd; CWKeyer::MsgConfigureCWKeyer *notif = new CWKeyer::MsgConfigureCWKeyer(cfg); - CWKeyer& cwKeyer = m_source.getCWKeyer(); - cwKeyer.getInputMessageQueue()->push(notif); + CWKeyer *cwKeyer = m_source.getCWKeyer(); + cwKeyer->getInputMessageQueue()->push(notif); return true; } diff --git a/plugins/channeltx/modssb/ssbmodbaseband.h b/plugins/channeltx/modssb/ssbmodbaseband.h index 57db8e3b5..96688f2a5 100644 --- a/plugins/channeltx/modssb/ssbmodbaseband.h +++ b/plugins/channeltx/modssb/ssbmodbaseband.h @@ -65,7 +65,7 @@ public: void reset(); void pull(const SampleVector::iterator& begin, unsigned int nbSamples); MessageQueue *getInputMessageQueue() { return &m_inputMessageQueue; } //!< Get the queue for asynchronous inbound communication - CWKeyer& getCWKeyer() { return m_source.getCWKeyer(); } + void setCWKeyer(CWKeyer *cwKeyer) { m_source.setCWKeyer(cwKeyer); } double getMagSq() const { return m_source.getMagSq(); } int getAudioSampleRate() const { return m_source.getAudioSampleRate(); } int getFeedbackAudioSampleRate() const { return m_source.getFeedbackAudioSampleRate(); } diff --git a/plugins/channeltx/modssb/ssbmodsource.cpp b/plugins/channeltx/modssb/ssbmodsource.cpp index 6310ca9a0..b829b3701 100644 --- a/plugins/channeltx/modssb/ssbmodsource.cpp +++ b/plugins/channeltx/modssb/ssbmodsource.cpp @@ -39,7 +39,8 @@ SSBModSource::SSBModSource() : m_levelCalcCount(0), m_peakLevel(0.0f), m_levelSum(0.0f), - m_ifstream(nullptr) + m_ifstream(nullptr), + m_cwKeyer(nullptr) { m_audioFifo.setLabel("SSBModSource.m_audioFifo"); m_feedbackAudioFifo.setLabel("SSBModSource.m_feedbackAudioFifo"); @@ -69,9 +70,6 @@ SSBModSource::SSBModSource() : m_magsq = 0.0; m_toneNco.setFreq(1000.0, m_audioSampleRate); - m_cwKeyer.setSampleRate(m_audioSampleRate); - m_cwKeyer.reset(); - m_audioCompressor.initSimple( m_audioSampleRate, m_settings.m_cmpPreGainDB, // pregain (dB) @@ -354,11 +352,15 @@ void SSBModSource::pullAF(Complex& sample) break; case SSBModSettings::SSBModInputCWTone: + if (!m_cwKeyer) { + break; + } + Real fadeFactor; - if (m_cwKeyer.getSample()) + if (m_cwKeyer->getSample()) { - m_cwKeyer.getCWSmoother().getFadeSample(true, fadeFactor); + m_cwKeyer->getCWSmoother().getFadeSample(true, fadeFactor); if (m_settings.m_dsb) { @@ -377,7 +379,7 @@ void SSBModSource::pullAF(Complex& sample) } else { - if (m_cwKeyer.getCWSmoother().getFadeSample(false, fadeFactor)) + if (m_cwKeyer->getCWSmoother().getFadeSample(false, fadeFactor)) { if (m_settings.m_dsb) { @@ -623,8 +625,12 @@ void SSBModSource::applyAudioSampleRate(int sampleRate) m_settings.m_usb = usb; m_toneNco.setFreq(m_settings.m_toneFrequency, sampleRate); - m_cwKeyer.setSampleRate(sampleRate); - m_cwKeyer.reset(); + + if (m_cwKeyer) + { + m_cwKeyer->setSampleRate(sampleRate); + m_cwKeyer->reset(); + } m_audioCompressor.m_rate = sampleRate; m_audioCompressor.initState(); diff --git a/plugins/channeltx/modssb/ssbmodsource.h b/plugins/channeltx/modssb/ssbmodsource.h index 164ca1225..1eb4cb348 100644 --- a/plugins/channeltx/modssb/ssbmodsource.h +++ b/plugins/channeltx/modssb/ssbmodsource.h @@ -39,6 +39,7 @@ class ChannelAPI; class SpectrumVis; +class CWKeyer; class SSBModSource : public QObject, public ChannelSampleSource { @@ -59,7 +60,8 @@ public: int getAudioSampleRate() const { return m_audioSampleRate; } int getFeedbackAudioSampleRate() const { return m_feedbackAudioSampleRate; } void setChannel(ChannelAPI *channel) { m_channel = channel; } - CWKeyer& getCWKeyer() { return m_cwKeyer; } + CWKeyer* getCWKeyer() { return m_cwKeyer; } + void setCWKeyer(CWKeyer *cwKeyer) { m_cwKeyer = cwKeyer; } double getMagSq() const { return m_magsq; } void getLevels(qreal& rmsLevel, qreal& peakLevel, int& numSamples) const { @@ -131,7 +133,7 @@ private: Real m_levelSum; std::ifstream *m_ifstream; - CWKeyer m_cwKeyer; + CWKeyer *m_cwKeyer; AudioCompressorSnd m_audioCompressor; int m_agcStepLength; From 24dba6f7f198e729fa7d6137f85c8388bf15da3a Mon Sep 17 00:00:00 2001 From: f4exb Date: Sun, 18 Aug 2024 13:37:27 +0200 Subject: [PATCH 10/16] Fixed threading model for DSPDeviceSinkEngine plus other fixes. Part of #2159 --- sdrbase/dsp/dspdevicesinkengine.cpp | 46 ++++++++--------------------- sdrbase/dsp/dspdevicesinkengine.h | 10 ++----- sdrbase/dsp/dspengine.cpp | 37 ++++++++++++++++++----- sdrgui/mainwindow.cpp | 18 ++--------- sdrsrv/mainserver.cpp | 14 ++------- 5 files changed, 51 insertions(+), 74 deletions(-) diff --git a/sdrbase/dsp/dspdevicesinkengine.cpp b/sdrbase/dsp/dspdevicesinkengine.cpp index 210bd5780..70090a1e3 100644 --- a/sdrbase/dsp/dspdevicesinkengine.cpp +++ b/sdrbase/dsp/dspdevicesinkengine.cpp @@ -28,7 +28,7 @@ #include "dsp/dspcommands.h" DSPDeviceSinkEngine::DSPDeviceSinkEngine(uint32_t uid, QObject* parent) : - QThread(parent), + QObject(parent), m_uid(uid), m_state(StNotStarted), m_deviceSampleSink(nullptr), @@ -41,8 +41,6 @@ DSPDeviceSinkEngine::DSPDeviceSinkEngine(uint32_t uid, QObject* parent) : { setState(StIdle); connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()), Qt::QueuedConnection); - - moveToThread(this); } DSPDeviceSinkEngine::~DSPDeviceSinkEngine() @@ -59,29 +57,6 @@ void DSPDeviceSinkEngine::setState(State state) } } -void DSPDeviceSinkEngine::run() -{ - qDebug() << "DSPDeviceSinkEngine::run"; - setState(StIdle); - exec(); -} - -void DSPDeviceSinkEngine::start() -{ - qDebug() << "DSPDeviceSinkEngine::start"; - QThread::start(); -} - -void DSPDeviceSinkEngine::stop() -{ - qDebug() << "DSPDeviceSinkEngine::stop"; - gotoIdle(); - setState(StNotStarted); - QThread::exit(); -// DSPExit cmd; -// m_syncMessenger.sendWait(cmd); -} - bool DSPDeviceSinkEngine::initGeneration() { qDebug() << "DSPDeviceSinkEngine::initGeneration"; @@ -101,7 +76,7 @@ bool DSPDeviceSinkEngine::startGeneration() void DSPDeviceSinkEngine::stopGeneration() { qDebug() << "DSPDeviceSinkEngine::stopGeneration"; - DSPGenerationStop *cmd = new DSPGenerationStop(); + auto *cmd = new DSPGenerationStop(); getInputMessageQueue()->push(cmd); } @@ -122,7 +97,7 @@ void DSPDeviceSinkEngine::setSinkSequence(int sequence) void DSPDeviceSinkEngine::addChannelSource(BasebandSampleSource* source) { qDebug() << "DSPDeviceSinkEngine::addChannelSource: " << source->getSourceName().toStdString().c_str(); - DSPAddBasebandSampleSource *cmd = new DSPAddBasebandSampleSource(source); + auto *cmd = new DSPAddBasebandSampleSource(source); getInputMessageQueue()->push(cmd); } @@ -167,7 +142,10 @@ void DSPDeviceSinkEngine::workSampleFifo() } SampleVector& data = sourceFifo->getData(); - unsigned int iPart1Begin, iPart1End, iPart2Begin, iPart2End; + unsigned int iPart1Begin; + unsigned int iPart1End; + unsigned int iPart2Begin; + unsigned int iPart2End; unsigned int remainder = sourceFifo->remainder(); while ((remainder > 0) && (m_inputMessageQueue.size() == 0)) @@ -208,7 +186,7 @@ void DSPDeviceSinkEngine::workSamples(SampleVector& data, unsigned int iBegin, u else { m_sourceSampleBuffer.allocate(nbSamples); - SampleVector::iterator sBegin = m_sourceSampleBuffer.m_vector.begin(); + auto sBegin = m_sourceSampleBuffer.m_vector.begin(); BasebandSampleSources::const_iterator srcIt = m_basebandSampleSources.begin(); BasebandSampleSource *source = *srcIt; source->pull(begin, nbSamples); @@ -309,7 +287,7 @@ DSPDeviceSinkEngine::State DSPDeviceSinkEngine::gotoInit() m_sampleRate = m_deviceSampleSink->getSampleRate(); qDebug() << "DSPDeviceSinkEngine::gotoInit: " - << " m_deviceDescription: " << m_deviceDescription.toStdString().c_str() + << " m_deviceDescription: " << m_deviceDescription.toStdString().c_str() << " sampleRate: " << m_sampleRate << " centerFrequency: " << m_centerFrequency; @@ -328,7 +306,7 @@ DSPDeviceSinkEngine::State DSPDeviceSinkEngine::gotoInit() // pass data to listeners if (m_deviceSampleSink->getMessageQueueToGUI()) { - DSPSignalNotification* rep = new DSPSignalNotification(notif); // make a copy for the output queue + auto* rep = new DSPSignalNotification(notif); // make a copy for the output queue m_deviceSampleSink->getMessageQueueToGUI()->push(rep); } @@ -413,7 +391,7 @@ void DSPDeviceSinkEngine::handleSetSink(DeviceSampleSink*) void DSPDeviceSinkEngine::handleData() { if (m_state == StRunning) { - workSampleFifo(); + workSampleFifo(); } } @@ -421,7 +399,7 @@ bool DSPDeviceSinkEngine::handleMessage(const Message& message) { if (DSPSignalNotification::match(message)) { - const DSPSignalNotification& notif = (const DSPSignalNotification&) message; + auto& notif = (const DSPSignalNotification&) message; // update DSP values diff --git a/sdrbase/dsp/dspdevicesinkengine.h b/sdrbase/dsp/dspdevicesinkengine.h index 608028176..db190782d 100644 --- a/sdrbase/dsp/dspdevicesinkengine.h +++ b/sdrbase/dsp/dspdevicesinkengine.h @@ -22,7 +22,7 @@ #ifndef SDRBASE_DSP_DSPDEVICESINKENGINE_H_ #define SDRBASE_DSP_DSPDEVICESINKENGINE_H_ -#include +#include #include #include #include @@ -40,7 +40,7 @@ class DeviceSampleSink; class BasebandSampleSource; class BasebandSampleSink; -class SDRBASE_API DSPDeviceSinkEngine : public QThread { +class SDRBASE_API DSPDeviceSinkEngine : public QObject { Q_OBJECT public: @@ -52,16 +52,13 @@ public: StError //!< engine is in error }; - DSPDeviceSinkEngine(uint32_t uid, QObject* parent = NULL); + DSPDeviceSinkEngine(uint32_t uid, QObject* parent = nullptr); ~DSPDeviceSinkEngine(); uint32_t getUID() const { return m_uid; } MessageQueue* getInputMessageQueue() { return &m_inputMessageQueue; } - void start(); //!< This thread start - void stop(); //!< This thread stop - bool initGeneration(); //!< Initialize generation sequence bool startGeneration(); //!< Start generation sequence void stopGeneration(); //!< Stop generation sequence @@ -106,7 +103,6 @@ private: bool m_realElseComplex; unsigned int m_sumIndex; //!< channel index when summing channels - void run(); void workSampleFifo(); //!< transfer samples from baseband sources to sink if in running state void workSamples(SampleVector& data, unsigned int iBegin, unsigned int iEnd); diff --git a/sdrbase/dsp/dspengine.cpp b/sdrbase/dsp/dspengine.cpp index 43e7be763..7e8f72d27 100644 --- a/sdrbase/dsp/dspengine.cpp +++ b/sdrbase/dsp/dspengine.cpp @@ -111,24 +111,45 @@ void DSPEngine::removeLastDeviceSourceEngine() DSPDeviceSinkEngine *DSPEngine::addDeviceSinkEngine() { - m_deviceSinkEngines.push_back(new DSPDeviceSinkEngine(m_deviceSinkEnginesUIDSequence)); + auto *deviceSinkEngine = new DSPDeviceSinkEngine(m_deviceSinkEnginesUIDSequence); + auto *deviceThread = new QThread(); m_deviceSinkEnginesUIDSequence++; - m_deviceEngineReferences.push_back(DeviceEngineReference{1, nullptr, m_deviceSinkEngines.back(), nullptr, nullptr}); - return m_deviceSinkEngines.back(); + m_deviceSinkEngines.push_back(deviceSinkEngine); + m_deviceEngineReferences.push_back(DeviceEngineReference{1, nullptr, m_deviceSinkEngines.back(), nullptr, deviceThread}); + deviceSinkEngine->moveToThread(deviceThread); + + QObject::connect( + deviceThread, + &QThread::finished, + deviceSinkEngine, + &QObject::deleteLater + ); + QObject::connect( + deviceThread, + &QThread::finished, + deviceThread, + &QThread::deleteLater + ); + + deviceThread->start(); + + return deviceSinkEngine; } void DSPEngine::removeLastDeviceSinkEngine() { - if (m_deviceSinkEngines.size() > 0) + if (!m_deviceSinkEngines.empty()) { - DSPDeviceSinkEngine *lastDeviceEngine = m_deviceSinkEngines.back(); - delete lastDeviceEngine; + const DSPDeviceSinkEngine *lastDeviceEngine = m_deviceSinkEngines.back(); m_deviceSinkEngines.pop_back(); for (int i = 0; i < m_deviceEngineReferences.size(); i++) { if (m_deviceEngineReferences[i].m_deviceSinkEngine == lastDeviceEngine) { + QThread* deviceThread = m_deviceEngineReferences[i].m_thread; + deviceThread->exit(); + deviceThread->wait(); m_deviceEngineReferences.removeAt(i); break; } @@ -201,7 +222,9 @@ void DSPEngine::removeDeviceEngineAt(int deviceIndex) else if (m_deviceEngineReferences[deviceIndex].m_deviceEngineType == 1) // sink { DSPDeviceSinkEngine *deviceEngine = m_deviceEngineReferences[deviceIndex].m_deviceSinkEngine; - delete deviceEngine; + QThread *deviceThread = m_deviceEngineReferences[deviceIndex].m_thread; + deviceThread->exit(); + deviceThread->wait(); m_deviceSinkEngines.removeAll(deviceEngine); } else if (m_deviceEngineReferences[deviceIndex].m_deviceEngineType == 2) // MIMO diff --git a/sdrgui/mainwindow.cpp b/sdrgui/mainwindow.cpp index 05815feb1..e0386a05e 100644 --- a/sdrgui/mainwindow.cpp +++ b/sdrgui/mainwindow.cpp @@ -565,7 +565,6 @@ void MainWindow::sampleSourceCreate( void MainWindow::sampleSinkAdd(Workspace *deviceWorkspace, Workspace *spectrumWorkspace, int deviceIndex) { DSPDeviceSinkEngine *dspDeviceSinkEngine = m_dspEngine->addDeviceSinkEngine(); - dspDeviceSinkEngine->start(); uint dspDeviceSinkEngineUID = dspDeviceSinkEngine->getUID(); char uidCStr[16]; @@ -993,7 +992,6 @@ void MainWindow::removeDeviceSet(int deviceSetIndex) if (deviceUISet->m_deviceSourceEngine) // source device { DSPDeviceSourceEngine *deviceEngine = deviceUISet->m_deviceSourceEngine; - deviceEngine->stopAcquistion(); deviceEngine->removeSink(deviceUISet->m_spectrumVis); // deletes old UI and core object @@ -1015,7 +1013,6 @@ void MainWindow::removeDeviceSet(int deviceSetIndex) else if (deviceUISet->m_deviceSinkEngine) // sink device { DSPDeviceSinkEngine *deviceEngine = deviceUISet->m_deviceSinkEngine; - deviceEngine->stopGeneration(); deviceEngine->removeSpectrumSink(deviceUISet->m_spectrumVis); // deletes old UI and output object @@ -1023,24 +1020,19 @@ void MainWindow::removeDeviceSet(int deviceSetIndex) deviceUISet->m_deviceAPI->getSampleSink()->setMessageQueueToGUI(nullptr); // have sink stop sending messages to the GUI deviceUISet->m_deviceGUI->destroy(); deviceUISet->m_deviceAPI->resetSamplingDeviceId(); - deviceUISet->m_deviceAPI->getPluginInterface()->deleteSampleSinkPluginInstanceOutput( - deviceUISet->m_deviceAPI->getSampleSink()); deviceUISet->m_deviceAPI->clearBuddiesLists(); // clear old API buddies lists - DeviceAPI *sinkAPI = deviceUISet->m_deviceAPI; - delete deviceUISet; - - deviceEngine->stop(); m_dspEngine->removeDeviceEngineAt(deviceSetIndex); DeviceEnumerator::instance()->removeTxSelection(deviceSetIndex); + DeviceAPI *sinkAPI = deviceUISet->m_deviceAPI; + delete deviceUISet; + delete sinkAPI->getSampleSink(); delete sinkAPI; } else if (deviceUISet->m_deviceMIMOEngine) // MIMO device { DSPDeviceMIMOEngine *deviceEngine = deviceUISet->m_deviceMIMOEngine; - deviceEngine->stopProcess(1); // Tx side - deviceEngine->stopProcess(0); // Rx side deviceEngine->removeSpectrumSink(deviceUISet->m_spectrumVis); // deletes old UI and output object @@ -1096,7 +1088,6 @@ void MainWindow::removeLastDeviceSet() if (m_deviceUIs.back()->m_deviceSourceEngine) // source tab { DSPDeviceSourceEngine *lastDeviceEngine = m_deviceUIs.back()->m_deviceSourceEngine; - lastDeviceEngine->stopAcquistion(); lastDeviceEngine->removeSink(m_deviceUIs.back()->m_spectrumVis); // deletes old UI and input object @@ -1116,7 +1107,6 @@ void MainWindow::removeLastDeviceSet() else if (m_deviceUIs.back()->m_deviceSinkEngine) // sink tab { DSPDeviceSinkEngine *lastDeviceEngine = m_deviceUIs.back()->m_deviceSinkEngine; - lastDeviceEngine->stopGeneration(); lastDeviceEngine->removeSpectrumSink(m_deviceUIs.back()->m_spectrumVis); // deletes old UI and output object @@ -1136,8 +1126,6 @@ void MainWindow::removeLastDeviceSet() else if (m_deviceUIs.back()->m_deviceMIMOEngine) // MIMO tab { DSPDeviceMIMOEngine *lastDeviceEngine = m_deviceUIs.back()->m_deviceMIMOEngine; - lastDeviceEngine->stopProcess(1); // Tx side - lastDeviceEngine->stopProcess(0); // Rx side lastDeviceEngine->removeSpectrumSink(m_deviceUIs.back()->m_spectrumVis); // deletes old UI and output object diff --git a/sdrsrv/mainserver.cpp b/sdrsrv/mainserver.cpp index c98f5decd..da49095cd 100644 --- a/sdrsrv/mainserver.cpp +++ b/sdrsrv/mainserver.cpp @@ -270,7 +270,6 @@ void MainServer::applySettings() void MainServer::addSinkDevice() { DSPDeviceSinkEngine *dspDeviceSinkEngine = m_dspEngine->addDeviceSinkEngine(); - dspDeviceSinkEngine->start(); uint dspDeviceSinkEngineUID = dspDeviceSinkEngine->getUID(); char uidCStr[16]; @@ -398,7 +397,6 @@ void MainServer::removeLastDevice() if (m_mainCore->m_deviceSets.back()->m_deviceSourceEngine) // source set { DSPDeviceSourceEngine *lastDeviceEngine = m_mainCore->m_deviceSets.back()->m_deviceSourceEngine; - lastDeviceEngine->stopAcquistion(); // deletes old UI and input object m_mainCore->m_deviceSets.back()->freeChannels(); // destroys the channel instances @@ -415,28 +413,22 @@ void MainServer::removeLastDevice() else if (m_mainCore->m_deviceSets.back()->m_deviceSinkEngine) // sink set { DSPDeviceSinkEngine *lastDeviceEngine = m_mainCore->m_deviceSets.back()->m_deviceSinkEngine; - lastDeviceEngine->stopGeneration(); // deletes old UI and output object m_mainCore->m_deviceSets.back()->freeChannels(); m_mainCore->m_deviceSets.back()->m_deviceAPI->resetSamplingDeviceId(); - m_mainCore->m_deviceSets.back()->m_deviceAPI->getPluginInterface()->deleteSampleSinkPluginInstanceOutput( - m_mainCore->m_deviceSets.back()->m_deviceAPI->getSampleSink()); m_mainCore->m_deviceSets.back()->m_deviceAPI->clearBuddiesLists(); // clear old API buddies lists + m_dspEngine->removeLastDeviceSinkEngine(); + DeviceAPI *sinkAPI = m_mainCore->m_deviceSets.back()->m_deviceAPI; delete m_mainCore->m_deviceSets.back(); - - lastDeviceEngine->stop(); - m_dspEngine->removeLastDeviceSinkEngine(); - + delete sinkAPI->getSampleSink(); delete sinkAPI; } else if (m_mainCore->m_deviceSets.back()->m_deviceMIMOEngine) // MIMO set { DSPDeviceMIMOEngine *lastDeviceEngine = m_mainCore->m_deviceSets.back()->m_deviceMIMOEngine; - lastDeviceEngine->stopProcess(1); // Tx side - lastDeviceEngine->stopProcess(0); // Rx side m_mainCore->m_deviceSets.back()->freeChannels(); m_mainCore->m_deviceSets.back()->m_deviceAPI->resetSamplingDeviceId(); From 49074d1ce94b0c70fb3035a3eee4937dff6fcf34 Mon Sep 17 00:00:00 2001 From: f4exb Date: Mon, 19 Aug 2024 00:31:55 +0200 Subject: [PATCH 11/16] DeviceSet and DeviceUISet: use delete channel API instead of destroy method so that the virtual destructor of the channel is called appropriately --- sdrbase/device/deviceset.cpp | 10 +++++----- sdrbase/device/deviceset.h | 4 +--- sdrgui/device/deviceuiset.cpp | 10 +++++----- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/sdrbase/device/deviceset.cpp b/sdrbase/device/deviceset.cpp index 704e4ae66..731188277 100644 --- a/sdrbase/device/deviceset.cpp +++ b/sdrbase/device/deviceset.cpp @@ -59,7 +59,7 @@ void DeviceSet::freeChannels() for(int i = 0; i < m_channelInstanceRegistrations.count(); i++) { qDebug("DeviceSet::freeChannels: destroying channel [%s]", qPrintable(m_channelInstanceRegistrations[i]->getURI())); - m_channelInstanceRegistrations[i]->destroy(); + delete m_channelInstanceRegistrations[i]; } MainCore::instance()->clearChannels(this); @@ -87,7 +87,7 @@ void DeviceSet::deleteChannel(int channelIndex) { if (channelIndex < m_channelInstanceRegistrations.count()) { - m_channelInstanceRegistrations[channelIndex]->destroy(); + delete m_channelInstanceRegistrations[channelIndex]; m_channelInstanceRegistrations.removeAt(channelIndex); MainCore::instance()->removeChannelInstanceAt(this, channelIndex); renameChannelInstances(); @@ -141,7 +141,7 @@ void DeviceSet::loadRxChannelSettings(const Preset *preset, PluginAPI *pluginAPI PluginAPI::ChannelRegistrations *channelRegistrations = pluginAPI->getRxChannelRegistrations(); // copy currently open channels and clear list - ChannelInstanceRegistrations openChannels = m_channelInstanceRegistrations; + QList openChannels = m_channelInstanceRegistrations; m_channelInstanceRegistrations.clear(); mainCore->clearChannels(this); @@ -241,7 +241,7 @@ void DeviceSet::loadTxChannelSettings(const Preset *preset, PluginAPI *pluginAPI PluginAPI::ChannelRegistrations *channelRegistrations = pluginAPI->getTxChannelRegistrations(); // copy currently open channels and clear list - ChannelInstanceRegistrations openChannels = m_channelInstanceRegistrations; + QList openChannels = m_channelInstanceRegistrations; m_channelInstanceRegistrations.clear(); mainCore->clearChannels(this); @@ -339,7 +339,7 @@ void DeviceSet::loadMIMOChannelSettings(const Preset *preset, PluginAPI *pluginA PluginAPI::ChannelRegistrations *channelRegistrations = pluginAPI->getMIMOChannelRegistrations(); // copy currently open channels and clear list - ChannelInstanceRegistrations openChannels = m_channelInstanceRegistrations; + QList openChannels = m_channelInstanceRegistrations; m_channelInstanceRegistrations.clear(); mainCore->clearChannels(this); diff --git a/sdrbase/device/deviceset.h b/sdrbase/device/deviceset.h index 7b65afe6e..f412bb788 100644 --- a/sdrbase/device/deviceset.h +++ b/sdrbase/device/deviceset.h @@ -86,9 +86,7 @@ public: int webapiSpectrumServerDelete(SWGSDRangel::SWGSuccessResponse& response, QString& errorMessage); private: - typedef QList ChannelInstanceRegistrations; - - ChannelInstanceRegistrations m_channelInstanceRegistrations; + QList m_channelInstanceRegistrations; int m_deviceTabIndex; void renameChannelInstances(); diff --git a/sdrgui/device/deviceuiset.cpp b/sdrgui/device/deviceuiset.cpp index 98a167374..d56a46cfb 100644 --- a/sdrgui/device/deviceuiset.cpp +++ b/sdrgui/device/deviceuiset.cpp @@ -170,7 +170,7 @@ void DeviceUISet::freeChannels() { qDebug("DeviceUISet::freeChannels: destroying channel [%s]", qPrintable(m_channelInstanceRegistrations[i].m_channelAPI->getURI())); m_channelInstanceRegistrations[i].m_gui->destroy(); - m_channelInstanceRegistrations[i].m_channelAPI->destroy(); + delete m_channelInstanceRegistrations[i].m_channelAPI; } m_channelInstanceRegistrations.clear(); @@ -185,7 +185,7 @@ void DeviceUISet::deleteChannel(int channelIndex) qPrintable(m_channelInstanceRegistrations[channelIndex].m_channelAPI->getURI()), channelIndex); m_channelInstanceRegistrations[channelIndex].m_gui->destroy(); - m_channelInstanceRegistrations[channelIndex].m_channelAPI->destroy(); + delete m_channelInstanceRegistrations[channelIndex].m_channelAPI; m_channelInstanceRegistrations.removeAt(channelIndex); } @@ -324,7 +324,7 @@ void DeviceUISet::loadRxChannelSettings(const Preset *preset, PluginAPI *pluginA qPrintable(m_channelInstanceRegistrations[i].m_channelAPI->getURI())); m_channelInstanceRegistrations[i].m_channelAPI->setMessageQueueToGUI(nullptr); // have channel stop sending messages to its GUI m_channelInstanceRegistrations[i].m_gui->destroy(); - m_channelInstanceRegistrations[i].m_channelAPI->destroy(); + delete m_channelInstanceRegistrations[i].m_channelAPI; } m_channelInstanceRegistrations.clear(); @@ -453,7 +453,7 @@ void DeviceUISet::loadTxChannelSettings(const Preset *preset, PluginAPI *pluginA qPrintable(m_channelInstanceRegistrations[i].m_channelAPI->getURI())); m_channelInstanceRegistrations[i].m_channelAPI->setMessageQueueToGUI(nullptr); // have channel stop sending messages to its GUI m_channelInstanceRegistrations[i].m_gui->destroy(); - m_channelInstanceRegistrations[i].m_channelAPI->destroy(); + delete m_channelInstanceRegistrations[i].m_channelAPI; } m_channelInstanceRegistrations.clear(); @@ -579,7 +579,7 @@ void DeviceUISet::loadMIMOChannelSettings(const Preset *preset, PluginAPI *plugi qDebug("DeviceUISet::loadMIMOChannelSettings: destroying old channel [%s]", qPrintable(m_channelInstanceRegistrations[i].m_channelAPI->getURI())); m_channelInstanceRegistrations[i].m_gui->destroy(); // stop GUI first (issue #1427) - m_channelInstanceRegistrations[i].m_channelAPI->destroy(); // stop channel before (issue #860) + delete m_channelInstanceRegistrations[i].m_channelAPI; // stop channel before (issue #860) } m_channelInstanceRegistrations.clear(); From 38043ebdbc19e491d236956779f887e89de35eef Mon Sep 17 00:00:00 2001 From: f4exb Date: Mon, 19 Aug 2024 00:42:57 +0200 Subject: [PATCH 12/16] BladeRF2Output: removed applySettings from stop method --- plugins/samplesink/bladerf2output/bladerf2output.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/plugins/samplesink/bladerf2output/bladerf2output.cpp b/plugins/samplesink/bladerf2output/bladerf2output.cpp index 6be8d6183..2bbc9d71a 100644 --- a/plugins/samplesink/bladerf2output/bladerf2output.cpp +++ b/plugins/samplesink/bladerf2output/bladerf2output.cpp @@ -399,14 +399,14 @@ void BladeRF2Output::stop() qDebug("BladeRF2Output::stop: SO mode. Just stop and delete the thread"); bladeRF2OutputThread->stopWork(); delete bladeRF2OutputThread; - m_thread = 0; + m_thread = nullptr; // remove old thread address from buddies (reset in all buddies) const std::vector& sinkBuddies = m_deviceAPI->getSinkBuddies(); std::vector::const_iterator it = sinkBuddies.begin(); for (; it != sinkBuddies.end(); ++it) { - ((DeviceBladeRF2Shared*) (*it)->getBuddySharedPtr())->m_sink->setThread(0); + ((DeviceBladeRF2Shared*) (*it)->getBuddySharedPtr())->m_sink->setThread(nullptr); } m_deviceShared.m_dev->closeTx(0); // close the unique channel @@ -422,7 +422,7 @@ void BladeRF2Output::stop() for (int i = 0; i < nbOriginalChannels-1; i++) // save original FIFO references { fifos[i] = bladeRF2OutputThread->getFifo(i); - stillActiveFIFO = stillActiveFIFO || (bladeRF2OutputThread->getFifo(i) != 0); + stillActiveFIFO = stillActiveFIFO || (bladeRF2OutputThread->getFifo(i) != nullptr); log2Interps[i] = bladeRF2OutputThread->getLog2Interpolation(i); } @@ -450,7 +450,7 @@ void BladeRF2Output::stop() std::vector::const_iterator it = sinkBuddies.begin(); for (; it != sinkBuddies.end(); ++it) { - ((DeviceBladeRF2Shared*) (*it)->getBuddySharedPtr())->m_sink->setThread(0); + ((DeviceBladeRF2Shared*) (*it)->getBuddySharedPtr())->m_sink->setThread(nullptr); } // close all channels @@ -479,11 +479,9 @@ void BladeRF2Output::stop() else // remove channel from existing thread { qDebug("BladeRF2Output::stop: MO mode. Not changing MO configuration. Just remove FIFO reference"); - bladeRF2OutputThread->setFifo(requestedChannel, 0); // remove FIFO + bladeRF2OutputThread->setFifo(requestedChannel, nullptr); // remove FIFO } - applySettings(m_settings, QList(), true); // re-apply forcibly to set sample rate with the new number of channels - m_running = false; } From 3a7de65ee529494da8a8f1e5ace9d106938e02d3 Mon Sep 17 00:00:00 2001 From: f4exb Date: Wed, 21 Aug 2024 05:27:01 +0200 Subject: [PATCH 13/16] All device plugins: make sure start and stop are effective once only. PArt of #2159 --- .../samplemimo/bladerf2mimo/bladerf2mimo.cpp | 44 +++++++++++-------- .../samplemimo/limesdrmimo/limesdrmimo.cpp | 44 +++++++++++-------- .../samplemimo/plutosdrmimo/plutosdrmimo.cpp | 44 +++++++++++-------- plugins/samplemimo/testmi/testmi.cpp | 2 +- plugins/samplemimo/xtrxmimo/xtrxmimo.cpp | 44 +++++++++++-------- .../bladerf1output/bladerf1output.cpp | 38 +++++++++------- plugins/samplesink/fileoutput/fileoutput.cpp | 15 ++++++- plugins/samplesink/fileoutput/fileoutput.h | 1 + .../samplesink/hackrfoutput/hackrfoutput.cpp | 21 +++++---- .../limesdroutput/limesdroutput.cpp | 23 ++++++---- .../plutosdroutput/plutosdroutput.cpp | 25 +++++++---- .../samplesink/remoteoutput/remoteoutput.cpp | 17 ++++++- .../samplesink/remoteoutput/remoteoutput.h | 3 +- .../soapysdroutput/soapysdroutput.cpp | 10 ++++- plugins/samplesink/usrpoutput/usrpoutput.cpp | 16 +++++-- plugins/samplesink/xtrxoutput/xtrxoutput.cpp | 19 +++++--- plugins/samplesource/airspy/airspyinput.cpp | 14 +++--- plugins/samplesource/airspy/airspyinput.h | 2 +- .../samplesource/airspyhf/airspyhfinput.cpp | 23 ++++++---- plugins/samplesource/airspyhf/airspyhfinput.h | 2 +- .../bladerf1input/bladerf1input.cpp | 28 +++++++----- .../bladerf1input/bladerf1input.h | 2 +- .../bladerf2input/bladerf2input.cpp | 12 +++-- plugins/samplesource/fcdpro/fcdproinput.cpp | 23 ++++++---- .../fcdproplus/fcdproplusinput.cpp | 18 +++++--- .../samplesource/hackrfinput/hackrfinput.cpp | 32 ++++++++------ .../samplesource/hackrfinput/hackrfinput.h | 2 +- .../limesdrinput/limesdrinput.cpp | 27 ++++++++---- .../samplesource/limesdrinput/limesdrinput.h | 2 +- .../plutosdrinput/plutosdrinput.cpp | 25 +++++++---- plugins/samplesource/sdrplay/sdrplayinput.cpp | 27 +++++++----- plugins/samplesource/sdrplay/sdrplayinput.h | 2 +- .../samplesource/sdrplayv3/sdrplayv3input.cpp | 21 ++++++--- .../samplesource/sdrplayv3/sdrplayv3input.h | 2 +- .../sigmffileinput/sigmffileinput.cpp | 17 ++++++- .../sigmffileinput/sigmffileinput.h | 1 + .../soapysdrinput/soapysdrinput.cpp | 9 +++- .../testsource/testsourceinput.cpp | 7 ++- plugins/samplesource/usrpinput/usrpinput.cpp | 19 +++++--- plugins/samplesource/xtrxinput/xtrxinput.cpp | 14 ++++-- 40 files changed, 454 insertions(+), 243 deletions(-) diff --git a/plugins/samplemimo/bladerf2mimo/bladerf2mimo.cpp b/plugins/samplemimo/bladerf2mimo/bladerf2mimo.cpp index 015f46ca1..e7c1591d7 100644 --- a/plugins/samplemimo/bladerf2mimo/bladerf2mimo.cpp +++ b/plugins/samplemimo/bladerf2mimo/bladerf2mimo.cpp @@ -142,6 +142,12 @@ void BladeRF2MIMO::init() bool BladeRF2MIMO::startRx() { + QMutexLocker mutexLocker(&m_mutex); + + if (m_runningRx) { + return true; + } + qDebug("BladeRF2MIMO::startRx"); if (!m_open) @@ -150,12 +156,6 @@ bool BladeRF2MIMO::startRx() return false; } - QMutexLocker mutexLocker(&m_mutex); - - if (m_runningRx) { - stopRx(); - } - m_sourceThread = new BladeRF2MIThread(m_dev->getDev()); m_sampleMIFifo.reset(); m_sourceThread->setFifo(&m_sampleMIFifo); @@ -178,6 +178,12 @@ bool BladeRF2MIMO::startRx() bool BladeRF2MIMO::startTx() { + QMutexLocker mutexLocker(&m_mutex); + + if (m_runningTx) { + return true; + } + qDebug("BladeRF2MIMO::startTx"); if (!m_open) @@ -186,12 +192,6 @@ bool BladeRF2MIMO::startTx() return false; } - QMutexLocker mutexLocker(&m_mutex); - - if (m_runningTx) { - stopTx(); - } - m_sinkThread = new BladeRF2MOThread(m_dev->getDev()); m_sampleMOFifo.reset(); m_sinkThread->setFifo(&m_sampleMOFifo); @@ -213,18 +213,22 @@ bool BladeRF2MIMO::startTx() void BladeRF2MIMO::stopRx() { - qDebug("BladeRF2MIMO::stopRx"); + QMutexLocker mutexLocker(&m_mutex); + + if (!m_runningRx) { + return; + } if (!m_sourceThread) { return; } - QMutexLocker mutexLocker(&m_mutex); + qDebug("BladeRF2MIMO::stopRx"); + m_runningRx = false; m_sourceThread->stopWork(); delete m_sourceThread; m_sourceThread = nullptr; - m_runningRx = false; for (int i = 0; i < 2; i++) { m_dev->closeRx(i); @@ -233,18 +237,22 @@ void BladeRF2MIMO::stopRx() void BladeRF2MIMO::stopTx() { - qDebug("BladeRF2MIMO::stopTx"); + QMutexLocker mutexLocker(&m_mutex); + + if (!m_runningTx) { + return; + } if (!m_sinkThread) { return; } - QMutexLocker mutexLocker(&m_mutex); + qDebug("BladeRF2MIMO::stopTx"); + m_runningTx = false; m_sinkThread->stopWork(); delete m_sinkThread; m_sinkThread = nullptr; - m_runningTx = false; for (int i = 0; i < 2; i++) { m_dev->closeTx(i); diff --git a/plugins/samplemimo/limesdrmimo/limesdrmimo.cpp b/plugins/samplemimo/limesdrmimo/limesdrmimo.cpp index c78f86975..1686cfa6f 100644 --- a/plugins/samplemimo/limesdrmimo/limesdrmimo.cpp +++ b/plugins/samplemimo/limesdrmimo/limesdrmimo.cpp @@ -256,6 +256,12 @@ void LimeSDRMIMO::init() bool LimeSDRMIMO::startRx() { + QMutexLocker mutexLocker(&m_mutex); + + if (m_runningRx) { + return true; + } + qDebug("LimeSDRMIMO::startRx"); lms_stream_t *streams[2]; @@ -265,12 +271,6 @@ bool LimeSDRMIMO::startRx() return false; } - QMutexLocker mutexLocker(&m_mutex); - - if (m_runningRx) { - stopRx(); - } - for (unsigned int channel = 0; channel < 2; channel++) { if (channel < m_deviceAPI->getNbSourceStreams()) @@ -307,18 +307,22 @@ bool LimeSDRMIMO::startRx() void LimeSDRMIMO::stopRx() { - qDebug("LimeSDRMIMO::stopRx"); + QMutexLocker mutexLocker(&m_mutex); + + if (!m_runningRx) { + return; + } if (!m_sourceThread) { return; } - QMutexLocker mutexLocker(&m_mutex); + qDebug("LimeSDRMIMO::stopRx"); + m_runningRx = false; m_sourceThread->stopWork(); delete m_sourceThread; m_sourceThread = nullptr; - m_runningRx = false; for (unsigned int channel = 0; channel < 2; channel++) { @@ -330,6 +334,12 @@ void LimeSDRMIMO::stopRx() bool LimeSDRMIMO::startTx() { + QMutexLocker mutexLocker(&m_mutex); + + if (m_runningTx) { + return true; + } + qDebug("LimeSDRMIMO::startTx"); lms_stream_t *streams[2]; @@ -339,12 +349,6 @@ bool LimeSDRMIMO::startTx() return false; } - QMutexLocker mutexLocker(&m_mutex); - - if (m_runningTx) { - stopTx(); - } - for (unsigned int channel = 0; channel < 2; channel++) { if (channel < m_deviceAPI->getNbSinkStreams()) @@ -380,18 +384,22 @@ bool LimeSDRMIMO::startTx() void LimeSDRMIMO::stopTx() { - qDebug("LimeSDRMIMO::stopTx"); + QMutexLocker mutexLocker(&m_mutex); + + if (!m_runningTx) { + return; + } if (!m_sinkThread) { return; } - QMutexLocker mutexLocker(&m_mutex); + qDebug("LimeSDRMIMO::stopTx"); + m_runningTx = false; m_sinkThread->stopWork(); delete m_sinkThread; m_sinkThread = nullptr; - m_runningTx = false; for (unsigned int channel = 0; channel < 2; channel++) { diff --git a/plugins/samplemimo/plutosdrmimo/plutosdrmimo.cpp b/plugins/samplemimo/plutosdrmimo/plutosdrmimo.cpp index 433b2dcb9..0c5016572 100644 --- a/plugins/samplemimo/plutosdrmimo/plutosdrmimo.cpp +++ b/plugins/samplemimo/plutosdrmimo/plutosdrmimo.cpp @@ -168,7 +168,11 @@ void PlutoSDRMIMO::init() bool PlutoSDRMIMO::startRx() { - qDebug("PlutoSDRMIMO::startRx"); + QMutexLocker mutexLocker(&m_mutex); + + if (m_runningRx) { + return true; + } if (!m_open) { @@ -176,11 +180,7 @@ bool PlutoSDRMIMO::startRx() return false; } - QMutexLocker mutexLocker(&m_mutex); - - if (m_runningRx) { - stopRx(); - } + qDebug("PlutoSDRMIMO::startRx"); m_sourceThread = new PlutoSDRMIThread(m_plutoParams->getBox()); m_sampleMIFifo.reset(); @@ -206,7 +206,11 @@ bool PlutoSDRMIMO::startRx() bool PlutoSDRMIMO::startTx() { - qDebug("PlutoSDRMIMO::startTx"); + QMutexLocker mutexLocker(&m_mutex); + + if (m_runningTx) { + return true; + } if (!m_open) { @@ -214,11 +218,7 @@ bool PlutoSDRMIMO::startTx() return false; } - QMutexLocker mutexLocker(&m_mutex); - - if (m_runningTx) { - stopTx(); - } + qDebug("PlutoSDRMIMO::startTx"); m_sinkThread = new PlutoSDRMOThread(m_plutoParams->getBox()); m_sampleMOFifo.reset(); @@ -243,18 +243,22 @@ bool PlutoSDRMIMO::startTx() void PlutoSDRMIMO::stopRx() { - qDebug("PlutoSDRMIMO::stopRx"); + QMutexLocker mutexLocker(&m_mutex); + + if (!m_runningRx) { + return; + } if (!m_sourceThread) { return; } - QMutexLocker mutexLocker(&m_mutex); + qDebug("PlutoSDRMIMO::stopRx"); + m_runningRx = false; m_sourceThread->stopWork(); delete m_sourceThread; m_sourceThread = nullptr; - m_runningRx = false; if (m_nbRx > 1) { m_plutoParams->getBox()->closeSecondRx(); @@ -270,18 +274,22 @@ void PlutoSDRMIMO::stopRx() void PlutoSDRMIMO::stopTx() { - qDebug("PlutoSDRMIMO::stopTx"); + QMutexLocker mutexLocker(&m_mutex); + + if (!m_runningTx) { + return; + } if (!m_sinkThread) { return; } - QMutexLocker mutexLocker(&m_mutex); + qDebug("PlutoSDRMIMO::stopTx"); + m_runningTx = false; m_sinkThread->stopWork(); delete m_sinkThread; m_sinkThread = nullptr; - m_runningTx = false; if (m_nbTx > 1) { m_plutoParams->getBox()->closeSecondTx(); diff --git a/plugins/samplemimo/testmi/testmi.cpp b/plugins/samplemimo/testmi/testmi.cpp index 92985611c..28d63e12b 100644 --- a/plugins/samplemimo/testmi/testmi.cpp +++ b/plugins/samplemimo/testmi/testmi.cpp @@ -127,7 +127,7 @@ void TestMI::stopRx() } qDebug("TestMI::stopRx"); - m_running = false; + m_running = false; stopWorkers(); m_testSourceWorkers.clear(); diff --git a/plugins/samplemimo/xtrxmimo/xtrxmimo.cpp b/plugins/samplemimo/xtrxmimo/xtrxmimo.cpp index 937a62c9c..c4a0ba32e 100644 --- a/plugins/samplemimo/xtrxmimo/xtrxmimo.cpp +++ b/plugins/samplemimo/xtrxmimo/xtrxmimo.cpp @@ -124,7 +124,11 @@ void XTRXMIMO::init() bool XTRXMIMO::startRx() { - qDebug("XTRXMIMO::startRx"); + QMutexLocker mutexLocker(&m_mutex); + + if (m_runningRx) { + return true; + } if (!m_open) { @@ -132,11 +136,7 @@ bool XTRXMIMO::startRx() return false; } - QMutexLocker mutexLocker(&m_mutex); - - if (m_runningRx) { - stopRx(); - } + qDebug("XTRXMIMO::startRx"); m_sourceThread = new XTRXMIThread(m_deviceShared.m_dev->getDevice()); m_sampleMIFifo.reset(); @@ -152,7 +152,11 @@ bool XTRXMIMO::startRx() bool XTRXMIMO::startTx() { - qDebug("XTRXMIMO::startTx"); + QMutexLocker mutexLocker(&m_mutex); + + if (m_runningTx) { + return true; + } if (!m_open) { @@ -160,11 +164,7 @@ bool XTRXMIMO::startTx() return false; } - QMutexLocker mutexLocker(&m_mutex); - - if (m_runningRx) { - stopRx(); - } + qDebug("XTRXMIMO::startTx"); m_sinkThread = new XTRXMOThread(m_deviceShared.m_dev->getDevice()); m_sampleMOFifo.reset(); @@ -179,34 +179,42 @@ bool XTRXMIMO::startTx() void XTRXMIMO::stopRx() { - qDebug("XTRXMIMO::stopRx"); + QMutexLocker mutexLocker(&m_mutex); + + if (!m_runningRx){ + return; + } if (!m_sourceThread) { return; } - QMutexLocker mutexLocker(&m_mutex); + qDebug("XTRXMIMO::stopRx"); + m_runningRx = false; m_sourceThread->stopWork(); delete m_sourceThread; m_sourceThread = nullptr; - m_runningRx = false; } void XTRXMIMO::stopTx() { - qDebug("XTRXMIMO::stopTx"); + QMutexLocker mutexLocker(&m_mutex); + + if (!m_runningTx) { + return; + } if (!m_sinkThread) { return; } - QMutexLocker mutexLocker(&m_mutex); + qDebug("XTRXMIMO::stopTx"); + m_runningTx = false; m_sinkThread->stopWork(); delete m_sinkThread; m_sinkThread = nullptr; - m_runningTx = false; } QByteArray XTRXMIMO::serialize() const diff --git a/plugins/samplesink/bladerf1output/bladerf1output.cpp b/plugins/samplesink/bladerf1output/bladerf1output.cpp index 04eb83a1a..df7a634ee 100644 --- a/plugins/samplesink/bladerf1output/bladerf1output.cpp +++ b/plugins/samplesink/bladerf1output/bladerf1output.cpp @@ -144,25 +144,24 @@ void Bladerf1Output::init() bool Bladerf1Output::start() { -// QMutexLocker mutexLocker(&m_mutex); + QMutexLocker mutexLocker(&m_mutex); + + if (m_running) { + return true; + } if (!m_dev) { return false; } - if (m_running) stop(); - m_bladerfThread = new Bladerf1OutputThread(m_dev, &m_sampleSourceFifo); - -// mutexLocker.unlock(); - applySettings(m_settings, QList(), true); - m_bladerfThread->setLog2Interpolation(m_settings.m_log2Interp); - m_bladerfThread->startWork(); - qDebug("BladerfOutput::start: started"); m_running = true; + mutexLocker.unlock(); + + applySettings(m_settings, QList(), true); return true; } @@ -171,7 +170,7 @@ void Bladerf1Output::closeDevice() { int res; - if (m_dev == 0) { // was never open + if (m_dev == nullptr) { // was never open return; } @@ -180,7 +179,7 @@ void Bladerf1Output::closeDevice() qCritical("BladerfOutput::closeDevice: bladerf_enable_module with return code %d", res); } - if (m_deviceAPI->getSourceBuddies().size() == 0) + if (m_deviceAPI->getSourceBuddies().empty()) { qDebug("BladerfOutput::closeDevice: closing device since Rx side is not open"); @@ -190,21 +189,26 @@ void Bladerf1Output::closeDevice() } } - m_sharedParams.m_dev = 0; + m_sharedParams.m_dev = nullptr; m_dev = 0; } void Bladerf1Output::stop() { -// QMutexLocker mutexLocker(&m_mutex); - if (m_bladerfThread != 0) + QMutexLocker mutexLocker(&m_mutex); + + if (!m_running) { + return; + } + + m_running = false; + + if (m_bladerfThread) { m_bladerfThread->stopWork(); delete m_bladerfThread; - m_bladerfThread = 0; + m_bladerfThread = nullptr; } - - m_running = false; } QByteArray Bladerf1Output::serialize() const diff --git a/plugins/samplesink/fileoutput/fileoutput.cpp b/plugins/samplesink/fileoutput/fileoutput.cpp index f8a479802..83034f8a3 100644 --- a/plugins/samplesink/fileoutput/fileoutput.cpp +++ b/plugins/samplesink/fileoutput/fileoutput.cpp @@ -44,6 +44,7 @@ MESSAGE_CLASS_DEFINITION(FileOutput::MsgReportFileOutputStreamTiming, Message) FileOutput::FileOutput(DeviceAPI *deviceAPI) : m_deviceAPI(deviceAPI), + m_running(false), m_settings(), m_fileOutputWorker(nullptr), m_deviceDescription("FileOutput"), @@ -94,6 +95,11 @@ void FileOutput::init() bool FileOutput::start() { QMutexLocker mutexLocker(&m_mutex); + + if (m_running) { + return true; + } + qDebug() << "FileOutput::start"; openFileStream(); @@ -104,6 +110,7 @@ bool FileOutput::start() m_fileOutputWorker->setLog2Interpolation(m_settings.m_log2Interp); m_fileOutputWorker->connectTimer(m_masterTimer); startWorker(); + m_running = true; mutexLocker.unlock(); //applySettings(m_generalSettings, m_settings, true); @@ -120,9 +127,15 @@ bool FileOutput::start() void FileOutput::stop() { - qDebug() << "FileSourceInput::stop"; QMutexLocker mutexLocker(&m_mutex); + if (!m_running) { + return; + } + + qDebug() << "FileSourceInput::stop"; + m_running = false; + if (m_fileOutputWorker) { stopWorker(); diff --git a/plugins/samplesink/fileoutput/fileoutput.h b/plugins/samplesink/fileoutput/fileoutput.h index 0678279dc..8c4847d96 100644 --- a/plugins/samplesink/fileoutput/fileoutput.h +++ b/plugins/samplesink/fileoutput/fileoutput.h @@ -234,6 +234,7 @@ public: private: DeviceAPI *m_deviceAPI; QMutex m_mutex; + bool m_running; FileOutputSettings m_settings; std::ofstream m_ofstream; FileOutputWorker* m_fileOutputWorker; diff --git a/plugins/samplesink/hackrfoutput/hackrfoutput.cpp b/plugins/samplesink/hackrfoutput/hackrfoutput.cpp index ad1adb401..409ca2e45 100644 --- a/plugins/samplesink/hackrfoutput/hackrfoutput.cpp +++ b/plugins/samplesink/hackrfoutput/hackrfoutput.cpp @@ -129,27 +129,28 @@ void HackRFOutput::init() bool HackRFOutput::start() { + QMutexLocker mutexLocker(&m_mutex); + if (!m_dev) { return false; } if (m_running) { - stop(); + return true; } m_hackRFThread = new HackRFOutputThread(m_dev, &m_sampleSourceFifo); -// mutexLocker.unlock(); - - applySettings(m_settings, QList(), true); m_hackRFThread->setLog2Interpolation(m_settings.m_log2Interp); m_hackRFThread->setFcPos((int) m_settings.m_fcPos); m_hackRFThread->startWork(); + m_running = true; + mutexLocker.unlock(); qDebug("HackRFOutput::start: started"); - m_running = true; + applySettings(m_settings, QList(), true); return true; } @@ -173,8 +174,14 @@ void HackRFOutput::closeDevice() void HackRFOutput::stop() { + QMutexLocker mutexLocker(&m_mutex); + + if (!m_running) { + return; + } + qDebug("HackRFOutput::stop"); -// QMutexLocker mutexLocker(&m_mutex); + m_running = false; if(m_hackRFThread != 0) { @@ -182,8 +189,6 @@ void HackRFOutput::stop() delete m_hackRFThread; m_hackRFThread = 0; } - - m_running = false; } QByteArray HackRFOutput::serialize() const diff --git a/plugins/samplesink/limesdroutput/limesdroutput.cpp b/plugins/samplesink/limesdroutput/limesdroutput.cpp index be4d95fa1..9551a18df 100644 --- a/plugins/samplesink/limesdroutput/limesdroutput.cpp +++ b/plugins/samplesink/limesdroutput/limesdroutput.cpp @@ -380,14 +380,17 @@ void LimeSDROutput::init() bool LimeSDROutput::start() { + QMutexLocker mutexLocker(&m_mutex); + + if (m_running) { + return true; + } + if (!m_deviceShared.m_deviceParams->getDevice()) { return false; } - if (m_running) { stop(); } - - if (!acquireChannel()) - { + if (!acquireChannel()) { return false; } @@ -396,20 +399,25 @@ bool LimeSDROutput::start() m_limeSDROutputThread = new LimeSDROutputThread(&m_streamId, &m_sampleSourceFifo); qDebug("LimeSDROutput::start: thread created"); - applySettings(m_settings, QList(), true); - m_limeSDROutputThread->setLog2Interpolation(m_settings.m_log2SoftInterp); m_limeSDROutputThread->startWork(); - m_deviceShared.m_thread = m_limeSDROutputThread; m_running = true; + mutexLocker.unlock(); + + applySettings(m_settings, QList(), true); return true; } void LimeSDROutput::stop() { + if (!m_running) { + return; + } + qDebug("LimeSDROutput::stop"); + m_running = false; if (m_limeSDROutputThread) { @@ -419,7 +427,6 @@ void LimeSDROutput::stop() } m_deviceShared.m_thread = 0; - m_running = false; releaseChannel(); } diff --git a/plugins/samplesink/plutosdroutput/plutosdroutput.cpp b/plugins/samplesink/plutosdroutput/plutosdroutput.cpp index 56b62d83f..3a3dba625 100644 --- a/plugins/samplesink/plutosdroutput/plutosdroutput.cpp +++ b/plugins/samplesink/plutosdroutput/plutosdroutput.cpp @@ -102,34 +102,44 @@ void PlutoSDROutput::init() bool PlutoSDROutput::start() { + QMutexLocker mutexLocker(&m_mutex); + + if (m_running) { + return true; + } + if (!m_deviceShared.m_deviceParams->getBox()) { qCritical("PlutoSDROutput::start: device not open"); return false; } - if (m_running) { - stop(); - } - // start / stop streaming is done in the thread. m_plutoSDROutputThread = new PlutoSDROutputThread(PLUTOSDR_BLOCKSIZE_SAMPLES, m_deviceShared.m_deviceParams->getBox(), &m_sampleSourceFifo); qDebug("PlutoSDROutput::start: thread created"); - applySettings(m_settings, QList(), true); - m_plutoSDROutputThread->setLog2Interpolation(m_settings.m_log2Interp); m_plutoSDROutputThread->startWork(); - m_deviceShared.m_thread = m_plutoSDROutputThread; m_running = true; + mutexLocker.unlock(); + + applySettings(m_settings, QList(), true); return true; } void PlutoSDROutput::stop() { + QMutexLocker mutexLocker(&m_mutex); + + if (!m_running) { + return; + } + + m_running = false; + if (m_plutoSDROutputThread != 0) { m_plutoSDROutputThread->stopWork(); @@ -138,7 +148,6 @@ void PlutoSDROutput::stop() } m_deviceShared.m_thread = 0; - m_running = false; } QByteArray PlutoSDROutput::serialize() const diff --git a/plugins/samplesink/remoteoutput/remoteoutput.cpp b/plugins/samplesink/remoteoutput/remoteoutput.cpp index 2abd3775a..6bffe0e5c 100644 --- a/plugins/samplesink/remoteoutput/remoteoutput.cpp +++ b/plugins/samplesink/remoteoutput/remoteoutput.cpp @@ -47,6 +47,7 @@ MESSAGE_CLASS_DEFINITION(RemoteOutput::MsgRequestFixedData, Message) RemoteOutput::RemoteOutput(DeviceAPI *deviceAPI) : m_deviceAPI(deviceAPI), + m_running(false), m_settings(), m_centerFrequency(435000000), m_sampleRate(48000), @@ -95,6 +96,11 @@ void RemoteOutput::destroy() bool RemoteOutput::start() { QMutexLocker mutexLocker(&m_mutex); + + if (m_running) { + return true; + } + qDebug() << "RemoteOutput::start"; m_remoteOutputWorker = new RemoteOutputWorker(&m_sampleSourceFifo); @@ -105,6 +111,7 @@ bool RemoteOutput::start() m_remoteOutputWorker->setNbBlocksFEC(m_settings.m_nbFECBlocks); m_remoteOutputWorker->connectTimer(m_masterTimer); startWorker(); + m_running = true; mutexLocker.unlock(); applySampleRate(); @@ -121,12 +128,18 @@ void RemoteOutput::init() void RemoteOutput::stop() { - qDebug() << "RemoteOutput::stop"; QMutexLocker mutexLocker(&m_mutex); + if (!m_running) { + return; + } + + qDebug() << "RemoteOutput::stop"; + m_running = false; + if (m_remoteOutputWorker) { - stopWorker(); + stopWorker(); delete m_remoteOutputWorker; m_remoteOutputWorker = nullptr; } diff --git a/plugins/samplesink/remoteoutput/remoteoutput.h b/plugins/samplesink/remoteoutput/remoteoutput.h index 522d04227..434e2916d 100644 --- a/plugins/samplesink/remoteoutput/remoteoutput.h +++ b/plugins/samplesink/remoteoutput/remoteoutput.h @@ -258,7 +258,8 @@ public: private: DeviceAPI *m_deviceAPI; - QMutex m_mutex; + QRecursiveMutex m_mutex; + bool m_running; RemoteOutputSettings m_settings; uint64_t m_centerFrequency; int m_sampleRate; diff --git a/plugins/samplesink/soapysdroutput/soapysdroutput.cpp b/plugins/samplesink/soapysdroutput/soapysdroutput.cpp index 43aa7f2d5..99d845941 100644 --- a/plugins/samplesink/soapysdroutput/soapysdroutput.cpp +++ b/plugins/samplesink/soapysdroutput/soapysdroutput.cpp @@ -453,6 +453,11 @@ bool SoapySDROutput::start() // // Note: this is quite similar to the BladeRF2 start handling. The main difference is that the channel allocation (enabling) process is // done in the thread object. + QMutexLocker mutexLocker(&m_mutex); + + if (m_running) { + return true; + } if (!m_openSuccess) { @@ -558,11 +563,13 @@ void SoapySDROutput::stop() // channel then the FIFO reference is simply removed from the thread so that this FIFO will not be used anymore. // In this case the channel is not closed (this is managed in the thread object) so that other channels can continue with the // same configuration. The device continues streaming on this channel but the samples are set to all zeros. + QMutexLocker mutexLocker(&m_mutex); if (!m_running) { return; } + m_running = false; int requestedChannel = m_deviceAPI->getDeviceItemIndex(); SoapySDROutputThread *soapySDROutputThread = findThread(); @@ -648,9 +655,8 @@ void SoapySDROutput::stop() soapySDROutputThread->setFifo(requestedChannel, nullptr); // remove FIFO } + mutexLocker.unlock(); applySettings(m_settings, true); // re-apply forcibly to set sample rate with the new number of channels - - m_running = false; } QByteArray SoapySDROutput::serialize() const diff --git a/plugins/samplesink/usrpoutput/usrpoutput.cpp b/plugins/samplesink/usrpoutput/usrpoutput.cpp index fdd989031..8f9444e8a 100644 --- a/plugins/samplesink/usrpoutput/usrpoutput.cpp +++ b/plugins/samplesink/usrpoutput/usrpoutput.cpp @@ -379,12 +379,16 @@ void USRPOutput::init() bool USRPOutput::start() { + QMutexLocker mutexLocker(&m_mutex); + + if (m_running) { + return true; + } + if (!m_deviceShared.m_deviceParams->getDevice()) { return false; } - if (m_running) { stop(); } - if (!acquireChannel()) { return false; } @@ -403,7 +407,14 @@ bool USRPOutput::start() void USRPOutput::stop() { + QMutexLocker mutexLocker(&m_mutex); + + if (!m_running) { + return; + } + qDebug("USRPOutput::stop"); + m_running = false; if (m_usrpOutputThread) { @@ -413,7 +424,6 @@ void USRPOutput::stop() } m_deviceShared.m_thread = 0; - m_running = false; releaseChannel(); } diff --git a/plugins/samplesink/xtrxoutput/xtrxoutput.cpp b/plugins/samplesink/xtrxoutput/xtrxoutput.cpp index d9aac937e..5eacc52c7 100644 --- a/plugins/samplesink/xtrxoutput/xtrxoutput.cpp +++ b/plugins/samplesink/xtrxoutput/xtrxoutput.cpp @@ -265,6 +265,11 @@ bool XTRXOutput::start() // // Eventually it registers the FIFO in the thread. If the thread has to be started it enables the channels up to the number of channels // allocated in the thread and starts the thread. + QMutexLocker mutexLocker(&m_mutex); + + if (m_running) { + return true; + } if (!m_deviceShared.m_dev || !m_deviceShared.m_dev->getDevice()) { @@ -341,6 +346,8 @@ bool XTRXOutput::start() xtrxOutputThread->setFifo(requestedChannel, &m_sampleSourceFifo); xtrxOutputThread->setLog2Interpolation(requestedChannel, m_settings.m_log2SoftInterp); + m_running = true; + mutexLocker.unlock(); applySettings(m_settings, QList(), true); @@ -351,7 +358,6 @@ bool XTRXOutput::start() } qDebug("XTRXOutput::start: started"); - m_running = true; return true; } @@ -366,16 +372,18 @@ void XTRXOutput::stop() // If the thread is currently managing both channels (MO mode) then we are removing one channel. Thus we must // transition from MO to SO. This transition is handled by stopping the thread, deleting it and creating a new one // managing a single channel. + QMutexLocker mutexLocker(&m_mutex); if (!m_running) { return; } + m_running = false; int removedChannel = m_deviceAPI->getDeviceItemIndex(); // channel to remove int requestedChannel = removedChannel ^ 1; // channel to keep (opposite channel) XTRXOutputThread *xtrxOutputThread = findThread(); - if (xtrxOutputThread == 0) { // no thread allocated + if (xtrxOutputThread == nullptr) { // no thread allocated return; } @@ -386,8 +394,8 @@ void XTRXOutput::stop() qDebug("XTRXOutput::stop: SO mode. Just stop and delete the thread"); xtrxOutputThread->stopWork(); delete xtrxOutputThread; - m_XTRXOutputThread = 0; - m_deviceShared.m_thread = 0; + m_XTRXOutputThread = nullptr; + m_deviceShared.m_thread = nullptr; // remove old thread address from buddies (reset in all buddies) const std::vector& sinkBuddies = m_deviceAPI->getSinkBuddies(); @@ -417,11 +425,10 @@ void XTRXOutput::stop() ((DeviceXTRXShared*) (*it)->getBuddySharedPtr())->m_sink->setThread(nullptr); } + mutexLocker.unlock(); applySettings(m_settings, QList(), true); xtrxOutputThread->startWork(); } - - m_running = false; } void XTRXOutput::suspendRxThread() diff --git a/plugins/samplesource/airspy/airspyinput.cpp b/plugins/samplesource/airspy/airspyinput.cpp index 26f04ef19..f9abf8bd1 100644 --- a/plugins/samplesource/airspy/airspyinput.cpp +++ b/plugins/samplesource/airspy/airspyinput.cpp @@ -197,14 +197,14 @@ bool AirspyInput::start() { QMutexLocker mutexLocker(&m_mutex); - if (!m_dev) { - return false; - } - if (m_running) { return true; } + if (!m_dev) { + return false; + } + m_airspyWorkerThread = new QThread(); m_airspyWorker = new AirspyWorker(m_dev, &m_sampleFifo); m_airspyWorker->moveToThread(m_airspyWorkerThread); @@ -217,13 +217,13 @@ bool AirspyInput::start() m_airspyWorker->setLog2Decimation(m_settings.m_log2Decim); m_airspyWorker->setIQOrder(m_settings.m_iqOrder); m_airspyWorker->setFcPos((int) m_settings.m_fcPos); - mutexLocker.unlock(); - m_airspyWorkerThread->start(); + m_running = true; + + mutexLocker.unlock(); qDebug("AirspyInput::startInput: started"); applySettings(m_settings, QList(), true); - m_running = true; return true; } diff --git a/plugins/samplesource/airspy/airspyinput.h b/plugins/samplesource/airspy/airspyinput.h index fc57a23a8..12d66b2f6 100644 --- a/plugins/samplesource/airspy/airspyinput.h +++ b/plugins/samplesource/airspy/airspyinput.h @@ -141,7 +141,7 @@ public: private: DeviceAPI *m_deviceAPI; - QMutex m_mutex; + QRecursiveMutex m_mutex; AirspySettings m_settings; struct airspy_device* m_dev; AirspyWorker* m_airspyWorker; diff --git a/plugins/samplesource/airspyhf/airspyhfinput.cpp b/plugins/samplesource/airspyhf/airspyhfinput.cpp index 7bc5067ec..efc5f6898 100644 --- a/plugins/samplesource/airspyhf/airspyhfinput.cpp +++ b/plugins/samplesource/airspyhf/airspyhfinput.cpp @@ -171,12 +171,12 @@ bool AirspyHFInput::start() { QMutexLocker mutexLocker(&m_mutex); - if (!m_dev) { - return false; + if (m_running) { + return true; } - if (m_running) { - stop(); + if (!m_dev) { + return false; } m_airspyHFWorkerThread = new QThread(); @@ -198,13 +198,13 @@ bool AirspyHFInput::start() m_airspyHFWorker->setLog2Decimation(m_settings.m_log2Decim); m_airspyHFWorker->setIQOrder(m_settings.m_iqOrder); - mutexLocker.unlock(); - m_airspyHFWorkerThread->start(); + m_running = true; + + mutexLocker.unlock(); qDebug("AirspyHFInput::startInput: started"); applySettings(m_settings, QList(), true); - m_running = true; return m_running; } @@ -223,9 +223,15 @@ void AirspyHFInput::closeDevice() void AirspyHFInput::stop() { - qDebug("AirspyHFInput::stop"); QMutexLocker mutexLocker(&m_mutex); + if (!m_running) { + return; + } + + qDebug("AirspyHFInput::stop"); + m_running = false; + if (m_airspyHFWorkerThread) { m_airspyHFWorkerThread->quit(); @@ -234,7 +240,6 @@ void AirspyHFInput::stop() m_airspyHFWorker = nullptr; } - m_running = false; } QByteArray AirspyHFInput::serialize() const diff --git a/plugins/samplesource/airspyhf/airspyhfinput.h b/plugins/samplesource/airspyhf/airspyhfinput.h index 3f1c9ec0d..85325a349 100644 --- a/plugins/samplesource/airspyhf/airspyhfinput.h +++ b/plugins/samplesource/airspyhf/airspyhfinput.h @@ -165,7 +165,7 @@ public: private: DeviceAPI *m_deviceAPI; - QMutex m_mutex; + QRecursiveMutex m_mutex; AirspyHFSettings m_settings; airspyhf_device_t* m_dev; AirspyHFWorker* m_airspyHFWorker; diff --git a/plugins/samplesource/bladerf1input/bladerf1input.cpp b/plugins/samplesource/bladerf1input/bladerf1input.cpp index ad284afd1..8d4e24b91 100644 --- a/plugins/samplesource/bladerf1input/bladerf1input.cpp +++ b/plugins/samplesource/bladerf1input/bladerf1input.cpp @@ -151,7 +151,11 @@ void Bladerf1Input::init() bool Bladerf1Input::start() { -// QMutexLocker mutexLocker(&m_mutex); + QMutexLocker mutexLocker(&m_mutex); + + if (m_running) { + return true; + } if (!m_dev) { @@ -159,20 +163,17 @@ bool Bladerf1Input::start() return false; } - if (m_running) stop(); - m_bladerfThread = new Bladerf1InputThread(m_dev, &m_sampleFifo); m_bladerfThread->setLog2Decimation(m_settings.m_log2Decim); m_bladerfThread->setFcPos((int) m_settings.m_fcPos); m_bladerfThread->setIQOrder(m_settings.m_iqOrder); - m_bladerfThread->startWork(); + m_running = true; -// mutexLocker.unlock(); + mutexLocker.unlock(); applySettings(m_settings, QList(), true); qDebug("BladerfInput::startInput: started"); - m_running = true; return true; } @@ -194,19 +195,25 @@ void Bladerf1Input::closeDevice() { qDebug("BladerfInput::closeDevice: closing device since Tx side is not open"); - if(m_dev != 0) // close BladeRF + if(m_dev != nullptr) // close BladeRF { bladerf_close(m_dev); } } - m_sharedParams.m_dev = 0; - m_dev = 0; + m_sharedParams.m_dev = nullptr; + m_dev = nullptr; } void Bladerf1Input::stop() { -// QMutexLocker mutexLocker(&m_mutex); + QMutexLocker mutexLocker(&m_mutex); + + if (!m_running) { + return; + } + + m_running = false; if(m_bladerfThread) { @@ -215,7 +222,6 @@ void Bladerf1Input::stop() m_bladerfThread = nullptr; } - m_running = false; } QByteArray Bladerf1Input::serialize() const diff --git a/plugins/samplesource/bladerf1input/bladerf1input.h b/plugins/samplesource/bladerf1input/bladerf1input.h index 6d95f3c52..3b20bd16c 100644 --- a/plugins/samplesource/bladerf1input/bladerf1input.h +++ b/plugins/samplesource/bladerf1input/bladerf1input.h @@ -135,7 +135,7 @@ public: private: DeviceAPI *m_deviceAPI; - QMutex m_mutex; + QRecursiveMutex m_mutex; BladeRF1InputSettings m_settings; struct bladerf* m_dev; Bladerf1InputThread* m_bladerfThread; diff --git a/plugins/samplesource/bladerf2input/bladerf2input.cpp b/plugins/samplesource/bladerf2input/bladerf2input.cpp index 9aa313132..b3dd2c4f3 100644 --- a/plugins/samplesource/bladerf2input/bladerf2input.cpp +++ b/plugins/samplesource/bladerf2input/bladerf2input.cpp @@ -290,6 +290,11 @@ bool BladeRF2Input::start() // // Eventually it registers the FIFO in the thread. If the thread has to be started it enables the channels up to the number of channels // allocated in the thread and starts the thread. + QMutexLocker mutexLocker(&m_mutex); + + if (m_running) { + return true; + } if (!m_deviceShared.m_dev) { @@ -383,10 +388,11 @@ bool BladeRF2Input::start() bladerf2InputThread->startWork(); } + m_running = true; + mutexLocker.unlock(); applySettings(m_settings, QList(), true); qDebug("BladeRF2Input::start: started"); - m_running = true; return true; } @@ -408,6 +414,7 @@ void BladeRF2Input::stop() // anymore. In this case the channel is not closed (disabled) so that other channels can continue with the // same configuration. The device continues streaming on this channel but the samples are simply dropped (by // removing FIFO reference). + QMutexLocker mutexLocker(&m_mutex); if (!m_running) { return; @@ -420,6 +427,7 @@ void BladeRF2Input::stop() return; } + m_running = false; int nbOriginalChannels = bladerf2InputThread->getNbChannels(); if (nbOriginalChannels == 1) // SI mode => just stop and delete the thread @@ -500,8 +508,6 @@ void BladeRF2Input::stop() qDebug("BladeRF2Input::stop: MI mode. Not changing MI configuration. Just remove FIFO reference"); bladerf2InputThread->setFifo(requestedChannel, 0); // remove FIFO } - - m_running = false; } QByteArray BladeRF2Input::serialize() const diff --git a/plugins/samplesource/fcdpro/fcdproinput.cpp b/plugins/samplesource/fcdpro/fcdproinput.cpp index 6d4e9ca63..bb9ed3aa8 100644 --- a/plugins/samplesource/fcdpro/fcdproinput.cpp +++ b/plugins/samplesource/fcdpro/fcdproinput.cpp @@ -121,15 +121,18 @@ void FCDProInput::init() bool FCDProInput::start() { - qDebug() << "FCDProInput::start"; -// QMutexLocker mutexLocker(&m_mutex); + QMutexLocker mutexLocker(&m_mutex); + + if (m_running) { + return true; + } if (!m_dev) { return false; } - if (m_running) stop(); + qDebug() << "FCDProInput::start"; /* Apply settings before streaming to avoid bus contention; * there is very little spare bandwidth on a full speed USB device. @@ -149,12 +152,12 @@ bool FCDProInput::start() m_FCDThread->setFcPos(m_settings.m_fcPos); m_FCDThread->setIQOrder(m_settings.m_iqOrder); m_FCDThread->startWork(); + m_running = true; -// mutexLocker.unlock(); + mutexLocker.unlock(); applySettings(m_settings, QList(), true); qDebug("FCDProInput::started"); - m_running = true; return true; } @@ -204,7 +207,13 @@ void FCDProInput::closeFCDAudio() void FCDProInput::stop() { -// QMutexLocker mutexLocker(&m_mutex); + QMutexLocker mutexLocker(&m_mutex); + + if (!m_running) { + return; + } + + m_running = false; if (m_FCDThread) { @@ -213,8 +222,6 @@ void FCDProInput::stop() delete m_FCDThread; m_FCDThread = nullptr; } - - m_running = false; } QByteArray FCDProInput::serialize() const diff --git a/plugins/samplesource/fcdproplus/fcdproplusinput.cpp b/plugins/samplesource/fcdproplus/fcdproplusinput.cpp index 7ab4119b2..358ef7620 100644 --- a/plugins/samplesource/fcdproplus/fcdproplusinput.cpp +++ b/plugins/samplesource/fcdproplus/fcdproplusinput.cpp @@ -121,14 +121,14 @@ void FCDProPlusInput::init() bool FCDProPlusInput::start() { -// QMutexLocker mutexLocker(&m_mutex); + QMutexLocker mutexLocker(&m_mutex); if (!m_dev) { return false; } if (m_running) { - stop(); + return true; } qDebug() << "FCDProPlusInput::start"; @@ -151,12 +151,12 @@ bool FCDProPlusInput::start() m_FCDThread->setFcPos(m_settings.m_fcPos); m_FCDThread->setIQOrder(m_settings.m_iqOrder); m_FCDThread->startWork(); + m_running = true; -// mutexLocker.unlock(); + mutexLocker.unlock(); applySettings(m_settings, QList(), true); qDebug("FCDProPlusInput::started"); - m_running = true; return true; } @@ -170,7 +170,7 @@ void FCDProPlusInput::closeDevice() fcdClose(m_dev); m_dev = 0; - closeFCDAudio(); + closeFCDAudio(); } bool FCDProPlusInput::openFCDAudio(const char* cardname) @@ -208,6 +208,12 @@ void FCDProPlusInput::stop() { QMutexLocker mutexLocker(&m_mutex); + if (!m_running) { + return; + } + + m_running = false; + if (m_FCDThread) { m_FCDThread->stopWork(); @@ -215,8 +221,6 @@ void FCDProPlusInput::stop() delete m_FCDThread; m_FCDThread = nullptr; } - - m_running = false; } QByteArray FCDProPlusInput::serialize() const diff --git a/plugins/samplesource/hackrfinput/hackrfinput.cpp b/plugins/samplesource/hackrfinput/hackrfinput.cpp index 19321afc2..9b1ee95aa 100644 --- a/plugins/samplesource/hackrfinput/hackrfinput.cpp +++ b/plugins/samplesource/hackrfinput/hackrfinput.cpp @@ -142,29 +142,29 @@ void HackRFInput::init() bool HackRFInput::start() { -// QMutexLocker mutexLocker(&m_mutex); + QMutexLocker mutexLocker(&m_mutex); + + if (m_running) { + return true; + } + if (!m_dev) { return false; } - if (m_running) { - stop(); - } - m_hackRFThread = new HackRFInputThread(m_dev, &m_sampleFifo); -// mutexLocker.unlock(); - - applySettings(m_settings, QList(), true); - m_hackRFThread->setSamplerate(m_settings.m_devSampleRate); m_hackRFThread->setLog2Decimation(m_settings.m_log2Decim); m_hackRFThread->setFcPos((int) m_settings.m_fcPos); m_hackRFThread->setIQOrder(m_settings.m_iqOrder); m_hackRFThread->startWork(); + m_running = true; + + mutexLocker.unlock(); + applySettings(m_settings, QList(), true); qDebug("HackRFInput::startInput: started"); - m_running = true; return true; } @@ -188,8 +188,14 @@ void HackRFInput::closeDevice() void HackRFInput::stop() { + QMutexLocker mutexLocker(&m_mutex); + + if (!m_running) { + return; + } + qDebug("HackRFInput::stop"); -// QMutexLocker mutexLocker(&m_mutex); + m_running = false; if (m_hackRFThread) { @@ -197,8 +203,6 @@ void HackRFInput::stop() delete m_hackRFThread; m_hackRFThread = nullptr; } - - m_running = false; } QByteArray HackRFInput::serialize() const @@ -349,7 +353,7 @@ void HackRFInput::setDeviceCenterFrequency(quint64 freq_hz, int loPpmTenths) bool HackRFInput::applySettings(const HackRFInputSettings& settings, const QList& settingsKeys, bool force) { -// QMutexLocker mutexLocker(&m_mutex); + QMutexLocker mutexLocker(&m_mutex); qDebug() << "HackRFInput::applySettings: forcE: " << force << settings.getDebugString(settingsKeys, force); bool forwardChange = false; hackrf_error rc; diff --git a/plugins/samplesource/hackrfinput/hackrfinput.h b/plugins/samplesource/hackrfinput/hackrfinput.h index a13ec3eb1..0ac97587f 100644 --- a/plugins/samplesource/hackrfinput/hackrfinput.h +++ b/plugins/samplesource/hackrfinput/hackrfinput.h @@ -153,7 +153,7 @@ public: private: DeviceAPI *m_deviceAPI; - QMutex m_mutex; + QRecursiveMutex m_mutex; HackRFInputSettings m_settings; struct hackrf_device* m_dev; HackRFInputThread* m_hackRFThread; diff --git a/plugins/samplesource/limesdrinput/limesdrinput.cpp b/plugins/samplesource/limesdrinput/limesdrinput.cpp index d15187270..62d1a6efc 100644 --- a/plugins/samplesource/limesdrinput/limesdrinput.cpp +++ b/plugins/samplesource/limesdrinput/limesdrinput.cpp @@ -409,14 +409,17 @@ void LimeSDRInput::init() bool LimeSDRInput::start() { + QMutexLocker mutexLocker(&m_mutex); + + if (m_running) { + return true; + } + if (!m_deviceShared.m_deviceParams->getDevice()) { return false; } - if (m_running) { stop(); } - - if (!acquireChannel()) - { + if (!acquireChannel()) { return false; } @@ -425,21 +428,28 @@ bool LimeSDRInput::start() m_limeSDRInputThread = new LimeSDRInputThread(&m_streamId, &m_sampleFifo, &m_replayBuffer); qDebug("LimeSDRInput::start: thread created"); - applySettings(m_settings, QList(), true); - m_limeSDRInputThread->setLog2Decimation(m_settings.m_log2SoftDecim); m_limeSDRInputThread->setIQOrder(m_settings.m_iqOrder); m_limeSDRInputThread->startWork(); - m_deviceShared.m_thread = m_limeSDRInputThread; m_running = true; + mutexLocker.unlock(); + applySettings(m_settings, QList(), true); + return true; } void LimeSDRInput::stop() { + QMutexLocker mutexLocker(&m_mutex); + + if (!m_running) { + return; + } + qDebug("LimeSDRInput::stop"); + m_running = false; if (m_limeSDRInputThread) { @@ -449,7 +459,6 @@ void LimeSDRInput::stop() } m_deviceShared.m_thread = 0; - m_running = false; releaseChannel(); } @@ -803,7 +812,7 @@ bool LimeSDRInput::applySettings(const LimeSDRInputSettings& settings, const QLi bool doLPCalibration = false; double clockGenFreq = 0.0; -// QMutexLocker mutexLocker(&m_mutex); + QMutexLocker mutexLocker(&m_mutex); qint64 deviceCenterFrequency = settings.m_centerFrequency; deviceCenterFrequency -= settings.m_transverterMode ? settings.m_transverterDeltaFrequency : 0; diff --git a/plugins/samplesource/limesdrinput/limesdrinput.h b/plugins/samplesource/limesdrinput/limesdrinput.h index d86128e48..a21c69de1 100644 --- a/plugins/samplesource/limesdrinput/limesdrinput.h +++ b/plugins/samplesource/limesdrinput/limesdrinput.h @@ -290,7 +290,7 @@ public: private: DeviceAPI *m_deviceAPI; - QMutex m_mutex; + QRecursiveMutex m_mutex; LimeSDRInputSettings m_settings; LimeSDRInputThread* m_limeSDRInputThread; QString m_deviceDescription; diff --git a/plugins/samplesource/plutosdrinput/plutosdrinput.cpp b/plugins/samplesource/plutosdrinput/plutosdrinput.cpp index ac2f6051b..71a82ae0e 100644 --- a/plugins/samplesource/plutosdrinput/plutosdrinput.cpp +++ b/plugins/samplesource/plutosdrinput/plutosdrinput.cpp @@ -102,35 +102,45 @@ void PlutoSDRInput::init() bool PlutoSDRInput::start() { + QMutexLocker mutexLocker(&m_mutex); + + if (m_running) { + return true; + } + if (!m_deviceShared.m_deviceParams->getBox()) { qCritical("PlutoSDRInput::start: device not open"); return false; } - if (m_running) { - stop(); - } - // start / stop streaming is done in the thread. m_plutoSDRInputThread = new PlutoSDRInputThread(PLUTOSDR_BLOCKSIZE_SAMPLES, m_deviceShared.m_deviceParams->getBox(), &m_sampleFifo); qDebug("PlutoSDRInput::start: thread created"); - applySettings(m_settings, QList(), true); - m_plutoSDRInputThread->setLog2Decimation(m_settings.m_log2Decim); m_plutoSDRInputThread->setIQOrder(m_settings.m_iqOrder); m_plutoSDRInputThread->startWork(); - m_deviceShared.m_thread = m_plutoSDRInputThread; m_running = true; + mutexLocker.unlock(); + applySettings(m_settings, QList(), true); + return true; } void PlutoSDRInput::stop() { + QMutexLocker mutexLocker(&m_mutex); + + if (!m_running) { + return; + } + + m_running = false; + if (m_plutoSDRInputThread) { m_plutoSDRInputThread->stopWork(); @@ -139,7 +149,6 @@ void PlutoSDRInput::stop() } m_deviceShared.m_thread = nullptr; - m_running = false; } QByteArray PlutoSDRInput::serialize() const diff --git a/plugins/samplesource/sdrplay/sdrplayinput.cpp b/plugins/samplesource/sdrplay/sdrplayinput.cpp index e2e25d236..8fe704936 100644 --- a/plugins/samplesource/sdrplay/sdrplayinput.cpp +++ b/plugins/samplesource/sdrplay/sdrplayinput.cpp @@ -149,15 +149,17 @@ bool SDRPlayInput::openDevice() bool SDRPlayInput::start() { -// QMutexLocker mutexLocker(&m_mutex); - int res; + QMutexLocker mutexLocker(&m_mutex); + + if (m_running) { + return true; + } if (!m_dev) { return false; } - if (m_running) stop(); - + int res; char s12FormatString[] = "336_S16"; if ((res = mirisdr_set_sample_format(m_dev, s12FormatString))) // sample format S12 @@ -197,12 +199,11 @@ bool SDRPlayInput::start() m_sdrPlayThread->setFcPos((int) m_settings.m_fcPos); m_sdrPlayThread->setIQOrder(m_settings.m_iqOrder); m_sdrPlayThread->startWork(); - -// mutexLocker.unlock(); - - applySettings(m_settings, QList(), true, true); m_running = true; + mutexLocker.unlock(); + applySettings(m_settings, QList(), true, true); + return true; } @@ -224,7 +225,13 @@ void SDRPlayInput::init() void SDRPlayInput::stop() { -// QMutexLocker mutexLocker(&m_mutex); + QMutexLocker mutexLocker(&m_mutex); + + if (!m_running) { + return; + } + + m_running = false; if(m_sdrPlayThread) { @@ -232,8 +239,6 @@ void SDRPlayInput::stop() delete m_sdrPlayThread; m_sdrPlayThread = nullptr; } - - m_running = false; } QByteArray SDRPlayInput::serialize() const diff --git a/plugins/samplesource/sdrplay/sdrplayinput.h b/plugins/samplesource/sdrplay/sdrplayinput.h index dd3bae13e..26be4d9b0 100644 --- a/plugins/samplesource/sdrplay/sdrplayinput.h +++ b/plugins/samplesource/sdrplay/sdrplayinput.h @@ -173,7 +173,7 @@ public: private: DeviceAPI *m_deviceAPI; - QMutex m_mutex; + QRecursiveMutex m_mutex; SDRPlayVariant m_variant; SDRPlaySettings m_settings; mirisdr_dev_t* m_dev; diff --git a/plugins/samplesource/sdrplayv3/sdrplayv3input.cpp b/plugins/samplesource/sdrplayv3/sdrplayv3input.cpp index 5e25b0f68..2c64d457f 100644 --- a/plugins/samplesource/sdrplayv3/sdrplayv3input.cpp +++ b/plugins/samplesource/sdrplayv3/sdrplayv3input.cpp @@ -147,20 +147,25 @@ bool SDRPlayV3Input::openDevice() bool SDRPlayV3Input::start() { - qDebug() << "SDRPlayV3Input::start"; + QMutexLocker mutexLocker(&m_mutex); + + if (m_running) { + return true; + } if (!m_dev) { return false; } - if (m_running) stop(); + qDebug() << "SDRPlayV3Input::start"; m_sdrPlayThread = new SDRPlayV3Thread(m_dev, &m_sampleFifo, &m_replayBuffer); m_sdrPlayThread->setLog2Decimation(m_settings.m_log2Decim); m_sdrPlayThread->setFcPos((int) m_settings.m_fcPos); m_sdrPlayThread->startWork(); - m_running = m_sdrPlayThread->isRunning(); + + mutexLocker.unlock(); applySettings(m_settings, QList(), true, true); return true; @@ -184,17 +189,21 @@ void SDRPlayV3Input::init() void SDRPlayV3Input::stop() { - qDebug() << "SDRPlayV3Input::stop"; QMutexLocker mutexLocker(&m_mutex); + if (!m_running) { + return; + } + + qDebug() << "SDRPlayV3Input::stop"; + m_running = false; + if(m_sdrPlayThread) { m_sdrPlayThread->stopWork(); delete m_sdrPlayThread; m_sdrPlayThread = nullptr; } - - m_running = false; } QByteArray SDRPlayV3Input::serialize() const diff --git a/plugins/samplesource/sdrplayv3/sdrplayv3input.h b/plugins/samplesource/sdrplayv3/sdrplayv3input.h index 743e82d89..2b5e28f65 100644 --- a/plugins/samplesource/sdrplayv3/sdrplayv3input.h +++ b/plugins/samplesource/sdrplayv3/sdrplayv3input.h @@ -158,7 +158,7 @@ public: private: DeviceAPI *m_deviceAPI; - QMutex m_mutex; + QRecursiveMutex m_mutex; SDRPlayV3Settings m_settings; sdrplay_api_DeviceT m_devs[SDRPLAY_MAX_DEVICES]; sdrplay_api_DeviceT* m_dev; diff --git a/plugins/samplesource/sigmffileinput/sigmffileinput.cpp b/plugins/samplesource/sigmffileinput/sigmffileinput.cpp index eaa852b74..aade8c16a 100644 --- a/plugins/samplesource/sigmffileinput/sigmffileinput.cpp +++ b/plugins/samplesource/sigmffileinput/sigmffileinput.cpp @@ -61,6 +61,7 @@ MESSAGE_CLASS_DEFINITION(SigMFFileInput::MsgReportTotalSamplesCheck, Message) SigMFFileInput::SigMFFileInput(DeviceAPI *deviceAPI) : m_deviceAPI(deviceAPI), + m_running(false), m_settings(), m_trackMode(false), m_currentTrackIndex(0), @@ -446,13 +447,18 @@ void SigMFFileInput::init() bool SigMFFileInput::start() { + QMutexLocker mutexLocker(&m_mutex); + + if (m_running) { + return true; + } + if (!m_dataStream.is_open()) { qWarning("SigMFFileInput::start: file not open. not starting"); return false; } - QMutexLocker mutexLocker(&m_mutex); qDebug() << "SigMFFileInput::start"; if (m_dataStream.tellg() != (std::streampos) 0) { @@ -472,6 +478,7 @@ bool SigMFFileInput::start() m_fileInputWorker->setTrackIndex(0); m_fileInputWorker->moveToThread(&m_fileInputWorkerThread); m_deviceDescription = "SigMFFileInput"; + m_running = true; mutexLocker.unlock(); qDebug("SigMFFileInput::startInput: started"); @@ -486,9 +493,15 @@ bool SigMFFileInput::start() void SigMFFileInput::stop() { - qDebug() << "SigMFFileInput::stop"; QMutexLocker mutexLocker(&m_mutex); + if (!m_running) { + return; + } + + qDebug() << "SigMFFileInput::stop"; + m_running = false; + if (m_fileInputWorker) { stopWorker(); diff --git a/plugins/samplesource/sigmffileinput/sigmffileinput.h b/plugins/samplesource/sigmffileinput/sigmffileinput.h index 3705ff9b8..f612b31bf 100644 --- a/plugins/samplesource/sigmffileinput/sigmffileinput.h +++ b/plugins/samplesource/sigmffileinput/sigmffileinput.h @@ -446,6 +446,7 @@ public: private: DeviceAPI *m_deviceAPI; QMutex m_mutex; + bool m_running; SigMFFileInputSettings m_settings; std::ifstream m_metaStream; std::ifstream m_dataStream; diff --git a/plugins/samplesource/soapysdrinput/soapysdrinput.cpp b/plugins/samplesource/soapysdrinput/soapysdrinput.cpp index a7b5b9ddb..f7280fd93 100644 --- a/plugins/samplesource/soapysdrinput/soapysdrinput.cpp +++ b/plugins/samplesource/soapysdrinput/soapysdrinput.cpp @@ -481,6 +481,11 @@ bool SoapySDRInput::start() // // Note: this is quite similar to the BladeRF2 start handling. The main difference is that the channel allocation (enabling) process is // done in the thread object. + QMutexLocker mutexLocker(&m_mutex); + + if (m_running) { + return true; + } if (!m_openSuccess) { @@ -595,11 +600,13 @@ void SoapySDRInput::stop() // // Note: this is quite similar to the BladeRF2 stop handling. The main difference is that the channel allocation (enabling) process is // done in the thread object. + QMutexLocker mutexLocker(&m_mutex); if (!m_running) { return; } + m_running = false; int requestedChannel = m_deviceAPI->getDeviceItemIndex(); SoapySDRInputThread *soapySDRInputThread = findThread(); @@ -688,8 +695,6 @@ void SoapySDRInput::stop() qDebug("SoapySDRInput::stop: MI mode. Not changing MI configuration. Just remove FIFO reference"); soapySDRInputThread->setFifo(requestedChannel, nullptr); // remove FIFO } - - m_running = false; } QByteArray SoapySDRInput::serialize() const diff --git a/plugins/samplesource/testsource/testsourceinput.cpp b/plugins/samplesource/testsource/testsourceinput.cpp index 350a49f5f..9e79c7446 100644 --- a/plugins/samplesource/testsource/testsourceinput.cpp +++ b/plugins/samplesource/testsource/testsourceinput.cpp @@ -119,11 +119,16 @@ bool TestSourceInput::start() void TestSourceInput::stop() { QMutexLocker mutexLocker(&m_mutex); + + if (!m_running) { + return; + } + m_running = false; if (m_testSourceWorkerThread) { - m_testSourceWorker->stopWork(); + m_testSourceWorker->stopWork(); m_testSourceWorkerThread->quit(); m_testSourceWorkerThread->wait(); m_testSourceWorker = nullptr; diff --git a/plugins/samplesource/usrpinput/usrpinput.cpp b/plugins/samplesource/usrpinput/usrpinput.cpp index e317aa5b8..b6d8eb1c7 100644 --- a/plugins/samplesource/usrpinput/usrpinput.cpp +++ b/plugins/samplesource/usrpinput/usrpinput.cpp @@ -414,14 +414,17 @@ void USRPInput::init() bool USRPInput::start() { + QMutexLocker mutexLocker(&m_mutex); + + if (m_running) { + return true; + } + if (!m_deviceShared.m_deviceParams->getDevice()) { return false; } - if (m_running) { stop(); } - - if (!acquireChannel()) - { + if (!acquireChannel()) { return false; } @@ -441,7 +444,14 @@ bool USRPInput::start() void USRPInput::stop() { + QMutexLocker mutexLocker(&m_mutex); + + if (!m_running) { + return; + } + qDebug("USRPInput::stop"); + m_running = false; if (m_usrpInputThread) { @@ -451,7 +461,6 @@ void USRPInput::stop() } m_deviceShared.m_thread = 0; - m_running = false; releaseChannel(); } diff --git a/plugins/samplesource/xtrxinput/xtrxinput.cpp b/plugins/samplesource/xtrxinput/xtrxinput.cpp index cf9f4ad70..5aac520ca 100644 --- a/plugins/samplesource/xtrxinput/xtrxinput.cpp +++ b/plugins/samplesource/xtrxinput/xtrxinput.cpp @@ -275,6 +275,11 @@ bool XTRXInput::start() // // Eventually it registers the FIFO in the thread. If the thread has to be started it enables the channels up to the number of channels // allocated in the thread and starts the thread. + QMutexLocker mutexLocker(&m_mutex); + + if (m_running) { + return true; + } if (!m_deviceShared.m_dev || !m_deviceShared.m_dev->getDevice()) { @@ -353,8 +358,6 @@ bool XTRXInput::start() xtrxInputThread->setFifo(requestedChannel, &m_sampleFifo); xtrxInputThread->setLog2Decimation(requestedChannel, m_settings.m_log2SoftDecim); - applySettings(m_settings, QList(), true); - if (needsStart) { qDebug("XTRXInput::start: (re)start thread"); @@ -364,6 +367,9 @@ bool XTRXInput::start() qDebug("XTRXInput::start: started"); m_running = true; + m_mutex.unlock(); + applySettings(m_settings, QList(), true); + return true; } @@ -377,11 +383,13 @@ void XTRXInput::stop() // If the thread is currently managing both channels (MI mode) then we are removing one channel. Thus we must // transition from MI to SI. This transition is handled by stopping the thread, deleting it and creating a new one // managing a single channel. + QMutexLocker mutexLocker(&m_mutex); if (!m_running) { return; } + m_running = false; int removedChannel = m_deviceAPI->getDeviceItemIndex(); // channel to remove int requestedChannel = removedChannel ^ 1; // channel to keep (opposite channel) XTRXInputThread *xtrxInputThread = findThread(); @@ -432,8 +440,6 @@ void XTRXInput::stop() applySettings(m_settings, QList(), true); xtrxInputThread->startWork(); } - - m_running = false; } void XTRXInput::suspendTxThread() From 36349e28378dcbfff9e09cefcc58a431584a9d97 Mon Sep 17 00:00:00 2001 From: f4exb Date: Sat, 24 Aug 2024 13:17:02 +0200 Subject: [PATCH 14/16] Sonar fixes --- plugins/channelrx/wdsprx/wdsprxbaseband.cpp | 1 + plugins/channelrx/wdsprx/wdsprxgui.cpp | 58 ++- plugins/channelrx/wdsprx/wdsprxgui.h | 44 +- plugins/channeltx/modam/ammod.cpp | 83 ++-- plugins/channeltx/modam/ammod.h | 22 +- plugins/channeltx/modam/ammodgui.cpp | 64 +-- plugins/channeltx/modam/ammodgui.h | 46 ++- plugins/channeltx/modam/ammodplugin.cpp | 4 +- plugins/channeltx/modam/ammodplugin.h | 14 +- plugins/channeltx/modam/ammodsource.cpp | 62 +-- plugins/channeltx/modam/ammodsource.h | 28 +- plugins/channeltx/modnfm/nfmmod.cpp | 77 ++-- plugins/channeltx/modnfm/nfmmod.h | 94 ++--- plugins/channeltx/modnfm/nfmmodsource.cpp | 88 ++-- plugins/channeltx/modnfm/nfmmodsource.h | 30 +- plugins/channeltx/modssb/ssbmod.cpp | 95 +++-- plugins/channeltx/modssb/ssbmod.h | 96 ++--- plugins/channeltx/modssb/ssbmodsource.cpp | 337 ++++++++-------- plugins/channeltx/modssb/ssbmodsource.h | 32 +- .../bladerf1output/bladerf1output.cpp | 242 +++++------ .../bladerf1output/bladerf1output.h | 78 ++-- plugins/samplesink/fileoutput/fileoutput.cpp | 56 ++- plugins/samplesink/fileoutput/fileoutput.h | 84 ++-- .../samplesink/remoteoutput/remoteoutput.cpp | 76 ++-- .../samplesink/remoteoutput/remoteoutput.h | 90 ++--- .../bladerf1input/bladerf1input.cpp | 238 +++++------ .../bladerf1input/bladerf1input.h | 78 ++-- .../sigmffileinput/sigmffileinput.cpp | 141 +++---- .../sigmffileinput/sigmffileinput.h | 150 +++---- sdrbase/device/deviceapi.cpp | 54 ++- sdrbase/device/deviceapi.h | 13 +- sdrbase/dsp/dspdevicemimoengine.cpp | 239 ++++++----- sdrbase/dsp/dspdevicemimoengine.h | 43 +- sdrbase/dsp/dspdevicesinkengine.cpp | 84 ++-- sdrbase/dsp/dspdevicesinkengine.h | 12 +- sdrbase/dsp/dspdevicesourceengine.cpp | 86 ++-- sdrbase/dsp/dspdevicesourceengine.h | 6 +- sdrbase/plugin/plugininterface.h | 14 +- sdrgui/device/deviceuiset.cpp | 93 +++-- sdrgui/device/deviceuiset.h | 12 +- sdrgui/mainwindow.cpp | 379 ++++++++---------- sdrgui/mainwindow.h | 47 +-- sdrsrv/mainserver.cpp | 99 ++--- 43 files changed, 1713 insertions(+), 1976 deletions(-) diff --git a/plugins/channelrx/wdsprx/wdsprxbaseband.cpp b/plugins/channelrx/wdsprx/wdsprxbaseband.cpp index b079bd566..f0a1e176d 100644 --- a/plugins/channelrx/wdsprx/wdsprxbaseband.cpp +++ b/plugins/channelrx/wdsprx/wdsprxbaseband.cpp @@ -59,6 +59,7 @@ void WDSPRxBaseband::reset() { QMutexLocker mutexLocker(&m_mutex); m_sink.applyAudioSampleRate(DSPEngine::instance()->getAudioDeviceManager()->getOutputSampleRate()); + mutexLocker.unlock(); m_sampleFifo.reset(); m_channelSampleRate = 0; } diff --git a/plugins/channelrx/wdsprx/wdsprxgui.cpp b/plugins/channelrx/wdsprx/wdsprxgui.cpp index b648c9c4b..46501630d 100644 --- a/plugins/channelrx/wdsprx/wdsprxgui.cpp +++ b/plugins/channelrx/wdsprx/wdsprxgui.cpp @@ -49,7 +49,7 @@ WDSPRxGUI* WDSPRxGUI::create(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, BasebandSampleSink *rxChannel) { - WDSPRxGUI* gui = new WDSPRxGUI(pluginAPI, deviceUISet, rxChannel); + auto* gui = new WDSPRxGUI(pluginAPI, deviceUISet, rxChannel); return gui; } @@ -98,7 +98,7 @@ bool WDSPRxGUI::handleMessage(const Message& message) if (WDSPRx::MsgConfigureWDSPRx::match(message)) { qDebug("WDSPRxGUI::handleMessage: WDSPRx::MsgConfigureWDSPRx"); - const WDSPRx::MsgConfigureWDSPRx& cfg = (WDSPRx::MsgConfigureWDSPRx&) message; + auto& cfg = (const WDSPRx::MsgConfigureWDSPRx&) message; m_settings = cfg.getSettings(); blockApplySettings(true); ui->spectrumGUI->updateSettings(); @@ -118,7 +118,7 @@ bool WDSPRxGUI::handleMessage(const Message& message) } else if (DSPSignalNotification::match(message)) { - const DSPSignalNotification& notif = (const DSPSignalNotification&) message; + auto& notif = (const DSPSignalNotification&) message; m_deviceCenterFrequency = notif.getCenterFrequency(); m_basebandSampleRate = notif.getSampleRate(); qDebug("WDSPRxGUI::handleMessage: DSPSignalNotification: centerFrequency: %lld sampleRate: %d", @@ -138,7 +138,7 @@ void WDSPRxGUI::handleInputMessages() { Message* message; - while ((message = getInputMessageQueue()->pop()) != 0) + while ((message = getInputMessageQueue()->pop()) != nullptr) { if (handleMessage(*message)) { @@ -183,7 +183,7 @@ void WDSPRxGUI::on_dsb_toggled(bool dsb) void WDSPRxGUI::on_deltaFrequency_changed(qint64 value) { - m_channelMarker.setCenterFrequency(value); + m_channelMarker.setCenterFrequency((int) value); m_settings.m_inputFrequencyOffset = m_channelMarker.getCenterFrequency(); updateAbsoluteCenterFrequency(); applySettings(); @@ -205,7 +205,7 @@ void WDSPRxGUI::on_lowCut_valueChanged(int value) void WDSPRxGUI::on_volume_valueChanged(int value) { ui->volumeText->setText(QString("%1").arg(value)); - m_settings.m_volume = CalcDb::powerFromdB(value); + m_settings.m_volume = (Real) CalcDb::powerFromdB(value); applySettings(); } @@ -279,7 +279,7 @@ void WDSPRxGUI::on_rit_toggled(bool checked) { m_settings.m_rit = checked; m_settings.m_profiles[m_settings.m_profileIndex].m_rit = m_settings.m_rit; - m_channelMarker.setShift(checked ? m_settings.m_ritFrequency: 0); + m_channelMarker.setShift(checked ? (int) m_settings.m_ritFrequency: 0); applySettings(); } @@ -406,7 +406,7 @@ void WDSPRxGUI::on_profileIndex_valueChanged(int value) void WDSPRxGUI::on_demod_currentIndexChanged(int index) { - WDSPRxProfile::WDSPRxDemod demod = (WDSPRxProfile::WDSPRxDemod) index; + auto demod = (WDSPRxProfile::WDSPRxDemod) index; if ((m_settings.m_demod != WDSPRxProfile::DemodSSB) && (demod == WDSPRxProfile::DemodSSB)) { m_settings.m_dsb = false; @@ -480,7 +480,7 @@ void WDSPRxGUI::onMenuDialogCalled(const QPoint &p) resetContextMenuType(); } -void WDSPRxGUI::onWidgetRolled(QWidget* widget, bool rollDown) +void WDSPRxGUI::onWidgetRolled(const QWidget* widget, bool rollDown) { (void) widget; (void) rollDown; @@ -524,7 +524,7 @@ WDSPRxGUI::WDSPRxGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, BasebandSam m_wdspRx = (WDSPRx*) rxChannel; m_spectrumVis = m_wdspRx->getSpectrumVis(); m_spectrumVis->setGLSpectrum(ui->glSpectrum); - m_wdspRx->setMessageQueueToGUI(getInputMessageQueue()); + m_wdspRx->setMessageQueueToGUI(WDSPRxGUI::getInputMessageQueue()); m_audioMuteRightClickEnabler = new CRightClickEnabler(ui->audioMute); connect(m_audioMuteRightClickEnabler, SIGNAL(rightClick(const QPoint &)), this, SLOT(audioSelect(const QPoint &))); @@ -588,7 +588,7 @@ WDSPRxGUI::WDSPRxGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, BasebandSam m_deviceUISet->addChannelMarker(&m_channelMarker); connect(&m_channelMarker, SIGNAL(changedByCursor()), this, SLOT(channelMarkerChangedByCursor())); connect(&m_channelMarker, SIGNAL(highlightedByCursor()), this, SLOT(channelMarkerHighlightedByCursor())); - connect(getInputMessageQueue(), SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages())); + connect(WDSPRxGUI::getInputMessageQueue(), SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages())); m_iconDSBUSB.addPixmap(QPixmap("://dsb.png"), QIcon::Normal, QIcon::On); @@ -654,7 +654,7 @@ uint32_t WDSPRxGUI::getValidAudioSampleRate() const return sr; } -unsigned int WDSPRxGUI::spanLog2Max() +unsigned int WDSPRxGUI::spanLog2Max() const { unsigned int spanLog2 = 0; for (; getValidAudioSampleRate() / (1<= 1000; spanLog2++); @@ -668,7 +668,6 @@ void WDSPRxGUI::applyBandwidths(unsigned int spanLog2, bool force) unsigned int limit = s2max < 1 ? 0 : s2max - 1; ui->spanLog2->setMaximum(limit); bool dsb = ui->dsb->isChecked(); - //int spanLog2 = ui->spanLog2->value(); m_spectrumRate = getValidAudioSampleRate() / (1<BW->value(); int lw = ui->lowCut->value(); @@ -764,8 +763,8 @@ void WDSPRxGUI::applyBandwidths(unsigned int spanLog2, bool force) m_settings.m_dsb = dsb; m_settings.m_profiles[m_settings.m_profileIndex].m_dsb = dsb; m_settings.m_profiles[m_settings.m_profileIndex].m_spanLog2 = spanLog2; - m_settings.m_profiles[m_settings.m_profileIndex].m_highCutoff = bw * 100; - m_settings.m_profiles[m_settings.m_profileIndex].m_lowCutoff = lw * 100; + m_settings.m_profiles[m_settings.m_profileIndex].m_highCutoff = (Real) (bw * 100); + m_settings.m_profiles[m_settings.m_profileIndex].m_lowCutoff = (Real) (lw * 100); applySettings(force); @@ -785,11 +784,11 @@ void WDSPRxGUI::displaySettings() { m_channelMarker.blockSignals(true); m_channelMarker.setCenterFrequency(m_settings.m_inputFrequencyOffset); - m_channelMarker.setBandwidth(m_settings.m_profiles[m_settings.m_profileIndex].m_highCutoff * 2); + m_channelMarker.setBandwidth((int) (m_settings.m_profiles[m_settings.m_profileIndex].m_highCutoff * 2)); m_channelMarker.setTitle(m_settings.m_title); - m_channelMarker.setLowCutoff(m_settings.m_profiles[m_settings.m_profileIndex].m_lowCutoff); + m_channelMarker.setLowCutoff((int) m_settings.m_profiles[m_settings.m_profileIndex].m_lowCutoff); int shift = m_settings.m_profiles[m_settings.m_profileIndex].m_rit ? - m_settings.m_profiles[m_settings.m_profileIndex].m_ritFrequency : + (int) m_settings.m_profiles[m_settings.m_profileIndex].m_ritFrequency : 0; m_channelMarker.setShift(shift); @@ -880,7 +879,7 @@ void WDSPRxGUI::displaySettings() ui->dsb->setChecked(m_settings.m_dsb); ui->spanLog2->setValue(1 + ui->spanLog2->maximum() - m_settings.m_profiles[m_settings.m_profileIndex].m_spanLog2); - ui->BW->setValue(m_settings.m_profiles[m_settings.m_profileIndex].m_highCutoff / 100.0); + ui->BW->setValue((int) (m_settings.m_profiles[m_settings.m_profileIndex].m_highCutoff / 100.0)); s = QString::number(m_settings.m_profiles[m_settings.m_profileIndex].m_highCutoff/1000.0, 'f', 1); if (m_settings.m_dsb) { @@ -899,10 +898,10 @@ void WDSPRxGUI::displaySettings() // The only one of the four signals triggering applyBandwidths will trigger it once only with all other values // set correctly and therefore validate the settings and apply them to dependent widgets - ui->lowCut->setValue(m_settings.m_profiles[m_settings.m_profileIndex].m_lowCutoff / 100.0); + ui->lowCut->setValue((int) (m_settings.m_profiles[m_settings.m_profileIndex].m_lowCutoff / 100.0)); ui->lowCutText->setText(tr("%1k").arg(m_settings.m_profiles[m_settings.m_profileIndex].m_lowCutoff / 1000.0)); - int volume = CalcDb::dbPower(m_settings.m_volume); + auto volume = (int) CalcDb::dbPower(m_settings.m_volume); ui->volume->setValue(volume); ui->volumeText->setText(QString("%1").arg(volume)); @@ -1199,15 +1198,11 @@ void WDSPRxGUI::amSetup(int iValueChanged) auto valueChanged = (WDSPRxAMDialog::ValueChanged) iValueChanged; - switch (valueChanged) + if (valueChanged == WDSPRxAMDialog::ChangedFadeLevel) { - case WDSPRxAMDialog::ChangedFadeLevel: m_settings.m_amFadeLevel = m_amDialog->getFadeLevel(); m_settings.m_profiles[m_settings.m_profileIndex].m_amFadeLevel = m_settings.m_amFadeLevel; applySettings(); - break; - default: - break; } } @@ -1369,21 +1364,18 @@ void WDSPRxGUI::panSetup(int iValueChanged) auto valueChanged = (WDSPRxPanDialog::ValueChanged) iValueChanged; - switch (valueChanged) + if (valueChanged == WDSPRxPanDialog::ChangedPan) { - case WDSPRxPanDialog::ChangedPan: m_settings.m_audioPan = m_panDialog->getPan(); m_settings.m_profiles[m_settings.m_profileIndex].m_audioPan = m_settings.m_audioPan; applySettings(); - break; - default: - break; } } void WDSPRxGUI::tick() { - double powDbAvg, powDbPeak; + double powDbAvg; + double powDbPeak; int nbMagsqSamples; m_wdspRx->getMagSqLevels(powDbAvg, powDbPeak, nbMagsqSamples); // powers directly in dB @@ -1416,7 +1408,7 @@ void WDSPRxGUI::tick() m_tickCount++; } -void WDSPRxGUI::makeUIConnections() +void WDSPRxGUI::makeUIConnections() const { QObject::connect(ui->deltaFrequency, &ValueDialZ::changed, this, &WDSPRxGUI::on_deltaFrequency_changed); QObject::connect(ui->audioBinaural, &QToolButton::toggled, this, &WDSPRxGUI::on_audioBinaural_toggled); diff --git a/plugins/channelrx/wdsprx/wdsprxgui.h b/plugins/channelrx/wdsprx/wdsprxgui.h index c89c3cc15..3f2b59da3 100644 --- a/plugins/channelrx/wdsprx/wdsprxgui.h +++ b/plugins/channelrx/wdsprx/wdsprxgui.h @@ -58,21 +58,21 @@ public: static WDSPRxGUI* create(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, BasebandSampleSink *rxChannel); virtual void destroy(); - void resetToDefaults(); - QByteArray serialize() const; - bool deserialize(const QByteArray& data); - virtual MessageQueue *getInputMessageQueue() { return &m_inputMessageQueue; } - virtual void setWorkspaceIndex(int index) { m_settings.m_workspaceIndex = index; }; - virtual int getWorkspaceIndex() const { return m_settings.m_workspaceIndex; }; - virtual void setGeometryBytes(const QByteArray& blob) { m_settings.m_geometryBytes = blob; }; - virtual QByteArray getGeometryBytes() const { return m_settings.m_geometryBytes; }; - virtual QString getTitle() const { return m_settings.m_title; }; - virtual QColor getTitleColor() const { return m_settings.m_rgbColor; }; - virtual void zetHidden(bool hidden) { m_settings.m_hidden = hidden; } - virtual bool getHidden() const { return m_settings.m_hidden; } - virtual ChannelMarker& getChannelMarker() { return m_channelMarker; } - virtual int getStreamIndex() const { return m_settings.m_streamIndex; } - virtual void setStreamIndex(int streamIndex) { m_settings.m_streamIndex = streamIndex; } + void resetToDefaults() final; + QByteArray serialize() const final; + bool deserialize(const QByteArray& data) final; + MessageQueue *getInputMessageQueue() final { return &m_inputMessageQueue; } + void setWorkspaceIndex(int index) final { m_settings.m_workspaceIndex = index; }; + int getWorkspaceIndex() const final { return m_settings.m_workspaceIndex; }; + void setGeometryBytes(const QByteArray& blob) final { m_settings.m_geometryBytes = blob; }; + QByteArray getGeometryBytes() const final { return m_settings.m_geometryBytes; }; + QString getTitle() const final { return m_settings.m_title; }; + QColor getTitleColor() const final { return m_settings.m_rgbColor; }; + void zetHidden(bool hidden) final { m_settings.m_hidden = hidden; } + bool getHidden() const final { return m_settings.m_hidden; } + ChannelMarker& getChannelMarker() final { return m_channelMarker; } + int getStreamIndex() const final { return m_settings.m_streamIndex; } + void setStreamIndex(int streamIndex) final { m_settings.m_streamIndex = streamIndex; } public slots: void channelMarkerChangedByCursor(); @@ -122,21 +122,21 @@ private: QIcon m_iconDSBUSB; QIcon m_iconDSBLSB; - explicit WDSPRxGUI(PluginAPI* pluginAPI, DeviceUISet* deviceUISet, BasebandSampleSink *rxChannel, QWidget* parent = 0); - virtual ~WDSPRxGUI(); + explicit WDSPRxGUI(PluginAPI* pluginAPI, DeviceUISet* deviceUISet, BasebandSampleSink *rxChannel, QWidget* parent = nullptr); + ~WDSPRxGUI() final; bool blockApplySettings(bool block); void applySettings(bool force = false); void applyBandwidths(unsigned int spanLog2, bool force = false); - unsigned int spanLog2Max(); + unsigned int spanLog2Max() const; void displaySettings(); bool handleMessage(const Message& message); - void makeUIConnections(); + void makeUIConnections() const; void updateAbsoluteCenterFrequency(); uint32_t getValidAudioSampleRate() const; - void leaveEvent(QEvent*); - void enterEvent(EnterEventType*); + void leaveEvent(QEvent*) final; + void enterEvent(EnterEventType*) final; private slots: void on_deltaFrequency_changed(qint64 value); @@ -164,7 +164,7 @@ private slots: void on_rit_toggled(bool checked); void on_ritFrequency_valueChanged(int value); void on_dbOrS_toggled(bool checked); - void onWidgetRolled(QWidget* widget, bool rollDown); + void onWidgetRolled(const QWidget* widget, bool rollDown); void onMenuDialogCalled(const QPoint& p); void handleInputMessages(); void audioSelect(const QPoint& p); diff --git a/plugins/channeltx/modam/ammod.cpp b/plugins/channeltx/modam/ammod.cpp index 39430c63b..6647816bc 100644 --- a/plugins/channeltx/modam/ammod.cpp +++ b/plugins/channeltx/modam/ammod.cpp @@ -55,12 +55,7 @@ const char* const AMMod::m_channelId ="AMMod"; AMMod::AMMod(DeviceAPI *deviceAPI) : ChannelAPI(m_channelIdURI, ChannelAPI::StreamSingleSource), - m_deviceAPI(deviceAPI), - m_running(false), - m_fileSize(0), - m_recordLength(0), - m_sampleRate(48000), - m_levelMeter(nullptr) + m_deviceAPI(deviceAPI) { setObjectName(m_channelId); applySettings(m_settings, true); @@ -89,7 +84,7 @@ AMMod::~AMMod() m_deviceAPI->removeChannelSourceAPI(this); m_deviceAPI->removeChannelSource(this); - stop(); + AMMod::stop(); } void AMMod::setDeviceAPI(DeviceAPI *deviceAPI) @@ -185,7 +180,7 @@ bool AMMod::handleMessage(const Message& cmd) { if (MsgConfigureAMMod::match(cmd)) { - MsgConfigureAMMod& cfg = (MsgConfigureAMMod&) cmd; + auto& cfg = (const MsgConfigureAMMod&) cmd; qDebug() << "AMMod::handleMessage: MsgConfigureAMMod"; applySettings(cfg.getSettings(), cfg.getForce()); @@ -194,7 +189,7 @@ bool AMMod::handleMessage(const Message& cmd) } else if (MsgConfigureFileSourceName::match(cmd)) { - MsgConfigureFileSourceName& conf = (MsgConfigureFileSourceName&) cmd; + auto& conf = (const MsgConfigureFileSourceName&) cmd; m_fileName = conf.getFileName(); qDebug() << "AMMod::handleMessage: MsgConfigureFileSourceName"; openFileStream(); @@ -202,7 +197,7 @@ bool AMMod::handleMessage(const Message& cmd) } else if (MsgConfigureFileSourceSeek::match(cmd)) { - MsgConfigureFileSourceSeek& conf = (MsgConfigureFileSourceSeek&) cmd; + auto& conf = (const MsgConfigureFileSourceSeek&) cmd; int seekPercentage = conf.getPercentage(); qDebug() << "AMMod::handleMessage: MsgConfigureFileSourceSeek"; seekFileStream(seekPercentage); @@ -211,13 +206,13 @@ bool AMMod::handleMessage(const Message& cmd) } else if (MsgConfigureFileSourceStreamTiming::match(cmd)) { - std::size_t samplesCount; + std::size_t samplesCount; - if (m_ifstream.eof()) { - samplesCount = m_fileSize / sizeof(Real); - } else { - samplesCount = m_ifstream.tellg() / sizeof(Real); - } + if (m_ifstream.eof()) { + samplesCount = m_fileSize / sizeof(Real); + } else { + samplesCount = m_ifstream.tellg() / sizeof(Real); + } MsgReportFileSourceStreamTiming *report; report = MsgReportFileSourceStreamTiming::create(samplesCount); @@ -227,7 +222,7 @@ bool AMMod::handleMessage(const Message& cmd) } else if (CWKeyer::MsgConfigureCWKeyer::match(cmd)) { - const CWKeyer::MsgConfigureCWKeyer& cfg = (CWKeyer::MsgConfigureCWKeyer&) cmd; + auto& cfg = (const CWKeyer::MsgConfigureCWKeyer&) cmd; qDebug() << "AMMod::handleMessage: MsgConfigureCWKeyer"; if (m_settings.m_useReverseAPI) { @@ -240,7 +235,7 @@ bool AMMod::handleMessage(const Message& cmd) { qDebug() << "AMMod::handleMessage: DSPSignalNotification"; // Forward to the source - DSPSignalNotification& notif = (DSPSignalNotification&) cmd; + auto& notif = (const DSPSignalNotification&) cmd; if (m_running) { m_basebandSource->getInputMessageQueue()->push(new DSPSignalNotification(notif)); @@ -276,7 +271,7 @@ void AMMod::openFileStream() m_ifstream.seekg(0,std::ios_base::beg); m_sampleRate = 48000; // fixed rate - m_recordLength = m_fileSize / (sizeof(Real) * m_sampleRate); + m_recordLength = (quint32) (m_fileSize / (sizeof(Real) * m_sampleRate)); qDebug() << "AMMod::openFileStream: " << m_fileName.toStdString().c_str() << " fileSize: " << m_fileSize << "bytes" @@ -394,7 +389,7 @@ void AMMod::applySettings(const AMModSettings& settings, bool force) QList pipes; MainCore::instance()->getMessagePipes().getMessagePipes(this, "settings", pipes); - if (pipes.size() > 0) { + if (!pipes.empty()) { sendChannelSettings(pipes, reverseAPIKeys, settings, force); } @@ -423,12 +418,12 @@ bool AMMod::deserialize(const QByteArray& data) } } -void AMMod::sendSampleRateToDemodAnalyzer() +void AMMod::sendSampleRateToDemodAnalyzer() const { QList pipes; MainCore::instance()->getMessagePipes().getMessagePipes(this, "reportdemod", pipes); - if (pipes.size() > 0) + if (!pipes.empty()) { for (const auto& pipe : pipes) { @@ -555,13 +550,13 @@ void AMMod::webapiUpdateChannelSettings( settings.m_reverseAPIAddress = *response.getAmModSettings()->getReverseApiAddress(); } if (channelSettingsKeys.contains("reverseAPIPort")) { - settings.m_reverseAPIPort = response.getAmModSettings()->getReverseApiPort(); + settings.m_reverseAPIPort = (uint16_t) response.getAmModSettings()->getReverseApiPort(); } if (channelSettingsKeys.contains("reverseAPIDeviceIndex")) { - settings.m_reverseAPIDeviceIndex = response.getAmModSettings()->getReverseApiDeviceIndex(); + settings.m_reverseAPIDeviceIndex = (uint16_t) response.getAmModSettings()->getReverseApiDeviceIndex(); } if (channelSettingsKeys.contains("reverseAPIChannelIndex")) { - settings.m_reverseAPIChannelIndex = response.getAmModSettings()->getReverseApiChannelIndex(); + settings.m_reverseAPIChannelIndex = (uint16_t) response.getAmModSettings()->getReverseApiChannelIndex(); } if (settings.m_channelMarker && channelSettingsKeys.contains("channelMarker")) { settings.m_channelMarker->updateFrom(channelSettingsKeys, response.getAmModSettings()->getChannelMarker()); @@ -631,7 +626,7 @@ void AMMod::webapiFormatChannelSettings(SWGSDRangel::SWGChannelSettings& respons } else { - SWGSDRangel::SWGChannelMarker *swgChannelMarker = new SWGSDRangel::SWGChannelMarker(); + auto *swgChannelMarker = new SWGSDRangel::SWGChannelMarker(); settings.m_channelMarker->formatTo(swgChannelMarker); response.getAmModSettings()->setChannelMarker(swgChannelMarker); } @@ -645,16 +640,16 @@ void AMMod::webapiFormatChannelSettings(SWGSDRangel::SWGChannelSettings& respons } else { - SWGSDRangel::SWGRollupState *swgRollupState = new SWGSDRangel::SWGRollupState(); + auto *swgRollupState = new SWGSDRangel::SWGRollupState(); settings.m_rollupState->formatTo(swgRollupState); response.getAmModSettings()->setRollupState(swgRollupState); } } } -void AMMod::webapiFormatChannelReport(SWGSDRangel::SWGChannelReport& response) +void AMMod::webapiFormatChannelReport(SWGSDRangel::SWGChannelReport& response) const { - response.getAmModReport()->setChannelPowerDb(CalcDb::dbPower(getMagSq())); + response.getAmModReport()->setChannelPowerDb((float) CalcDb::dbPower(getMagSq())); if (m_running) { @@ -663,9 +658,9 @@ void AMMod::webapiFormatChannelReport(SWGSDRangel::SWGChannelReport& response) } } -void AMMod::webapiReverseSendSettings(QList& channelSettingsKeys, const AMModSettings& settings, bool force) +void AMMod::webapiReverseSendSettings(const QList& channelSettingsKeys, const AMModSettings& settings, bool force) { - SWGSDRangel::SWGChannelSettings *swgChannelSettings = new SWGSDRangel::SWGChannelSettings(); + auto *swgChannelSettings = new SWGSDRangel::SWGChannelSettings(); webapiFormatChannelSettings(channelSettingsKeys, swgChannelSettings, settings, force); QString channelSettingsURL = QString("http://%1:%2/sdrangel/deviceset/%3/channel/%4/settings") @@ -676,8 +671,8 @@ void AMMod::webapiReverseSendSettings(QList& channelSettingsKeys, const m_networkRequest.setUrl(QUrl(channelSettingsURL)); m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); - QBuffer *buffer = new QBuffer(); - buffer->open((QBuffer::ReadWrite)); + auto *buffer = new QBuffer(); + buffer->open(QBuffer::ReadWrite); buffer->write(swgChannelSettings->asJson().toUtf8()); buffer->seek(0); @@ -690,7 +685,7 @@ void AMMod::webapiReverseSendSettings(QList& channelSettingsKeys, const void AMMod::webapiReverseSendCWSettings(const CWKeyerSettings& cwKeyerSettings) { - SWGSDRangel::SWGChannelSettings *swgChannelSettings = new SWGSDRangel::SWGChannelSettings(); + auto *swgChannelSettings = new SWGSDRangel::SWGChannelSettings(); swgChannelSettings->setDirection(1); // single source (Tx) swgChannelSettings->setChannelType(new QString("AMMod")); swgChannelSettings->setAmModSettings(new SWGSDRangel::SWGAMModSettings()); @@ -698,7 +693,7 @@ void AMMod::webapiReverseSendCWSettings(const CWKeyerSettings& cwKeyerSettings) swgAMModSettings->setCwKeyer(new SWGSDRangel::SWGCWKeyerSettings()); SWGSDRangel::SWGCWKeyerSettings *apiCwKeyerSettings = swgAMModSettings->getCwKeyer(); - getCWKeyer()->webapiFormatChannelSettings(apiCwKeyerSettings, cwKeyerSettings); + CWKeyer::webapiFormatChannelSettings(apiCwKeyerSettings, cwKeyerSettings); QString channelSettingsURL = QString("http://%1:%2/sdrangel/deviceset/%3/channel/%4/settings") .arg(m_settings.m_reverseAPIAddress) @@ -708,8 +703,8 @@ void AMMod::webapiReverseSendCWSettings(const CWKeyerSettings& cwKeyerSettings) m_networkRequest.setUrl(QUrl(channelSettingsURL)); m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); - QBuffer *buffer = new QBuffer(); - buffer->open((QBuffer::ReadWrite)); + auto *buffer = new QBuffer(); + buffer->open(QBuffer::ReadWrite); buffer->write(swgChannelSettings->asJson().toUtf8()); buffer->seek(0); @@ -722,7 +717,7 @@ void AMMod::webapiReverseSendCWSettings(const CWKeyerSettings& cwKeyerSettings) void AMMod::sendChannelSettings( const QList& pipes, - QList& channelSettingsKeys, + const QList& channelSettingsKeys, const AMModSettings& settings, bool force) { @@ -732,7 +727,7 @@ void AMMod::sendChannelSettings( if (messageQueue) { - SWGSDRangel::SWGChannelSettings *swgChannelSettings = new SWGSDRangel::SWGChannelSettings(); + auto *swgChannelSettings = new SWGSDRangel::SWGChannelSettings(); webapiFormatChannelSettings(channelSettingsKeys, swgChannelSettings, settings, force); MainCore::MsgChannelSettings *msg = MainCore::MsgChannelSettings::create( this, @@ -746,7 +741,7 @@ void AMMod::sendChannelSettings( } void AMMod::webapiFormatChannelSettings( - QList& channelSettingsKeys, + const QList& channelSettingsKeys, SWGSDRangel::SWGChannelSettings *swgChannelSettings, const AMModSettings& settings, bool force @@ -803,25 +798,25 @@ void AMMod::webapiFormatChannelSettings( const CWKeyerSettings& cwKeyerSettings = getCWKeyer()->getSettings(); swgAMModSettings->setCwKeyer(new SWGSDRangel::SWGCWKeyerSettings()); SWGSDRangel::SWGCWKeyerSettings *apiCwKeyerSettings = swgAMModSettings->getCwKeyer(); - getCWKeyer()->webapiFormatChannelSettings(apiCwKeyerSettings, cwKeyerSettings); + CWKeyer::webapiFormatChannelSettings(apiCwKeyerSettings, cwKeyerSettings); } if (settings.m_channelMarker && (channelSettingsKeys.contains("channelMarker") || force)) { - SWGSDRangel::SWGChannelMarker *swgChannelMarker = new SWGSDRangel::SWGChannelMarker(); + auto *swgChannelMarker = new SWGSDRangel::SWGChannelMarker(); settings.m_channelMarker->formatTo(swgChannelMarker); swgAMModSettings->setChannelMarker(swgChannelMarker); } if (settings.m_rollupState && (channelSettingsKeys.contains("rollupState") || force)) { - SWGSDRangel::SWGRollupState *swgRollupState = new SWGSDRangel::SWGRollupState(); + auto *swgRollupState = new SWGSDRangel::SWGRollupState(); settings.m_rollupState->formatTo(swgRollupState); swgAMModSettings->setRollupState(swgRollupState); } } -void AMMod::networkManagerFinished(QNetworkReply *reply) +void AMMod::networkManagerFinished(QNetworkReply *reply) const { QNetworkReply::NetworkError replyError = reply->error(); diff --git a/plugins/channeltx/modam/ammod.h b/plugins/channeltx/modam/ammod.h index 28fdc6553..bf1be19ee 100644 --- a/plugins/channeltx/modam/ammod.h +++ b/plugins/channeltx/modam/ammod.h @@ -251,7 +251,7 @@ private: DeviceAPI* m_deviceAPI; QThread *m_thread; - bool m_running; + bool m_running = false; AMModBaseband* m_basebandSource; AMModSettings m_settings; @@ -260,38 +260,38 @@ private: std::ifstream m_ifstream; QString m_fileName; - quint64 m_fileSize; //!< raw file size (bytes) - quint32 m_recordLength; //!< record length in seconds computed from file size - int m_sampleRate; + quint64 m_fileSize = 0; //!< raw file size (bytes) + quint32 m_recordLength = 0; //!< record length in seconds computed from file size + int m_sampleRate = 48000; QNetworkAccessManager *m_networkManager; QNetworkRequest m_networkRequest; CWKeyer m_cwKeyer; - QObject *m_levelMeter; + QObject *m_levelMeter = nullptr; virtual bool handleMessage(const Message& cmd); void applySettings(const AMModSettings& settings, bool force = false); - void sendSampleRateToDemodAnalyzer(); + void sendSampleRateToDemodAnalyzer() const; void openFileStream(); void seekFileStream(int seekPercentage); - void webapiFormatChannelReport(SWGSDRangel::SWGChannelReport& response); - void webapiReverseSendSettings(QList& channelSettingsKeys, const AMModSettings& settings, bool force); + void webapiFormatChannelReport(SWGSDRangel::SWGChannelReport& response) const; + void webapiReverseSendSettings(const QList& channelSettingsKeys, const AMModSettings& settings, bool force); void webapiReverseSendCWSettings(const CWKeyerSettings& settings); void sendChannelSettings( const QList& pipes, - QList& channelSettingsKeys, + const QList& channelSettingsKeys, const AMModSettings& settings, bool force ); void webapiFormatChannelSettings( - QList& channelSettingsKeys, + const QList& channelSettingsKeys, SWGSDRangel::SWGChannelSettings *swgChannelSettings, const AMModSettings& settings, bool force ); private slots: - void networkManagerFinished(QNetworkReply *reply); + void networkManagerFinished(QNetworkReply *reply) const; }; diff --git a/plugins/channeltx/modam/ammodgui.cpp b/plugins/channeltx/modam/ammodgui.cpp index 5a0cfd791..ee02347bd 100644 --- a/plugins/channeltx/modam/ammodgui.cpp +++ b/plugins/channeltx/modam/ammodgui.cpp @@ -45,7 +45,7 @@ AMModGUI* AMModGUI::create(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, BasebandSampleSource *channelTx) { - AMModGUI* gui = new AMModGUI(pluginAPI, deviceUISet, channelTx); + auto* gui = new AMModGUI(pluginAPI, deviceUISet, channelTx); return gui; } @@ -82,21 +82,23 @@ bool AMModGUI::handleMessage(const Message& message) { if (AMMod::MsgReportFileSourceStreamData::match(message)) { - m_recordSampleRate = ((AMMod::MsgReportFileSourceStreamData&)message).getSampleRate(); - m_recordLength = ((AMMod::MsgReportFileSourceStreamData&)message).getRecordLength(); + auto& cmd = (const AMMod::MsgReportFileSourceStreamData&) message; + m_recordSampleRate = cmd.getSampleRate(); + m_recordLength = cmd.getRecordLength(); m_samplesCount = 0; updateWithStreamData(); return true; } else if (AMMod::MsgReportFileSourceStreamTiming::match(message)) { - m_samplesCount = ((AMMod::MsgReportFileSourceStreamTiming&)message).getSamplesCount(); + auto& cmd = (const AMMod::MsgReportFileSourceStreamTiming&) message; + m_samplesCount = (int) cmd.getSamplesCount(); updateWithStreamTime(); return true; } else if (AMMod::MsgConfigureAMMod::match(message)) { - const AMMod::MsgConfigureAMMod& cfg = (AMMod::MsgConfigureAMMod&) message; + auto& cfg = (const AMMod::MsgConfigureAMMod&) message; m_settings = cfg.getSettings(); blockApplySettings(true); m_channelMarker.updateSettings(static_cast(m_settings.m_channelMarker)); @@ -106,14 +108,14 @@ bool AMModGUI::handleMessage(const Message& message) } else if (CWKeyer::MsgConfigureCWKeyer::match(message)) { - const CWKeyer::MsgConfigureCWKeyer& cfg = (CWKeyer::MsgConfigureCWKeyer&) message; + auto& cfg = (const CWKeyer::MsgConfigureCWKeyer&) message; ui->cwKeyerGUI->setSettings(cfg.getSettings()); ui->cwKeyerGUI->displaySettings(); return true; } else if (DSPSignalNotification::match(message)) { - const DSPSignalNotification& notif = (const DSPSignalNotification&) message; + auto& notif = (const DSPSignalNotification&) message; m_deviceCenterFrequency = notif.getCenterFrequency(); m_basebandSampleRate = notif.getSampleRate(); ui->deltaFrequency->setValueRange(false, 7, -m_basebandSampleRate/2, m_basebandSampleRate/2); @@ -138,7 +140,7 @@ void AMModGUI::handleSourceMessages() { Message* message; - while ((message = getInputMessageQueue()->pop()) != 0) + while ((message = getInputMessageQueue()->pop()) != nullptr) { if (handleMessage(*message)) { @@ -149,7 +151,7 @@ void AMModGUI::handleSourceMessages() void AMModGUI::on_deltaFrequency_changed(qint64 value) { - m_channelMarker.setCenterFrequency(value); + m_channelMarker.setCenterFrequency((int) value); m_settings.m_inputFrequencyOffset = value; updateAbsoluteCenterFrequency(); applySettings(); @@ -158,7 +160,7 @@ void AMModGUI::on_deltaFrequency_changed(qint64 value) void AMModGUI::on_rfBW_valueChanged(int value) { ui->rfBWText->setText(QString("%1 kHz").arg(value / 10.0, 0, 'f', 1)); - m_settings.m_rfBandwidth = value * 100.0; + m_settings.m_rfBandwidth = (float) value * 100.0f; m_channelMarker.setBandwidth(value * 100); applySettings(); } @@ -166,21 +168,21 @@ void AMModGUI::on_rfBW_valueChanged(int value) void AMModGUI::on_modPercent_valueChanged(int value) { ui->modPercentText->setText(QString("%1").arg(value)); - m_settings.m_modFactor = value / 100.0; + m_settings.m_modFactor = (float) value / 100.0f; applySettings(); } void AMModGUI::on_volume_valueChanged(int value) { ui->volumeText->setText(QString("%1").arg(value / 10.0, 0, 'f', 1)); - m_settings.m_volumeFactor = value / 10.0; + m_settings.m_volumeFactor = (float) value / 10.0f; applySettings(); } void AMModGUI::on_toneFrequency_valueChanged(int value) { ui->toneFrequencyText->setText(QString("%1k").arg(value / 100.0, 0, 'f', 2)); - m_settings.m_toneFrequency = value * 10.0; + m_settings.m_toneFrequency = (float) value * 10.0f; applySettings(); } @@ -244,7 +246,7 @@ void AMModGUI::on_feedbackEnable_toggled(bool checked) void AMModGUI::on_feedbackVolume_valueChanged(int value) { ui->feedbackVolumeText->setText(QString("%1").arg(value / 100.0, 0, 'f', 2)); - m_settings.m_feedbackVolumeFactor = value / 100.0; + m_settings.m_feedbackVolumeFactor = (float) value / 100.0f; applySettings(); } @@ -265,7 +267,7 @@ void AMModGUI::on_showFileDialog_clicked(bool checked) { (void) checked; QString fileName = QFileDialog::getOpenFileName(this, - tr("Open raw audio file"), ".", tr("Raw audio Files (*.raw)"), 0, QFileDialog::DontUseNativeDialog); + tr("Open raw audio file"), ".", tr("Raw audio Files (*.raw)"), nullptr, QFileDialog::DontUseNativeDialog); if (fileName != "") { @@ -283,7 +285,7 @@ void AMModGUI::configureFileName() m_amMod->getInputMessageQueue()->push(message); } -void AMModGUI::onWidgetRolled(QWidget* widget, bool rollDown) +void AMModGUI::onWidgetRolled(const QWidget* widget, bool rollDown) { (void) widget; (void) rollDown; @@ -367,15 +369,15 @@ AMModGUI::AMModGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, BasebandSampl connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(onMenuDialogCalled(const QPoint &))); m_amMod = (AMMod*) channelTx; - m_amMod->setMessageQueueToGUI(getInputMessageQueue()); + m_amMod->setMessageQueueToGUI(AMModGUI::getInputMessageQueue()); connect(&MainCore::instance()->getMasterTimer(), SIGNAL(timeout()), this, SLOT(tick())); - CRightClickEnabler *audioMuteRightClickEnabler = new CRightClickEnabler(ui->mic); - connect(audioMuteRightClickEnabler, SIGNAL(rightClick(const QPoint &)), this, SLOT(audioSelect(const QPoint &))); + m_audioMuteRightClickEnabler = new CRightClickEnabler(ui->mic); + connect(m_audioMuteRightClickEnabler, SIGNAL(rightClick(const QPoint &)), this, SLOT(audioSelect(const QPoint &))); - CRightClickEnabler *feedbackRightClickEnabler = new CRightClickEnabler(ui->feedbackEnable); - connect(feedbackRightClickEnabler, SIGNAL(rightClick(const QPoint &)), this, SLOT(audioFeedbackSelect(const QPoint &))); + m_feedbackRightClickEnabler = new CRightClickEnabler(ui->feedbackEnable); + connect(m_feedbackRightClickEnabler, SIGNAL(rightClick(const QPoint &)), this, SLOT(audioFeedbackSelect(const QPoint &))); ui->deltaFrequencyLabel->setText(QString("%1f").arg(QChar(0x94, 0x03))); ui->deltaFrequency->setColorMapper(ColorMapper(ColorMapper::GrayGold)); @@ -406,7 +408,7 @@ AMModGUI::AMModGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, BasebandSampl ui->cwKeyerGUI->setCWKeyer(m_amMod->getCWKeyer()); - connect(getInputMessageQueue(), SIGNAL(messageEnqueued()), this, SLOT(handleSourceMessages())); + connect(AMModGUI::getInputMessageQueue(), SIGNAL(messageEnqueued()), this, SLOT(handleSourceMessages())); m_amMod->setLevelMeter(ui->volumeMeter); displaySettings(); @@ -419,6 +421,8 @@ AMModGUI::AMModGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, BasebandSampl AMModGUI::~AMModGUI() { delete ui; + delete m_audioMuteRightClickEnabler; + delete m_feedbackRightClickEnabler; } void AMModGUI::blockApplySettings(bool block) @@ -439,9 +443,9 @@ void AMModGUI::applySettings(bool force) void AMModGUI::displaySettings() { m_channelMarker.blockSignals(true); - m_channelMarker.setCenterFrequency(m_settings.m_inputFrequencyOffset); + m_channelMarker.setCenterFrequency((int) m_settings.m_inputFrequencyOffset); m_channelMarker.setTitle(m_settings.m_title); - m_channelMarker.setBandwidth(m_settings.m_rfBandwidth); + m_channelMarker.setBandwidth((int) m_settings.m_rfBandwidth); m_channelMarker.blockSignals(false); m_channelMarker.setColor(m_settings.m_rgbColor); // activate signal on the last setting only @@ -453,17 +457,17 @@ void AMModGUI::displaySettings() ui->deltaFrequency->setValue(m_channelMarker.getCenterFrequency()); - ui->rfBW->setValue(roundf(m_settings.m_rfBandwidth / 100.0)); + ui->rfBW->setValue((int) roundf(m_settings.m_rfBandwidth / 100.f)); ui->rfBWText->setText(QString("%1 kHz").arg(m_settings.m_rfBandwidth / 1000.0, 0, 'f', 1)); - int modPercent = roundf(m_settings.m_modFactor * 100.0); + auto modPercent = (int) roundf(m_settings.m_modFactor * 100.0f); ui->modPercent->setValue(modPercent); ui->modPercentText->setText(QString("%1").arg(modPercent)); - ui->toneFrequency->setValue(roundf(m_settings.m_toneFrequency / 10.0)); + ui->toneFrequency->setValue((int) roundf(m_settings.m_toneFrequency / 10.0f)); ui->toneFrequencyText->setText(QString("%1k").arg(m_settings.m_toneFrequency / 1000.0, 0, 'f', 2)); - ui->volume->setValue(roundf(m_settings.m_volumeFactor * 10.0)); + ui->volume->setValue((int) roundf(m_settings.m_volumeFactor * 10.0f)); ui->volumeText->setText(QString("%1").arg(m_settings.m_volumeFactor, 0, 'f', 1)); ui->channelMute->setChecked(m_settings.m_channelMute); @@ -480,7 +484,7 @@ void AMModGUI::displaySettings() ui->morseKeyer->setChecked(m_settings.m_modAFInput == AMModSettings::AMModInputAF::AMModInputCWTone); ui->feedbackEnable->setChecked(m_settings.m_feedbackAudioEnable); - ui->feedbackVolume->setValue(roundf(m_settings.m_feedbackVolumeFactor * 100.0)); + ui->feedbackVolume->setValue((int) roundf(m_settings.m_feedbackVolumeFactor * 100.0f)); ui->feedbackVolumeText->setText(QString("%1").arg(m_settings.m_feedbackVolumeFactor, 0, 'f', 2)); updateIndexLabel(); @@ -605,7 +609,7 @@ void AMModGUI::updateWithStreamTime() } } -void AMModGUI::makeUIConnections() +void AMModGUI::makeUIConnections() const { QObject::connect(ui->deltaFrequency, &ValueDialZ::changed, this, &AMModGUI::on_deltaFrequency_changed); QObject::connect(ui->rfBW, &QSlider::valueChanged, this, &AMModGUI::on_rfBW_valueChanged); diff --git a/plugins/channeltx/modam/ammodgui.h b/plugins/channeltx/modam/ammodgui.h index 7c4220c52..1ee214775 100644 --- a/plugins/channeltx/modam/ammodgui.h +++ b/plugins/channeltx/modam/ammodgui.h @@ -33,6 +33,7 @@ class DeviceUISet; class AMMod; class BasebandSampleSource; +class CRightClickEnabler; namespace Ui { class AMModGUI; @@ -45,21 +46,21 @@ public: static AMModGUI* create(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, BasebandSampleSource *channelTx); virtual void destroy(); - void resetToDefaults(); - QByteArray serialize() const; - bool deserialize(const QByteArray& data); - virtual MessageQueue *getInputMessageQueue() { return &m_inputMessageQueue; } - virtual void setWorkspaceIndex(int index) { m_settings.m_workspaceIndex = index; }; - virtual int getWorkspaceIndex() const { return m_settings.m_workspaceIndex; }; - virtual void setGeometryBytes(const QByteArray& blob) { m_settings.m_geometryBytes = blob; }; - virtual QByteArray getGeometryBytes() const { return m_settings.m_geometryBytes; }; - virtual QString getTitle() const { return m_settings.m_title; }; - virtual QColor getTitleColor() const { return m_settings.m_rgbColor; }; - virtual void zetHidden(bool hidden) { m_settings.m_hidden = hidden; } - virtual bool getHidden() const { return m_settings.m_hidden; } - virtual ChannelMarker& getChannelMarker() { return m_channelMarker; } - virtual int getStreamIndex() const { return m_settings.m_streamIndex; } - virtual void setStreamIndex(int streamIndex) { m_settings.m_streamIndex = streamIndex; } + void resetToDefaults() final; + QByteArray serialize() const final; + bool deserialize(const QByteArray& data) final; + MessageQueue *getInputMessageQueue() final { return &m_inputMessageQueue; } + void setWorkspaceIndex(int index) final { m_settings.m_workspaceIndex = index; }; + int getWorkspaceIndex() const final { return m_settings.m_workspaceIndex; }; + void setGeometryBytes(const QByteArray& blob) final { m_settings.m_geometryBytes = blob; }; + QByteArray getGeometryBytes() const final { return m_settings.m_geometryBytes; }; + QString getTitle() const final { return m_settings.m_title; }; + QColor getTitleColor() const final { return m_settings.m_rgbColor; }; + void zetHidden(bool hidden) final { m_settings.m_hidden = hidden; } + bool getHidden() const final { return m_settings.m_hidden; } + ChannelMarker& getChannelMarker() final { return m_channelMarker; } + int getStreamIndex() const final { return m_settings.m_streamIndex; } + void setStreamIndex(int streamIndex) final { m_settings.m_streamIndex = streamIndex; } public slots: void channelMarkerChangedByCursor(); @@ -75,6 +76,9 @@ private: int m_basebandSampleRate; bool m_doApplySettings; + CRightClickEnabler *m_audioMuteRightClickEnabler; + CRightClickEnabler *m_feedbackRightClickEnabler; + AMMod* m_amMod; MovingAverageUtil m_channelPowerDbAvg; @@ -88,8 +92,8 @@ private: bool m_enableNavTime; MessageQueue m_inputMessageQueue; - explicit AMModGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, BasebandSampleSource *channelTx, QWidget* parent = 0); - virtual ~AMModGUI(); + explicit AMModGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, BasebandSampleSource *channelTx, QWidget* parent = nullptr); + ~AMModGUI() final; void blockApplySettings(bool block); void applySettings(bool force = false); @@ -97,11 +101,11 @@ private: void updateWithStreamData(); void updateWithStreamTime(); bool handleMessage(const Message& message); - void makeUIConnections(); + void makeUIConnections() const; void updateAbsoluteCenterFrequency(); - void leaveEvent(QEvent*); - void enterEvent(EnterEventType*); + void leaveEvent(QEvent*) final; + void enterEvent(EnterEventType*) final; private slots: void handleSourceMessages(); @@ -124,7 +128,7 @@ private slots: void on_feedbackEnable_toggled(bool checked); void on_feedbackVolume_valueChanged(int value); - void onWidgetRolled(QWidget* widget, bool rollDown); + void onWidgetRolled(const QWidget* widget, bool rollDown); void onMenuDialogCalled(const QPoint& p); void configureFileName(); diff --git a/plugins/channeltx/modam/ammodplugin.cpp b/plugins/channeltx/modam/ammodplugin.cpp index 669f53928..dcb20f7c1 100644 --- a/plugins/channeltx/modam/ammodplugin.cpp +++ b/plugins/channeltx/modam/ammodplugin.cpp @@ -41,7 +41,7 @@ const PluginDescriptor AMModPlugin::m_pluginDescriptor = { AMModPlugin::AMModPlugin(QObject* parent) : QObject(parent), - m_pluginAPI(0) + m_pluginAPI(nullptr) { } @@ -62,7 +62,7 @@ void AMModPlugin::createTxChannel(DeviceAPI *deviceAPI, BasebandSampleSource **b { if (bs || cs) { - AMMod *instance = new AMMod(deviceAPI); + auto *instance = new AMMod(deviceAPI); if (bs) { *bs = instance; diff --git a/plugins/channeltx/modam/ammodplugin.h b/plugins/channeltx/modam/ammodplugin.h index 25feb8fe3..d3acb5a6d 100644 --- a/plugins/channeltx/modam/ammodplugin.h +++ b/plugins/channeltx/modam/ammodplugin.h @@ -27,20 +27,20 @@ class DeviceUISet; class BasebandSampleSource; -class AMModPlugin : public QObject, PluginInterface { +class AMModPlugin : public QObject, public PluginInterface { Q_OBJECT Q_INTERFACES(PluginInterface) Q_PLUGIN_METADATA(IID "sdrangel.channeltx.ammod") public: - explicit AMModPlugin(QObject* parent = 0); + explicit AMModPlugin(QObject* parent = nullptr); - const PluginDescriptor& getPluginDescriptor() const; - void initPlugin(PluginAPI* pluginAPI); + const PluginDescriptor& getPluginDescriptor() const final; + void initPlugin(PluginAPI* pluginAPI) final; - virtual void createTxChannel(DeviceAPI *deviceAPI, BasebandSampleSource **bs, ChannelAPI **cs) const; - virtual ChannelGUI* createTxChannelGUI(DeviceUISet *deviceUISet, BasebandSampleSource *txChannel) const; - virtual ChannelWebAPIAdapter* createChannelWebAPIAdapter() const; + void createTxChannel(DeviceAPI *deviceAPI, BasebandSampleSource **bs, ChannelAPI **cs) const final; + ChannelGUI* createTxChannelGUI(DeviceUISet *deviceUISet, BasebandSampleSource *txChannel) const final; + ChannelWebAPIAdapter* createChannelWebAPIAdapter() const final; private: static const PluginDescriptor m_pluginDescriptor; diff --git a/plugins/channeltx/modam/ammodsource.cpp b/plugins/channeltx/modam/ammodsource.cpp index 01921618c..5277c145f 100644 --- a/plugins/channeltx/modam/ammodsource.cpp +++ b/plugins/channeltx/modam/ammodsource.cpp @@ -28,16 +28,8 @@ const int AMModSource::m_levelNbSamples = 480; // every 10ms AMModSource::AMModSource() : - m_channelSampleRate(48000), - m_channelFrequencyOffset(0), - m_audioSampleRate(48000), m_audioFifo(12000), - m_feedbackAudioFifo(48000), - m_levelCalcCount(0), - m_peakLevel(0.0f), - m_levelSum(0.0f), - m_ifstream(nullptr), - m_cwKeyer(nullptr) + m_feedbackAudioFifo(48000) { m_audioFifo.setLabel("AMModSource.m_audioFifo"); m_feedbackAudioFifo.setLabel("AMModSource.m_feedbackAudioFifo"); @@ -57,9 +49,7 @@ AMModSource::AMModSource() : applyChannelSettings(m_channelSampleRate, m_channelFrequencyOffset, true); } -AMModSource::~AMModSource() -{ -} +AMModSource::~AMModSource() = default; void AMModSource::pull(SampleVector::iterator begin, unsigned int nbSamples) { @@ -111,7 +101,7 @@ void AMModSource::pullOne(Sample& sample) sample.m_real = (FixReal) ci.real(); sample.m_imag = (FixReal) ci.imag(); - m_demodBuffer[m_demodBufferFill] = ci.real() + ci.imag(); + m_demodBuffer[m_demodBufferFill] = (qint16) (ci.real() + ci.imag()); ++m_demodBufferFill; if (m_demodBufferFill >= m_demodBuffer.size()) @@ -119,13 +109,11 @@ void AMModSource::pullOne(Sample& sample) QList dataPipes; MainCore::instance()->getDataPipes().getDataPipes(m_channel, "demod", dataPipes); - if (dataPipes.size() > 0) + if (!dataPipes.empty()) { - QList::iterator it = dataPipes.begin(); - - for (; it != dataPipes.end(); ++it) + for (auto& dataPipe : dataPipes) { - DataFifo *fifo = qobject_cast((*it)->m_element); + DataFifo *fifo = qobject_cast(dataPipe->m_element); if (fifo) { fifo->write((quint8*) &m_demodBuffer[0], m_demodBuffer.size() * sizeof(qint16), DataFifo::DataTypeI16); @@ -139,7 +127,7 @@ void AMModSource::pullOne(Sample& sample) void AMModSource::prefetch(unsigned int nbSamples) { - unsigned int nbSamplesAudio = nbSamples * ((Real) m_audioSampleRate / (Real) m_channelSampleRate); + auto nbSamplesAudio = (nbSamples * (unsigned int) ((Real) m_audioSampleRate / (Real) m_channelSampleRate)); pullAudio(nbSamplesAudio); } @@ -163,7 +151,7 @@ void AMModSource::pullAudio(unsigned int nbSamples) void AMModSource::modulateSample() { - Real t; + Real t = 0.0f; pullAF(t); @@ -186,17 +174,12 @@ void AMModSource::pullAF(Real& sample) sample = m_toneNco.next(); break; case AMModSettings::AMModInputFile: - // sox f4exb_call.wav --encoding float --endian little f4exb_call.raw - // ffplay -f f32le -ar 48k -ac 1 f4exb_call.raw if (m_ifstream && m_ifstream->is_open()) { - if (m_ifstream->eof()) + if ((m_ifstream->eof()) && (m_settings.m_playLoop)) { - if (m_settings.m_playLoop) - { - m_ifstream->clear(); - m_ifstream->seekg(0, std::ios::beg); - } + m_ifstream->clear(); + m_ifstream->seekg(0, std::ios::beg); } if (m_ifstream->eof()) @@ -242,7 +225,6 @@ void AMModSource::pullAF(Real& sample) } } break; - case AMModSettings::AMModInputNone: default: sample = 0.0f; break; @@ -272,10 +254,10 @@ void AMModSource::pushFeedback(Real sample) } } -void AMModSource::processOneSample(Complex& ci) +void AMModSource::processOneSample(const Complex& ci) { - m_feedbackAudioBuffer[m_feedbackAudioBufferFill].l = ci.real(); - m_feedbackAudioBuffer[m_feedbackAudioBufferFill].r = ci.imag(); + m_feedbackAudioBuffer[m_feedbackAudioBufferFill].l = (qint16) ci.real(); + m_feedbackAudioBuffer[m_feedbackAudioBufferFill].r = (qint16) ci.imag(); ++m_feedbackAudioBufferFill; if (m_feedbackAudioBufferFill >= m_feedbackAudioBuffer.size()) @@ -293,7 +275,7 @@ void AMModSource::processOneSample(Complex& ci) } } -void AMModSource::calculateLevel(Real& sample) +void AMModSource::calculateLevel(const Real& sample) { if (m_levelCalcCount < m_levelNbSamples) { @@ -325,7 +307,7 @@ void AMModSource::applyAudioSampleRate(int sampleRate) m_interpolatorConsumed = false; m_interpolatorDistance = (Real) sampleRate / (Real) m_channelSampleRate; m_interpolator.create(48, sampleRate, m_settings.m_rfBandwidth / 2.2, 3.0); - m_toneNco.setFreq(m_settings.m_toneFrequency, sampleRate); + m_toneNco.setFreq(m_settings.m_toneFrequency, (float) sampleRate); if (m_cwKeyer) { @@ -336,7 +318,7 @@ void AMModSource::applyAudioSampleRate(int sampleRate) QList pipes; MainCore::instance()->getMessagePipes().getMessagePipes(m_channel, "reportdemod", pipes); - if (pipes.size() > 0) + if (!pipes.empty()) { for (const auto& pipe : pipes) { @@ -362,7 +344,7 @@ void AMModSource::applyFeedbackAudioSampleRate(int sampleRate) m_feedbackInterpolatorDistanceRemain = 0; m_feedbackInterpolatorDistance = (Real) sampleRate / (Real) m_audioSampleRate; - Real cutoff = std::min(sampleRate, m_audioSampleRate) / 2.2f; + Real cutoff = ((float) std::min(sampleRate, m_audioSampleRate)) / 2.2f; m_feedbackInterpolator.create(48, sampleRate, cutoff, 3.0); m_feedbackAudioSampleRate = sampleRate; } @@ -375,9 +357,8 @@ void AMModSource::applySettings(const AMModSettings& settings, bool force) applyAudioSampleRate(m_audioSampleRate); } - if ((settings.m_toneFrequency != m_settings.m_toneFrequency) || force) - { - m_toneNco.setFreq(settings.m_toneFrequency, m_audioSampleRate); + if ((settings.m_toneFrequency != m_settings.m_toneFrequency) || force) { + m_toneNco.setFreq(settings.m_toneFrequency, (float) m_audioSampleRate); } if ((settings.m_modAFInput != m_settings.m_modAFInput) || force) @@ -401,7 +382,7 @@ void AMModSource::applyChannelSettings(int channelSampleRate, int channelFrequen if ((channelFrequencyOffset != m_channelFrequencyOffset) || (channelSampleRate != m_channelSampleRate) || force) { - m_carrierNco.setFreq(channelFrequencyOffset, channelSampleRate); + m_carrierNco.setFreq((float) channelFrequencyOffset, (float) channelSampleRate); } if ((channelSampleRate != m_channelSampleRate) || force) @@ -418,7 +399,6 @@ void AMModSource::applyChannelSettings(int channelSampleRate, int channelFrequen void AMModSource::handleAudio() { - QMutexLocker mlock(&m_mutex); unsigned int nbRead; while ((nbRead = m_audioFifo.read(reinterpret_cast(&m_audioReadBuffer[m_audioReadBufferFill]), 4096)) != 0) diff --git a/plugins/channeltx/modam/ammodsource.h b/plugins/channeltx/modam/ammodsource.h index a032ff774..bcec5d7b2 100644 --- a/plugins/channeltx/modam/ammodsource.h +++ b/plugins/channeltx/modam/ammodsource.h @@ -43,11 +43,11 @@ class AMModSource : public QObject, public ChannelSampleSource Q_OBJECT public: AMModSource(); - virtual ~AMModSource(); + ~AMModSource() final; - virtual void pull(SampleVector::iterator begin, unsigned int nbSamples); - virtual void pullOne(Sample& sample); - virtual void prefetch(unsigned int nbSamples); + void pull(SampleVector::iterator begin, unsigned int nbSamples) final; + void pullOne(Sample& sample) final; + void prefetch(unsigned int nbSamples) final; void setInputFileStream(std::ifstream *ifstream) { m_ifstream = ifstream; } AudioFifo *getAudioFifo() { return &m_audioFifo; } @@ -70,8 +70,8 @@ public: void applyChannelSettings(int channelSampleRate, int channelFrequencyOffset, bool force = false); private: - int m_channelSampleRate; - int m_channelFrequencyOffset; + int m_channelSampleRate = 48000; + int m_channelFrequencyOffset = 0; AMModSettings m_settings; ChannelAPI *m_channel; @@ -91,7 +91,7 @@ private: double m_magsq; MovingAverageUtil m_movingAverage; - int m_audioSampleRate; + int m_audioSampleRate = 48000; AudioVector m_audioBuffer; unsigned int m_audioBufferFill; AudioVector m_audioReadBuffer; @@ -106,24 +106,24 @@ private: int m_demodBufferFill; bool m_demodBufferEnabled; - quint32 m_levelCalcCount; + quint32 m_levelCalcCount = 0; qreal m_rmsLevel; qreal m_peakLevelOut; - Real m_peakLevel; - Real m_levelSum; + Real m_peakLevel = 0.0f; + Real m_levelSum = 0.0f; - std::ifstream *m_ifstream; - CWKeyer *m_cwKeyer; + std::ifstream *m_ifstream = nullptr; + CWKeyer *m_cwKeyer = nullptr; QRecursiveMutex m_mutex; static const int m_levelNbSamples; - void processOneSample(Complex& ci); + void processOneSample(const Complex& ci); void pullAF(Real& sample); void pullAudio(unsigned int nbSamples); void pushFeedback(Real sample); - void calculateLevel(Real& sample); + void calculateLevel(const Real& sample); void modulateSample(); private slots: diff --git a/plugins/channeltx/modnfm/nfmmod.cpp b/plugins/channeltx/modnfm/nfmmod.cpp index dc4b0d549..2a2dbb94b 100644 --- a/plugins/channeltx/modnfm/nfmmod.cpp +++ b/plugins/channeltx/modnfm/nfmmod.cpp @@ -56,12 +56,7 @@ const char* const NFMMod::m_channelId = "NFMMod"; NFMMod::NFMMod(DeviceAPI *deviceAPI) : ChannelAPI(m_channelIdURI, ChannelAPI::StreamSingleSource), - m_deviceAPI(deviceAPI), - m_running(false), - m_fileSize(0), - m_recordLength(0), - m_sampleRate(48000), - m_levelMeter(nullptr) + m_deviceAPI(deviceAPI) { setObjectName(m_channelId); @@ -91,7 +86,7 @@ NFMMod::~NFMMod() m_deviceAPI->removeChannelSourceAPI(this); m_deviceAPI->removeChannelSource(this); - stop(); + NFMMod::stop(); } void NFMMod::setDeviceAPI(DeviceAPI *deviceAPI) @@ -182,7 +177,7 @@ bool NFMMod::handleMessage(const Message& cmd) { if (MsgConfigureNFMMod::match(cmd)) { - MsgConfigureNFMMod& cfg = (MsgConfigureNFMMod&) cmd; + auto& cfg = (const MsgConfigureNFMMod&) cmd; qDebug() << "NFMMod::handleMessage: MsgConfigureNFMMod"; applySettings(cfg.getSettings(), cfg.getForce()); @@ -191,7 +186,7 @@ bool NFMMod::handleMessage(const Message& cmd) } else if (MsgConfigureFileSourceName::match(cmd)) { - MsgConfigureFileSourceName& conf = (MsgConfigureFileSourceName&) cmd; + auto& conf = (const MsgConfigureFileSourceName&) cmd; m_fileName = conf.getFileName(); openFileStream(); qDebug() << "NFMMod::handleMessage: MsgConfigureFileSourceName:" @@ -200,7 +195,7 @@ bool NFMMod::handleMessage(const Message& cmd) } else if (MsgConfigureFileSourceSeek::match(cmd)) { - MsgConfigureFileSourceSeek& conf = (MsgConfigureFileSourceSeek&) cmd; + auto& conf = (const MsgConfigureFileSourceSeek&) cmd; int seekPercentage = conf.getPercentage(); seekFileStream(seekPercentage); qDebug() << "NFMMod::handleMessage: MsgConfigureFileSourceSeek:" @@ -226,7 +221,7 @@ bool NFMMod::handleMessage(const Message& cmd) } else if (MsgConfigureFileSourceName::match(cmd)) { - MsgConfigureFileSourceName& conf = (MsgConfigureFileSourceName&) cmd; + auto& conf = (const MsgConfigureFileSourceName&) cmd; m_fileName = conf.getFileName(); openFileStream(); qDebug() << "NFMMod::handleMessage: MsgConfigureFileSourceName:" @@ -235,7 +230,7 @@ bool NFMMod::handleMessage(const Message& cmd) } else if (MsgConfigureFileSourceSeek::match(cmd)) { - MsgConfigureFileSourceSeek& conf = (MsgConfigureFileSourceSeek&) cmd; + auto& conf = (const MsgConfigureFileSourceSeek&) cmd; int seekPercentage = conf.getPercentage(); seekFileStream(seekPercentage); qDebug() << "NFMMod::handleMessage: MsgConfigureFileSourceSeek:" @@ -261,7 +256,7 @@ bool NFMMod::handleMessage(const Message& cmd) } else if (CWKeyer::MsgConfigureCWKeyer::match(cmd)) { - const CWKeyer::MsgConfigureCWKeyer& cfg = (CWKeyer::MsgConfigureCWKeyer&) cmd; + auto& cfg = (const CWKeyer::MsgConfigureCWKeyer&) cmd; if (m_settings.m_useReverseAPI) { webapiReverseSendCWSettings(cfg.getSettings()); @@ -274,8 +269,8 @@ bool NFMMod::handleMessage(const Message& cmd) // Forward to the source if (m_running) { - DSPSignalNotification& notif = (DSPSignalNotification&) cmd; - DSPSignalNotification* rep = new DSPSignalNotification(notif); // make a copy + auto& notif = (const DSPSignalNotification&) cmd; + auto* rep = new DSPSignalNotification(notif); // make a copy qDebug() << "NFMMod::handleMessage: DSPSignalNotification"; m_basebandSource->getInputMessageQueue()->push(rep); // Forward to GUI if any @@ -310,7 +305,7 @@ void NFMMod::openFileStream() m_ifstream.seekg(0,std::ios_base::beg); m_sampleRate = 48000; // fixed rate - m_recordLength = m_fileSize / (sizeof(Real) * m_sampleRate); + m_recordLength = (quint32) (m_fileSize / (sizeof(Real) * m_sampleRate)); qDebug() << "NFMMod::openFileStream: " << m_fileName.toStdString().c_str() << " fileSize: " << m_fileSize << "bytes" @@ -444,7 +439,7 @@ void NFMMod::applySettings(const NFMModSettings& settings, bool force) QList pipes; MainCore::instance()->getMessagePipes().getMessagePipes(this, "settings", pipes); - if (pipes.size() > 0) { + if (!pipes.empty()) { sendChannelSettings(pipes, reverseAPIKeys, settings, force); } @@ -472,12 +467,12 @@ bool NFMMod::deserialize(const QByteArray& data) return success; } -void NFMMod::sendSampleRateToDemodAnalyzer() +void NFMMod::sendSampleRateToDemodAnalyzer() const { QList pipes; MainCore::instance()->getMessagePipes().getMessagePipes(this, "reportdemod", pipes); - if (pipes.size() > 0) + if (!pipes.empty()) { for (const auto& pipe : pipes) { @@ -625,13 +620,13 @@ void NFMMod::webapiUpdateChannelSettings( settings.m_reverseAPIAddress = *response.getNfmModSettings()->getReverseApiAddress(); } if (channelSettingsKeys.contains("reverseAPIPort")) { - settings.m_reverseAPIPort = response.getNfmModSettings()->getReverseApiPort(); + settings.m_reverseAPIPort = (uint16_t) response.getNfmModSettings()->getReverseApiPort(); } if (channelSettingsKeys.contains("reverseAPIDeviceIndex")) { - settings.m_reverseAPIDeviceIndex = response.getNfmModSettings()->getReverseApiDeviceIndex(); + settings.m_reverseAPIDeviceIndex = (uint16_t) response.getNfmModSettings()->getReverseApiDeviceIndex(); } if (channelSettingsKeys.contains("reverseAPIChannelIndex")) { - settings.m_reverseAPIChannelIndex = response.getNfmModSettings()->getReverseApiChannelIndex(); + settings.m_reverseAPIChannelIndex = (uint16_t) response.getNfmModSettings()->getReverseApiChannelIndex(); } if (settings.m_channelMarker && channelSettingsKeys.contains("channelMarker")) { settings.m_channelMarker->updateFrom(channelSettingsKeys, response.getNfmModSettings()->getChannelMarker()); @@ -709,7 +704,7 @@ void NFMMod::webapiFormatChannelSettings(SWGSDRangel::SWGChannelSettings& respon } else { - SWGSDRangel::SWGChannelMarker *swgChannelMarker = new SWGSDRangel::SWGChannelMarker(); + auto *swgChannelMarker = new SWGSDRangel::SWGChannelMarker(); settings.m_channelMarker->formatTo(swgChannelMarker); response.getNfmModSettings()->setChannelMarker(swgChannelMarker); } @@ -723,16 +718,16 @@ void NFMMod::webapiFormatChannelSettings(SWGSDRangel::SWGChannelSettings& respon } else { - SWGSDRangel::SWGRollupState *swgRollupState = new SWGSDRangel::SWGRollupState(); + auto *swgRollupState = new SWGSDRangel::SWGRollupState(); settings.m_rollupState->formatTo(swgRollupState); response.getNfmModSettings()->setRollupState(swgRollupState); } } } -void NFMMod::webapiFormatChannelReport(SWGSDRangel::SWGChannelReport& response) +void NFMMod::webapiFormatChannelReport(SWGSDRangel::SWGChannelReport& response) const { - response.getNfmModReport()->setChannelPowerDb(CalcDb::dbPower(getMagSq())); + response.getNfmModReport()->setChannelPowerDb((float) CalcDb::dbPower(getMagSq())); if (m_running) { @@ -741,9 +736,9 @@ void NFMMod::webapiFormatChannelReport(SWGSDRangel::SWGChannelReport& response) } } -void NFMMod::webapiReverseSendSettings(QList& channelSettingsKeys, const NFMModSettings& settings, bool force) +void NFMMod::webapiReverseSendSettings(const QList& channelSettingsKeys, const NFMModSettings& settings, bool force) { - SWGSDRangel::SWGChannelSettings *swgChannelSettings = new SWGSDRangel::SWGChannelSettings(); + auto *swgChannelSettings = new SWGSDRangel::SWGChannelSettings(); webapiFormatChannelSettings(channelSettingsKeys, swgChannelSettings, settings, force); QString channelSettingsURL = QString("http://%1:%2/sdrangel/deviceset/%3/channel/%4/settings") @@ -754,8 +749,8 @@ void NFMMod::webapiReverseSendSettings(QList& channelSettingsKeys, cons m_networkRequest.setUrl(QUrl(channelSettingsURL)); m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); - QBuffer *buffer = new QBuffer(); - buffer->open((QBuffer::ReadWrite)); + auto *buffer = new QBuffer(); + buffer->open(QBuffer::ReadWrite); buffer->write(swgChannelSettings->asJson().toUtf8()); buffer->seek(0); @@ -768,7 +763,7 @@ void NFMMod::webapiReverseSendSettings(QList& channelSettingsKeys, cons void NFMMod::webapiReverseSendCWSettings(const CWKeyerSettings& cwKeyerSettings) { - SWGSDRangel::SWGChannelSettings *swgChannelSettings = new SWGSDRangel::SWGChannelSettings(); + auto *swgChannelSettings = new SWGSDRangel::SWGChannelSettings(); swgChannelSettings->setDirection(1); // single source (Tx) swgChannelSettings->setChannelType(new QString("NFMMod")); swgChannelSettings->setNfmModSettings(new SWGSDRangel::SWGNFMModSettings()); @@ -776,7 +771,7 @@ void NFMMod::webapiReverseSendCWSettings(const CWKeyerSettings& cwKeyerSettings) swgNFModSettings->setCwKeyer(new SWGSDRangel::SWGCWKeyerSettings()); SWGSDRangel::SWGCWKeyerSettings *apiCwKeyerSettings = swgNFModSettings->getCwKeyer(); - getCWKeyer()->webapiFormatChannelSettings(apiCwKeyerSettings, cwKeyerSettings); + CWKeyer::webapiFormatChannelSettings(apiCwKeyerSettings, cwKeyerSettings); QString channelSettingsURL = QString("http://%1:%2/sdrangel/deviceset/%3/channel/%4/settings") .arg(m_settings.m_reverseAPIAddress) @@ -786,8 +781,8 @@ void NFMMod::webapiReverseSendCWSettings(const CWKeyerSettings& cwKeyerSettings) m_networkRequest.setUrl(QUrl(channelSettingsURL)); m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); - QBuffer *buffer = new QBuffer(); - buffer->open((QBuffer::ReadWrite)); + auto *buffer = new QBuffer(); + buffer->open(QBuffer::ReadWrite); buffer->write(swgChannelSettings->asJson().toUtf8()); buffer->seek(0); @@ -800,7 +795,7 @@ void NFMMod::webapiReverseSendCWSettings(const CWKeyerSettings& cwKeyerSettings) void NFMMod::sendChannelSettings( const QList& pipes, - QList& channelSettingsKeys, + const QList& channelSettingsKeys, const NFMModSettings& settings, bool force) { @@ -810,7 +805,7 @@ void NFMMod::sendChannelSettings( if (messageQueue) { - SWGSDRangel::SWGChannelSettings *swgChannelSettings = new SWGSDRangel::SWGChannelSettings(); + auto *swgChannelSettings = new SWGSDRangel::SWGChannelSettings(); webapiFormatChannelSettings(channelSettingsKeys, swgChannelSettings, settings, force); MainCore::MsgChannelSettings *msg = MainCore::MsgChannelSettings::create( this, @@ -824,7 +819,7 @@ void NFMMod::sendChannelSettings( } void NFMMod::webapiFormatChannelSettings( - QList& channelSettingsKeys, + const QList& channelSettingsKeys, SWGSDRangel::SWGChannelSettings *swgChannelSettings, const NFMModSettings& settings, bool force @@ -902,14 +897,14 @@ void NFMMod::webapiFormatChannelSettings( if (settings.m_channelMarker && (channelSettingsKeys.contains("channelMarker") || force)) { - SWGSDRangel::SWGChannelMarker *swgChannelMarker = new SWGSDRangel::SWGChannelMarker(); + auto *swgChannelMarker = new SWGSDRangel::SWGChannelMarker(); settings.m_channelMarker->formatTo(swgChannelMarker); swgNFMModSettings->setChannelMarker(swgChannelMarker); } if (settings.m_rollupState && (channelSettingsKeys.contains("rollupState") || force)) { - SWGSDRangel::SWGRollupState *swgRollupState = new SWGSDRangel::SWGRollupState(); + auto *swgRollupState = new SWGSDRangel::SWGRollupState(); settings.m_rollupState->formatTo(swgRollupState); swgNFMModSettings->setRollupState(swgRollupState); } @@ -919,11 +914,11 @@ void NFMMod::webapiFormatChannelSettings( const CWKeyerSettings& cwKeyerSettings = getCWKeyer()->getSettings(); swgNFMModSettings->setCwKeyer(new SWGSDRangel::SWGCWKeyerSettings()); SWGSDRangel::SWGCWKeyerSettings *apiCwKeyerSettings = swgNFMModSettings->getCwKeyer(); - getCWKeyer()->webapiFormatChannelSettings(apiCwKeyerSettings, cwKeyerSettings); + CWKeyer::webapiFormatChannelSettings(apiCwKeyerSettings, cwKeyerSettings); } } -void NFMMod::networkManagerFinished(QNetworkReply *reply) +void NFMMod::networkManagerFinished(QNetworkReply *reply) const { QNetworkReply::NetworkError replyError = reply->error(); diff --git a/plugins/channeltx/modnfm/nfmmod.h b/plugins/channeltx/modnfm/nfmmod.h index de0ad0c8b..44300800b 100644 --- a/plugins/channeltx/modnfm/nfmmod.h +++ b/plugins/channeltx/modnfm/nfmmod.h @@ -82,7 +82,7 @@ public: private: QString m_fileName; - MsgConfigureFileSourceName(const QString& fileName) : + explicit MsgConfigureFileSourceName(const QString& fileName) : Message(), m_fileName(fileName) { } @@ -100,10 +100,10 @@ public: return new MsgConfigureFileSourceSeek(seekPercentage); } - protected: + private: int m_seekPercentage; //!< percentage of seek position from the beginning 0..100 - MsgConfigureFileSourceSeek(int seekPercentage) : + explicit MsgConfigureFileSourceSeek(int seekPercentage) : Message(), m_seekPercentage(seekPercentage) { } @@ -138,10 +138,10 @@ public: return new MsgReportFileSourceStreamTiming(samplesCount); } - protected: + private: std::size_t m_samplesCount; - MsgReportFileSourceStreamTiming(std::size_t samplesCount) : + explicit MsgReportFileSourceStreamTiming(std::size_t samplesCount) : Message(), m_samplesCount(samplesCount) { } @@ -160,7 +160,7 @@ public: return new MsgReportFileSourceStreamData(sampleRate, recordLength); } - protected: + private: int m_sampleRate; quint32 m_recordLength; @@ -174,55 +174,55 @@ public: //================================================================= - NFMMod(DeviceAPI *deviceAPI); - virtual ~NFMMod(); - virtual void destroy() { delete this; } - virtual void setDeviceAPI(DeviceAPI *deviceAPI); - virtual DeviceAPI *getDeviceAPI() { return m_deviceAPI; } + explicit NFMMod(DeviceAPI *deviceAPI); + ~NFMMod() final; + void destroy() final { delete this; } + void setDeviceAPI(DeviceAPI *deviceAPI) final; + DeviceAPI *getDeviceAPI() final { return m_deviceAPI; } - virtual void start(); - virtual void stop(); - virtual void pull(SampleVector::iterator& begin, unsigned int nbSamples); - virtual void pushMessage(Message *msg) { m_inputMessageQueue.push(msg); } - virtual QString getSourceName() { return objectName(); } + void start() final; + void stop() final; + void pull(SampleVector::iterator& begin, unsigned int nbSamples) final; + void pushMessage(Message *msg) final { m_inputMessageQueue.push(msg); } + QString getSourceName() final { return objectName(); } - virtual void getIdentifier(QString& id) { id = objectName(); } - virtual QString getIdentifier() const { return objectName(); } - virtual void getTitle(QString& title) { title = m_settings.m_title; } - virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; } - virtual void setCenterFrequency(qint64 frequency); + void getIdentifier(QString& id) final { id = objectName(); } + QString getIdentifier() const final { return objectName(); } + void getTitle(QString& title) final { title = m_settings.m_title; } + qint64 getCenterFrequency() const final { return m_settings.m_inputFrequencyOffset; } + void setCenterFrequency(qint64 frequency) final; - virtual QByteArray serialize() const; - virtual bool deserialize(const QByteArray& data); + QByteArray serialize() const final; + bool deserialize(const QByteArray& data) final; - virtual int getNbSinkStreams() const { return 1; } - virtual int getNbSourceStreams() const { return 0; } - virtual int getStreamIndex() const { return m_settings.m_streamIndex; } + int getNbSinkStreams() const final { return 1; } + int getNbSourceStreams() const final { return 0; } + int getStreamIndex() const final { return m_settings.m_streamIndex; } - virtual qint64 getStreamCenterFrequency(int streamIndex, bool sinkElseSource) const + qint64 getStreamCenterFrequency(int streamIndex, bool sinkElseSource) const final { (void) streamIndex; (void) sinkElseSource; return m_settings.m_inputFrequencyOffset; } - virtual int webapiSettingsGet( + int webapiSettingsGet( SWGSDRangel::SWGChannelSettings& response, - QString& errorMessage); + QString& errorMessage) final; - virtual int webapiWorkspaceGet( + int webapiWorkspaceGet( SWGSDRangel::SWGWorkspaceInfo& response, - QString& errorMessage); + QString& errorMessage) final; - virtual int webapiSettingsPutPatch( + int webapiSettingsPutPatch( bool force, const QStringList& channelSettingsKeys, SWGSDRangel::SWGChannelSettings& response, - QString& errorMessage); + QString& errorMessage) final; - virtual int webapiReportGet( + int webapiReportGet( SWGSDRangel::SWGChannelReport& response, - QString& errorMessage); + QString& errorMessage) final; static void webapiFormatChannelSettings( SWGSDRangel::SWGChannelSettings& response, @@ -251,7 +251,7 @@ private: DeviceAPI* m_deviceAPI; QThread *m_thread; - bool m_running; + bool m_running = false; NFMModBaseband* m_basebandSource; NFMModSettings m_settings; @@ -260,39 +260,39 @@ private: std::ifstream m_ifstream; QString m_fileName; - quint64 m_fileSize; //!< raw file size (bytes) - quint32 m_recordLength; //!< record length in seconds computed from file size - int m_sampleRate; + quint64 m_fileSize = 0; //!< raw file size (bytes) + quint32 m_recordLength = 0; //!< record length in seconds computed from file size + int m_sampleRate = 48000; QNetworkAccessManager *m_networkManager; QNetworkRequest m_networkRequest; CWKeyer m_cwKeyer; - QObject *m_levelMeter; + QObject *m_levelMeter = nullptr; - virtual bool handleMessage(const Message& cmd); + bool handleMessage(const Message& cmd) final; void applySettings(const NFMModSettings& settings, bool force = false); - void sendSampleRateToDemodAnalyzer(); + void sendSampleRateToDemodAnalyzer() const; void openFileStream(); void seekFileStream(int seekPercentage); - void webapiFormatChannelReport(SWGSDRangel::SWGChannelReport& response); - void webapiReverseSendSettings(QList& channelSettingsKeys, const NFMModSettings& settings, bool force); + void webapiFormatChannelReport(SWGSDRangel::SWGChannelReport& response) const; + void webapiReverseSendSettings(const QList& channelSettingsKeys, const NFMModSettings& settings, bool force); void webapiReverseSendCWSettings(const CWKeyerSettings& settings); void sendChannelSettings( const QList& pipes, - QList& channelSettingsKeys, + const QList& channelSettingsKeys, const NFMModSettings& settings, bool force ); void webapiFormatChannelSettings( - QList& channelSettingsKeys, + const QList& channelSettingsKeys, SWGSDRangel::SWGChannelSettings *swgChannelSettings, const NFMModSettings& settings, bool force ); private slots: - void networkManagerFinished(QNetworkReply *reply); + void networkManagerFinished(QNetworkReply *reply) const; }; diff --git a/plugins/channeltx/modnfm/nfmmodsource.cpp b/plugins/channeltx/modnfm/nfmmodsource.cpp index 39d758f1b..ff37ccfb7 100644 --- a/plugins/channeltx/modnfm/nfmmodsource.cpp +++ b/plugins/channeltx/modnfm/nfmmodsource.cpp @@ -27,21 +27,12 @@ #include "nfmmodsource.h" const int NFMModSource::m_levelNbSamples = 480; // every 10ms -const float NFMModSource::m_preemphasis = 120.0e-6; // 120us +const float NFMModSource::m_preemphasis = 120.0e-6f; // 120us NFMModSource::NFMModSource() : - m_channelSampleRate(48000), - m_channelFrequencyOffset(0), - m_modPhasor(0.0f), m_preemphasisFilter(m_preemphasis*48000), - m_audioSampleRate(48000), m_audioFifo(12000), - m_feedbackAudioFifo(48000), - m_levelCalcCount(0), - m_peakLevel(0.0f), - m_levelSum(0.0f), - m_ifstream(nullptr), - m_cwKeyer(nullptr) + m_feedbackAudioFifo(48000) { m_audioFifo.setLabel("NFMModSource.m_audioFifo"); m_feedbackAudioFifo.setLabel("NFMModSource.m_feedbackAudioFifo"); @@ -64,7 +55,7 @@ NFMModSource::NFMModSource() : -20, // threshold (dB) 20, // knee (dB) 15, // ratio (dB) - 0.003, // attack (s) + 0.003f,// attack (s) 0.25 // release (s) ); @@ -72,9 +63,7 @@ NFMModSource::NFMModSource() : applyChannelSettings(m_channelSampleRate, m_channelFrequencyOffset, true); } -NFMModSource::~NFMModSource() -{ -} +NFMModSource::~NFMModSource() = default; void NFMModSource::pull(SampleVector::iterator begin, unsigned int nbSamples) { @@ -130,7 +119,7 @@ void NFMModSource::pullOne(Sample& sample) void NFMModSource::prefetch(unsigned int nbSamples) { - unsigned int nbSamplesAudio = nbSamples * ((Real) m_audioSampleRate / (Real) m_channelSampleRate); + unsigned int nbSamplesAudio = (nbSamples * (unsigned int) ((Real) m_audioSampleRate / (Real) m_channelSampleRate)); pullAudio(nbSamplesAudio); } @@ -154,7 +143,9 @@ void NFMModSource::pullAudio(unsigned int nbSamplesAudio) void NFMModSource::modulateSample() { - Real t0, t1, t; + Real t0 = 0.0f; + Real t1 = 0.0f; + Real t = 0.0f; pullAF(t0); @@ -173,24 +164,24 @@ void NFMModSource::modulateSample() if (m_settings.m_ctcssOn) { t1 = 0.85f * m_bandpass.filter(t) + 0.15f * 0.625f * m_ctcssNco.next(); } else if (m_settings.m_dcsOn) { - t1 = 0.9f * m_bandpass.filter(t) + 0.1f * 0.625f * m_dcsMod.next(); + t1 = 0.9f * m_bandpass.filter(t) + 0.1f * 0.625f * (float) m_dcsMod.next(); } else if (m_settings.m_bpfOn) { t1 = m_bandpass.filter(t); } else { t1 = m_lowpass.filter(t); } - m_modPhasor += (M_PI * m_settings.m_fmDeviation / (float) m_audioSampleRate) * t1; + m_modPhasor += (float) ((M_PI * m_settings.m_fmDeviation / (float) m_audioSampleRate) * t1); // limit phasor range to ]-pi,pi] if (m_modPhasor > M_PI) { - m_modPhasor -= (2.0f * M_PI); + m_modPhasor -= (float) (2.0 * M_PI); } - m_modSample.real(cos(m_modPhasor) * 0.891235351562f * SDR_TX_SCALEF); // -1 dB - m_modSample.imag(sin(m_modPhasor) * 0.891235351562f * SDR_TX_SCALEF); + m_modSample.real((float) (cos(m_modPhasor) * 0.891235351562f * SDR_TX_SCALEF)); // -1 dB + m_modSample.imag((float) (sin(m_modPhasor) * 0.891235351562f * SDR_TX_SCALEF)); - m_demodBuffer[m_demodBufferFill] = t1 * std::numeric_limits::max(); + m_demodBuffer[m_demodBufferFill] = (qint16) (t1 * std::numeric_limits::max()); ++m_demodBufferFill; if (m_demodBufferFill >= m_demodBuffer.size()) @@ -198,13 +189,11 @@ void NFMModSource::modulateSample() QList dataPipes; MainCore::instance()->getDataPipes().getDataPipes(m_channel, "demod", dataPipes); - if (dataPipes.size() > 0) + if (!dataPipes.empty()) { - QList::iterator it = dataPipes.begin(); - - for (; it != dataPipes.end(); ++it) + for (auto& dataPipe : dataPipes) { - DataFifo *fifo = qobject_cast((*it)->m_element); + DataFifo *fifo = qobject_cast(dataPipe->m_element); if (fifo) { fifo->write((quint8*) &m_demodBuffer[0], m_demodBuffer.size() * sizeof(qint16), DataFifo::DataTypeI16); @@ -224,17 +213,12 @@ void NFMModSource::pullAF(Real& sample) sample = m_toneNco.next(); break; case NFMModSettings::NFMModInputFile: - // sox f4exb_call.wav --encoding float --endian little f4exb_call.raw - // ffplay -f f32le -ar 48k -ac 1 f4exb_call.raw if (m_ifstream && m_ifstream->is_open()) { - if (m_ifstream->eof()) + if (m_ifstream->eof() && m_settings.m_playLoop) { - if (m_settings.m_playLoop) - { - m_ifstream->clear(); - m_ifstream->seekg(0, std::ios::beg); - } + m_ifstream->clear(); + m_ifstream->seekg(0, std::ios::beg); } if (m_ifstream->eof()) @@ -269,8 +253,8 @@ void NFMModSource::pullAF(Real& sample) } else { - unsigned int size = m_audioBuffer.size(); - qDebug("NFMModSource::pullAF: starve audio samples: size: %u", size); + std::size_t size = m_audioBuffer.size(); + qDebug("NFMModSource::pullAF: starve audio samples: size: %lu", size); sample = ((m_audioBuffer[size-1].l + m_audioBuffer[size-1].r) / 65536.0f) * m_settings.m_volumeFactor; } @@ -300,7 +284,6 @@ void NFMModSource::pullAF(Real& sample) } } break; - case NFMModSettings::NFMModInputNone: default: sample = 0.0f; break; @@ -330,10 +313,10 @@ void NFMModSource::pushFeedback(Real sample) } } -void NFMModSource::processOneSample(Complex& ci) +void NFMModSource::processOneSample(const Complex& ci) { - m_feedbackAudioBuffer[m_feedbackAudioBufferFill].l = ci.real(); - m_feedbackAudioBuffer[m_feedbackAudioBufferFill].r = ci.imag(); + m_feedbackAudioBuffer[m_feedbackAudioBufferFill].l = (qint16) ci.real(); + m_feedbackAudioBuffer[m_feedbackAudioBufferFill].r = (qint16) ci.imag(); ++m_feedbackAudioBufferFill; if (m_feedbackAudioBufferFill >= m_feedbackAudioBuffer.size()) @@ -351,7 +334,7 @@ void NFMModSource::processOneSample(Complex& ci) } } -void NFMModSource::calculateLevel(Real& sample) +void NFMModSource::calculateLevel(const Real& sample) { if (m_levelCalcCount < m_levelNbSamples) { @@ -385,8 +368,8 @@ void NFMModSource::applyAudioSampleRate(int sampleRate) m_interpolator.create(48, sampleRate, m_settings.m_rfBandwidth / 2.2, 3.0); m_lowpass.create(301, sampleRate, m_settings.m_afBandwidth); m_bandpass.create(301, sampleRate, 300.0, m_settings.m_afBandwidth); - m_toneNco.setFreq(m_settings.m_toneFrequency, sampleRate); - m_ctcssNco.setFreq(NFMModSettings::getCTCSSFreq(m_settings.m_ctcssIndex), sampleRate); + m_toneNco.setFreq(m_settings.m_toneFrequency, (float) sampleRate); + m_ctcssNco.setFreq(NFMModSettings::getCTCSSFreq(m_settings.m_ctcssIndex), (float) sampleRate); m_dcsMod.setSampleRate(sampleRate); if (m_cwKeyer) @@ -395,8 +378,8 @@ void NFMModSource::applyAudioSampleRate(int sampleRate) m_cwKeyer->reset(); } - m_preemphasisFilter.configure(m_preemphasis*sampleRate); - m_audioCompressor.m_rate = sampleRate; + m_preemphasisFilter.configure(m_preemphasis * (float) sampleRate); + m_audioCompressor.m_rate = (float) sampleRate; m_audioCompressor.initState(); m_audioSampleRate = sampleRate; applyFeedbackAudioSampleRate(m_feedbackAudioSampleRate); @@ -404,7 +387,7 @@ void NFMModSource::applyAudioSampleRate(int sampleRate) QList pipes; MainCore::instance()->getMessagePipes().getMessagePipes(m_channel, "reportdemod", pipes); - if (pipes.size() > 0) + if (!pipes.empty()) { for (const auto& pipe : pipes) { @@ -428,7 +411,7 @@ void NFMModSource::applyFeedbackAudioSampleRate(int sampleRate) m_feedbackInterpolatorDistanceRemain = 0; m_feedbackInterpolatorConsumed = false; m_feedbackInterpolatorDistance = (Real) sampleRate / (Real) m_audioSampleRate; - Real cutoff = std::min(sampleRate, m_audioSampleRate) / 2.2f; + Real cutoff = (float) std::min(sampleRate, m_audioSampleRate) / 2.2f; m_feedbackInterpolator.create(48, sampleRate, cutoff, 3.0); m_feedbackAudioSampleRate = sampleRate; } @@ -444,11 +427,11 @@ void NFMModSource::applySettings(const NFMModSettings& settings, bool force) } if ((settings.m_toneFrequency != m_settings.m_toneFrequency) || force) { - m_toneNco.setFreq(settings.m_toneFrequency, m_audioSampleRate); + m_toneNco.setFreq(settings.m_toneFrequency, (float) m_audioSampleRate); } if ((settings.m_ctcssIndex != m_settings.m_ctcssIndex) || force) { - m_ctcssNco.setFreq(NFMModSettings::getCTCSSFreq(settings.m_ctcssIndex), m_audioSampleRate); + m_ctcssNco.setFreq(NFMModSettings::getCTCSSFreq(settings.m_ctcssIndex), (float) m_audioSampleRate); } if ((settings.m_dcsCode != m_settings.m_dcsCode) || force) { @@ -480,7 +463,7 @@ void NFMModSource::applyChannelSettings(int channelSampleRate, int channelFreque if ((channelFrequencyOffset != m_channelFrequencyOffset) || (channelSampleRate != m_channelSampleRate) || force) { - m_carrierNco.setFreq(channelFrequencyOffset, channelSampleRate); + m_carrierNco.setFreq((float) channelFrequencyOffset, (float) channelSampleRate); } if ((channelSampleRate != m_channelSampleRate) || force) @@ -497,7 +480,6 @@ void NFMModSource::applyChannelSettings(int channelSampleRate, int channelFreque void NFMModSource::handleAudio() { - QMutexLocker mlock(&m_mutex); unsigned int nbRead; while ((nbRead = m_audioFifo.read(reinterpret_cast(&m_audioReadBuffer[m_audioReadBufferFill]), 4096)) != 0) diff --git a/plugins/channeltx/modnfm/nfmmodsource.h b/plugins/channeltx/modnfm/nfmmodsource.h index 9a6d31ed9..8aad901af 100644 --- a/plugins/channeltx/modnfm/nfmmodsource.h +++ b/plugins/channeltx/modnfm/nfmmodsource.h @@ -47,11 +47,11 @@ class NFMModSource : public QObject, public ChannelSampleSource Q_OBJECT public: NFMModSource(); - virtual ~NFMModSource(); + ~NFMModSource() final; - virtual void pull(SampleVector::iterator begin, unsigned int nbSamples); - virtual void pullOne(Sample& sample); - virtual void prefetch(unsigned int nbSamples); + void pull(SampleVector::iterator begin, unsigned int nbSamples) final; + void pullOne(Sample& sample) final; + void prefetch(unsigned int nbSamples) final; void setInputFileStream(std::ifstream *ifstream) { m_ifstream = ifstream; } AudioFifo *getAudioFifo() { return &m_audioFifo; } @@ -74,8 +74,8 @@ public: void applyChannelSettings(int channelSampleRate, int channelFrequencyOffset, bool force = false); private: - int m_channelSampleRate; - int m_channelFrequencyOffset; + int m_channelSampleRate = 48000; + int m_channelFrequencyOffset = 0; NFMModSettings m_settings; ChannelAPI *m_channel; @@ -83,7 +83,7 @@ private: NCOF m_toneNco; NCOF m_ctcssNco; NFMModDCS m_dcsMod; - float m_modPhasor; //!< baseband modulator phasor + float m_modPhasor = 0.0f; //!< baseband modulator phasor Complex m_modSample; Interpolator m_interpolator; @@ -106,7 +106,7 @@ private: double m_magsq; MovingAverageUtil m_movingAverage; - int m_audioSampleRate; + int m_audioSampleRate = 48000; AudioVector m_audioBuffer; unsigned int m_audioBufferFill; AudioVector m_audioReadBuffer; @@ -118,14 +118,14 @@ private: uint m_feedbackAudioBufferFill; AudioFifo m_feedbackAudioFifo; - quint32 m_levelCalcCount; + quint32 m_levelCalcCount = 0; qreal m_rmsLevel; qreal m_peakLevelOut; - Real m_peakLevel; - Real m_levelSum; + Real m_peakLevel = 0.0f; + Real m_levelSum = 0.0f; - std::ifstream *m_ifstream; - CWKeyer *m_cwKeyer; + std::ifstream *m_ifstream = nullptr; + CWKeyer *m_cwKeyer = nullptr; AudioCompressorSnd m_audioCompressor; @@ -134,11 +134,11 @@ private: static const int m_levelNbSamples; static const float m_preemphasis; - void processOneSample(Complex& ci); + void processOneSample(const Complex& ci); void pullAF(Real& sample); void pullAudio(unsigned int nbSamples); void pushFeedback(Real sample); - void calculateLevel(Real& sample); + void calculateLevel(const Real& sample); void modulateSample(); private slots: diff --git a/plugins/channeltx/modssb/ssbmod.cpp b/plugins/channeltx/modssb/ssbmod.cpp index 9ae2b047a..7fd668786 100644 --- a/plugins/channeltx/modssb/ssbmod.cpp +++ b/plugins/channeltx/modssb/ssbmod.cpp @@ -57,11 +57,7 @@ const char* const SSBMod::m_channelId = "SSBMod"; SSBMod::SSBMod(DeviceAPI *deviceAPI) : ChannelAPI(m_channelIdURI, ChannelAPI::StreamSingleSource), m_deviceAPI(deviceAPI), - m_running(false), - m_spectrumVis(SDR_TX_SCALEF), - m_fileSize(0), - m_recordLength(0), - m_sampleRate(48000) + m_spectrumVis(SDR_TX_SCALEF) { setObjectName(m_channelId); applySettings(m_settings, true); @@ -90,7 +86,7 @@ SSBMod::~SSBMod() m_deviceAPI->removeChannelSourceAPI(this); m_deviceAPI->removeChannelSource(this); - stop(); + SSBMod::stop(); } void SSBMod::setDeviceAPI(DeviceAPI *deviceAPI) @@ -182,7 +178,7 @@ bool SSBMod::handleMessage(const Message& cmd) { if (MsgConfigureSSBMod::match(cmd)) { - MsgConfigureSSBMod& cfg = (MsgConfigureSSBMod&) cmd; + auto& cfg = (const MsgConfigureSSBMod&) cmd; qDebug() << "SSBMod::handleMessage: MsgConfigureSSBMod"; applySettings(cfg.getSettings(), cfg.getForce()); @@ -191,14 +187,14 @@ bool SSBMod::handleMessage(const Message& cmd) } else if (MsgConfigureFileSourceName::match(cmd)) { - MsgConfigureFileSourceName& conf = (MsgConfigureFileSourceName&) cmd; + auto& conf = (const MsgConfigureFileSourceName&) cmd; m_fileName = conf.getFileName(); openFileStream(); return true; } else if (MsgConfigureFileSourceSeek::match(cmd)) { - MsgConfigureFileSourceSeek& conf = (MsgConfigureFileSourceSeek&) cmd; + auto& conf = (const MsgConfigureFileSourceSeek&) cmd; int seekPercentage = conf.getPercentage(); seekFileStream(seekPercentage); @@ -206,18 +202,17 @@ bool SSBMod::handleMessage(const Message& cmd) } else if (MsgConfigureFileSourceStreamTiming::match(cmd)) { - std::size_t samplesCount; + std::size_t samplesCount; - if (m_ifstream.eof()) { - samplesCount = m_fileSize / sizeof(Real); - } else { - samplesCount = m_ifstream.tellg() / sizeof(Real); - } + if (m_ifstream.eof()) { + samplesCount = m_fileSize / sizeof(Real); + } else { + samplesCount = m_ifstream.tellg() / sizeof(Real); + } if (getMessageQueueToGUI()) { - MsgReportFileSourceStreamTiming *report; - report = MsgReportFileSourceStreamTiming::create(samplesCount); + auto *report = MsgReportFileSourceStreamTiming::create(samplesCount); getMessageQueueToGUI()->push(report); } @@ -225,7 +220,7 @@ bool SSBMod::handleMessage(const Message& cmd) } else if (CWKeyer::MsgConfigureCWKeyer::match(cmd)) { - const CWKeyer::MsgConfigureCWKeyer& cfg = (CWKeyer::MsgConfigureCWKeyer&) cmd; + auto& cfg = (const CWKeyer::MsgConfigureCWKeyer&) cmd; if (m_settings.m_useReverseAPI) { webapiReverseSendCWSettings(cfg.getSettings()); @@ -235,11 +230,11 @@ bool SSBMod::handleMessage(const Message& cmd) } else if (DSPSignalNotification::match(cmd)) { - DSPSignalNotification& notif = (DSPSignalNotification&) cmd; + auto& notif = (const DSPSignalNotification&) cmd; // Forward to the source if (m_running) { - DSPSignalNotification* rep = new DSPSignalNotification(notif); // make a copy + auto* rep = new DSPSignalNotification(notif); // make a copy qDebug() << "SSBMod::handleMessage: DSPSignalNotification"; m_basebandSource->getInputMessageQueue()->push(rep); } @@ -274,7 +269,7 @@ void SSBMod::openFileStream() m_ifstream.seekg(0,std::ios_base::beg); m_sampleRate = 48000; // fixed rate - m_recordLength = m_fileSize / (sizeof(Real) * m_sampleRate); + m_recordLength = (quint32) (m_fileSize / (sizeof(Real) * m_sampleRate)); qDebug() << "SSBMod::openFileStream: " << m_fileName.toStdString().c_str() << " fileSize: " << m_fileSize << "bytes" @@ -416,7 +411,7 @@ void SSBMod::applySettings(const SSBModSettings& settings, bool force) QList pipes; MainCore::instance()->getMessagePipes().getMessagePipes(this, "settings", pipes); - if (pipes.size() > 0) { + if (!pipes.empty()) { sendChannelSettings(pipes, reverseAPIKeys, settings, force); } @@ -448,12 +443,12 @@ bool SSBMod::deserialize(const QByteArray& data) } } -void SSBMod::sendSampleRateToDemodAnalyzer() +void SSBMod::sendSampleRateToDemodAnalyzer() const { QList pipes; MainCore::instance()->getMessagePipes().getMessagePipes(this, "reportdemod", pipes); - if (pipes.size() > 0) + if (!pipes.empty()) { for (const auto& pipe : pipes) { @@ -604,13 +599,13 @@ void SSBMod::webapiUpdateChannelSettings( settings.m_reverseAPIAddress = *response.getSsbModSettings()->getReverseApiAddress(); } if (channelSettingsKeys.contains("reverseAPIPort")) { - settings.m_reverseAPIPort = response.getSsbModSettings()->getReverseApiPort(); + settings.m_reverseAPIPort = (uint16_t) response.getSsbModSettings()->getReverseApiPort(); } if (channelSettingsKeys.contains("reverseAPIDeviceIndex")) { - settings.m_reverseAPIDeviceIndex = response.getSsbModSettings()->getReverseApiDeviceIndex(); + settings.m_reverseAPIDeviceIndex = (uint16_t) response.getSsbModSettings()->getReverseApiDeviceIndex(); } if (channelSettingsKeys.contains("reverseAPIChannelIndex")) { - settings.m_reverseAPIChannelIndex = response.getSsbModSettings()->getReverseApiChannelIndex(); + settings.m_reverseAPIChannelIndex = (uint16_t) response.getSsbModSettings()->getReverseApiChannelIndex(); } if (settings.m_spectrumGUI && channelSettingsKeys.contains("spectrumConfig")) { settings.m_spectrumGUI->updateFrom(channelSettingsKeys, response.getSsbModSettings()->getSpectrumConfig()); @@ -691,7 +686,7 @@ void SSBMod::webapiFormatChannelSettings(SWGSDRangel::SWGChannelSettings& respon } else { - SWGSDRangel::SWGGLSpectrum *swgGLSpectrum = new SWGSDRangel::SWGGLSpectrum(); + auto *swgGLSpectrum = new SWGSDRangel::SWGGLSpectrum(); settings.m_spectrumGUI->formatTo(swgGLSpectrum); response.getSsbModSettings()->setSpectrumConfig(swgGLSpectrum); } @@ -705,7 +700,7 @@ void SSBMod::webapiFormatChannelSettings(SWGSDRangel::SWGChannelSettings& respon } else { - SWGSDRangel::SWGChannelMarker *swgChannelMarker = new SWGSDRangel::SWGChannelMarker(); + auto *swgChannelMarker = new SWGSDRangel::SWGChannelMarker(); settings.m_channelMarker->formatTo(swgChannelMarker); response.getSsbModSettings()->setChannelMarker(swgChannelMarker); } @@ -719,16 +714,16 @@ void SSBMod::webapiFormatChannelSettings(SWGSDRangel::SWGChannelSettings& respon } else { - SWGSDRangel::SWGRollupState *swgRollupState = new SWGSDRangel::SWGRollupState(); + auto *swgRollupState = new SWGSDRangel::SWGRollupState(); settings.m_rollupState->formatTo(swgRollupState); response.getSsbModSettings()->setRollupState(swgRollupState); } } } -void SSBMod::webapiFormatChannelReport(SWGSDRangel::SWGChannelReport& response) +void SSBMod::webapiFormatChannelReport(SWGSDRangel::SWGChannelReport& response) const { - response.getSsbModReport()->setChannelPowerDb(CalcDb::dbPower(getMagSq())); + response.getSsbModReport()->setChannelPowerDb((float) CalcDb::dbPower(getMagSq())); if (m_running) { @@ -737,9 +732,9 @@ void SSBMod::webapiFormatChannelReport(SWGSDRangel::SWGChannelReport& response) } } -void SSBMod::webapiReverseSendSettings(QList& channelSettingsKeys, const SSBModSettings& settings, bool force) +void SSBMod::webapiReverseSendSettings(const QList& channelSettingsKeys, const SSBModSettings& settings, bool force) { - SWGSDRangel::SWGChannelSettings *swgChannelSettings = new SWGSDRangel::SWGChannelSettings(); + auto *swgChannelSettings = new SWGSDRangel::SWGChannelSettings(); webapiFormatChannelSettings(channelSettingsKeys, swgChannelSettings, settings, force); QString channelSettingsURL = QString("http://%1:%2/sdrangel/deviceset/%3/channel/%4/settings") @@ -750,8 +745,8 @@ void SSBMod::webapiReverseSendSettings(QList& channelSettingsKeys, cons m_networkRequest.setUrl(QUrl(channelSettingsURL)); m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); - QBuffer *buffer = new QBuffer(); - buffer->open((QBuffer::ReadWrite)); + auto *buffer = new QBuffer(); + buffer->open(QBuffer::ReadWrite); buffer->write(swgChannelSettings->asJson().toUtf8()); buffer->seek(0); @@ -764,7 +759,7 @@ void SSBMod::webapiReverseSendSettings(QList& channelSettingsKeys, cons void SSBMod::webapiReverseSendCWSettings(const CWKeyerSettings& cwKeyerSettings) { - SWGSDRangel::SWGChannelSettings *swgChannelSettings = new SWGSDRangel::SWGChannelSettings(); + auto *swgChannelSettings = new SWGSDRangel::SWGChannelSettings(); swgChannelSettings->setDirection(1); // single source (Tx) swgChannelSettings->setChannelType(new QString("SSBMod")); swgChannelSettings->setSsbModSettings(new SWGSDRangel::SWGSSBModSettings()); @@ -772,7 +767,7 @@ void SSBMod::webapiReverseSendCWSettings(const CWKeyerSettings& cwKeyerSettings) swgSSBModSettings->setCwKeyer(new SWGSDRangel::SWGCWKeyerSettings()); SWGSDRangel::SWGCWKeyerSettings *apiCwKeyerSettings = swgSSBModSettings->getCwKeyer(); - m_cwKeyer.webapiFormatChannelSettings(apiCwKeyerSettings, cwKeyerSettings); + CWKeyer::webapiFormatChannelSettings(apiCwKeyerSettings, cwKeyerSettings); QString channelSettingsURL = QString("http://%1:%2/sdrangel/deviceset/%3/channel/%4/settings") .arg(m_settings.m_reverseAPIAddress) @@ -782,8 +777,8 @@ void SSBMod::webapiReverseSendCWSettings(const CWKeyerSettings& cwKeyerSettings) m_networkRequest.setUrl(QUrl(channelSettingsURL)); m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); - QBuffer *buffer = new QBuffer(); - buffer->open((QBuffer::ReadWrite)); + auto *buffer = new QBuffer(); + buffer->open(QBuffer::ReadWrite); buffer->write(swgChannelSettings->asJson().toUtf8()); buffer->seek(0); @@ -796,9 +791,9 @@ void SSBMod::webapiReverseSendCWSettings(const CWKeyerSettings& cwKeyerSettings) void SSBMod::sendChannelSettings( const QList& pipes, - QList& channelSettingsKeys, + const QList& channelSettingsKeys, const SSBModSettings& settings, - bool force) + bool force) const { for (const auto& pipe : pipes) { @@ -806,7 +801,7 @@ void SSBMod::sendChannelSettings( if (messageQueue) { - SWGSDRangel::SWGChannelSettings *swgChannelSettings = new SWGSDRangel::SWGChannelSettings(); + auto *swgChannelSettings = new SWGSDRangel::SWGChannelSettings(); webapiFormatChannelSettings(channelSettingsKeys, swgChannelSettings, settings, force); MainCore::MsgChannelSettings *msg = MainCore::MsgChannelSettings::create( this, @@ -820,11 +815,11 @@ void SSBMod::sendChannelSettings( } void SSBMod::webapiFormatChannelSettings( - QList& channelSettingsKeys, + const QList& channelSettingsKeys, SWGSDRangel::SWGChannelSettings *swgChannelSettings, const SSBModSettings& settings, bool force -) +) const { swgChannelSettings->setDirection(1); // single source (Tx) swgChannelSettings->setOriginatorChannelIndex(getIndexInDeviceSet()); @@ -898,21 +893,21 @@ void SSBMod::webapiFormatChannelSettings( if (settings.m_spectrumGUI && (channelSettingsKeys.contains("spectrunConfig") || force)) { - SWGSDRangel::SWGGLSpectrum *swgGLSpectrum = new SWGSDRangel::SWGGLSpectrum(); + auto *swgGLSpectrum = new SWGSDRangel::SWGGLSpectrum(); settings.m_spectrumGUI->formatTo(swgGLSpectrum); swgSSBModSettings->setSpectrumConfig(swgGLSpectrum); } if (settings.m_channelMarker && (channelSettingsKeys.contains("channelMarker") || force)) { - SWGSDRangel::SWGChannelMarker *swgChannelMarker = new SWGSDRangel::SWGChannelMarker(); + auto *swgChannelMarker = new SWGSDRangel::SWGChannelMarker(); settings.m_channelMarker->formatTo(swgChannelMarker); swgSSBModSettings->setChannelMarker(swgChannelMarker); } if (settings.m_rollupState && (channelSettingsKeys.contains("rollupState") || force)) { - SWGSDRangel::SWGRollupState *swgRollupState = new SWGSDRangel::SWGRollupState(); + auto *swgRollupState = new SWGSDRangel::SWGRollupState(); settings.m_rollupState->formatTo(swgRollupState); swgSSBModSettings->setRollupState(swgRollupState); } @@ -922,11 +917,11 @@ void SSBMod::webapiFormatChannelSettings( const CWKeyerSettings& cwKeyerSettings = m_cwKeyer.getSettings(); swgSSBModSettings->setCwKeyer(new SWGSDRangel::SWGCWKeyerSettings()); SWGSDRangel::SWGCWKeyerSettings *apiCwKeyerSettings = swgSSBModSettings->getCwKeyer(); - m_cwKeyer.webapiFormatChannelSettings(apiCwKeyerSettings, cwKeyerSettings); + CWKeyer::webapiFormatChannelSettings(apiCwKeyerSettings, cwKeyerSettings); } } -void SSBMod::networkManagerFinished(QNetworkReply *reply) +void SSBMod::networkManagerFinished(QNetworkReply *reply) const { QNetworkReply::NetworkError replyError = reply->error(); diff --git a/plugins/channeltx/modssb/ssbmod.h b/plugins/channeltx/modssb/ssbmod.h index 166086428..fc962d32e 100644 --- a/plugins/channeltx/modssb/ssbmod.h +++ b/plugins/channeltx/modssb/ssbmod.h @@ -83,7 +83,7 @@ public: private: QString m_fileName; - MsgConfigureFileSourceName(const QString& fileName) : + explicit MsgConfigureFileSourceName(const QString& fileName) : Message(), m_fileName(fileName) { } @@ -101,10 +101,10 @@ public: return new MsgConfigureFileSourceSeek(seekPercentage); } - protected: + private: int m_seekPercentage; //!< percentage of seek position from the beginning 0..100 - MsgConfigureFileSourceSeek(int seekPercentage) : + explicit MsgConfigureFileSourceSeek(int seekPercentage) : Message(), m_seekPercentage(seekPercentage) { } @@ -139,10 +139,10 @@ public: return new MsgReportFileSourceStreamTiming(samplesCount); } - protected: + private: std::size_t m_samplesCount; - MsgReportFileSourceStreamTiming(std::size_t samplesCount) : + explicit MsgReportFileSourceStreamTiming(std::size_t samplesCount) : Message(), m_samplesCount(samplesCount) { } @@ -161,7 +161,7 @@ public: return new MsgReportFileSourceStreamData(sampleRate, recordLength); } - protected: + private: int m_sampleRate; quint32 m_recordLength; @@ -175,55 +175,55 @@ public: //================================================================= - SSBMod(DeviceAPI *deviceAPI); - virtual ~SSBMod(); - virtual void destroy() { delete this; } - virtual void setDeviceAPI(DeviceAPI *deviceAPI); - virtual DeviceAPI *getDeviceAPI() { return m_deviceAPI; } + explicit SSBMod(DeviceAPI *deviceAPI); + ~SSBMod() final; + void destroy() final { delete this; } + void setDeviceAPI(DeviceAPI *deviceAPI) final; + DeviceAPI *getDeviceAPI() final { return m_deviceAPI; } - virtual void start(); - virtual void stop(); - virtual void pull(SampleVector::iterator& begin, unsigned int nbSamples); - virtual void pushMessage(Message *msg) { m_inputMessageQueue.push(msg); } - virtual QString getSourceName() { return objectName(); } + void start() final; + void stop() final; + void pull(SampleVector::iterator& begin, unsigned int nbSamples) final; + void pushMessage(Message *msg) final { m_inputMessageQueue.push(msg); } + QString getSourceName() final { return objectName(); } - virtual void getIdentifier(QString& id) { id = objectName(); } - virtual QString getIdentifier() const { return objectName(); } - virtual void getTitle(QString& title) { title = m_settings.m_title; } - virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; } - virtual void setCenterFrequency(qint64 frequency); + void getIdentifier(QString& id) final { id = objectName(); } + QString getIdentifier() const final { return objectName(); } + void getTitle(QString& title) final { title = m_settings.m_title; } + qint64 getCenterFrequency() const final { return m_settings.m_inputFrequencyOffset; } + void setCenterFrequency(qint64 frequency) final; - virtual QByteArray serialize() const; - virtual bool deserialize(const QByteArray& data); + QByteArray serialize() const final; + bool deserialize(const QByteArray& data) final; - virtual int getNbSinkStreams() const { return 1; } - virtual int getNbSourceStreams() const { return 0; } - virtual int getStreamIndex() const { return m_settings.m_streamIndex; } + int getNbSinkStreams() const final { return 1; } + int getNbSourceStreams() const final { return 0; } + int getStreamIndex() const final { return m_settings.m_streamIndex; } - virtual qint64 getStreamCenterFrequency(int streamIndex, bool sinkElseSource) const + qint64 getStreamCenterFrequency(int streamIndex, bool sinkElseSource) const final { (void) streamIndex; (void) sinkElseSource; return m_settings.m_inputFrequencyOffset; } - virtual int webapiSettingsGet( + int webapiSettingsGet( SWGSDRangel::SWGChannelSettings& response, - QString& errorMessage); + QString& errorMessage) final; - virtual int webapiWorkspaceGet( + int webapiWorkspaceGet( SWGSDRangel::SWGWorkspaceInfo& response, - QString& errorMessage); + QString& errorMessage) final; - virtual int webapiSettingsPutPatch( + int webapiSettingsPutPatch( bool force, const QStringList& channelSettingsKeys, SWGSDRangel::SWGChannelSettings& response, - QString& errorMessage); + QString& errorMessage) final; - virtual int webapiReportGet( + int webapiReportGet( SWGSDRangel::SWGChannelReport& response, - QString& errorMessage); + QString& errorMessage) final; static void webapiFormatChannelSettings( SWGSDRangel::SWGChannelSettings& response, @@ -253,7 +253,7 @@ private: DeviceAPI* m_deviceAPI; QThread *m_thread; - bool m_running; + bool m_running = false; SSBModBaseband* m_basebandSource; SSBModSettings m_settings; SpectrumVis m_spectrumVis; @@ -263,38 +263,38 @@ private: std::ifstream m_ifstream; QString m_fileName; - quint64 m_fileSize; //!< raw file size (bytes) - quint32 m_recordLength; //!< record length in seconds computed from file size - int m_sampleRate; + quint64 m_fileSize = 0; //!< raw file size (bytes) + quint32 m_recordLength = 0; //!< record length in seconds computed from file size + int m_sampleRate = 48000; QNetworkAccessManager *m_networkManager; QNetworkRequest m_networkRequest; CWKeyer m_cwKeyer; QObject *m_levelMeter; - virtual bool handleMessage(const Message& cmd); + bool handleMessage(const Message& cmd) final; void applySettings(const SSBModSettings& settings, bool force = false); - void sendSampleRateToDemodAnalyzer(); + void sendSampleRateToDemodAnalyzer() const; void openFileStream(); void seekFileStream(int seekPercentage); - void webapiFormatChannelReport(SWGSDRangel::SWGChannelReport& response); - void webapiReverseSendSettings(QList& channelSettingsKeys, const SSBModSettings& settings, bool force); + void webapiFormatChannelReport(SWGSDRangel::SWGChannelReport& response) const; + void webapiReverseSendSettings(const QList& channelSettingsKeys, const SSBModSettings& settings, bool force); void webapiReverseSendCWSettings(const CWKeyerSettings& settings); void sendChannelSettings( const QList& pipes, - QList& channelSettingsKeys, + const QList& channelSettingsKeys, const SSBModSettings& settings, bool force - ); + ) const; void webapiFormatChannelSettings( - QList& channelSettingsKeys, + const QList& channelSettingsKeys, SWGSDRangel::SWGChannelSettings *swgChannelSettings, const SSBModSettings& settings, bool force - ); + ) const; private slots: - void networkManagerFinished(QNetworkReply *reply); + void networkManagerFinished(QNetworkReply *reply) const; }; diff --git a/plugins/channeltx/modssb/ssbmodsource.cpp b/plugins/channeltx/modssb/ssbmodsource.cpp index b829b3701..c2e1f9df2 100644 --- a/plugins/channeltx/modssb/ssbmodsource.cpp +++ b/plugins/channeltx/modssb/ssbmodsource.cpp @@ -30,22 +30,13 @@ const int SSBModSource::m_ssbFftLen = 1024; const int SSBModSource::m_levelNbSamples = 480; // every 10ms SSBModSource::SSBModSource() : - m_channelSampleRate(48000), - m_channelFrequencyOffset(0), - m_spectrumSink(nullptr), - m_audioSampleRate(48000), m_audioFifo(12000), - m_feedbackAudioFifo(12000), - m_levelCalcCount(0), - m_peakLevel(0.0f), - m_levelSum(0.0f), - m_ifstream(nullptr), - m_cwKeyer(nullptr) + m_feedbackAudioFifo(12000) { m_audioFifo.setLabel("SSBModSource.m_audioFifo"); m_feedbackAudioFifo.setLabel("SSBModSource.m_feedbackAudioFifo"); - m_SSBFilter = new fftfilt(m_settings.m_lowCutoff / m_audioSampleRate, m_settings.m_bandwidth / m_audioSampleRate, m_ssbFftLen); - m_DSBFilter = new fftfilt((2.0f * m_settings.m_bandwidth) / m_audioSampleRate, 2 * m_ssbFftLen); + m_SSBFilter = new fftfilt(m_settings.m_lowCutoff / (float) m_audioSampleRate, m_settings.m_bandwidth / (float) m_audioSampleRate, m_ssbFftLen); + m_DSBFilter = new fftfilt((2.0f * m_settings.m_bandwidth) / (float) m_audioSampleRate, 2 * m_ssbFftLen); m_SSBFilterBuffer = new Complex[m_ssbFftLen>>1]; // filter returns data exactly half of its size m_DSBFilterBuffer = new Complex[m_ssbFftLen]; std::fill(m_SSBFilterBuffer, m_SSBFilterBuffer+(m_ssbFftLen>>1), Complex{0,0}); @@ -68,15 +59,15 @@ SSBModSource::SSBModSource() : m_sumCount = 0; m_magsq = 0.0; - m_toneNco.setFreq(1000.0, m_audioSampleRate); + m_toneNco.setFreq(1000.0, (float) m_audioSampleRate); m_audioCompressor.initSimple( m_audioSampleRate, - m_settings.m_cmpPreGainDB, // pregain (dB) - m_settings.m_cmpThresholdDB, // threshold (dB) + (float) m_settings.m_cmpPreGainDB, // pregain (dB) + (float) m_settings.m_cmpThresholdDB, // threshold (dB) 20, // knee (dB) 12, // ratio (dB) - 0.003, // attack (s) + 0.003f,// attack (s) 0.25 // release (s) ); @@ -140,7 +131,7 @@ void SSBModSource::pullOne(Sample& sample) void SSBModSource::prefetch(unsigned int nbSamples) { - unsigned int nbSamplesAudio = nbSamples * ((Real) m_audioSampleRate / (Real) m_channelSampleRate); + unsigned int nbSamplesAudio = (nbSamples * (unsigned int) ((Real) m_audioSampleRate / (Real) m_channelSampleRate)); pullAudio(nbSamplesAudio); } @@ -174,13 +165,16 @@ void SSBModSource::modulateSample() if (m_settings.m_audioBinaural) { - m_demodBuffer[m_demodBufferFill++] = m_modSample.real() * std::numeric_limits::max(); - m_demodBuffer[m_demodBufferFill++] = m_modSample.imag() * std::numeric_limits::max(); + m_demodBuffer[m_demodBufferFill] = (qint16) (m_modSample.real() * std::numeric_limits::max()); + m_demodBufferFill++; + m_demodBuffer[m_demodBufferFill] = (qint16) (m_modSample.imag() * std::numeric_limits::max()); + m_demodBufferFill++; } else { // take projection on real axis - m_demodBuffer[m_demodBufferFill++] = m_modSample.real() * std::numeric_limits::max(); + m_demodBuffer[m_demodBufferFill] = (qint16) (m_modSample.real() * std::numeric_limits::max()); + m_demodBufferFill++; } if (m_demodBufferFill >= m_demodBuffer.size()) @@ -188,13 +182,11 @@ void SSBModSource::modulateSample() QList dataPipes; MainCore::instance()->getDataPipes().getDataPipes(m_channel, "demod", dataPipes); - if (dataPipes.size() > 0) + if (!dataPipes.empty()) { - QList::iterator it = dataPipes.begin(); - - for (; it != dataPipes.end(); ++it) + for (auto& dataPipe : dataPipes) { - DataFifo *fifo = qobject_cast((*it)->m_element); + DataFifo *fifo = qobject_cast(dataPipe->m_element); if (fifo) { @@ -225,42 +217,33 @@ void SSBModSource::pullAF(Complex& sample) int n_out = 0; int decim = 1<<(m_settings.m_spanLog2 - 1); - unsigned char decim_mask = decim - 1; // counter LSB bit mask for decimation by 2^(m_scaleLog2 - 1) + auto decim_mask = (unsigned char) ((decim - 1) & 0xFF); // counter LSB bit mask for decimation by 2^(m_scaleLog2 - 1) switch (m_settings.m_modAFInput) { case SSBModSettings::SSBModInputTone: - if (m_settings.m_dsb) - { - Real t = m_toneNco.next()/1.25; - sample.real(t); - sample.imag(t); - } - else - { - if (m_settings.m_usb) { - sample = m_toneNco.nextIQ(); - } else { - sample = m_toneNco.nextQI(); - } - } + if (m_settings.m_dsb) + { + Real t = m_toneNco.next()/1.25f; + sample.real(t); + sample.imag(t); + } + else + { + if (m_settings.m_usb) { + sample = m_toneNco.nextIQ(); + } else { + sample = m_toneNco.nextQI(); + } + } break; case SSBModSettings::SSBModInputFile: - // Monaural (mono): - // sox f4exb_call.wav --encoding float --endian little f4exb_call.raw - // ffplay -f f32le -ar 48k -ac 1 f4exb_call.raw - // Binaural (stereo): - // sox f4exb_call.wav --encoding float --endian little f4exb_call.raw - // ffplay -f f32le -ar 48k -ac 2 f4exb_call.raw if (m_ifstream && m_ifstream->is_open()) { - if (m_ifstream->eof()) + if (m_ifstream->eof() && m_settings.m_playLoop) { - if (m_settings.m_playLoop) - { - m_ifstream->clear(); - m_ifstream->seekg(0, std::ios::beg); - } + m_ifstream->clear(); + m_ifstream->seekg(0, std::ios::beg); } if (m_ifstream->eof()) @@ -270,38 +253,38 @@ void SSBModSource::pullAF(Complex& sample) } else { - if (m_settings.m_audioBinaural) - { - Complex c; - m_ifstream->read(reinterpret_cast(&c), sizeof(Complex)); + if (m_settings.m_audioBinaural) + { + Complex c; + m_ifstream->read(reinterpret_cast(&c), sizeof(Complex)); - if (m_settings.m_audioFlipChannels) - { + if (m_settings.m_audioFlipChannels) + { ci.real(c.imag() * m_settings.m_volumeFactor); ci.imag(c.real() * m_settings.m_volumeFactor); - } - else - { - ci = c * m_settings.m_volumeFactor; - } - } - else - { + } + else + { + ci = c * m_settings.m_volumeFactor; + } + } + else + { Real real; - m_ifstream->read(reinterpret_cast(&real), sizeof(Real)); + m_ifstream->read(reinterpret_cast(&real), sizeof(Real)); - if (m_settings.m_agc) - { + if (m_settings.m_agc) + { ci.real(clamp(m_audioCompressor.compress(real), -1.0f, 1.0f)); ci.imag(0.0f); ci *= m_settings.m_volumeFactor; - } - else - { + } + else + { ci.real(real * m_settings.m_volumeFactor); ci.imag(0.0f); - } - } + } + } } } else @@ -312,24 +295,24 @@ void SSBModSource::pullAF(Complex& sample) break; case SSBModSettings::SSBModInputAudio: if (m_settings.m_audioBinaural) - { - if (m_settings.m_audioFlipChannels) - { + { + if (m_settings.m_audioFlipChannels) + { ci.real((m_audioBuffer[m_audioBufferFill].r / SDR_TX_SCALEF) * m_settings.m_volumeFactor); ci.imag((m_audioBuffer[m_audioBufferFill].l / SDR_TX_SCALEF) * m_settings.m_volumeFactor); - } - else - { + } + else + { ci.real((m_audioBuffer[m_audioBufferFill].l / SDR_TX_SCALEF) * m_settings.m_volumeFactor); ci.imag((m_audioBuffer[m_audioBufferFill].r / SDR_TX_SCALEF) * m_settings.m_volumeFactor); - } - } + } + } else { if (m_settings.m_agc) { - float sample = (m_audioBuffer[m_audioBufferFill].l + m_audioBuffer[m_audioBufferFill].r) / 65536.0f; - ci.real(clamp(m_audioCompressor.compress(sample), -1.0f, 1.0f)); + float xsample = (m_audioBuffer[m_audioBufferFill].l + m_audioBuffer[m_audioBufferFill].r) / 65536.0f; + ci.real(clamp(m_audioCompressor.compress(xsample), -1.0f, 1.0f)); ci.imag(0.0f); ci *= m_settings.m_volumeFactor; } @@ -347,7 +330,7 @@ void SSBModSource::pullAF(Complex& sample) else { qDebug("SSBModSource::pullAF: starve audio samples: size: %lu", m_audioBuffer.size()); - m_audioBufferFill = m_audioBuffer.size() - 1; + m_audioBufferFill = (unsigned int) (m_audioBuffer.size() - 1); } break; @@ -356,56 +339,55 @@ void SSBModSource::pullAF(Complex& sample) break; } - Real fadeFactor; + Real fadeFactor; if (m_cwKeyer->getSample()) { m_cwKeyer->getCWSmoother().getFadeSample(true, fadeFactor); - if (m_settings.m_dsb) - { - Real t = m_toneNco.next() * fadeFactor; - sample.real(t); - sample.imag(t); - } - else - { - if (m_settings.m_usb) { - sample = m_toneNco.nextIQ() * fadeFactor; - } else { - sample = m_toneNco.nextQI() * fadeFactor; - } - } + if (m_settings.m_dsb) + { + Real t = m_toneNco.next() * fadeFactor; + sample.real(t); + sample.imag(t); + } + else + { + if (m_settings.m_usb) { + sample = m_toneNco.nextIQ() * fadeFactor; + } else { + sample = m_toneNco.nextQI() * fadeFactor; + } + } } else { - if (m_cwKeyer->getCWSmoother().getFadeSample(false, fadeFactor)) - { - if (m_settings.m_dsb) - { - Real t = (m_toneNco.next() * fadeFactor)/1.25; - sample.real(t); - sample.imag(t); - } - else - { - if (m_settings.m_usb) { - sample = m_toneNco.nextIQ() * fadeFactor; - } else { - sample = m_toneNco.nextQI() * fadeFactor; - } - } - } - else - { + if (m_cwKeyer->getCWSmoother().getFadeSample(false, fadeFactor)) + { + if (m_settings.m_dsb) + { + Real t = (m_toneNco.next() * fadeFactor)/1.25f; + sample.real(t); + sample.imag(t); + } + else + { + if (m_settings.m_usb) { + sample = m_toneNco.nextIQ() * fadeFactor; + } else { + sample = m_toneNco.nextQI() * fadeFactor; + } + } + } + else + { sample.real(0.0f); sample.imag(0.0f); m_toneNco.setPhase(0); - } + } } break; - case SSBModSettings::SSBModInputNone: default: sample.real(0.0f); sample.imag(0.0f); @@ -415,35 +397,35 @@ void SSBModSource::pullAF(Complex& sample) if ((m_settings.m_modAFInput == SSBModSettings::SSBModInputFile) || (m_settings.m_modAFInput == SSBModSettings::SSBModInputAudio)) // real audio { - if (m_settings.m_dsb) - { - n_out = m_DSBFilter->runDSB(ci, &filtered); + if (m_settings.m_dsb) + { + n_out = m_DSBFilter->runDSB(ci, &filtered); - if (n_out > 0) - { - memcpy((void *) m_DSBFilterBuffer, (const void *) filtered, n_out*sizeof(Complex)); - m_DSBFilterBufferIndex = 0; - } + if (n_out > 0) + { + memcpy((void *) m_DSBFilterBuffer, (const void *) filtered, n_out*sizeof(Complex)); + m_DSBFilterBufferIndex = 0; + } - sample = m_DSBFilterBuffer[m_DSBFilterBufferIndex]; - m_DSBFilterBufferIndex++; - } - else - { - n_out = m_SSBFilter->runSSB(ci, &filtered, m_settings.m_usb); + sample = m_DSBFilterBuffer[m_DSBFilterBufferIndex]; + m_DSBFilterBufferIndex++; + } + else + { + n_out = m_SSBFilter->runSSB(ci, &filtered, m_settings.m_usb); - if (n_out > 0) - { - memcpy((void *) m_SSBFilterBuffer, (const void *) filtered, n_out*sizeof(Complex)); - m_SSBFilterBufferIndex = 0; - } + if (n_out > 0) + { + memcpy((void *) m_SSBFilterBuffer, (const void *) filtered, n_out*sizeof(Complex)); + m_SSBFilterBufferIndex = 0; + } - sample = m_SSBFilterBuffer[m_SSBFilterBufferIndex]; - m_SSBFilterBufferIndex++; - } + sample = m_SSBFilterBuffer[m_SSBFilterBufferIndex]; + m_SSBFilterBufferIndex++; + } - if (n_out > 0) - { + if (n_out > 0) + { for (int i = 0; i < n_out; i++) { // Downsample by 2^(m_scaleLog2 - 1) for SSB band spectrum display @@ -453,23 +435,23 @@ void SSBModSource::pullAF(Complex& sample) if (!(m_undersampleCount++ & decim_mask)) { - Real avgr = (m_sum.real() / decim) * 0.891235351562f * SDR_TX_SCALEF; //scaling at -1 dB to account for possible filter overshoot - Real avgi = (m_sum.imag() / decim) * 0.891235351562f * SDR_TX_SCALEF; + Real avgr = (m_sum.real() / (float) decim) * 0.891235351562f * SDR_TX_SCALEF; //scaling at -1 dB to account for possible filter overshoot + Real avgi = (m_sum.imag() / (float) decim) * 0.891235351562f * SDR_TX_SCALEF; - if (!m_settings.m_dsb & !m_settings.m_usb) + if (!m_settings.m_dsb && !m_settings.m_usb) { // invert spectrum for LSB - m_sampleBuffer.push_back(Sample(avgi, avgr)); + m_sampleBuffer.push_back(Sample((FixReal) avgi, (FixReal) avgr)); } else { - m_sampleBuffer.push_back(Sample(avgr, avgi)); + m_sampleBuffer.push_back(Sample((FixReal) avgr, (FixReal)avgi)); } m_sum.real(0.0); m_sum.imag(0.0); } } - } + } } // Real audio else if ((m_settings.m_modAFInput == SSBModSettings::SSBModInputTone) || (m_settings.m_modAFInput == SSBModSettings::SSBModInputCWTone)) // tone @@ -478,16 +460,16 @@ void SSBModSource::pullAF(Complex& sample) if (!(m_undersampleCount++ & decim_mask)) { - Real avgr = (m_sum.real() / decim) * 0.891235351562f * SDR_TX_SCALEF; //scaling at -1 dB to account for possible filter overshoot - Real avgi = (m_sum.imag() / decim) * 0.891235351562f * SDR_TX_SCALEF; + Real avgr = (m_sum.real() / (float) decim) * 0.891235351562f * SDR_TX_SCALEF; //scaling at -1 dB to account for possible filter overshoot + Real avgi = (m_sum.imag() / (float) decim) * 0.891235351562f * SDR_TX_SCALEF; - if (!m_settings.m_dsb & !m_settings.m_usb) + if (!m_settings.m_dsb && !m_settings.m_usb) { // invert spectrum for LSB - m_sampleBuffer.push_back(Sample(avgi, avgr)); + m_sampleBuffer.push_back(Sample((FixReal) avgi, (FixReal) avgr)); } else { - m_sampleBuffer.push_back(Sample(avgr, avgi)); + m_sampleBuffer.push_back(Sample((FixReal) avgr, (FixReal) avgi)); } m_sum.real(0.0); @@ -538,18 +520,18 @@ void SSBModSource::pushFeedback(Complex c) } } -void SSBModSource::processOneSample(Complex& ci) +void SSBModSource::processOneSample(const Complex& ci) { if (m_settings.m_modAFInput == SSBModSettings::SSBModInputCWTone) // minimize latency for CW { - m_feedbackAudioBuffer[0].l = ci.real(); - m_feedbackAudioBuffer[0].r = ci.imag(); + m_feedbackAudioBuffer[0].l = (qint16) ci.real(); + m_feedbackAudioBuffer[0].r = (qint16) ci.imag(); m_feedbackAudioFifo.writeOne((const quint8*) &m_feedbackAudioBuffer[0]); } else { - m_feedbackAudioBuffer[m_feedbackAudioBufferFill].l = ci.real(); - m_feedbackAudioBuffer[m_feedbackAudioBufferFill].r = ci.imag(); + m_feedbackAudioBuffer[m_feedbackAudioBufferFill].l = (qint16) ci.real(); + m_feedbackAudioBuffer[m_feedbackAudioBufferFill].r = (qint16) ci.imag(); ++m_feedbackAudioBufferFill; if (m_feedbackAudioBufferFill >= m_feedbackAudioBuffer.size()) @@ -568,9 +550,9 @@ void SSBModSource::processOneSample(Complex& ci) } } -void SSBModSource::calculateLevel(Complex& sample) +void SSBModSource::calculateLevel(const Complex& sample) { - Real t = sample.real(); // TODO: possibly adjust depending on sample type + Real t = sample.real(); if (m_levelCalcCount < m_levelNbSamples) { @@ -617,14 +599,14 @@ void SSBModSource::applyAudioSampleRate(int sampleRate) lowCutoff = band - 100.0f; } - m_SSBFilter->create_filter(lowCutoff / sampleRate, band / sampleRate); - m_DSBFilter->create_dsb_filter((2.0f * band) / sampleRate); + m_SSBFilter->create_filter(lowCutoff / (float) sampleRate, band / (float) sampleRate); + m_DSBFilter->create_dsb_filter((2.0f * band) / (float) sampleRate); m_settings.m_bandwidth = band; m_settings.m_lowCutoff = lowCutoff; m_settings.m_usb = usb; - m_toneNco.setFreq(m_settings.m_toneFrequency, sampleRate); + m_toneNco.setFreq(m_settings.m_toneFrequency, (float) sampleRate); if (m_cwKeyer) { @@ -632,7 +614,7 @@ void SSBModSource::applyAudioSampleRate(int sampleRate) m_cwKeyer->reset(); } - m_audioCompressor.m_rate = sampleRate; + m_audioCompressor.m_rate = (float) sampleRate; m_audioCompressor.initState(); m_audioSampleRate = sampleRate; @@ -641,7 +623,7 @@ void SSBModSource::applyAudioSampleRate(int sampleRate) QList pipes; MainCore::instance()->getMessagePipes().getMessagePipes(m_channel, "reportdemod", pipes); - if (pipes.size() > 0) + if (!pipes.empty()) { for (const auto& pipe : pipes) { @@ -665,7 +647,7 @@ void SSBModSource::applyFeedbackAudioSampleRate(int sampleRate) m_feedbackInterpolatorDistanceRemain = 0; m_feedbackInterpolatorConsumed = false; m_feedbackInterpolatorDistance = (Real) sampleRate / (Real) m_audioSampleRate; - Real cutoff = std::min(sampleRate, m_audioSampleRate) / 2.2f; + Real cutoff = (float) (std::min(sampleRate, m_audioSampleRate)) / 2.2f; m_feedbackInterpolator.create(48, sampleRate, cutoff, 3.0); m_feedbackAudioSampleRate = sampleRate; } @@ -693,12 +675,12 @@ void SSBModSource::applySettings(const SSBModSettings& settings, bool force) m_interpolatorConsumed = false; m_interpolatorDistance = (Real) m_audioSampleRate / (Real) m_channelSampleRate; m_interpolator.create(48, m_audioSampleRate, band, 3.0); - m_SSBFilter->create_filter(lowCutoff / m_audioSampleRate, band / m_audioSampleRate); - m_DSBFilter->create_dsb_filter((2.0f * band) / m_audioSampleRate); + m_SSBFilter->create_filter(lowCutoff / (float) m_audioSampleRate, band / (float) m_audioSampleRate); + m_DSBFilter->create_dsb_filter((2.0f * band) / (float) m_audioSampleRate); } if ((settings.m_toneFrequency != m_settings.m_toneFrequency) || force) { - m_toneNco.setFreq(settings.m_toneFrequency, m_audioSampleRate); + m_toneNco.setFreq(settings.m_toneFrequency, (float) m_audioSampleRate); } if ((settings.m_dsb != m_settings.m_dsb) || force) @@ -729,11 +711,11 @@ void SSBModSource::applySettings(const SSBModSettings& settings, bool force) { m_audioCompressor.initSimple( m_audioSampleRate, - settings.m_cmpPreGainDB, // pregain (dB) - settings.m_cmpThresholdDB, // threshold (dB) + (float) settings.m_cmpPreGainDB, // pregain (dB) + (float) settings.m_cmpThresholdDB, // threshold (dB) 20, // knee (dB) 12, // ratio (dB) - 0.003, // attack (s) + 0.003f,// attack (s) 0.25 // release (s) ); } @@ -751,8 +733,8 @@ void SSBModSource::applyChannelSettings(int channelSampleRate, int channelFreque << " channelFrequencyOffset: " << channelFrequencyOffset; if ((channelFrequencyOffset != m_channelFrequencyOffset) - || (channelSampleRate != m_channelSampleRate) || force) { - m_carrierNco.setFreq(channelFrequencyOffset, channelSampleRate); + || (channelSampleRate != m_channelSampleRate) || force) { + m_carrierNco.setFreq((float) channelFrequencyOffset, (float) channelSampleRate); } if ((channelSampleRate != m_channelSampleRate) || force) @@ -769,7 +751,6 @@ void SSBModSource::applyChannelSettings(int channelSampleRate, int channelFreque void SSBModSource::handleAudio() { - QMutexLocker mlock(&m_mutex); unsigned int nbRead; while ((nbRead = m_audioFifo.read(reinterpret_cast(&m_audioReadBuffer[m_audioReadBufferFill]), 4096)) != 0) diff --git a/plugins/channeltx/modssb/ssbmodsource.h b/plugins/channeltx/modssb/ssbmodsource.h index 1eb4cb348..20fed05b5 100644 --- a/plugins/channeltx/modssb/ssbmodsource.h +++ b/plugins/channeltx/modssb/ssbmodsource.h @@ -46,11 +46,11 @@ class SSBModSource : public QObject, public ChannelSampleSource Q_OBJECT public: SSBModSource(); - virtual ~SSBModSource(); + ~SSBModSource() final; - virtual void pull(SampleVector::iterator begin, unsigned int nbSamples); - virtual void pullOne(Sample& sample); - virtual void prefetch(unsigned int nbSamples); + void pull(SampleVector::iterator begin, unsigned int nbSamples) final; + void pullOne(Sample& sample) final; + void prefetch(unsigned int nbSamples) final; void setInputFileStream(std::ifstream *ifstream) { m_ifstream = ifstream; } AudioFifo *getAudioFifo() { return &m_audioFifo; } @@ -70,12 +70,12 @@ public: numSamples = m_levelNbSamples; } void applySettings(const SSBModSettings& settings, bool force = false); - void applyChannelSettings(int channelSampleRate, int channelFrequencyOffset, bool force = 0); + void applyChannelSettings(int channelSampleRate, int channelFrequencyOffset, bool force = false); void setSpectrumSink(SpectrumVis *sampleSink) { m_spectrumSink = sampleSink; } private: - int m_channelSampleRate; - int m_channelFrequencyOffset; + int m_channelSampleRate = 48000; + int m_channelFrequencyOffset = 0; SSBModSettings m_settings; ChannelAPI *m_channel; @@ -104,7 +104,7 @@ private: int m_DSBFilterBufferIndex; static const int m_ssbFftLen; - SpectrumVis* m_spectrumSink; + SpectrumVis* m_spectrumSink = nullptr; SampleVector m_sampleBuffer; fftfilt::cmplx m_sum; @@ -114,7 +114,7 @@ private: double m_magsq; MovingAverageUtil m_movingAverage; - int m_audioSampleRate; + int m_audioSampleRate = 48000; AudioVector m_audioBuffer; unsigned int m_audioBufferFill; AudioVector m_audioReadBuffer; @@ -126,14 +126,14 @@ private: uint m_feedbackAudioBufferFill; AudioFifo m_feedbackAudioFifo; - quint32 m_levelCalcCount; + quint32 m_levelCalcCount = 0; qreal m_rmsLevel; qreal m_peakLevelOut; - Real m_peakLevel; - Real m_levelSum; + Real m_peakLevel = 0.0f; + Real m_levelSum = 0.0f; - std::ifstream *m_ifstream; - CWKeyer *m_cwKeyer; + std::ifstream *m_ifstream = nullptr; + CWKeyer *m_cwKeyer = nullptr; AudioCompressorSnd m_audioCompressor; int m_agcStepLength; @@ -142,11 +142,11 @@ private: static const int m_levelNbSamples; - void processOneSample(Complex& ci); + void processOneSample(const Complex& ci); void pullAF(Complex& sample); void pullAudio(unsigned int nbSamples); void pushFeedback(Complex sample); - void calculateLevel(Complex& sample); + void calculateLevel(const Complex& sample); void modulateSample(); private slots: diff --git a/plugins/samplesink/bladerf1output/bladerf1output.cpp b/plugins/samplesink/bladerf1output/bladerf1output.cpp index df7a634ee..9d03add8e 100644 --- a/plugins/samplesink/bladerf1output/bladerf1output.cpp +++ b/plugins/samplesink/bladerf1output/bladerf1output.cpp @@ -68,11 +68,11 @@ Bladerf1Output::~Bladerf1Output() delete m_networkManager; if (m_running) { - stop(); + Bladerf1Output::stop(); } closeDevice(); - m_deviceAPI->setBuddySharedPtr(0); + m_deviceAPI->setBuddySharedPtr(nullptr); } void Bladerf1Output::destroy() @@ -82,7 +82,7 @@ void Bladerf1Output::destroy() bool Bladerf1Output::openDevice() { - if (m_dev != 0) { + if (m_dev != nullptr) { closeDevice(); } @@ -90,24 +90,24 @@ bool Bladerf1Output::openDevice() m_sampleSourceFifo.resize(SampleSourceFifo::getSizePolicy(m_settings.m_devSampleRate)); - if (m_deviceAPI->getSourceBuddies().size() > 0) + if (!m_deviceAPI->getSourceBuddies().empty()) { - DeviceAPI *sourceBuddy = m_deviceAPI->getSourceBuddies()[0]; - DeviceBladeRF1Params *buddySharedParams = (DeviceBladeRF1Params *) sourceBuddy->getBuddySharedPtr(); + const DeviceAPI *sourceBuddy = m_deviceAPI->getSourceBuddies()[0]; + const DeviceBladeRF1Params *buddySharedParams = (DeviceBladeRF1Params *) sourceBuddy->getBuddySharedPtr(); - if (buddySharedParams == 0) + if (buddySharedParams == nullptr) { qCritical("BladerfOutput::start: could not get shared parameters from buddy"); return false; } - if (buddySharedParams->m_dev == 0) // device is not opened by buddy + if (buddySharedParams->m_dev == nullptr) // device is not opened by buddy { qCritical("BladerfOutput::start: could not get BladeRF handle from buddy"); return false; } - m_sharedParams = *(buddySharedParams); // copy parameters from buddy + m_sharedParams = *buddySharedParams; // copy parameters from buddy m_dev = m_sharedParams.m_dev; // get BladeRF handle } else @@ -121,7 +121,6 @@ bool Bladerf1Output::openDevice() m_sharedParams.m_dev = m_dev; } - // TODO: adjust USB transfer data according to sample rate if ((res = bladerf_sync_config(m_dev, BLADERF_TX_X1, BLADERF_FORMAT_SC16_Q11, 64, 8192, 32, 10000)) < 0) { qCritical("BladerfOutput::start: bladerf_sync_config with return code %d", res); @@ -183,14 +182,14 @@ void Bladerf1Output::closeDevice() { qDebug("BladerfOutput::closeDevice: closing device since Rx side is not open"); - if (m_dev != 0) // close BladeRF + if (m_dev != nullptr) // close BladeRF { bladerf_close(m_dev); } } m_sharedParams.m_dev = nullptr; - m_dev = 0; + m_dev = nullptr; } void Bladerf1Output::stop() @@ -273,7 +272,7 @@ bool Bladerf1Output::handleMessage(const Message& message) { if (MsgConfigureBladerf1::match(message)) { - MsgConfigureBladerf1& conf = (MsgConfigureBladerf1&) message; + auto& conf = (const MsgConfigureBladerf1&) message; qDebug() << "BladerfOutput::handleMessage: MsgConfigureBladerf"; if (!applySettings(conf.getSettings(), conf.getSettingsKeys(), conf.getForce())) { @@ -284,7 +283,7 @@ bool Bladerf1Output::handleMessage(const Message& message) } else if (MsgStartStop::match(message)) { - MsgStartStop& cmd = (MsgStartStop&) message; + auto& cmd = (const MsgStartStop&) message; qDebug() << "BladerfOutput::handleMessage: MsgStartStop: " << (cmd.getStartStop() ? "start" : "stop"); if (cmd.getStartStop()) @@ -316,7 +315,7 @@ bool Bladerf1Output::applySettings(const BladeRF1OutputSettings& settings, const bool forwardChange = false; bool suspendOwnThread = false; bool threadWasRunning = false; -// QMutexLocker mutexLocker(&m_mutex); + QMutexLocker mutexLocker(&m_mutex); if (settingsKeys.contains("devSampleRate") || settingsKeys.contains("log2Interp") || force) @@ -324,16 +323,10 @@ bool Bladerf1Output::applySettings(const BladeRF1OutputSettings& settings, const suspendOwnThread = true; } - if (suspendOwnThread) + if (suspendOwnThread && m_bladerfThread && m_bladerfThread->isRunning()) { - if (m_bladerfThread) - { - if (m_bladerfThread->isRunning()) - { - m_bladerfThread->stopWork(); - threadWasRunning = true; - } - } + m_bladerfThread->stopWork(); + threadWasRunning = true; } if (settingsKeys.contains("devSampleRate") || @@ -354,7 +347,7 @@ bool Bladerf1Output::applySettings(const BladeRF1OutputSettings& settings, const { forwardChange = true; - if (m_dev != 0) + if (m_dev != nullptr) { unsigned int actualSamplerate; @@ -370,129 +363,108 @@ bool Bladerf1Output::applySettings(const BladeRF1OutputSettings& settings, const { forwardChange = true; - if (m_bladerfThread != 0) + if (m_bladerfThread != nullptr) { m_bladerfThread->setLog2Interpolation(settings.m_log2Interp); qDebug() << "BladerfOutput::applySettings: set interpolation to " << (1<getSourceBuddies().size() > 0) - { - DeviceAPI *buddy = m_deviceAPI->getSourceBuddies()[0]; - - if (buddy->getDeviceSourceEngine()->state() == DSPDeviceSourceEngine::StRunning) { // Tx side running - changeSettings = false; - } else { - changeSettings = true; - } - } - else // No Rx open - { - changeSettings = true; - } - - if (changeSettings) - { - if (settings.m_xb200) - { - if (bladerf_expansion_attach(m_dev, BLADERF_XB_200) != 0) { - qDebug("BladerfOutput::applySettings: bladerf_expansion_attach(xb200) failed"); - } else { - qDebug() << "BladerfOutput::applySettings: Attach XB200"; - } - } - else - { - if (bladerf_expansion_attach(m_dev, BLADERF_XB_NONE) != 0) { - qDebug("BladerfOutput::applySettings: bladerf_expansion_attach(none) failed"); - } else { - qDebug() << "BladerfOutput::applySettings: Detach XB200"; - } - } - - m_sharedParams.m_xb200Attached = settings.m_xb200; - } + if (bladerf_set_txvga1(m_dev, settings.m_vga1) != 0) { + qDebug("BladerfOutput::applySettings: bladerf_set_txvga1() failed"); + } else { + qDebug() << "BladerfOutput::applySettings: VGA1 gain set to " << settings.m_vga1; } } - if (settingsKeys.contains("xb200Path") || force) + if ((m_dev != nullptr) && (settingsKeys.contains("vga2") || force)) { - if (m_dev != 0) - { - if (bladerf_xb200_set_path(m_dev, BLADERF_MODULE_TX, settings.m_xb200Path) != 0) { - qDebug("BladerfOutput::applySettings: bladerf_xb200_set_path(BLADERF_MODULE_TX) failed"); - } else { - qDebug() << "BladerfOutput::applySettings: set xb200 path to " << settings.m_xb200Path; - } - } + if (bladerf_set_txvga2(m_dev, settings.m_vga2) != 0) { + qDebug("BladerfOutput::applySettings:bladerf_set_rxvga2() failed"); + } else { + qDebug() << "BladerfOutput::applySettings: VGA2 gain set to " << settings.m_vga2; + } } - if (settingsKeys.contains("xb200Filter") || force) + if ((m_dev != nullptr) && (settingsKeys.contains("xb200") || force)) { - if (m_dev != 0) - { - if (bladerf_xb200_set_filterbank(m_dev, BLADERF_MODULE_TX, settings.m_xb200Filter) != 0) { - qDebug("BladerfOutput::applySettings: bladerf_xb200_set_filterbank(BLADERF_MODULE_TX) failed"); - } else { - qDebug() << "BladerfOutput::applySettings: set xb200 filter to " << settings.m_xb200Filter; - } - } + bool changeSettings; + + if (!m_deviceAPI->getSourceBuddies().empty()) + { + DeviceAPI *buddy = m_deviceAPI->getSourceBuddies()[0]; + + if (buddy->getDeviceSourceEngine()->state() == DSPDeviceSourceEngine::State::StRunning) { // Tx side running + changeSettings = false; + } else { + changeSettings = true; + } + } + else // No Rx open + { + changeSettings = true; + } + + if (changeSettings) + { + if (settings.m_xb200) + { + if (bladerf_expansion_attach(m_dev, BLADERF_XB_200) != 0) { + qDebug("BladerfOutput::applySettings: bladerf_expansion_attach(xb200) failed"); + } else { + qDebug() << "BladerfOutput::applySettings: Attach XB200"; + } + } + else + { + if (bladerf_expansion_attach(m_dev, BLADERF_XB_NONE) != 0) { + qDebug("BladerfOutput::applySettings: bladerf_expansion_attach(none) failed"); + } else { + qDebug() << "BladerfOutput::applySettings: Detach XB200"; + } + } + + m_sharedParams.m_xb200Attached = settings.m_xb200; + } } - if (settingsKeys.contains("bandwidth") || force) + if ((m_dev != nullptr) && (settingsKeys.contains("xb200Path") || force)) { - if (m_dev != 0) - { - unsigned int actualBandwidth; + if (bladerf_xb200_set_path(m_dev, BLADERF_MODULE_TX, settings.m_xb200Path) != 0) { + qDebug("BladerfOutput::applySettings: bladerf_xb200_set_path(BLADERF_MODULE_TX) failed"); + } else { + qDebug() << "BladerfOutput::applySettings: set xb200 path to " << settings.m_xb200Path; + } + } - if (bladerf_set_bandwidth(m_dev, BLADERF_MODULE_TX, settings.m_bandwidth, &actualBandwidth) < 0) { - qCritical("BladerfOutput::applySettings: could not set bandwidth: %d", settings.m_bandwidth); - } else { - qDebug() << "BladerfOutput::applySettings: bladerf_set_bandwidth(BLADERF_MODULE_TX) actual bandwidth is " << actualBandwidth; - } - } + if ((m_dev != nullptr) && (settingsKeys.contains("xb200Filter") || force)) + { + if (bladerf_xb200_set_filterbank(m_dev, BLADERF_MODULE_TX, settings.m_xb200Filter) != 0) { + qDebug("BladerfOutput::applySettings: bladerf_xb200_set_filterbank(BLADERF_MODULE_TX) failed"); + } else { + qDebug() << "BladerfOutput::applySettings: set xb200 filter to " << settings.m_xb200Filter; + } + } + + if ((m_dev != nullptr) && (settingsKeys.contains("bandwidth") || force)) + { + unsigned int actualBandwidth; + + if (bladerf_set_bandwidth(m_dev, BLADERF_MODULE_TX, settings.m_bandwidth, &actualBandwidth) < 0) { + qCritical("BladerfOutput::applySettings: could not set bandwidth: %d", settings.m_bandwidth); + } else { + qDebug() << "BladerfOutput::applySettings: bladerf_set_bandwidth(BLADERF_MODULE_TX) actual bandwidth is " << actualBandwidth; + } } if (settingsKeys.contains("centerFrequency")) { forwardChange = true; - if (m_dev != 0) - { - if (bladerf_set_frequency( m_dev, BLADERF_MODULE_TX, settings.m_centerFrequency ) != 0) { - qDebug("BladerfOutput::applySettings: bladerf_set_frequency(%lld) failed", settings.m_centerFrequency); - } + if ((m_dev != nullptr) && (bladerf_set_frequency( m_dev, BLADERF_MODULE_TX, settings.m_centerFrequency ) != 0)) { + qDebug("BladerfOutput::applySettings: bladerf_set_frequency(%lld) failed", settings.m_centerFrequency); } } @@ -519,7 +491,7 @@ bool Bladerf1Output::applySettings(const BladeRF1OutputSettings& settings, const if (forwardChange) { int sampleRate = m_settings.m_devSampleRate/(1<getDeviceEngineInputMessageQueue()->push(notif); } @@ -608,7 +580,7 @@ void Bladerf1Output::webapiUpdateDeviceSettings( settings.m_log2Interp = response.getBladeRf1OutputSettings()->getLog2Interp(); } if (deviceSettingsKeys.contains("xb200")) { - settings.m_xb200 = response.getBladeRf1OutputSettings()->getXb200() == 0 ? 0 : 1; + settings.m_xb200 = response.getBladeRf1OutputSettings()->getXb200() == 0 ? false : true; } if (deviceSettingsKeys.contains("xb200Path")) { settings.m_xb200Path = static_cast(response.getBladeRf1OutputSettings()->getXb200Path()); @@ -623,10 +595,10 @@ void Bladerf1Output::webapiUpdateDeviceSettings( settings.m_reverseAPIAddress = *response.getBladeRf1OutputSettings()->getReverseApiAddress(); } if (deviceSettingsKeys.contains("reverseAPIPort")) { - settings.m_reverseAPIPort = response.getBladeRf1OutputSettings()->getReverseApiPort(); + settings.m_reverseAPIPort = (uint16_t) response.getBladeRf1OutputSettings()->getReverseApiPort(); } if (deviceSettingsKeys.contains("reverseAPIDeviceIndex")) { - settings.m_reverseAPIDeviceIndex = response.getBladeRf1OutputSettings()->getReverseApiDeviceIndex(); + settings.m_reverseAPIDeviceIndex = (uint16_t) response.getBladeRf1OutputSettings()->getReverseApiDeviceIndex(); } } @@ -660,7 +632,7 @@ int Bladerf1Output::webapiRun( void Bladerf1Output::webapiReverseSendSettings(const QList& deviceSettingsKeys, const BladeRF1OutputSettings& settings, bool force) { - SWGSDRangel::SWGDeviceSettings *swgDeviceSettings = new SWGSDRangel::SWGDeviceSettings(); + auto *swgDeviceSettings = new SWGSDRangel::SWGDeviceSettings(); swgDeviceSettings->setDirection(1); // single Tx swgDeviceSettings->setOriginatorIndex(m_deviceAPI->getDeviceSetIndex()); swgDeviceSettings->setDeviceHwType(new QString("BladeRF1")); @@ -704,8 +676,8 @@ void Bladerf1Output::webapiReverseSendSettings(const QList& deviceSetti m_networkRequest.setUrl(QUrl(deviceSettingsURL)); m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); - QBuffer *buffer = new QBuffer(); - buffer->open((QBuffer::ReadWrite)); + auto *buffer = new QBuffer(); + buffer->open(QBuffer::ReadWrite); buffer->write(swgDeviceSettings->asJson().toUtf8()); buffer->seek(0); @@ -718,7 +690,7 @@ void Bladerf1Output::webapiReverseSendSettings(const QList& deviceSetti void Bladerf1Output::webapiReverseSendStartStop(bool start) { - SWGSDRangel::SWGDeviceSettings *swgDeviceSettings = new SWGSDRangel::SWGDeviceSettings(); + auto *swgDeviceSettings = new SWGSDRangel::SWGDeviceSettings(); swgDeviceSettings->setDirection(1); // single Tx swgDeviceSettings->setOriginatorIndex(m_deviceAPI->getDeviceSetIndex()); swgDeviceSettings->setDeviceHwType(new QString("BladeRF1")); @@ -730,8 +702,8 @@ void Bladerf1Output::webapiReverseSendStartStop(bool start) m_networkRequest.setUrl(QUrl(deviceSettingsURL)); m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); - QBuffer *buffer = new QBuffer(); - buffer->open((QBuffer::ReadWrite)); + auto *buffer = new QBuffer(); + buffer->open(QBuffer::ReadWrite); buffer->write(swgDeviceSettings->asJson().toUtf8()); buffer->seek(0); QNetworkReply *reply; @@ -746,7 +718,7 @@ void Bladerf1Output::webapiReverseSendStartStop(bool start) delete swgDeviceSettings; } -void Bladerf1Output::networkManagerFinished(QNetworkReply *reply) +void Bladerf1Output::networkManagerFinished(QNetworkReply *reply) const { QNetworkReply::NetworkError replyError = reply->error(); diff --git a/plugins/samplesink/bladerf1output/bladerf1output.h b/plugins/samplesink/bladerf1output/bladerf1output.h index e1d796971..480b3fa4f 100644 --- a/plugins/samplesink/bladerf1output/bladerf1output.h +++ b/plugins/samplesink/bladerf1output/bladerf1output.h @@ -74,10 +74,10 @@ public: return new MsgStartStop(startStop); } - protected: + private: bool m_startStop; - MsgStartStop(bool startStop) : + explicit MsgStartStop(bool startStop) : Message(), m_startStop(startStop) { } @@ -100,57 +100,57 @@ public: { } }; - Bladerf1Output(DeviceAPI *deviceAPI); - virtual ~Bladerf1Output(); - virtual void destroy(); + explicit Bladerf1Output(DeviceAPI *deviceAPI); + ~Bladerf1Output() final; + void destroy() final; - virtual void init(); - virtual bool start(); - virtual void stop(); + void init() final; + bool start() final; + void stop() final; - virtual QByteArray serialize() const; - virtual bool deserialize(const QByteArray& data); + QByteArray serialize() const final; + bool deserialize(const QByteArray& data) final; - virtual void setMessageQueueToGUI(MessageQueue *queue) { m_guiMessageQueue = queue; } - virtual const QString& getDeviceDescription() const; - virtual int getSampleRate() const; - virtual void setSampleRate(int sampleRate) { (void) sampleRate; } - virtual quint64 getCenterFrequency() const; - virtual void setCenterFrequency(qint64 centerFrequency); + void setMessageQueueToGUI(MessageQueue *queue) final { m_guiMessageQueue = queue; } + const QString& getDeviceDescription() const final; + int getSampleRate() const final; + void setSampleRate(int sampleRate) final { (void) sampleRate; } + quint64 getCenterFrequency() const final; + void setCenterFrequency(qint64 centerFrequency) final; - virtual bool handleMessage(const Message& message); + bool handleMessage(const Message& message) final; - virtual int webapiSettingsGet( - SWGSDRangel::SWGDeviceSettings& response, - QString& errorMessage); + int webapiSettingsGet( + SWGSDRangel::SWGDeviceSettings& response, + QString& errorMessage) final; - virtual int webapiSettingsPutPatch( - bool force, - const QStringList& deviceSettingsKeys, - SWGSDRangel::SWGDeviceSettings& response, // query + response - QString& errorMessage); + int webapiSettingsPutPatch( + bool force, + const QStringList& deviceSettingsKeys, + SWGSDRangel::SWGDeviceSettings& response, // query + response + QString& errorMessage) final; - virtual int webapiRunGet( - SWGSDRangel::SWGDeviceState& response, - QString& errorMessage); + int webapiRunGet( + SWGSDRangel::SWGDeviceState& response, + QString& errorMessage) final; - virtual int webapiRun( - bool run, - SWGSDRangel::SWGDeviceState& response, - QString& errorMessage); + int webapiRun( + bool run, + SWGSDRangel::SWGDeviceState& response, + QString& errorMessage) final; static void webapiFormatDeviceSettings( - SWGSDRangel::SWGDeviceSettings& response, - const BladeRF1OutputSettings& settings); + SWGSDRangel::SWGDeviceSettings& response, + const BladeRF1OutputSettings& settings); static void webapiUpdateDeviceSettings( - BladeRF1OutputSettings& settings, - const QStringList& deviceSettingsKeys, - SWGSDRangel::SWGDeviceSettings& response); + BladeRF1OutputSettings& settings, + const QStringList& deviceSettingsKeys, + SWGSDRangel::SWGDeviceSettings& response); private: DeviceAPI *m_deviceAPI; - QMutex m_mutex; + QRecursiveMutex m_mutex; BladeRF1OutputSettings m_settings; struct bladerf* m_dev; Bladerf1OutputThread* m_bladerfThread; @@ -167,7 +167,7 @@ private: void webapiReverseSendStartStop(bool start); private slots: - void networkManagerFinished(QNetworkReply *reply); + void networkManagerFinished(QNetworkReply *reply) const; }; #endif // INCLUDE_BLADERFOUTPUT_H diff --git a/plugins/samplesink/fileoutput/fileoutput.cpp b/plugins/samplesink/fileoutput/fileoutput.cpp index 83034f8a3..d00c38f66 100644 --- a/plugins/samplesink/fileoutput/fileoutput.cpp +++ b/plugins/samplesink/fileoutput/fileoutput.cpp @@ -44,11 +44,8 @@ MESSAGE_CLASS_DEFINITION(FileOutput::MsgReportFileOutputStreamTiming, Message) FileOutput::FileOutput(DeviceAPI *deviceAPI) : m_deviceAPI(deviceAPI), - m_running(false), m_settings(), - m_fileOutputWorker(nullptr), m_deviceDescription("FileOutput"), - m_startingTimeStamp(0), m_masterTimer(deviceAPI->getMasterTimer()) { m_deviceAPI->setNbSinkStreams(1); @@ -58,7 +55,7 @@ FileOutput::FileOutput(DeviceAPI *deviceAPI) : FileOutput::~FileOutput() { delete m_networkManager; - stop(); + FileOutput::stop(); } void FileOutput::destroy() @@ -75,7 +72,7 @@ void FileOutput::openFileStream() m_ofstream.open(m_settings.m_fileName.toStdString().c_str(), std::ios::binary); FileRecord::Header header; - int actualSampleRate = m_settings.m_sampleRate * (1<moveToThread(&m_fileOutputWorkerThread); - m_fileOutputWorker->setSamplerate(m_settings.m_sampleRate); + m_fileOutputWorker->setSamplerate((int) m_settings.m_sampleRate); m_fileOutputWorker->setLog2Interpolation(m_settings.m_log2Interp); m_fileOutputWorker->connectTimer(m_masterTimer); startWorker(); m_running = true; mutexLocker.unlock(); - //applySettings(m_generalSettings, m_settings, true); qDebug("FileOutput::start: started"); if (getMessageQueueToGUI()) @@ -201,7 +197,7 @@ const QString& FileOutput::getDeviceDescription() const int FileOutput::getSampleRate() const { - return m_settings.m_sampleRate; + return (int) m_settings.m_sampleRate; } quint64 FileOutput::getCenterFrequency() const @@ -233,14 +229,14 @@ bool FileOutput::handleMessage(const Message& message) { if (MsgConfigureFileOutputName::match(message)) { - MsgConfigureFileOutputName& conf = (MsgConfigureFileOutputName&) message; + auto& conf = (const MsgConfigureFileOutputName&) message; m_settings.m_fileName = conf.getFileName(); openFileStream(); return true; } else if (MsgStartStop::match(message)) { - MsgStartStop& cmd = (MsgStartStop&) message; + auto& cmd = (const MsgStartStop&) message; qDebug() << "FileOutput::handleMessage: MsgStartStop: " << (cmd.getStartStop() ? "start" : "stop"); if (cmd.getStartStop()) @@ -262,17 +258,17 @@ bool FileOutput::handleMessage(const Message& message) } else if (MsgConfigureFileOutput::match(message)) { - qDebug() << "FileOutput::handleMessage: MsgConfigureFileOutput"; - MsgConfigureFileOutput& conf = (MsgConfigureFileOutput&) message; + qDebug() << "FileOutput::handleMessage: MsgConfigureFileOutput"; + auto& conf = (const MsgConfigureFileOutput&) message; applySettings(conf.getSettings(), conf.getSettingsKeys(), conf.getForce()); return true; } else if (MsgConfigureFileOutputWork::match(message)) { - MsgConfigureFileOutputWork& conf = (MsgConfigureFileOutputWork&) message; + auto& conf = (const MsgConfigureFileOutputWork&) message; bool working = conf.isWorking(); - if (m_fileOutputWorker != 0) + if (m_fileOutputWorker != nullptr) { if (working) { startWorker(); @@ -285,11 +281,9 @@ bool FileOutput::handleMessage(const Message& message) } else if (MsgConfigureFileOutputStreamTiming::match(message)) { - MsgReportFileOutputStreamTiming *report; - - if (m_fileOutputWorker != 0 && getMessageQueueToGUI()) + if (m_fileOutputWorker != nullptr && getMessageQueueToGUI()) { - report = MsgReportFileOutputStreamTiming::create(m_fileOutputWorker->getSamplesCount()); + auto *report = MsgReportFileOutputStreamTiming::create(m_fileOutputWorker->getSamplesCount()); getMessageQueueToGUI()->push(report); } @@ -314,8 +308,8 @@ void FileOutput::applySettings(const FileOutputSettings& settings, const QListsetSamplerate(settings.m_sampleRate); + if (m_fileOutputWorker != nullptr) { + m_fileOutputWorker->setSamplerate((int) settings.m_sampleRate); } forwardChange = true; @@ -323,7 +317,7 @@ void FileOutput::applySettings(const FileOutputSettings& settings, const QListsetLog2Interpolation(settings.m_log2Interp); } @@ -351,7 +345,7 @@ void FileOutput::applySettings(const FileOutputSettings& settings, const QListgetDeviceEngineInputMessageQueue()->push(notif); } } @@ -461,16 +455,16 @@ void FileOutput::webapiUpdateDeviceSettings( settings.m_reverseAPIAddress = *response.getFileOutputSettings()->getReverseApiAddress(); } if (deviceSettingsKeys.contains("reverseAPIPort")) { - settings.m_reverseAPIPort = response.getFileOutputSettings()->getReverseApiPort(); + settings.m_reverseAPIPort = (uint16_t) response.getFileOutputSettings()->getReverseApiPort(); } if (deviceSettingsKeys.contains("reverseAPIDeviceIndex")) { - settings.m_reverseAPIDeviceIndex = response.getFileOutputSettings()->getReverseApiDeviceIndex(); + settings.m_reverseAPIDeviceIndex = (uint16_t) response.getFileOutputSettings()->getReverseApiDeviceIndex(); } } void FileOutput::webapiReverseSendSettings(const QList& deviceSettingsKeys, const FileOutputSettings& settings, bool force) { - SWGSDRangel::SWGDeviceSettings *swgDeviceSettings = new SWGSDRangel::SWGDeviceSettings(); + auto *swgDeviceSettings = new SWGSDRangel::SWGDeviceSettings(); swgDeviceSettings->setDirection(1); // single Tx swgDeviceSettings->setOriginatorIndex(m_deviceAPI->getDeviceSetIndex()); swgDeviceSettings->setDeviceHwType(new QString("FileOutput")); @@ -499,8 +493,8 @@ void FileOutput::webapiReverseSendSettings(const QList& deviceSettingsK m_networkRequest.setUrl(QUrl(deviceSettingsURL)); m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); - QBuffer *buffer = new QBuffer(); - buffer->open((QBuffer::ReadWrite)); + auto *buffer = new QBuffer(); + buffer->open(QBuffer::ReadWrite); buffer->write(swgDeviceSettings->asJson().toUtf8()); buffer->seek(0); @@ -513,7 +507,7 @@ void FileOutput::webapiReverseSendSettings(const QList& deviceSettingsK void FileOutput::webapiReverseSendStartStop(bool start) { - SWGSDRangel::SWGDeviceSettings *swgDeviceSettings = new SWGSDRangel::SWGDeviceSettings(); + auto *swgDeviceSettings = new SWGSDRangel::SWGDeviceSettings(); swgDeviceSettings->setDirection(1); // single Tx swgDeviceSettings->setOriginatorIndex(m_deviceAPI->getDeviceSetIndex()); swgDeviceSettings->setDeviceHwType(new QString("FileOutput")); @@ -525,8 +519,8 @@ void FileOutput::webapiReverseSendStartStop(bool start) m_networkRequest.setUrl(QUrl(deviceSettingsURL)); m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); - QBuffer *buffer = new QBuffer(); - buffer->open((QBuffer::ReadWrite)); + auto *buffer = new QBuffer(); + buffer->open(QBuffer::ReadWrite); buffer->write(swgDeviceSettings->asJson().toUtf8()); buffer->seek(0); QNetworkReply *reply; @@ -541,7 +535,7 @@ void FileOutput::webapiReverseSendStartStop(bool start) delete swgDeviceSettings; } -void FileOutput::networkManagerFinished(QNetworkReply *reply) +void FileOutput::networkManagerFinished(QNetworkReply *reply) const { QNetworkReply::NetworkError replyError = reply->error(); diff --git a/plugins/samplesink/fileoutput/fileoutput.h b/plugins/samplesink/fileoutput/fileoutput.h index 8c4847d96..7c405d888 100644 --- a/plugins/samplesink/fileoutput/fileoutput.h +++ b/plugins/samplesink/fileoutput/fileoutput.h @@ -76,10 +76,10 @@ public: return new MsgStartStop(startStop); } - protected: + private: bool m_startStop; - MsgStartStop(bool startStop) : + explicit MsgStartStop(bool startStop) : Message(), m_startStop(startStop) { } @@ -99,7 +99,7 @@ public: private: QString m_fileName; - MsgConfigureFileOutputName(const QString& fileName) : + explicit MsgConfigureFileOutputName(const QString& fileName) : Message(), m_fileName(fileName) { } @@ -119,7 +119,7 @@ public: private: bool m_working; - MsgConfigureFileOutputWork(bool working) : + explicit MsgConfigureFileOutputWork(bool working) : Message(), m_working(working) { } @@ -153,10 +153,10 @@ public: return new MsgReportFileOutputGeneration(acquisition); } - protected: + private: bool m_acquisition; - MsgReportFileOutputGeneration(bool acquisition) : + explicit MsgReportFileOutputGeneration(bool acquisition) : Message(), m_acquisition(acquisition) { } @@ -173,54 +173,54 @@ public: return new MsgReportFileOutputStreamTiming(samplesCount); } - protected: + private: std::size_t m_samplesCount; - MsgReportFileOutputStreamTiming(std::size_t samplesCount) : + explicit MsgReportFileOutputStreamTiming(std::size_t samplesCount) : Message(), m_samplesCount(samplesCount) { } }; - FileOutput(DeviceAPI *deviceAPI); - virtual ~FileOutput(); - virtual void destroy(); + explicit FileOutput(DeviceAPI *deviceAPI); + ~FileOutput() final; + void destroy() final; - virtual void init(); - virtual bool start(); - virtual void stop(); + void init() final; + bool start() final; + void stop() final; - virtual QByteArray serialize() const; - virtual bool deserialize(const QByteArray& data); + QByteArray serialize() const final; + bool deserialize(const QByteArray& data) final; - virtual void setMessageQueueToGUI(MessageQueue *queue) { m_guiMessageQueue = queue; } - virtual const QString& getDeviceDescription() const; - virtual int getSampleRate() const; - virtual void setSampleRate(int sampleRate) { (void) sampleRate; } - virtual quint64 getCenterFrequency() const; - virtual void setCenterFrequency(qint64 centerFrequency); + void setMessageQueueToGUI(MessageQueue *queue) final { m_guiMessageQueue = queue; } + const QString& getDeviceDescription() const final; + int getSampleRate() const final; + void setSampleRate(int sampleRate) final { (void) sampleRate; } + quint64 getCenterFrequency() const final; + void setCenterFrequency(qint64 centerFrequency) final; std::time_t getStartingTimeStamp() const; - virtual bool handleMessage(const Message& message); + bool handleMessage(const Message& message) final; - virtual int webapiSettingsGet( - SWGSDRangel::SWGDeviceSettings& response, - QString& errorMessage); + int webapiSettingsGet( + SWGSDRangel::SWGDeviceSettings& response, + QString& errorMessage) final; - virtual int webapiSettingsPutPatch( - bool force, - const QStringList& deviceSettingsKeys, - SWGSDRangel::SWGDeviceSettings& response, // query + response - QString& errorMessage); + int webapiSettingsPutPatch( + bool force, + const QStringList& deviceSettingsKeys, + SWGSDRangel::SWGDeviceSettings& response, // query + response + QString& errorMessage) final; - virtual int webapiRunGet( - SWGSDRangel::SWGDeviceState& response, - QString& errorMessage); + int webapiRunGet( + SWGSDRangel::SWGDeviceState& response, + QString& errorMessage) final; - virtual int webapiRun( - bool run, - SWGSDRangel::SWGDeviceState& response, - QString& errorMessage); + int webapiRun( + bool run, + SWGSDRangel::SWGDeviceState& response, + QString& errorMessage) final; static void webapiFormatDeviceSettings( SWGSDRangel::SWGDeviceSettings& response, @@ -234,13 +234,13 @@ public: private: DeviceAPI *m_deviceAPI; QMutex m_mutex; - bool m_running; + bool m_running = false; FileOutputSettings m_settings; std::ofstream m_ofstream; - FileOutputWorker* m_fileOutputWorker; + FileOutputWorker* m_fileOutputWorker = nullptr; QThread m_fileOutputWorkerThread; QString m_deviceDescription; - qint64 m_startingTimeStamp; + qint64 m_startingTimeStamp = 0; const QTimer& m_masterTimer; QNetworkAccessManager *m_networkManager; QNetworkRequest m_networkRequest; @@ -253,7 +253,7 @@ private: void webapiReverseSendStartStop(bool start); private slots: - void networkManagerFinished(QNetworkReply *reply); + void networkManagerFinished(QNetworkReply *reply) const; }; #endif // INCLUDE_FILEOUTPUT_H diff --git a/plugins/samplesink/remoteoutput/remoteoutput.cpp b/plugins/samplesink/remoteoutput/remoteoutput.cpp index 6bffe0e5c..cbd20ca60 100644 --- a/plugins/samplesink/remoteoutput/remoteoutput.cpp +++ b/plugins/samplesink/remoteoutput/remoteoutput.cpp @@ -84,7 +84,7 @@ RemoteOutput::~RemoteOutput() this, &RemoteOutput::networkManagerFinished ); - stop(); + RemoteOutput::stop(); delete m_networkManager; } @@ -211,21 +211,21 @@ bool RemoteOutput::handleMessage(const Message& message) if (MsgConfigureRemoteOutput::match(message)) { qDebug() << "RemoteOutput::handleMessage:" << message.getIdentifier(); - MsgConfigureRemoteOutput& conf = (MsgConfigureRemoteOutput&) message; + auto& conf = (const MsgConfigureRemoteOutput&) message; applySettings(conf.getSettings(), conf.getSettingsKeys(), conf.getForce()); return true; } else if (MsgConfigureRemoteOutputWork::match(message)) { - MsgConfigureRemoteOutputWork& conf = (MsgConfigureRemoteOutputWork&) message; + auto& conf = (const MsgConfigureRemoteOutputWork&) message; bool working = conf.isWorking(); if (m_remoteOutputWorker != nullptr) { if (working) { - m_remoteOutputWorker->startWork(); + m_remoteOutputWorker->startWork(); } else { - m_remoteOutputWorker->stopWork(); + m_remoteOutputWorker->stopWork(); } } @@ -233,7 +233,7 @@ bool RemoteOutput::handleMessage(const Message& message) } else if (MsgStartStop::match(message)) { - MsgStartStop& cmd = (MsgStartStop&) message; + auto& cmd = (const MsgStartStop&) message; qDebug() << "RemoteOutput::handleMessage: MsgStartStop: " << (cmd.getStartStop() ? "start" : "stop"); if (cmd.getStartStop()) @@ -255,13 +255,13 @@ bool RemoteOutput::handleMessage(const Message& message) } else if (MsgConfigureRemoteOutputChunkCorrection::match(message)) { - MsgConfigureRemoteOutputChunkCorrection& conf = (MsgConfigureRemoteOutputChunkCorrection&) message; + auto& conf = (const MsgConfigureRemoteOutputChunkCorrection&) message; - if (m_remoteOutputWorker != nullptr) { - m_remoteOutputWorker->setChunkCorrection(conf.getChunkCorrection()); + if (m_remoteOutputWorker != nullptr) { + m_remoteOutputWorker->setChunkCorrection(conf.getChunkCorrection()); } - return true; + return true; } else if (MsgRequestFixedData::match(message)) { @@ -287,30 +287,23 @@ void RemoteOutput::applySettings(const RemoteOutputSettings& settings, const QLi qDebug() << "RemoteOutput::applySettings: force:" << force << settings.getDebugString(settingsKeys, force); QMutexLocker mutexLocker(&m_mutex); - if (force || + if ((force || settingsKeys.contains("dataAddress") || - settingsKeys.contains("dataPort")) + settingsKeys.contains("dataPort")) && m_remoteOutputWorker) { - if (m_remoteOutputWorker) { - m_remoteOutputWorker->setDataAddress(settings.m_dataAddress, settings.m_dataPort); - } + m_remoteOutputWorker->setDataAddress(settings.m_dataAddress, settings.m_dataPort); } - if (force || settingsKeys.contains("nbFECBlocks")) + if ((force || settingsKeys.contains("nbFECBlocks")) && m_remoteOutputWorker) { - if (m_remoteOutputWorker) { - m_remoteOutputWorker->setNbBlocksFEC(settings.m_nbFECBlocks); - } + m_remoteOutputWorker->setNbBlocksFEC(settings.m_nbFECBlocks); } - if (force || settingsKeys.contains("nbTxBytes")) + if ((force || settingsKeys.contains("nbTxBytes")) && m_remoteOutputWorker) { - if (m_remoteOutputWorker) - { - stopWorker(); - m_remoteOutputWorker->setNbTxBytes(settings.m_nbTxBytes); - startWorker(); - } + stopWorker(); + m_remoteOutputWorker->setNbTxBytes(settings.m_nbTxBytes); + startWorker(); } mutexLocker.unlock(); @@ -333,7 +326,7 @@ void RemoteOutput::applySettings(const RemoteOutputSettings& settings, const QLi void RemoteOutput::applyCenterFrequency() { - DSPSignalNotification *notif = new DSPSignalNotification(m_sampleRate, m_centerFrequency); + auto *notif = new DSPSignalNotification(m_sampleRate, m_centerFrequency); m_deviceAPI->getDeviceEngineInputMessageQueue()->push(notif); } @@ -344,10 +337,11 @@ void RemoteOutput::applySampleRate() } m_tickMultiplier = 480000 / m_sampleRate; - m_tickMultiplier = m_tickMultiplier < 1 ? 1 : m_tickMultiplier > 10 ? 10 : m_tickMultiplier; + m_tickMultiplier = m_tickMultiplier < 1 ? 1 : m_tickMultiplier; + m_tickMultiplier = m_tickMultiplier > 10 ? 10 : m_tickMultiplier; m_greaterTickCount = 0; - DSPSignalNotification *notif = new DSPSignalNotification(m_sampleRate, m_centerFrequency); + auto *notif = new DSPSignalNotification(m_sampleRate, m_centerFrequency); m_deviceAPI->getDeviceEngineInputMessageQueue()->push(notif); } @@ -428,13 +422,13 @@ void RemoteOutput::webapiUpdateDeviceSettings( settings.m_apiAddress = *response.getRemoteOutputSettings()->getApiAddress(); } if (deviceSettingsKeys.contains("apiPort")) { - settings.m_apiPort = response.getRemoteOutputSettings()->getApiPort(); + settings.m_apiPort = (quint16) response.getRemoteOutputSettings()->getApiPort(); } if (deviceSettingsKeys.contains("dataAddress")) { settings.m_dataAddress = *response.getRemoteOutputSettings()->getDataAddress(); } if (deviceSettingsKeys.contains("dataPort")) { - settings.m_dataPort = response.getRemoteOutputSettings()->getDataPort(); + settings.m_dataPort = (quint16) response.getRemoteOutputSettings()->getDataPort(); } if (deviceSettingsKeys.contains("deviceIndex")) { settings.m_deviceIndex = response.getRemoteOutputSettings()->getDeviceIndex(); @@ -449,10 +443,10 @@ void RemoteOutput::webapiUpdateDeviceSettings( settings.m_reverseAPIAddress = *response.getRemoteOutputSettings()->getReverseApiAddress(); } if (deviceSettingsKeys.contains("reverseAPIPort")) { - settings.m_reverseAPIPort = response.getRemoteOutputSettings()->getReverseApiPort(); + settings.m_reverseAPIPort = (quint16) response.getRemoteOutputSettings()->getReverseApiPort(); } if (deviceSettingsKeys.contains("reverseAPIDeviceIndex")) { - settings.m_reverseAPIDeviceIndex = response.getRemoteOutputSettings()->getReverseApiDeviceIndex(); + settings.m_reverseAPIDeviceIndex = (uint16_t) response.getRemoteOutputSettings()->getReverseApiDeviceIndex(); } } @@ -489,10 +483,10 @@ void RemoteOutput::webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings& re response.getRemoteOutputSettings()->setReverseApiDeviceIndex(settings.m_reverseAPIDeviceIndex); } -void RemoteOutput::webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& response) +void RemoteOutput::webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& response) const { uint64_t nowus = TimeUtil::nowus(); - response.getRemoteOutputReport()->setTvSec(nowus / 1000000U); + response.getRemoteOutputReport()->setTvSec((qint32) (nowus / 1000000U)); response.getRemoteOutputReport()->setTvUSec(nowus % 1000000U); response.getRemoteOutputReport()->setCenterFrequency(m_centerFrequency); response.getRemoteOutputReport()->setSampleRate(m_sampleRate); @@ -666,7 +660,7 @@ void RemoteOutput::queueLengthCompensation( void RemoteOutput::webapiReverseSendSettings(const QList& deviceSettingsKeys, const RemoteOutputSettings& settings, bool force) { - SWGSDRangel::SWGDeviceSettings *swgDeviceSettings = new SWGSDRangel::SWGDeviceSettings(); + auto *swgDeviceSettings = new SWGSDRangel::SWGDeviceSettings(); swgDeviceSettings->setDirection(1); // single Tx swgDeviceSettings->setOriginatorIndex(m_deviceAPI->getDeviceSetIndex()); swgDeviceSettings->setDeviceHwType(new QString("RemoteOutput")); @@ -707,8 +701,8 @@ void RemoteOutput::webapiReverseSendSettings(const QList& deviceSetting m_networkRequest.setUrl(QUrl(deviceSettingsURL)); m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); - QBuffer *buffer = new QBuffer(); - buffer->open((QBuffer::ReadWrite)); + auto *buffer = new QBuffer(); + buffer->open(QBuffer::ReadWrite); buffer->write(swgDeviceSettings->asJson().toUtf8()); buffer->seek(0); @@ -721,7 +715,7 @@ void RemoteOutput::webapiReverseSendSettings(const QList& deviceSetting void RemoteOutput::webapiReverseSendStartStop(bool start) { - SWGSDRangel::SWGDeviceSettings *swgDeviceSettings = new SWGSDRangel::SWGDeviceSettings(); + auto *swgDeviceSettings = new SWGSDRangel::SWGDeviceSettings(); swgDeviceSettings->setDirection(1); // single Tx swgDeviceSettings->setOriginatorIndex(m_deviceAPI->getDeviceSetIndex()); swgDeviceSettings->setDeviceHwType(new QString("RemoteOutput")); @@ -733,8 +727,8 @@ void RemoteOutput::webapiReverseSendStartStop(bool start) m_networkRequest.setUrl(QUrl(deviceSettingsURL)); m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); - QBuffer *buffer = new QBuffer(); - buffer->open((QBuffer::ReadWrite)); + auto *buffer = new QBuffer(); + buffer->open(QBuffer::ReadWrite); buffer->write(swgDeviceSettings->asJson().toUtf8()); buffer->seek(0); QNetworkReply *reply; diff --git a/plugins/samplesink/remoteoutput/remoteoutput.h b/plugins/samplesink/remoteoutput/remoteoutput.h index 434e2916d..825215d27 100644 --- a/plugins/samplesink/remoteoutput/remoteoutput.h +++ b/plugins/samplesink/remoteoutput/remoteoutput.h @@ -83,7 +83,7 @@ public: private: bool m_working; - MsgConfigureRemoteOutputWork(bool working) : + explicit MsgConfigureRemoteOutputWork(bool working) : Message(), m_working(working) { } @@ -99,10 +99,10 @@ public: return new MsgStartStop(startStop); } - protected: + private: bool m_startStop; - MsgStartStop(bool startStop) : + explicit MsgStartStop(bool startStop) : Message(), m_startStop(startStop) { } @@ -122,7 +122,7 @@ public: private: int m_chunkCorrection; - MsgConfigureRemoteOutputChunkCorrection(int chunkCorrection) : + explicit MsgConfigureRemoteOutputChunkCorrection(int chunkCorrection) : Message(), m_chunkCorrection(chunkCorrection) { } @@ -153,7 +153,7 @@ public: private: RemoteData m_remoteData; - MsgReportRemoteData(const RemoteData& remoteData) : + explicit MsgReportRemoteData(const RemoteData& remoteData) : Message(), m_remoteData(remoteData) {} @@ -182,7 +182,7 @@ public: private: RemoteData m_remoteData; - MsgReportRemoteFixedData(const RemoteData& remoteData) : + explicit MsgReportRemoteFixedData(const RemoteData& remoteData) : Message(), m_remoteData(remoteData) {} @@ -203,58 +203,58 @@ public: }; - RemoteOutput(DeviceAPI *deviceAPI); - virtual ~RemoteOutput(); - virtual void destroy(); + explicit RemoteOutput(DeviceAPI *deviceAPI); + ~RemoteOutput() final; + void destroy() final; - virtual void init(); - virtual bool start(); - virtual void stop(); + void init() final; + bool start() final; + void stop() final; - virtual QByteArray serialize() const; - virtual bool deserialize(const QByteArray& data); + QByteArray serialize() const final; + bool deserialize(const QByteArray& data) final; - virtual void setMessageQueueToGUI(MessageQueue *queue) { m_guiMessageQueue = queue; } - virtual const QString& getDeviceDescription() const; - virtual int getSampleRate() const; - virtual void setSampleRate(int sampleRate) { (void) sampleRate; } - virtual quint64 getCenterFrequency() const; - virtual void setCenterFrequency(qint64 centerFrequency) { (void) centerFrequency; } + void setMessageQueueToGUI(MessageQueue *queue) final { m_guiMessageQueue = queue; } + const QString& getDeviceDescription() const final; + int getSampleRate() const final; + void setSampleRate(int sampleRate) final { (void) sampleRate; } + quint64 getCenterFrequency() const final; + void setCenterFrequency(qint64 centerFrequency) final { (void) centerFrequency; } std::time_t getStartingTimeStamp() const; - virtual bool handleMessage(const Message& message); + bool handleMessage(const Message& message) final; - virtual int webapiSettingsGet( - SWGSDRangel::SWGDeviceSettings& response, - QString& errorMessage); + int webapiSettingsGet( + SWGSDRangel::SWGDeviceSettings& response, + QString& errorMessage) final; - virtual int webapiSettingsPutPatch( - bool force, - const QStringList& deviceSettingsKeys, - SWGSDRangel::SWGDeviceSettings& response, // query + response - QString& errorMessage); + int webapiSettingsPutPatch( + bool force, + const QStringList& deviceSettingsKeys, + SWGSDRangel::SWGDeviceSettings& response, // query + response + QString& errorMessage) final; - virtual int webapiReportGet( - SWGSDRangel::SWGDeviceReport& response, - QString& errorMessage); + int webapiReportGet( + SWGSDRangel::SWGDeviceReport& response, + QString& errorMessage) final; - virtual int webapiRunGet( - SWGSDRangel::SWGDeviceState& response, - QString& errorMessage); + int webapiRunGet( + SWGSDRangel::SWGDeviceState& response, + QString& errorMessage) final; - virtual int webapiRun( - bool run, - SWGSDRangel::SWGDeviceState& response, - QString& errorMessage); + int webapiRun( + bool run, + SWGSDRangel::SWGDeviceState& response, + QString& errorMessage) final; static void webapiFormatDeviceSettings( - SWGSDRangel::SWGDeviceSettings& response, - const RemoteOutputSettings& settings); + SWGSDRangel::SWGDeviceSettings& response, + const RemoteOutputSettings& settings); static void webapiUpdateDeviceSettings( - RemoteOutputSettings& settings, - const QStringList& deviceSettingsKeys, - SWGSDRangel::SWGDeviceSettings& response); + RemoteOutputSettings& settings, + const QStringList& deviceSettingsKeys, + SWGSDRangel::SWGDeviceSettings& response); private: DeviceAPI *m_deviceAPI; @@ -284,7 +284,7 @@ private: void applySettings(const RemoteOutputSettings& settings, const QList& settingsKeys, bool force = false); void applyCenterFrequency(); void applySampleRate(); - void webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& response); + void webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& response) const; void analyzeApiReply(const QJsonObject& jsonObject, const QString& answer); void queueLengthCompensation( diff --git a/plugins/samplesource/bladerf1input/bladerf1input.cpp b/plugins/samplesource/bladerf1input/bladerf1input.cpp index 8d4e24b91..aa8c82bde 100644 --- a/plugins/samplesource/bladerf1input/bladerf1input.cpp +++ b/plugins/samplesource/bladerf1input/bladerf1input.cpp @@ -40,7 +40,7 @@ MESSAGE_CLASS_DEFINITION(Bladerf1Input::MsgStartStop, Message) Bladerf1Input::Bladerf1Input(DeviceAPI *deviceAPI) : m_deviceAPI(deviceAPI), m_settings(), - m_dev(0), + m_dev(nullptr), m_bladerfThread(nullptr), m_deviceDescription("BladeRFInput"), m_running(false) @@ -70,11 +70,11 @@ Bladerf1Input::~Bladerf1Input() delete m_networkManager; if (m_running) { - stop(); + Bladerf1Input::stop(); } closeDevice(); - m_deviceAPI->setBuddySharedPtr(0); + m_deviceAPI->setBuddySharedPtr(nullptr); } void Bladerf1Input::destroy() @@ -84,7 +84,7 @@ void Bladerf1Input::destroy() bool Bladerf1Input::openDevice() { - if (m_dev != 0) + if (m_dev != nullptr) { closeDevice(); } @@ -97,24 +97,24 @@ bool Bladerf1Input::openDevice() return false; } - if (m_deviceAPI->getSinkBuddies().size() > 0) + if (!m_deviceAPI->getSinkBuddies().empty()) { - DeviceAPI *sinkBuddy = m_deviceAPI->getSinkBuddies()[0]; - DeviceBladeRF1Params *buddySharedParams = (DeviceBladeRF1Params *) sinkBuddy->getBuddySharedPtr(); + const DeviceAPI *sinkBuddy = m_deviceAPI->getSinkBuddies()[0]; + const DeviceBladeRF1Params *buddySharedParams = (DeviceBladeRF1Params *) sinkBuddy->getBuddySharedPtr(); - if (buddySharedParams == 0) + if (buddySharedParams == nullptr) { qCritical("BladerfInput::openDevice: could not get shared parameters from buddy"); return false; } - if (buddySharedParams->m_dev == 0) // device is not opened by buddy + if (buddySharedParams->m_dev == nullptr) // device is not opened by buddy { qCritical("BladerfInput::openDevice: could not get BladeRF handle from buddy"); return false; } - m_sharedParams = *(buddySharedParams); // copy parameters from buddy + m_sharedParams = *buddySharedParams; // copy parameters from buddy m_dev = m_sharedParams.m_dev; // get BladeRF handle } else @@ -128,7 +128,6 @@ bool Bladerf1Input::openDevice() m_sharedParams.m_dev = m_dev; } - // TODO: adjust USB transfer data according to sample rate if ((res = bladerf_sync_config(m_dev, BLADERF_RX_X1, BLADERF_FORMAT_SC16_Q11, 64, 8192, 32, 10000)) < 0) { qCritical("BladerfInput::start: bladerf_sync_config with return code %d", res); @@ -182,7 +181,7 @@ void Bladerf1Input::closeDevice() { int res; - if (m_dev == 0) { // was never open + if (m_dev == nullptr) { // was never open return; } @@ -191,7 +190,7 @@ void Bladerf1Input::closeDevice() qCritical("BladerfInput::stop: bladerf_enable_module with return code %d", res); } - if (m_deviceAPI->getSinkBuddies().size() == 0) + if (m_deviceAPI->getSinkBuddies().empty()) { qDebug("BladerfInput::closeDevice: closing device since Tx side is not open"); @@ -286,7 +285,7 @@ bool Bladerf1Input::handleMessage(const Message& message) { if (MsgConfigureBladerf1::match(message)) { - MsgConfigureBladerf1& conf = (MsgConfigureBladerf1&) message; + auto& conf = (const MsgConfigureBladerf1&) message; qDebug() << "Bladerf1Input::handleMessage: MsgConfigureBladerf1"; if (!applySettings(conf.getSettings(), conf.getSettingsKeys(), conf.getForce())) { @@ -297,7 +296,7 @@ bool Bladerf1Input::handleMessage(const Message& message) } else if (MsgStartStop::match(message)) { - MsgStartStop& cmd = (MsgStartStop&) message; + auto& cmd = (const MsgStartStop&) message; qDebug() << "BladerfInput::handleMessage: MsgStartStop: " << (cmd.getStartStop() ? "start" : "stop"); if (cmd.getStartStop()) @@ -326,126 +325,107 @@ bool Bladerf1Input::handleMessage(const Message& message) bool Bladerf1Input::applySettings(const BladeRF1InputSettings& settings, const QList& settingsKeys, bool force) { bool forwardChange = false; -// QMutexLocker mutexLocker(&m_mutex); qDebug() << "BladerfInput::applySettings: force: " << force << settings.getDebugString(settingsKeys, force); if ((settingsKeys.contains("dcBlock")) || - settingsKeys.contains("iqCorrection") || force) + settingsKeys.contains("iqCorrection") || force) { m_deviceAPI->configureCorrections(settings.m_dcBlock, settings.m_iqCorrection); } - if (settingsKeys.contains("lnaGain") || force) + if ((m_dev != nullptr) && (settingsKeys.contains("lnaGain") || force)) { - if (m_dev != 0) - { - if(bladerf_set_lna_gain(m_dev, getLnaGain(settings.m_lnaGain)) != 0) { - qDebug("BladerfInput::applySettings: bladerf_set_lna_gain() failed"); - } else { - qDebug() << "BladerfInput::applySettings: LNA gain set to " << getLnaGain(settings.m_lnaGain); - } - } + if(bladerf_set_lna_gain(m_dev, getLnaGain(settings.m_lnaGain)) != 0) { + qDebug("BladerfInput::applySettings: bladerf_set_lna_gain() failed"); + } else { + qDebug() << "BladerfInput::applySettings: LNA gain set to " << getLnaGain(settings.m_lnaGain); + } } - if (settingsKeys.contains("vga1") || force) + if ((m_dev != nullptr) && (settingsKeys.contains("vga1") || force)) { - if (m_dev != 0) - { - if(bladerf_set_rxvga1(m_dev, settings.m_vga1) != 0) { - qDebug("BladerfInput::applySettings: bladerf_set_rxvga1() failed"); - } else { - qDebug() << "BladerfInput::applySettings: VGA1 gain set to " << settings.m_vga1; - } - } + if(bladerf_set_rxvga1(m_dev, settings.m_vga1) != 0) { + qDebug("BladerfInput::applySettings: bladerf_set_rxvga1() failed"); + } else { + qDebug() << "BladerfInput::applySettings: VGA1 gain set to " << settings.m_vga1; + } } - if (settingsKeys.contains("vga2") || force) + if ((m_dev != nullptr) && (settingsKeys.contains("vga2") || force)) { - if(m_dev != 0) - { - if(bladerf_set_rxvga2(m_dev, settings.m_vga2) != 0) { - qDebug("BladerfInput::applySettings: bladerf_set_rxvga2() failed"); - } else { - qDebug() << "BladerfInput::applySettings: VGA2 gain set to " << settings.m_vga2; - } - } + if(bladerf_set_rxvga2(m_dev, settings.m_vga2) != 0) { + qDebug("BladerfInput::applySettings: bladerf_set_rxvga2() failed"); + } else { + qDebug() << "BladerfInput::applySettings: VGA2 gain set to " << settings.m_vga2; + } } - if (settingsKeys.contains("xb200") || force) + if ((m_dev != nullptr) && (settingsKeys.contains("xb200") || force)) { - if (m_dev != 0) - { - bool changeSettings; + bool changeSettings; - if (m_deviceAPI->getSinkBuddies().size() > 0) - { - DeviceAPI *buddy = m_deviceAPI->getSinkBuddies()[0]; + if (!m_deviceAPI->getSinkBuddies().empty()) + { + DeviceAPI *buddy = m_deviceAPI->getSinkBuddies()[0]; - if (buddy->getDeviceSinkEngine()->state() == DSPDeviceSinkEngine::StRunning) { // Tx side running - changeSettings = false; - } else { - changeSettings = true; - } - } - else // No Tx open - { + if (buddy->getDeviceSinkEngine()->state() == DSPDeviceSinkEngine::State::StRunning) { // Tx side running + changeSettings = false; + } else { changeSettings = true; - } + } + } + else // No Tx open + { + changeSettings = true; + } - if (changeSettings) - { - if (settings.m_xb200) - { - if (bladerf_expansion_attach(m_dev, BLADERF_XB_200) != 0) { - qDebug("BladerfInput::applySettings: bladerf_expansion_attach(xb200) failed"); - } else { - qDebug() << "BladerfInput::applySettings: Attach XB200"; - } - } - else - { - if (bladerf_expansion_attach(m_dev, BLADERF_XB_NONE) != 0) { - qDebug("BladerfInput::applySettings: bladerf_expansion_attach(none) failed"); - } else { - qDebug() << "BladerfInput::applySettings: Detach XB200"; - } - } + if (changeSettings) + { + if (settings.m_xb200) + { + if (bladerf_expansion_attach(m_dev, BLADERF_XB_200) != 0) { + qDebug("BladerfInput::applySettings: bladerf_expansion_attach(xb200) failed"); + } else { + qDebug() << "BladerfInput::applySettings: Attach XB200"; + } + } + else + { + if (bladerf_expansion_attach(m_dev, BLADERF_XB_NONE) != 0) { + qDebug("BladerfInput::applySettings: bladerf_expansion_attach(none) failed"); + } else { + qDebug() << "BladerfInput::applySettings: Detach XB200"; + } + } - m_sharedParams.m_xb200Attached = settings.m_xb200; - } - } + m_sharedParams.m_xb200Attached = settings.m_xb200; + } } - if (settingsKeys.contains("xb200Path") || force) + if ((m_dev != nullptr) && (settingsKeys.contains("xb200Path") || force)) { - if (m_dev != 0) - { - if(bladerf_xb200_set_path(m_dev, BLADERF_MODULE_RX, settings.m_xb200Path) != 0) { - qDebug("BladerfInput::applySettings: bladerf_xb200_set_path(BLADERF_MODULE_RX) failed"); - } else { - qDebug() << "BladerfInput::applySettings: set xb200 path to " << settings.m_xb200Path; - } - } + if(bladerf_xb200_set_path(m_dev, BLADERF_MODULE_RX, settings.m_xb200Path) != 0) { + qDebug("BladerfInput::applySettings: bladerf_xb200_set_path(BLADERF_MODULE_RX) failed"); + } else { + qDebug() << "BladerfInput::applySettings: set xb200 path to " << settings.m_xb200Path; + } } - if (settingsKeys.contains("xb200Filter") || force) + if ((m_dev != nullptr) && (settingsKeys.contains("xb200Filter") || force)) { - if (m_dev != 0) - { - if(bladerf_xb200_set_filterbank(m_dev, BLADERF_MODULE_RX, settings.m_xb200Filter) != 0) { - qDebug("BladerfInput::applySettings: bladerf_xb200_set_filterbank(BLADERF_MODULE_RX) failed"); - } else { - qDebug() << "BladerfInput::applySettings: set xb200 filter to " << settings.m_xb200Filter; - } - } + if(bladerf_xb200_set_filterbank(m_dev, BLADERF_MODULE_RX, settings.m_xb200Filter) != 0) { + qDebug("BladerfInput::applySettings: bladerf_xb200_set_filterbank(BLADERF_MODULE_RX) failed"); + } else { + qDebug() << "BladerfInput::applySettings: set xb200 filter to " << settings.m_xb200Filter; + } } if (settingsKeys.contains("devSampleRate") || force) { forwardChange = true; - if (m_dev != 0) + if (m_dev != nullptr) { unsigned int actualSamplerate; @@ -457,27 +437,21 @@ bool Bladerf1Input::applySettings(const BladeRF1InputSettings& settings, const Q } } - if (settingsKeys.contains("bandwidth") || force) + if ((m_dev != nullptr) && (settingsKeys.contains("bandwidth") || force)) { - if(m_dev != 0) - { - unsigned int actualBandwidth; + unsigned int actualBandwidth; - if( bladerf_set_bandwidth(m_dev, BLADERF_MODULE_RX, settings.m_bandwidth, &actualBandwidth) < 0) { - qCritical("BladerfInput::applySettings: could not set bandwidth: %d", settings.m_bandwidth); - } else { - qDebug() << "BladerfInput::applySettings: bladerf_set_bandwidth(BLADERF_MODULE_RX) actual bandwidth is " << actualBandwidth; - } - } + if( bladerf_set_bandwidth(m_dev, BLADERF_MODULE_RX, settings.m_bandwidth, &actualBandwidth) < 0) { + qCritical("BladerfInput::applySettings: could not set bandwidth: %d", settings.m_bandwidth); + } else { + qDebug() << "BladerfInput::applySettings: bladerf_set_bandwidth(BLADERF_MODULE_RX) actual bandwidth is " << actualBandwidth; + } } - if (settingsKeys.contains("fcPos") || force) + if (m_bladerfThread && (settingsKeys.contains("fcPos") || force)) { - if (m_bladerfThread) - { - m_bladerfThread->setFcPos((int) settings.m_fcPos); - qDebug() << "BladerfInput::applySettings: set fc pos (enum) to " << (int) settings.m_fcPos; - } + m_bladerfThread->setFcPos((int) settings.m_fcPos); + qDebug() << "BladerfInput::applySettings: set fc pos (enum) to " << (int) settings.m_fcPos; } if (settingsKeys.contains("log2Decim") || force) @@ -491,11 +465,9 @@ bool Bladerf1Input::applySettings(const BladeRF1InputSettings& settings, const Q } } - if (settingsKeys.contains("iqOrder") || force) + if (m_bladerfThread && (settingsKeys.contains("iqOrder") || force)) { - if (m_bladerfThread) { - m_bladerfThread->setIQOrder(settings.m_iqOrder); - } + m_bladerfThread->setIQOrder(settings.m_iqOrder); } if (settingsKeys.contains("centerFrequency") @@ -514,7 +486,7 @@ bool Bladerf1Input::applySettings(const BladeRF1InputSettings& settings, const Q forwardChange = true; - if (m_dev != 0) + if (m_dev != nullptr) { if (bladerf_set_frequency( m_dev, BLADERF_MODULE_RX, deviceCenterFrequency ) != 0) { qWarning("BladerfInput::applySettings: bladerf_set_frequency(%lld) failed", settings.m_centerFrequency); @@ -527,7 +499,7 @@ bool Bladerf1Input::applySettings(const BladeRF1InputSettings& settings, const Q if (forwardChange) { int sampleRate = settings.m_devSampleRate/(1<getDeviceEngineInputMessageQueue()->push(notif); } @@ -549,7 +521,7 @@ bool Bladerf1Input::applySettings(const BladeRF1InputSettings& settings, const Q return true; } -bladerf_lna_gain Bladerf1Input::getLnaGain(int lnaGain) +bladerf_lna_gain Bladerf1Input::getLnaGain(int lnaGain) const { if (lnaGain == 2) { return BLADERF_LNA_GAIN_MAX; @@ -656,7 +628,7 @@ void Bladerf1Input::webapiUpdateDeviceSettings( settings.m_fcPos = static_cast(response.getBladeRf1InputSettings()->getFcPos()); } if (deviceSettingsKeys.contains("xb200")) { - settings.m_xb200 = response.getBladeRf1InputSettings()->getXb200() == 0 ? 0 : 1; + settings.m_xb200 = response.getBladeRf1InputSettings()->getXb200() == 0 ? false : true; } if (deviceSettingsKeys.contains("xb200Path")) { settings.m_xb200Path = static_cast(response.getBladeRf1InputSettings()->getXb200Path()); @@ -677,10 +649,10 @@ void Bladerf1Input::webapiUpdateDeviceSettings( settings.m_reverseAPIAddress = *response.getBladeRf1InputSettings()->getReverseApiAddress(); } if (deviceSettingsKeys.contains("reverseAPIPort")) { - settings.m_reverseAPIPort = response.getBladeRf1InputSettings()->getReverseApiPort(); + settings.m_reverseAPIPort = (uint16_t) response.getBladeRf1InputSettings()->getReverseApiPort(); } if (deviceSettingsKeys.contains("reverseAPIDeviceIndex")) { - settings.m_reverseAPIDeviceIndex = response.getBladeRf1InputSettings()->getReverseApiDeviceIndex(); + settings.m_reverseAPIDeviceIndex = (uint16_t) response.getBladeRf1InputSettings()->getReverseApiDeviceIndex(); } } @@ -714,7 +686,7 @@ int Bladerf1Input::webapiRun( void Bladerf1Input::webapiReverseSendSettings(const QList& deviceSettingsKeys, const BladeRF1InputSettings& settings, bool force) { - SWGSDRangel::SWGDeviceSettings *swgDeviceSettings = new SWGSDRangel::SWGDeviceSettings(); + auto *swgDeviceSettings = new SWGSDRangel::SWGDeviceSettings(); swgDeviceSettings->setDirection(0); // single Rx swgDeviceSettings->setOriginatorIndex(m_deviceAPI->getDeviceSetIndex()); swgDeviceSettings->setDeviceHwType(new QString("BladeRF1")); @@ -773,8 +745,8 @@ void Bladerf1Input::webapiReverseSendSettings(const QList& deviceSettin m_networkRequest.setUrl(QUrl(deviceSettingsURL)); m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); - QBuffer *buffer = new QBuffer(); - buffer->open((QBuffer::ReadWrite)); + auto *buffer = new QBuffer(); + buffer->open(QBuffer::ReadWrite); buffer->write(swgDeviceSettings->asJson().toUtf8()); buffer->seek(0); @@ -787,7 +759,7 @@ void Bladerf1Input::webapiReverseSendSettings(const QList& deviceSettin void Bladerf1Input::webapiReverseSendStartStop(bool start) { - SWGSDRangel::SWGDeviceSettings *swgDeviceSettings = new SWGSDRangel::SWGDeviceSettings(); + auto *swgDeviceSettings = new SWGSDRangel::SWGDeviceSettings(); swgDeviceSettings->setDirection(0); // single Rx swgDeviceSettings->setOriginatorIndex(m_deviceAPI->getDeviceSetIndex()); swgDeviceSettings->setDeviceHwType(new QString("BladeRF1")); @@ -799,8 +771,8 @@ void Bladerf1Input::webapiReverseSendStartStop(bool start) m_networkRequest.setUrl(QUrl(deviceSettingsURL)); m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); - QBuffer *buffer = new QBuffer(); - buffer->open((QBuffer::ReadWrite)); + auto *buffer = new QBuffer(); + buffer->open(QBuffer::ReadWrite); buffer->write(swgDeviceSettings->asJson().toUtf8()); buffer->seek(0); QNetworkReply *reply; @@ -815,7 +787,7 @@ void Bladerf1Input::webapiReverseSendStartStop(bool start) delete swgDeviceSettings; } -void Bladerf1Input::networkManagerFinished(QNetworkReply *reply) +void Bladerf1Input::networkManagerFinished(QNetworkReply *reply) const { QNetworkReply::NetworkError replyError = reply->error(); diff --git a/plugins/samplesource/bladerf1input/bladerf1input.h b/plugins/samplesource/bladerf1input/bladerf1input.h index 3b20bd16c..d0a34653e 100644 --- a/plugins/samplesource/bladerf1input/bladerf1input.h +++ b/plugins/samplesource/bladerf1input/bladerf1input.h @@ -76,62 +76,62 @@ public: return new MsgStartStop(startStop); } - protected: + private: bool m_startStop; - MsgStartStop(bool startStop) : + explicit MsgStartStop(bool startStop) : Message(), m_startStop(startStop) { } }; - Bladerf1Input(DeviceAPI *deviceAPI); - virtual ~Bladerf1Input(); - virtual void destroy(); + explicit Bladerf1Input(DeviceAPI *deviceAPI); + ~Bladerf1Input() final; + void destroy() final; - virtual void init(); - virtual bool start(); - virtual void stop(); + void init() final; + bool start() final; + void stop() final; - virtual QByteArray serialize() const; - virtual bool deserialize(const QByteArray& data); + QByteArray serialize() const final; + bool deserialize(const QByteArray& data) final; - virtual void setMessageQueueToGUI(MessageQueue *queue) { m_guiMessageQueue = queue; } - virtual const QString& getDeviceDescription() const; - virtual int getSampleRate() const; - virtual void setSampleRate(int sampleRate) { (void) sampleRate; } - virtual quint64 getCenterFrequency() const; - virtual void setCenterFrequency(qint64 centerFrequency); + void setMessageQueueToGUI(MessageQueue *queue) final { m_guiMessageQueue = queue; } + const QString& getDeviceDescription() const final; + int getSampleRate() const final; + void setSampleRate(int sampleRate) final { (void) sampleRate; } + quint64 getCenterFrequency() const final; + void setCenterFrequency(qint64 centerFrequency) final; - virtual bool handleMessage(const Message& message); + bool handleMessage(const Message& message) final; - virtual int webapiSettingsGet( - SWGSDRangel::SWGDeviceSettings& response, - QString& errorMessage); + int webapiSettingsGet( + SWGSDRangel::SWGDeviceSettings& response, + QString& errorMessage) final; - virtual int webapiSettingsPutPatch( - bool force, - const QStringList& deviceSettingsKeys, - SWGSDRangel::SWGDeviceSettings& response, // query + response - QString& errorMessage); + int webapiSettingsPutPatch( + bool force, + const QStringList& deviceSettingsKeys, + SWGSDRangel::SWGDeviceSettings& response, // query + response + QString& errorMessage) final; - virtual int webapiRunGet( - SWGSDRangel::SWGDeviceState& response, - QString& errorMessage); + int webapiRunGet( + SWGSDRangel::SWGDeviceState& response, + QString& errorMessage) final; - virtual int webapiRun( - bool run, - SWGSDRangel::SWGDeviceState& response, - QString& errorMessage); + int webapiRun( + bool run, + SWGSDRangel::SWGDeviceState& response, + QString& errorMessage) final; static void webapiFormatDeviceSettings( - SWGSDRangel::SWGDeviceSettings& response, - const BladeRF1InputSettings& settings); + SWGSDRangel::SWGDeviceSettings& response, + const BladeRF1InputSettings& settings); static void webapiUpdateDeviceSettings( - BladeRF1InputSettings& settings, - const QStringList& deviceSettingsKeys, - SWGSDRangel::SWGDeviceSettings& response); + BladeRF1InputSettings& settings, + const QStringList& deviceSettingsKeys, + SWGSDRangel::SWGDeviceSettings& response); private: DeviceAPI *m_deviceAPI; @@ -148,12 +148,12 @@ private: bool openDevice(); void closeDevice(); bool applySettings(const BladeRF1InputSettings& settings, const QList& settingsKeys, bool force); - bladerf_lna_gain getLnaGain(int lnaGain); + bladerf_lna_gain getLnaGain(int lnaGain) const; void webapiReverseSendSettings(const QList& deviceSettingsKeys, const BladeRF1InputSettings& settings, bool force); void webapiReverseSendStartStop(bool start); private slots: - void networkManagerFinished(QNetworkReply *reply); + void networkManagerFinished(QNetworkReply *reply) const; }; #endif // INCLUDE_BLADERFINPUT_H diff --git a/plugins/samplesource/sigmffileinput/sigmffileinput.cpp b/plugins/samplesource/sigmffileinput/sigmffileinput.cpp index aade8c16a..54fcd8f3a 100644 --- a/plugins/samplesource/sigmffileinput/sigmffileinput.cpp +++ b/plugins/samplesource/sigmffileinput/sigmffileinput.cpp @@ -61,21 +61,8 @@ MESSAGE_CLASS_DEFINITION(SigMFFileInput::MsgReportTotalSamplesCheck, Message) SigMFFileInput::SigMFFileInput(DeviceAPI *deviceAPI) : m_deviceAPI(deviceAPI), - m_running(false), m_settings(), - m_trackMode(false), - m_currentTrackIndex(0), - m_recordOpen(false), - m_crcAvailable(false), - m_crcOK(false), - m_recordLengthOK(false), - m_fileInputWorker(nullptr), - m_deviceDescription("SigMFFileInput"), - m_sampleRate(48000), - m_sampleBytes(1), - m_centerFrequency(0), - m_recordLength(0), - m_startingTimeStamp(0) + m_deviceDescription("SigMFFileInput") { m_sampleFifo.setLabel(m_deviceDescription); m_deviceAPI->setNbSourceStreams(1); @@ -104,7 +91,7 @@ SigMFFileInput::~SigMFFileInput() ); delete m_networkManager; - stop(); + SigMFFileInput::stop(); } void SigMFFileInput::destroy() @@ -156,8 +143,8 @@ bool SigMFFileInput::openFileStreams(const QString& fileName) extractCaptures(&metaRecord); m_metaInfo.m_totalTimeMs = m_captures.back().m_cumulativeTime + ((m_captures.back().m_length * 1000)/m_captures.back().m_sampleRate); - uint64_t centerFrequency = (m_captures.size() > 0) ? m_captures.at(0).m_centerFrequency : 0; - DSPSignalNotification *notif = new DSPSignalNotification(m_metaInfo.m_coreSampleRate, centerFrequency); + uint64_t centerFrequency = (!m_captures.empty()) ? m_captures.at(0).m_centerFrequency : 0; + auto *notif = new DSPSignalNotification((int) m_metaInfo.m_coreSampleRate, centerFrequency); m_deviceAPI->getDeviceEngineInputMessageQueue()->push(notif); if (getMessageQueueToGUI()) @@ -244,14 +231,13 @@ void SigMFFileInput::extractMeta( m_metaInfo.m_arch = QString::fromStdString(metaRecord->global.access().arch); m_metaInfo.m_os = QString::fromStdString(metaRecord->global.access().os); // lists - m_metaInfo.m_nbCaptures = metaRecord->captures.size(); - m_metaInfo.m_nbAnnotations = metaRecord->annotations.size(); + m_metaInfo.m_nbCaptures = (unsigned int) metaRecord->captures.size(); + m_metaInfo.m_nbAnnotations = (unsigned int) metaRecord->annotations.size(); // correct sample bits if sdrangel - if (m_metaInfo.m_sdrAngelVersion.size() > 0) + if ((m_metaInfo.m_sdrAngelVersion.size() > 0) + && (m_metaInfo.m_dataType.m_sampleBits == 32)) { - if (m_metaInfo.m_dataType.m_sampleBits == 32) { - m_metaInfo.m_dataType.m_sampleBits = 24; - } + m_metaInfo.m_dataType.m_sampleBits = 24; } // negative sample rate means inversion m_metaInfo.m_dataType.m_swapIQ = m_metaInfo.m_coreSampleRate < 0; @@ -270,8 +256,7 @@ void SigMFFileInput::extractCaptures( std::regex datetime_reg("(\\d{4})-(\\d\\d)-(\\d\\d)T(\\d\\d):(\\d\\d):(\\d\\d)(\\.\\d+)?(([+-]\\d\\d:\\d\\d)|Z)?"); std::smatch datetime_match; - sigmf::SigMFVector>::iterator it = - metaRecord->captures.begin(); + auto it = metaRecord->captures.begin(); uint64_t lastSampleStart = 0; unsigned int i = 0; uint64_t cumulativeTime = 0; @@ -279,7 +264,7 @@ void SigMFFileInput::extractCaptures( for (; it != metaRecord->captures.end(); ++it, i++) { m_captures.push_back(SigMFFileCapture()); - m_captures.back().m_centerFrequency = it->get().frequency; + m_captures.back().m_centerFrequency = (uint64_t) it->get().frequency; m_captures.back().m_sampleStart = it->get().sample_start; m_captureStarts.push_back(m_captures.back().m_sampleStart); m_captures.back().m_cumulativeTime = cumulativeTime; @@ -287,7 +272,7 @@ void SigMFFileInput::extractCaptures( double globalSampleRate = metaRecord->global.access().sample_rate; if (sdrangelSampleRate == 0) { - m_captures.back().m_sampleRate = globalSampleRate < 0 ? -globalSampleRate : globalSampleRate; + m_captures.back().m_sampleRate = (unsigned int) (globalSampleRate < 0 ? -globalSampleRate : globalSampleRate); } else { m_captures.back().m_sampleRate = sdrangelSampleRate; } @@ -326,7 +311,7 @@ void SigMFFileInput::extractCaptures( dateTime = QDateTime::currentDateTimeUtc(); } - double seconds = dateTime.toSecsSinceEpoch(); + auto seconds = (double) dateTime.toSecsSinceEpoch(); // the subsecond part can be milli (strict ISO-8601) or micro or nano (RFC-3339). This will take any width if (datetime_match.size() > 7) { @@ -335,13 +320,13 @@ void SigMFFileInput::extractCaptures( double fractionalSecs = boost::lexical_cast(datetime_match[7]); seconds += fractionalSecs; } - catch (const boost::bad_lexical_cast &e) + catch (const boost::bad_lexical_cast&) { qDebug("SigMFFileInput::extractCaptures: invalid fractional seconds"); } } - m_captures.back().m_tsms = seconds * 1000.0; + m_captures.back().m_tsms = (uint64_t) (seconds * 1000.0); } m_captures.back().m_length = it->get().length; @@ -390,7 +375,7 @@ void SigMFFileInput::analyzeDataType(const std::string& dataTypeString, SigMFFil { dataType.m_sampleBits = boost::lexical_cast(dataType_match[3]); } - catch(const boost::bad_lexical_cast &e) + catch(const boost::bad_lexical_cast&) { qDebug("SigMFFileInput::analyzeDataType: invalid sample bits. Assume 32"); dataType.m_sampleBits = 32; @@ -414,7 +399,7 @@ uint64_t SigMFFileInput::getTrackSampleStart(unsigned int trackIndex) int SigMFFileInput::getTrackIndex(uint64_t sampleIndex) { auto it = std::upper_bound(m_captureStarts.begin(), m_captureStarts.end(), sampleIndex); - return (it - m_captureStarts.begin()) - 1; + return (int) ((it - m_captureStarts.begin()) - 1); } void SigMFFileInput::seekFileStream(uint64_t sampleIndex) @@ -441,7 +426,7 @@ void SigMFFileInput::seekFileMillis(int seekMillis) void SigMFFileInput::init() { - DSPSignalNotification *notif = new DSPSignalNotification(m_sampleRate, m_centerFrequency); + auto *notif = new DSPSignalNotification(m_sampleRate, m_centerFrequency); m_deviceAPI->getDeviceEngineInputMessageQueue()->push(notif); } @@ -596,13 +581,13 @@ bool SigMFFileInput::handleMessage(const Message& message) { if (MsgConfigureSigMFFileInput::match(message)) { - MsgConfigureSigMFFileInput& conf = (MsgConfigureSigMFFileInput&) message; + auto& conf = (const MsgConfigureSigMFFileInput&) message; applySettings(conf.getSettings(), conf.getSettingsKeys(), conf.getForce()); return true; } else if (MsgConfigureTrackIndex::match(message)) { - MsgConfigureTrackIndex& conf = (MsgConfigureTrackIndex&) message; + auto& conf = (const MsgConfigureTrackIndex&) message; m_currentTrackIndex = conf.getTrackIndex(); qDebug("SigMFFileInput::handleMessage MsgConfigureTrackIndex: m_currentTrackIndex: %d", m_currentTrackIndex); seekTrackMillis(0); @@ -623,7 +608,7 @@ bool SigMFFileInput::handleMessage(const Message& message) ); if (working) { - startWorker(); + startWorker(); } } @@ -631,7 +616,7 @@ bool SigMFFileInput::handleMessage(const Message& message) } else if (MsgConfigureTrackWork::match(message)) { - MsgConfigureTrackWork& conf = (MsgConfigureTrackWork&) message; + auto& conf = (const MsgConfigureTrackWork&) message; bool working = conf.isWorking(); m_trackMode = true; @@ -653,7 +638,7 @@ bool SigMFFileInput::handleMessage(const Message& message) } else if (MsgConfigureTrackSeek::match(message)) { - MsgConfigureTrackSeek& conf = (MsgConfigureTrackSeek&) message; + auto& conf = (const MsgConfigureTrackSeek&) message; int seekMillis = conf.getMillis(); seekTrackMillis(seekMillis); @@ -669,7 +654,7 @@ bool SigMFFileInput::handleMessage(const Message& message) m_captures[m_currentTrackIndex].m_sampleStart + ((m_captures[m_currentTrackIndex].m_length*seekMillis)/1000UL)); if (working) { - startWorker(); + startWorker(); } } @@ -677,7 +662,7 @@ bool SigMFFileInput::handleMessage(const Message& message) } else if (MsgConfigureFileSeek::match(message)) { - MsgConfigureFileSeek& conf = (MsgConfigureFileSeek&) message; + auto& conf = (const MsgConfigureFileSeek&) message; int seekMillis = conf.getMillis(); seekFileStream(seekMillis); uint64_t sampleCount = (m_metaInfo.m_totalSamples*seekMillis)/1000UL; @@ -695,7 +680,7 @@ bool SigMFFileInput::handleMessage(const Message& message) m_fileInputWorker->setSamplesCount(sampleCount); if (working) { - startWorker(); + startWorker(); } } @@ -703,7 +688,7 @@ bool SigMFFileInput::handleMessage(const Message& message) } else if (MsgConfigureFileWork::match(message)) { - MsgConfigureFileWork& conf = (MsgConfigureFileWork&) message; + auto& conf = (const MsgConfigureFileWork&) message; bool working = conf.isWorking(); m_trackMode = false; @@ -724,27 +709,24 @@ bool SigMFFileInput::handleMessage(const Message& message) } else if (MsgConfigureFileInputStreamTiming::match(message)) { - if (m_fileInputWorker) + if (m_fileInputWorker && getMessageQueueToGUI()) { - if (getMessageQueueToGUI()) - { - quint64 totalSamplesCount = m_fileInputWorker->getSamplesCount(); - quint64 trackSamplesCount = totalSamplesCount - m_captures[m_currentTrackIndex].m_sampleStart; - MsgReportFileInputStreamTiming *report = MsgReportFileInputStreamTiming::create( - totalSamplesCount, - trackSamplesCount, - m_captures[m_currentTrackIndex].m_cumulativeTime, - m_currentTrackIndex - ); - getMessageQueueToGUI()->push(report); - } + quint64 totalSamplesCount = m_fileInputWorker->getSamplesCount(); + quint64 trackSamplesCount = totalSamplesCount - m_captures[m_currentTrackIndex].m_sampleStart; + MsgReportFileInputStreamTiming *report = MsgReportFileInputStreamTiming::create( + totalSamplesCount, + trackSamplesCount, + m_captures[m_currentTrackIndex].m_cumulativeTime, + m_currentTrackIndex + ); + getMessageQueueToGUI()->push(report); } return true; } else if (MsgStartStop::match(message)) { - MsgStartStop& cmd = (MsgStartStop&) message; + auto& cmd = (const MsgStartStop&) message; qDebug() << "FileInput::handleMessage: MsgStartStop: " << (cmd.getStartStop() ? "start" : "stop"); if (cmd.getStartStop()) @@ -798,7 +780,7 @@ bool SigMFFileInput::handleMessage(const Message& message) } else if (SigMFFileInputWorker::MsgReportTrackChange::match(message)) { - SigMFFileInputWorker::MsgReportTrackChange& report = (SigMFFileInputWorker::MsgReportTrackChange&) message; + auto& report = (const SigMFFileInputWorker::MsgReportTrackChange&) message; m_currentTrackIndex = report.getTrackIndex(); qDebug("SigMFFileInput::handleMessage MsgReportTrackChange: m_currentTrackIndex: %d", m_currentTrackIndex); int sampleRate = m_captures.at(m_currentTrackIndex).m_sampleRate; @@ -806,7 +788,7 @@ bool SigMFFileInput::handleMessage(const Message& message) if ((m_sampleRate != sampleRate) || (m_centerFrequency != centerFrequency)) { - DSPSignalNotification *notif = new DSPSignalNotification(sampleRate, centerFrequency); + auto *notif = new DSPSignalNotification(sampleRate, centerFrequency); m_deviceAPI->getDeviceEngineInputMessageQueue()->push(notif); m_sampleRate = sampleRate; @@ -831,18 +813,15 @@ bool SigMFFileInput::applySettings(const SigMFFileInputSettings& settings, const { qDebug() << "SigMFFileInput::applySettings: force: " << force << settings.getDebugString(settingsKeys, force); - if (settingsKeys.contains("accelerationFactor") || force) + if (m_fileInputWorker && (settingsKeys.contains("accelerationFactor") || force)) { - if (m_fileInputWorker) - { - QMutexLocker mutexLocker(&m_mutex); - if (!m_sampleFifo.setSize(m_settings.m_accelerationFactor * m_sampleRate * sizeof(Sample))) { - qCritical("SigMFFileInput::applySettings: could not reallocate sample FIFO size to %lu", - m_settings.m_accelerationFactor * m_sampleRate * sizeof(Sample)); - } - - m_fileInputWorker->setAccelerationFactor(settings.m_accelerationFactor); // Fast Forward: 1 corresponds to live. 1/2 is half speed, 2 is double speed + QMutexLocker mutexLocker(&m_mutex); + if (!m_sampleFifo.setSize(m_settings.m_accelerationFactor * m_sampleRate * sizeof(Sample))) { + qCritical("SigMFFileInput::applySettings: could not reallocate sample FIFO size to %lu", + m_settings.m_accelerationFactor * m_sampleRate * sizeof(Sample)); } + + m_fileInputWorker->setAccelerationFactor(settings.m_accelerationFactor); // Fast Forward: 1 corresponds to live. 1/2 is half speed, 2 is double speed } if (settingsKeys.contains("fileName")) { @@ -925,10 +904,10 @@ void SigMFFileInput::webapiUpdateDeviceSettings( settings.m_reverseAPIAddress = *response.getSigMfFileInputSettings()->getReverseApiAddress(); } if (deviceSettingsKeys.contains("reverseAPIPort")) { - settings.m_reverseAPIPort = response.getSigMfFileInputSettings()->getReverseApiPort(); + settings.m_reverseAPIPort = (uint16_t) response.getSigMfFileInputSettings()->getReverseApiPort(); } if (deviceSettingsKeys.contains("reverseAPIDeviceIndex")) { - settings.m_reverseAPIDeviceIndex = response.getSigMfFileInputSettings()->getReverseApiDeviceIndex(); + settings.m_reverseAPIDeviceIndex = (uint16_t) response.getSigMfFileInputSettings()->getReverseApiDeviceIndex(); } } @@ -1080,7 +1059,11 @@ void SigMFFileInput::webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& resp response.getSigMfFileInputReport()->setSampleFormat(m_metaInfo.m_dataType.m_floatingPoint ? 1 : 0); response.getSigMfFileInputReport()->setSampleSigned(m_metaInfo.m_dataType.m_signed ? 1 : 0); response.getSigMfFileInputReport()->setSampleSwapIq(m_metaInfo.m_dataType.m_swapIQ ? 1 : 0); - response.getSigMfFileInputReport()->setCrcStatus(!m_crcAvailable ? 0 : m_crcOK ? 1 : 2); + if (!m_crcAvailable) { + response.getSigMfFileInputReport()->setCrcStatus(0); + } else { + response.getSigMfFileInputReport()->setCrcStatus(m_crcOK ? 1 : 2); + } response.getSigMfFileInputReport()->setTotalBytesStatus(m_recordLengthOK); response.getSigMfFileInputReport()->setTrackNumber(m_currentTrackIndex); QList::const_iterator it = m_captures.begin(); @@ -1124,7 +1107,7 @@ void SigMFFileInput::webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& resp posRatio = (float) totalSamplesCount / (float) m_metaInfo.m_totalSamples; response.getSigMfFileInputReport()->setRecordSamplesRatio(posRatio); - if (m_captures.size() > 0 ) + if (!m_captures.empty() ) { uint64_t totalTimeMs = m_captures.back().m_cumulativeTime + ((m_captures.back().m_length * 1000) / m_captures.back().m_sampleRate); response.getSigMfFileInputReport()->setRecordDurationMs(totalTimeMs); @@ -1137,7 +1120,7 @@ void SigMFFileInput::webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& resp void SigMFFileInput::webapiReverseSendSettings(const QList& deviceSettingsKeys, const SigMFFileInputSettings& settings, bool force) { - SWGSDRangel::SWGDeviceSettings *swgDeviceSettings = new SWGSDRangel::SWGDeviceSettings(); + auto *swgDeviceSettings = new SWGSDRangel::SWGDeviceSettings(); swgDeviceSettings->setDirection(0); // single Rx swgDeviceSettings->setOriginatorIndex(m_deviceAPI->getDeviceSetIndex()); swgDeviceSettings->setDeviceHwType(new QString("SigMFFileInput")); @@ -1166,8 +1149,8 @@ void SigMFFileInput::webapiReverseSendSettings(const QList& deviceSetti m_networkRequest.setUrl(QUrl(deviceSettingsURL)); m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); - QBuffer *buffer = new QBuffer(); - buffer->open((QBuffer::ReadWrite)); + auto *buffer = new QBuffer(); + buffer->open(QBuffer::ReadWrite); buffer->write(swgDeviceSettings->asJson().toUtf8()); buffer->seek(0); @@ -1180,7 +1163,7 @@ void SigMFFileInput::webapiReverseSendSettings(const QList& deviceSetti void SigMFFileInput::webapiReverseSendStartStop(bool start) { - SWGSDRangel::SWGDeviceSettings *swgDeviceSettings = new SWGSDRangel::SWGDeviceSettings(); + auto *swgDeviceSettings = new SWGSDRangel::SWGDeviceSettings(); swgDeviceSettings->setDirection(0); // single Rx swgDeviceSettings->setOriginatorIndex(m_deviceAPI->getDeviceSetIndex()); swgDeviceSettings->setDeviceHwType(new QString("SigMFFileInput")); @@ -1192,8 +1175,8 @@ void SigMFFileInput::webapiReverseSendStartStop(bool start) m_networkRequest.setUrl(QUrl(deviceSettingsURL)); m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); - QBuffer *buffer = new QBuffer(); - buffer->open((QBuffer::ReadWrite)); + auto *buffer = new QBuffer(); + buffer->open(QBuffer::ReadWrite); buffer->write(swgDeviceSettings->asJson().toUtf8()); buffer->seek(0); QNetworkReply *reply; @@ -1208,7 +1191,7 @@ void SigMFFileInput::webapiReverseSendStartStop(bool start) delete swgDeviceSettings; } -void SigMFFileInput::networkManagerFinished(QNetworkReply *reply) +void SigMFFileInput::networkManagerFinished(QNetworkReply *reply) const { QNetworkReply::NetworkError replyError = reply->error(); diff --git a/plugins/samplesource/sigmffileinput/sigmffileinput.h b/plugins/samplesource/sigmffileinput/sigmffileinput.h index f612b31bf..872db9e85 100644 --- a/plugins/samplesource/sigmffileinput/sigmffileinput.h +++ b/plugins/samplesource/sigmffileinput/sigmffileinput.h @@ -86,7 +86,7 @@ public: private: bool m_working; - MsgConfigureTrackWork(bool working) : + explicit MsgConfigureTrackWork(bool working) : Message(), m_working(working) { } @@ -109,7 +109,7 @@ public: private: bool m_working; - MsgConfigureFileWork(bool working) : + explicit MsgConfigureFileWork(bool working) : Message(), m_working(working) { } @@ -132,7 +132,7 @@ public: private: int m_trackIndex; - MsgConfigureTrackIndex(int trackIndex) : + explicit MsgConfigureTrackIndex(int trackIndex) : Message(), m_trackIndex(trackIndex) { } @@ -152,10 +152,10 @@ public: return new MsgConfigureTrackSeek(seekMillis); } - protected: + private: int m_seekMillis; //!< millis of seek position from the beginning 0..1000 - MsgConfigureTrackSeek(int seekMillis) : + explicit MsgConfigureTrackSeek(int seekMillis) : Message(), m_seekMillis(seekMillis) { } @@ -175,10 +175,10 @@ public: return new MsgConfigureFileSeek(seekMillis); } - protected: + private: int m_seekMillis; //!< millis of seek position from the beginning 0..1000 - MsgConfigureFileSeek(int seekMillis) : + explicit MsgConfigureFileSeek(int seekMillis) : Message(), m_seekMillis(seekMillis) { } @@ -217,10 +217,10 @@ public: return new MsgStartStop(startStop); } - protected: + private: bool m_startStop; - MsgStartStop(bool startStop) : + explicit MsgStartStop(bool startStop) : Message(), m_startStop(startStop) { } @@ -240,10 +240,10 @@ public: return new MsgReportStartStop(startStop); } - protected: + private: bool m_startStop; - MsgReportStartStop(bool startStop) : + explicit MsgReportStartStop(bool startStop) : Message(), m_startStop(startStop) { } @@ -257,13 +257,13 @@ public: public: const SigMFFileMetaInfo& getMetaInfo() const { return m_metaInfo; } - const QList& getCaptures() { return m_captures; } + const QList& getCaptures() const { return m_captures; } static MsgReportMetaData* create(const SigMFFileMetaInfo& metaInfo, const QList& captures) { return new MsgReportMetaData(metaInfo, captures); } - protected: + private: SigMFFileMetaInfo m_metaInfo; QList m_captures; @@ -288,7 +288,7 @@ public: private: int m_trackIndex; - MsgReportTrackChange(int trackIndex) : + explicit MsgReportTrackChange(int trackIndex) : Message(), m_trackIndex(trackIndex) { } @@ -321,7 +321,7 @@ public: ); } - protected: + private: quint64 m_samplesCount; quint64 m_trackSamplesCount; quint64 m_trackTimeStart; @@ -354,10 +354,10 @@ public: return new MsgReportCRC(ok); } - protected: + private: bool m_ok; - MsgReportCRC(bool ok) : + explicit MsgReportCRC(bool ok) : Message(), m_ok(ok) { } @@ -376,98 +376,98 @@ public: return new MsgReportTotalSamplesCheck(ok); } - protected: + private: bool m_ok; - MsgReportTotalSamplesCheck(bool ok) : + explicit MsgReportTotalSamplesCheck(bool ok) : Message(), m_ok(ok) { } }; - SigMFFileInput(DeviceAPI *deviceAPI); - virtual ~SigMFFileInput(); - virtual void destroy(); + explicit SigMFFileInput(DeviceAPI *deviceAPI); + ~SigMFFileInput() final; + void destroy() final; - virtual void init(); - virtual bool start(); - virtual void stop(); + void init() final; + bool start() final; + void stop() final; - virtual QByteArray serialize() const; - virtual bool deserialize(const QByteArray& data); + QByteArray serialize() const final; + bool deserialize(const QByteArray& data) final; - virtual void setMessageQueueToGUI(MessageQueue *queue) { m_guiMessageQueue = queue; } - virtual const QString& getDeviceDescription() const; - virtual int getSampleRate() const; - virtual void setSampleRate(int sampleRate) { (void) sampleRate; } - virtual quint64 getCenterFrequency() const; - virtual void setCenterFrequency(qint64 centerFrequency); + void setMessageQueueToGUI(MessageQueue *queue) final { m_guiMessageQueue = queue; } + const QString& getDeviceDescription() const final; + int getSampleRate() const final; + void setSampleRate(int sampleRate) final { (void) sampleRate; } + quint64 getCenterFrequency() const final; + void setCenterFrequency(qint64 centerFrequency) final; quint64 getStartingTimeStamp() const; - virtual bool handleMessage(const Message& message); + bool handleMessage(const Message& message) final; - virtual int webapiSettingsGet( - SWGSDRangel::SWGDeviceSettings& response, - QString& errorMessage); + int webapiSettingsGet( + SWGSDRangel::SWGDeviceSettings& response, + QString& errorMessage) final; - virtual int webapiSettingsPutPatch( - bool force, - const QStringList& deviceSettingsKeys, - SWGSDRangel::SWGDeviceSettings& response, // query + response - QString& errorMessage); + int webapiSettingsPutPatch( + bool force, + const QStringList& deviceSettingsKeys, + SWGSDRangel::SWGDeviceSettings& response, // query + response + QString& errorMessage) final; - virtual int webapiRunGet( - SWGSDRangel::SWGDeviceState& response, - QString& errorMessage); + int webapiRunGet( + SWGSDRangel::SWGDeviceState& response, + QString& errorMessage) final; - virtual int webapiActionsPost( - const QStringList& deviceActionsKeys, - SWGSDRangel::SWGDeviceActions& query, - QString& errorMessage); + int webapiActionsPost( + const QStringList& deviceActionsKeys, + SWGSDRangel::SWGDeviceActions& query, + QString& errorMessage) final; - virtual int webapiRun( - bool run, - SWGSDRangel::SWGDeviceState& response, - QString& errorMessage); + int webapiRun( + bool run, + SWGSDRangel::SWGDeviceState& response, + QString& errorMessage) final; - virtual int webapiReportGet( - SWGSDRangel::SWGDeviceReport& response, - QString& errorMessage); + int webapiReportGet( + SWGSDRangel::SWGDeviceReport& response, + QString& errorMessage) final; static void webapiFormatDeviceSettings( - SWGSDRangel::SWGDeviceSettings& response, - const SigMFFileInputSettings& settings); + SWGSDRangel::SWGDeviceSettings& response, + const SigMFFileInputSettings& settings); static void webapiUpdateDeviceSettings( - SigMFFileInputSettings& settings, - const QStringList& deviceSettingsKeys, - SWGSDRangel::SWGDeviceSettings& response); + SigMFFileInputSettings& settings, + const QStringList& deviceSettingsKeys, + SWGSDRangel::SWGDeviceSettings& response); private: DeviceAPI *m_deviceAPI; QMutex m_mutex; - bool m_running; + bool m_running = false; SigMFFileInputSettings m_settings; std::ifstream m_metaStream; std::ifstream m_dataStream; SigMFFileMetaInfo m_metaInfo; QList m_captures; std::vector m_captureStarts; - bool m_trackMode; - int m_currentTrackIndex; - bool m_recordOpen; - bool m_crcAvailable; - bool m_crcOK; - bool m_recordLengthOK; + bool m_trackMode = false; + int m_currentTrackIndex = 0; + bool m_recordOpen = false; + bool m_crcAvailable = false; + bool m_crcOK = false; + bool m_recordLengthOK = false; QString m_recordSummary; - SigMFFileInputWorker* m_fileInputWorker; + SigMFFileInputWorker* m_fileInputWorker = nullptr; QThread m_fileInputWorkerThread; QString m_deviceDescription; - int m_sampleRate; - unsigned int m_sampleBytes; - quint64 m_centerFrequency; - quint64 m_recordLength; //!< record length in seconds computed from file size - quint64 m_startingTimeStamp; + int m_sampleRate = 48000; + unsigned int m_sampleBytes = 1; + quint64 m_centerFrequency = 0; + quint64 m_recordLength = 0; //!< record length in seconds computed from file size + quint64 m_startingTimeStamp = 0; QTimer m_masterTimer; QNetworkAccessManager *m_networkManager; QNetworkRequest m_networkRequest; @@ -498,7 +498,7 @@ private: void webapiReverseSendStartStop(bool start); private slots: - void networkManagerFinished(QNetworkReply *reply); + void networkManagerFinished(QNetworkReply *reply) const; }; #endif // INCLUDE_SIGMFFILEINPUT_H diff --git a/sdrbase/device/deviceapi.cpp b/sdrbase/device/deviceapi.cpp index 65bd30529..fce595cb1 100644 --- a/sdrbase/device/deviceapi.cpp +++ b/sdrbase/device/deviceapi.cpp @@ -65,9 +65,7 @@ DeviceAPI::DeviceAPI( } } -DeviceAPI::~DeviceAPI() -{ -} +DeviceAPI::~DeviceAPI() = default; void DeviceAPI::setSpectrumSinkInput(bool sourceElseSink, unsigned int index) { @@ -269,7 +267,7 @@ DeviceAPI::EngineState DeviceAPI::state(int subsystemIndex) const } } -QString DeviceAPI::errorMessage(int subsystemIndex) +QString DeviceAPI::errorMessage(int subsystemIndex) const { if (m_deviceSourceEngine) { return m_deviceSourceEngine->errorMessage(); @@ -360,28 +358,28 @@ void DeviceAPI::setDeviceItemIndex(uint32_t index) void DeviceAPI::setSamplingDevicePluginInterface(PluginInterface *iface) { - m_pluginInterface = iface; + m_pluginInterface = iface; } -void DeviceAPI::getDeviceEngineStateStr(QString& state, int subsystemIndex) +void DeviceAPI::getDeviceEngineStateStr(QString& state, int subsystemIndex) const { if (m_deviceSourceEngine) { switch(m_deviceSourceEngine->state()) { - case DSPDeviceSourceEngine::StNotStarted: + case DSPDeviceSourceEngine::State::StNotStarted: state = "notStarted"; break; - case DSPDeviceSourceEngine::StIdle: + case DSPDeviceSourceEngine::State::StIdle: state = "idle"; break; - case DSPDeviceSourceEngine::StReady: + case DSPDeviceSourceEngine::State::StReady: state = "ready"; break; - case DSPDeviceSourceEngine::StRunning: + case DSPDeviceSourceEngine::State::StRunning: state = "running"; break; - case DSPDeviceSourceEngine::StError: + case DSPDeviceSourceEngine::State::StError: state = "error"; break; default: @@ -393,19 +391,19 @@ void DeviceAPI::getDeviceEngineStateStr(QString& state, int subsystemIndex) { switch(m_deviceSinkEngine->state()) { - case DSPDeviceSinkEngine::StNotStarted: + case DSPDeviceSinkEngine::State::StNotStarted: state = "notStarted"; break; - case DSPDeviceSinkEngine::StIdle: + case DSPDeviceSinkEngine::State::StIdle: state = "idle"; break; - case DSPDeviceSinkEngine::StReady: + case DSPDeviceSinkEngine::State::StReady: state = "ready"; break; - case DSPDeviceSinkEngine::StRunning: + case DSPDeviceSinkEngine::State::StRunning: state = "running"; break; - case DSPDeviceSinkEngine::StError: + case DSPDeviceSinkEngine::State::StError: state = "error"; break; default: @@ -417,19 +415,19 @@ void DeviceAPI::getDeviceEngineStateStr(QString& state, int subsystemIndex) { switch(m_deviceMIMOEngine->state(subsystemIndex)) { - case DSPDeviceMIMOEngine::StNotStarted: + case DSPDeviceMIMOEngine::State::StNotStarted: state = "notStarted"; break; - case DSPDeviceMIMOEngine::StIdle: + case DSPDeviceMIMOEngine::State::StIdle: state = "idle"; break; - case DSPDeviceMIMOEngine::StReady: + case DSPDeviceMIMOEngine::State::StReady: state = "ready"; break; - case DSPDeviceMIMOEngine::StRunning: + case DSPDeviceMIMOEngine::State::StRunning: state = "running"; break; - case DSPDeviceMIMOEngine::StError: + case DSPDeviceMIMOEngine::State::StError: state = "error"; break; default: @@ -546,26 +544,26 @@ bool DeviceAPI::deserialize(const QByteArray& data) if (d.getVersion() == 1) { - QByteArray data; + QByteArray bdata; QList centerFrequency; if (m_deviceSourceEngine && m_deviceSourceEngine->getSource()) { - d.readBlob(1, &data); + d.readBlob(1, &bdata); if (data.size() > 0) { m_deviceSourceEngine->getSource()->deserialize(data); } } if (m_deviceSinkEngine && m_deviceSinkEngine->getSink()) { - d.readBlob(2, &data); + d.readBlob(2, &bdata); if (data.size() > 0) { m_deviceSinkEngine->getSink()->deserialize(data); } } if (m_deviceMIMOEngine && m_deviceMIMOEngine->getMIMO()) { - d.readBlob(3, &data); + d.readBlob(3, &bdata); if (data.size() > 0) { m_deviceMIMOEngine->getMIMO()->deserialize(data); } @@ -596,7 +594,7 @@ void DeviceAPI::loadSamplingDeviceSettings(const Preset* preset) qDebug("DeviceAPI::loadSamplingDeviceSettings: deserializing source %s[%d]: %s", qPrintable(m_samplingDeviceId), m_samplingDeviceSequence, qPrintable(m_samplingDeviceSerial)); - if (m_deviceSourceEngine->getSource() != 0) // Server flavor + if (m_deviceSourceEngine->getSource() != nullptr) // Server flavor { m_deviceSourceEngine->getSource()->deserialize(*sourceConfig); } @@ -791,8 +789,8 @@ void DeviceAPI::removeBuddy(DeviceAPI* buddy) void DeviceAPI::clearBuddiesLists() { - std::vector::iterator itSource = m_sourceBuddies.begin(); - std::vector::iterator itSink = m_sinkBuddies.begin(); + auto itSource = m_sourceBuddies.begin(); + auto itSink = m_sinkBuddies.begin(); bool leaderElected = false; for (;itSource != m_sourceBuddies.end(); ++itSource) diff --git a/sdrbase/device/deviceapi.h b/sdrbase/device/deviceapi.h index 351816c9e..554495276 100644 --- a/sdrbase/device/deviceapi.h +++ b/sdrbase/device/deviceapi.h @@ -65,7 +65,7 @@ public: DSPDeviceSinkEngine *deviceSinkEngine, DSPDeviceMIMOEngine *deviceMIMOEngine ); - ~DeviceAPI(); + ~DeviceAPI() override; void setSpectrumSinkInput(bool sourceElseSink = true, unsigned int index = 0); //!< Used in the MIMO case to select which stream is used as input to main spectrum @@ -94,7 +94,7 @@ public: bool startDeviceEngine(int subsystemIndex = 0); //!< Start the device engine corresponding to the stream type void stopDeviceEngine(int subsystemIndex = 0); //!< Stop the device engine corresponding to the stream type EngineState state(int subsystemIndex = 0) const; //!< Return the state of the device engine corresponding to the stream type - QString errorMessage(int subsystemIndex = 0); //!< Last error message from the device engine + QString errorMessage(int subsystemIndex = 0) const; //!< Last error message from the device engine uint getDeviceUID() const; //!< Return the current device engine unique ID MessageQueue *getDeviceEngineInputMessageQueue(); //!< Device engine message queue @@ -131,7 +131,7 @@ public: void setDeviceSetIndex(int deviceSetIndex); PluginInterface *getPluginInterface() { return m_pluginInterface; } - void getDeviceEngineStateStr(QString& state, int subsystemIndex = 0); + void getDeviceEngineStateStr(QString& state, int subsystemIndex = 0) const; ChannelAPI *getChanelSinkAPIAt(int index); ChannelAPI *getChanelSourceAPIAt(int index); @@ -142,11 +142,7 @@ public: int getNbMIMOChannels() const { return m_mimoChannelAPIs.size(); } void loadSamplingDeviceSettings(const Preset* preset); - // void loadSourceSettings(const Preset* preset); - // void loadSinkSettings(const Preset* preset); void saveSamplingDeviceSettings(Preset* preset); - // void saveSourceSettings(Preset* preset); - // void saveSinkSettings(Preset* preset); QByteArray serialize() const override; bool deserialize(const QByteArray& data) override; @@ -176,7 +172,7 @@ public: const QTimer& getMasterTimer() const { return m_masterTimer; } //!< This is the DSPEngine master timer -protected: +private: // common StreamType m_streamType; @@ -217,7 +213,6 @@ protected: DSPDeviceMIMOEngine *m_deviceMIMOEngine; QList m_mimoChannelAPIs; -private: void renumerateChannels(); private slots: diff --git a/sdrbase/dsp/dspdevicemimoengine.cpp b/sdrbase/dsp/dspdevicemimoengine.cpp index 7fd4997ae..0cf3cd7d9 100644 --- a/sdrbase/dsp/dspdevicemimoengine.cpp +++ b/sdrbase/dsp/dspdevicemimoengine.cpp @@ -43,14 +43,14 @@ MESSAGE_CLASS_DEFINITION(DSPDeviceMIMOEngine::SetSpectrumSinkInput, Message) DSPDeviceMIMOEngine::DSPDeviceMIMOEngine(uint32_t uid, QObject* parent) : QObject(parent), m_uid(uid), - m_stateRx(StNotStarted), - m_stateTx(StNotStarted), + m_stateRx(State::StNotStarted), + m_stateTx(State::StNotStarted), m_deviceSampleMIMO(nullptr), m_spectrumInputSourceElseSink(true), m_spectrumInputIndex(0) { - setStateRx(StIdle); - setStateTx(StIdle); + setStateRx(State::StIdle); + setStateTx(State::StIdle); connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()), Qt::QueuedConnection); } @@ -127,7 +127,7 @@ void DSPDeviceMIMOEngine::stopProcess(int subsystemIndex) } else if (subsystemIndex == 1) // Tx side { - DSPGenerationStop *cmd = new DSPGenerationStop(); + auto *cmd = new DSPGenerationStop(); getInputMessageQueue()->push(cmd); } } @@ -255,11 +255,9 @@ void DSPDeviceMIMOEngine::workSampleSinkFifos() unsigned int iPart2Begin; unsigned int iPart2End; const std::vector& data = sampleFifo->getData(); - //unsigned int samplesDone = 0; while ((sampleFifo->fillSync() > 0) && (m_inputMessageQueue.size() == 0)) { - //unsigned int count = sampleFifo->readSync(sampleFifo->fillSync(), iPart1Begin, iPart1End, iPart2Begin, iPart2End); sampleFifo->readSync(iPart1Begin, iPart1End, iPart2Begin, iPart2End); if (iPart1Begin != iPart1End) @@ -288,7 +286,10 @@ void DSPDeviceMIMOEngine::workSampleSourceFifos() std::vector vbegin; std::vector& data = sampleFifo->getData(); - unsigned int iPart1Begin, iPart1End, iPart2Begin, iPart2End; + unsigned int iPart1Begin; + unsigned int iPart1End; + unsigned int iPart2Begin; + unsigned int iPart2End; unsigned int remainder = sampleFifo->remainderSync(); while ((remainder > 0) && (m_inputMessageQueue.size() == 0)) @@ -331,7 +332,6 @@ void DSPDeviceMIMOEngine::workSampleSinkFifo(unsigned int streamIndex) while ((sampleFifo->fillAsync(streamIndex) > 0) && (m_inputMessageQueue.size() == 0)) { - //unsigned int count = sampleFifo->readAsync(sampleFifo->fillAsync(stream), &part1begin, &part1end, &part2begin, &part2end, stream); sampleFifo->readAsync(&part1begin, &part1end, &part2begin, &part2end, streamIndex); if (part1begin != part1end) { // first part of FIFO data @@ -354,7 +354,10 @@ void DSPDeviceMIMOEngine::workSampleSourceFifo(unsigned int streamIndex) } SampleVector& data = sampleFifo->getData(streamIndex); - unsigned int iPart1Begin, iPart1End, iPart2Begin, iPart2End; + unsigned int iPart1Begin; + unsigned int iPart1End; + unsigned int iPart2Begin; + unsigned int iPart2End; unsigned int amount = sampleFifo->remainderAsync(streamIndex); while ((amount > 0) && (m_inputMessageQueue.size() == 0)) @@ -382,11 +385,6 @@ void DSPDeviceMIMOEngine::workSamplesSink(const SampleVector::const_iterator& vb std::map::const_iterator rcIt = m_rxRealElseComplex.find(streamIndex); bool positiveOnly = (rcIt == m_rxRealElseComplex.end() ? false : rcIt->second); - // DC and IQ corrections - // if (m_sourcesCorrections[streamIndex].m_dcOffsetCorrection) { - // iqCorrections(vbegin, vend, streamIndex, m_sourcesCorrections[streamIndex].m_iqImbalanceCorrection); - // } - // feed data to direct sinks if (streamIndex < m_basebandSampleSinks.size()) { @@ -396,7 +394,7 @@ void DSPDeviceMIMOEngine::workSamplesSink(const SampleVector::const_iterator& vb } // possibly feed data to spectrum sink - if ((m_spectrumSink) && (m_spectrumInputSourceElseSink) && (streamIndex == m_spectrumInputIndex)) { + if (m_spectrumSink && m_spectrumInputSourceElseSink && (streamIndex == m_spectrumInputIndex)) { m_spectrumSink->feed(vbegin, vend, positiveOnly); } @@ -445,14 +443,14 @@ void DSPDeviceMIMOEngine::workSamplesSource(SampleVector& data, unsigned int iBe for (; srcIt != m_basebandSampleSources[streamIndex].end(); ++srcIt, m_sumIndex++) { sampleSource = *srcIt; - SampleVector::iterator aBegin = m_sourceSampleBuffers[streamIndex].m_vector.begin(); + auto aBegin = m_sourceSampleBuffers[streamIndex].m_vector.begin(); sampleSource->pull(aBegin, nbSamples); std::transform( aBegin, aBegin + nbSamples, begin, begin, - [this](Sample& a, const Sample& b) -> Sample { + [this](Sample const& a, const Sample& b) -> Sample { FixReal den = m_sumIndex + 1; // at each stage scale sum by n/n+1 and input by 1/n+1 FixReal nom = m_sumIndex; // so that final sum is scaled by N (number of channels) FixReal x = a.real()/den + nom*(b.real()/den); @@ -468,7 +466,7 @@ void DSPDeviceMIMOEngine::workSamplesSource(SampleVector& data, unsigned int iBe std::map::const_iterator rcIt = m_txRealElseComplex.find(streamIndex); bool positiveOnly = (rcIt == m_txRealElseComplex.end() ? false : rcIt->second); - if ((m_spectrumSink) && (!m_spectrumInputSourceElseSink) && (streamIndex == m_spectrumInputIndex)) { + if (m_spectrumSink && (!m_spectrumInputSourceElseSink) && (streamIndex == m_spectrumInputIndex)) { m_spectrumSink->feed(begin, begin + nbSamples, positiveOnly); } } @@ -482,21 +480,21 @@ DSPDeviceMIMOEngine::State DSPDeviceMIMOEngine::gotoIdle(int subsystemIndex) qDebug() << "DSPDeviceMIMOEngine::gotoIdle: subsystemIndex:" << subsystemIndex; if (!m_deviceSampleMIMO) { - return StIdle; + return State::StIdle; } if (subsystemIndex == 0) // Rx { switch (m_stateRx) { - case StNotStarted: - return StNotStarted; + case State::StNotStarted: + return State::StNotStarted; - case StIdle: - case StError: - return StIdle; + case State::StIdle: + case State::StError: + return State::StIdle; - case StReady: - case StRunning: + case State::StReady: + case State::StRunning: break; } @@ -506,7 +504,7 @@ DSPDeviceMIMOEngine::State DSPDeviceMIMOEngine::gotoIdle(int subsystemIndex) for (; vbit != m_basebandSampleSinks.end(); ++vbit) { - for (BasebandSampleSinks::const_iterator it = vbit->begin(); it != vbit->end(); ++it) + for (auto it = vbit->begin(); it != vbit->end(); ++it) { qDebug() << "DSPDeviceMIMOEngine::gotoIdle: stopping BasebandSampleSink: " << (*it)->getSinkName().toStdString().c_str(); (*it)->stop(); @@ -522,15 +520,15 @@ DSPDeviceMIMOEngine::State DSPDeviceMIMOEngine::gotoIdle(int subsystemIndex) else if (subsystemIndex == 1) // Tx { switch (m_stateTx) { - case StNotStarted: - return StNotStarted; + case State::StNotStarted: + return State::StNotStarted; - case StIdle: - case StError: - return StIdle; + case State::StIdle: + case State::StError: + return State::StIdle; - case StReady: - case StRunning: + case State::StReady: + case State::StRunning: break; } @@ -540,7 +538,7 @@ DSPDeviceMIMOEngine::State DSPDeviceMIMOEngine::gotoIdle(int subsystemIndex) for (; vSourceIt != m_basebandSampleSources.end(); vSourceIt++) { - for (BasebandSampleSources::const_iterator it = vSourceIt->begin(); it != vSourceIt->end(); ++it) + for (auto it = vSourceIt->begin(); it != vSourceIt->end(); ++it) { qDebug() << "DSPDeviceMIMOEngine::gotoIdle: stopping BasebandSampleSource(" << (*it)->getSourceName().toStdString().c_str() << ")"; (*it)->stop(); @@ -555,12 +553,12 @@ DSPDeviceMIMOEngine::State DSPDeviceMIMOEngine::gotoIdle(int subsystemIndex) } else { - return StIdle; + return State::StIdle; } m_deviceDescription.clear(); - return StIdle; + return State::StIdle; } DSPDeviceMIMOEngine::State DSPDeviceMIMOEngine::gotoInit(int subsystemIndex) @@ -578,17 +576,17 @@ DSPDeviceMIMOEngine::State DSPDeviceMIMOEngine::gotoInit(int subsystemIndex) if (subsystemIndex == 0) // Rx { switch(m_stateRx) { - case StNotStarted: - return StNotStarted; + case State::StNotStarted: + return State::StNotStarted; - case StRunning: // FIXME: assumes it goes first through idle state. Could we get back to init from running directly? - return StRunning; + case State::StRunning: + return State::StRunning; - case StReady: - return StReady; + case State::StReady: + return State::StReady; - case StIdle: - case StError: + case State::StIdle: + case State::StError: break; } @@ -624,17 +622,17 @@ DSPDeviceMIMOEngine::State DSPDeviceMIMOEngine::gotoInit(int subsystemIndex) else if (subsystemIndex == 1) // Tx { switch(m_stateTx) { - case StNotStarted: - return StNotStarted; + case State::StNotStarted: + return State::StNotStarted; - case StRunning: // FIXME: assumes it goes first through idle state. Could we get back to init from running directly? - return StRunning; + case State::StRunning: + return State::StRunning; - case StReady: - return StReady; + case State::StReady: + return State::StReady; - case StIdle: - case StError: + case State::StIdle: + case State::StError: break; } @@ -659,7 +657,7 @@ DSPDeviceMIMOEngine::State DSPDeviceMIMOEngine::gotoInit(int subsystemIndex) } } - return StReady; + return State::StReady; } DSPDeviceMIMOEngine::State DSPDeviceMIMOEngine::gotoRunning(int subsystemIndex) @@ -676,17 +674,17 @@ DSPDeviceMIMOEngine::State DSPDeviceMIMOEngine::gotoRunning(int subsystemIndex) { switch (m_stateRx) { - case StNotStarted: - return StNotStarted; + case State::StNotStarted: + return State::StNotStarted; - case StIdle: - return StIdle; + case State::StIdle: + return State::StIdle; - case StRunning: - return StRunning; + case State::StRunning: + return State::StRunning; - case StReady: - case StError: + case State::StReady: + case State::StError: break; } @@ -698,7 +696,7 @@ DSPDeviceMIMOEngine::State DSPDeviceMIMOEngine::gotoRunning(int subsystemIndex) for (; vbit != m_basebandSampleSinks.end(); ++vbit) { - for (BasebandSampleSinks::const_iterator it = vbit->begin(); it != vbit->end(); ++it) + for (auto it = vbit->begin(); it != vbit->end(); ++it) { qDebug() << "DSPDeviceMIMOEngine::gotoRunning: starting BasebandSampleSink: " << (*it)->getSinkName().toStdString().c_str(); (*it)->start(); @@ -715,17 +713,17 @@ DSPDeviceMIMOEngine::State DSPDeviceMIMOEngine::gotoRunning(int subsystemIndex) { switch (m_stateTx) { - case StNotStarted: - return StNotStarted; + case State::StNotStarted: + return State::StNotStarted; - case StIdle: - return StIdle; + case State::StIdle: + return State::StIdle; - case StRunning: - return StRunning; + case State::StRunning: + return State::StRunning; - case StReady: - case StError: + case State::StReady: + case State::StError: break; } @@ -737,7 +735,7 @@ DSPDeviceMIMOEngine::State DSPDeviceMIMOEngine::gotoRunning(int subsystemIndex) for (; vSourceIt != m_basebandSampleSources.end(); vSourceIt++) { - for (BasebandSampleSources::const_iterator it = vSourceIt->begin(); it != vSourceIt->end(); ++it) + for (auto it = vSourceIt->begin(); it != vSourceIt->end(); ++it) { qDebug() << "DSPDeviceMIMOEngine::gotoRunning: starting BasebandSampleSource(" << (*it)->getSourceName().toStdString().c_str() << ")"; (*it)->start(); @@ -753,7 +751,7 @@ DSPDeviceMIMOEngine::State DSPDeviceMIMOEngine::gotoRunning(int subsystemIndex) qDebug() << "DSPDeviceMIMOEngine::gotoRunning:input message queue pending: " << m_inputMessageQueue.size(); - return StRunning; + return State::StRunning; } DSPDeviceMIMOEngine::State DSPDeviceMIMOEngine::gotoError(int subsystemIndex, const QString& errorMessage) @@ -765,42 +763,42 @@ DSPDeviceMIMOEngine::State DSPDeviceMIMOEngine::gotoError(int subsystemIndex, co if (subsystemIndex == 0) { - m_errorMessageRx = errorMessage; - setStateRx(StError); + m_errorMessageRx = errorMessage; + setStateRx(State::StError); } else if (subsystemIndex == 1) { - m_errorMessageTx = errorMessage; - setStateTx(StError); + m_errorMessageTx = errorMessage; + setStateTx(State::StError); } - return StError; + return State::StError; } void DSPDeviceMIMOEngine::handleDataRxSync() { - if (m_stateRx == StRunning) { + if (m_stateRx == State::StRunning) { workSampleSinkFifos(); } } void DSPDeviceMIMOEngine::handleDataRxAsync(int streamIndex) { - if (m_stateRx == StRunning) { + if (m_stateRx == State::StRunning) { workSampleSinkFifo(streamIndex); } } void DSPDeviceMIMOEngine::handleDataTxSync() { - if (m_stateTx == StRunning) { + if (m_stateTx == State::StRunning) { workSampleSourceFifos(); } } void DSPDeviceMIMOEngine::handleDataTxAsync(int streamIndex) { - if (m_stateTx == StRunning) { + if (m_stateTx == State::StRunning) { workSampleSourceFifo(streamIndex); } } @@ -815,21 +813,20 @@ void DSPDeviceMIMOEngine::handleSetMIMO(DeviceSampleMIMO* mimo) for (unsigned int i = 0; i < m_deviceSampleMIMO->getNbSinkFifos(); i++) { - m_basebandSampleSinks.push_back(BasebandSampleSinks()); - m_sourcesCorrections.push_back(SourceCorrection()); + m_basebandSampleSinks.emplace_back(); + m_sourcesCorrections.emplace_back(); } for (unsigned int i = 0; i < m_deviceSampleMIMO->getNbSourceFifos(); i++) { - m_basebandSampleSources.push_back(BasebandSampleSources()); - m_sourceSampleBuffers.push_back(IncrementalVector()); - m_sourceZeroBuffers.push_back(IncrementalVector()); + m_basebandSampleSources.emplace_back(); + m_sourceSampleBuffers.emplace_back(); + m_sourceZeroBuffers.emplace_back(); } if (m_deviceSampleMIMO->getMIMOType() == DeviceSampleMIMO::MIMOHalfSynchronous) // synchronous FIFOs on Rx and not with Tx { qDebug("DSPDeviceMIMOEngine::handleSetMIMO: synchronous sources set %s", qPrintable(mimo->getDeviceDescription())); - // connect(m_deviceSampleMIMO->getSampleSinkFifo(m_sampleSinkConnectionIndexes[0]), SIGNAL(dataReady()), this, SLOT(handleData()), Qt::QueuedConnection); QObject::connect( m_deviceSampleMIMO->getSampleMIFifo(), &SampleMIFifo::dataSyncReady, @@ -865,13 +862,6 @@ void DSPDeviceMIMOEngine::handleSetMIMO(DeviceSampleMIMO* mimo) &DSPDeviceMIMOEngine::handleDataTxAsync, Qt::QueuedConnection ); - // QObject::connect( - // m_deviceSampleMIMO->getSampleSinkFifo(stream), - // &SampleSinkFifo::dataReady, - // this, - // [=](){ this->handleDataRxAsync(stream); }, - // Qt::QueuedConnection - // ); } } } @@ -950,7 +940,7 @@ bool DSPDeviceMIMOEngine::handleMessage(const Message& message) { if (sourceElseSink) { - if ((istream < m_deviceSampleMIMO->getNbSourceStreams())) + if (istream < m_deviceSampleMIMO->getNbSourceStreams()) { // forward source changes to ancillary sinks @@ -983,7 +973,7 @@ bool DSPDeviceMIMOEngine::handleMessage(const Message& message) } else { - if ((istream < m_deviceSampleMIMO->getNbSinkStreams())) + if (istream < m_deviceSampleMIMO->getNbSinkStreams()) { // forward source changes to channel sources with immediate execution (no queuing) @@ -1023,7 +1013,7 @@ bool DSPDeviceMIMOEngine::handleMessage(const Message& message) { setStateRx(gotoIdle(0)); - if (m_stateRx == StIdle) { + if (m_stateRx == State::StIdle) { setStateRx(gotoInit(0)); // State goes ready if init is performed } @@ -1031,7 +1021,7 @@ bool DSPDeviceMIMOEngine::handleMessage(const Message& message) } else if (DSPAcquisitionStart::match(message)) { - if (m_stateRx == StReady) { + if (m_stateRx == State::StReady) { setStateRx(gotoRunning(0)); } @@ -1046,7 +1036,7 @@ bool DSPDeviceMIMOEngine::handleMessage(const Message& message) { setStateTx(gotoIdle(1)); - if (m_stateTx == StIdle) { + if (m_stateTx == State::StIdle) { setStateTx(gotoInit(1)); // State goes ready if init is performed } @@ -1054,7 +1044,7 @@ bool DSPDeviceMIMOEngine::handleMessage(const Message& message) } else if (DSPGenerationStart::match(message)) { - if (m_stateTx == StReady) { + if (m_stateTx == State::StReady) { setStateTx(gotoRunning(1)); } @@ -1085,7 +1075,7 @@ bool DSPDeviceMIMOEngine::handleMessage(const Message& message) auto *msgToSink = new DSPSignalNotification(sourceStreamSampleRate, sourceCenterFrequency); sink->pushMessage(msgToSink); // start the sink: - if (m_stateRx == StRunning) { + if (m_stateRx == State::StRunning) { sink->start(); } } @@ -1100,7 +1090,7 @@ bool DSPDeviceMIMOEngine::handleMessage(const Message& message) if (isource < m_basebandSampleSinks.size()) { - if (m_stateRx == StRunning) { + if (m_stateRx == State::StRunning) { sink->stop(); } @@ -1124,7 +1114,7 @@ bool DSPDeviceMIMOEngine::handleMessage(const Message& message) auto *msgToSource = new DSPSignalNotification(sinkStreamSampleRate, sinkCenterFrequency); sampleSource->pushMessage(msgToSource); // start the sink: - if (m_stateTx == StRunning) { + if (m_stateTx == State::StRunning) { sampleSource->start(); } } @@ -1173,11 +1163,11 @@ bool DSPDeviceMIMOEngine::handleMessage(const Message& message) channel->pushMessage(notif); } - if (m_stateRx == StRunning) { + if (m_stateRx == State::StRunning) { channel->startSinks(); } - if (m_stateTx == StRunning) { + if (m_stateTx == State::StRunning) { channel->startSources(); } @@ -1214,15 +1204,14 @@ bool DSPDeviceMIMOEngine::handleMessage(const Message& message) if ((spectrumInputSourceElseSink != m_spectrumInputSourceElseSink) || (spectrumInputIndex != m_spectrumInputIndex)) { - if ((!spectrumInputSourceElseSink) && (spectrumInputIndex < m_deviceSampleMIMO->getNbSinkStreams())) // add the source listener + if ((!spectrumInputSourceElseSink) + && (spectrumInputIndex < m_deviceSampleMIMO->getNbSinkStreams()) + && m_spectrumSink) // add the source listener { - if (m_spectrumSink) - { - auto *notif = new DSPSignalNotification( - m_deviceSampleMIMO->getSinkSampleRate(spectrumInputIndex), - m_deviceSampleMIMO->getSinkCenterFrequency(spectrumInputIndex)); - m_spectrumSink->pushMessage(notif); - } + auto *notif = new DSPSignalNotification( + m_deviceSampleMIMO->getSinkSampleRate(spectrumInputIndex), + m_deviceSampleMIMO->getSinkCenterFrequency(spectrumInputIndex)); + m_spectrumSink->pushMessage(notif); } if (m_spectrumSink && spectrumInputSourceElseSink && (spectrumInputIndex < m_deviceSampleMIMO->getNbSinkFifos())) @@ -1248,7 +1237,7 @@ void DSPDeviceMIMOEngine::handleInputMessages() { Message* message; - while ((message = m_inputMessageQueue.pop()) != 0) + while ((message = m_inputMessageQueue.pop()) != nullptr) { qDebug("DSPDeviceMIMOEngine::handleInputMessages: message: %s", message->getIdentifier()); @@ -1261,7 +1250,7 @@ void DSPDeviceMIMOEngine::handleInputMessages() void DSPDeviceMIMOEngine::configureCorrections(bool dcOffsetCorrection, bool iqImbalanceCorrection, int isource) { qDebug() << "DSPDeviceMIMOEngine::configureCorrections"; - ConfigureCorrection* cmd = new ConfigureCorrection(dcOffsetCorrection, iqImbalanceCorrection, isource); + auto* cmd = new ConfigureCorrection(dcOffsetCorrection, iqImbalanceCorrection, isource); m_inputMessageQueue.push(cmd); } @@ -1313,8 +1302,8 @@ void DSPDeviceMIMOEngine::iqCorrections(SampleVector::iterator begin, SampleVect #else // DC correction and conversion - float xi = (it->m_real - (int32_t) m_sourcesCorrections[isource].m_iBeta) / SDR_RX_SCALEF; - float xq = (it->m_imag - (int32_t) m_sourcesCorrections[isource].m_qBeta) / SDR_RX_SCALEF; + float xi = (float) (it->m_real - (int32_t) m_sourcesCorrections[isource].m_iBeta) / SDR_RX_SCALEF; + float xq = (float) (it->m_imag - (int32_t) m_sourcesCorrections[isource].m_qBeta) / SDR_RX_SCALEF; // phase imbalance m_sourcesCorrections[isource].m_avgII(xi*xi); // @@ -1325,8 +1314,8 @@ void DSPDeviceMIMOEngine::iqCorrections(SampleVector::iterator begin, SampleVect m_sourcesCorrections[isource].m_avgPhi(m_sourcesCorrections[isource].m_avgIQ.asDouble()/m_sourcesCorrections[isource].m_avgII.asDouble()); } - float& yi = xi; // the in phase remains the reference - float yq = xq - m_sourcesCorrections[isource].m_avgPhi.asDouble()*xi; + const float& yi = xi; // the in phase remains the reference + float yq = xq - (float) m_sourcesCorrections[isource].m_avgPhi.asDouble()*xi; // amplitude I/Q imbalance m_sourcesCorrections[isource].m_avgII2(yi*yi); // @@ -1337,12 +1326,12 @@ void DSPDeviceMIMOEngine::iqCorrections(SampleVector::iterator begin, SampleVect } // final correction - float& zi = yi; // the in phase remains the reference - float zq = m_sourcesCorrections[isource].m_avgAmp.asDouble() * yq; + const float& zi = yi; // the in phase remains the reference + auto zq = (float) (m_sourcesCorrections[isource].m_avgAmp.asDouble() * yq); // convert and store - it->m_real = zi * SDR_RX_SCALEF; - it->m_imag = zq * SDR_RX_SCALEF; + it->m_real = (FixReal) (zi * SDR_RX_SCALEF); + it->m_imag = (FixReal) (zq * SDR_RX_SCALEF); #endif } else diff --git a/sdrbase/dsp/dspdevicemimoengine.h b/sdrbase/dsp/dspdevicemimoengine.h index 57968680c..191b95c25 100644 --- a/sdrbase/dsp/dspdevicemimoengine.h +++ b/sdrbase/dsp/dspdevicemimoengine.h @@ -40,7 +40,7 @@ public: class SetSampleMIMO : public Message { MESSAGE_CLASS_DECLARATION public: - SetSampleMIMO(DeviceSampleMIMO* sampleMIMO) : Message(), m_sampleMIMO(sampleMIMO) { } + explicit SetSampleMIMO(DeviceSampleMIMO* sampleMIMO) : Message(), m_sampleMIMO(sampleMIMO) { } DeviceSampleMIMO* getSampleMIMO() const { return m_sampleMIMO; } private: DeviceSampleMIMO* m_sampleMIMO; @@ -80,7 +80,7 @@ public: class AddMIMOChannel : public Message { MESSAGE_CLASS_DECLARATION public: - AddMIMOChannel(MIMOChannel* channel) : + explicit AddMIMOChannel(MIMOChannel* channel) : Message(), m_channel(channel) { } @@ -92,7 +92,7 @@ public: class RemoveMIMOChannel : public Message { MESSAGE_CLASS_DECLARATION public: - RemoveMIMOChannel(MIMOChannel* channel) : + explicit RemoveMIMOChannel(MIMOChannel* channel) : Message(), m_channel(channel) { } @@ -134,7 +134,7 @@ public: class AddSpectrumSink : public Message { MESSAGE_CLASS_DECLARATION public: - AddSpectrumSink(BasebandSampleSink* sampleSink) : Message(), m_sampleSink(sampleSink) { } + explicit AddSpectrumSink(BasebandSampleSink* sampleSink) : Message(), m_sampleSink(sampleSink) { } BasebandSampleSink* getSampleSink() const { return m_sampleSink; } private: BasebandSampleSink* m_sampleSink; @@ -143,7 +143,7 @@ public: class RemoveSpectrumSink : public Message { MESSAGE_CLASS_DECLARATION public: - RemoveSpectrumSink(BasebandSampleSink* sampleSink) : Message(), m_sampleSink(sampleSink) { } + explicit RemoveSpectrumSink(BasebandSampleSink* sampleSink) : Message(), m_sampleSink(sampleSink) { } BasebandSampleSink* getSampleSink() const { return m_sampleSink; } private: BasebandSampleSink* m_sampleSink; @@ -152,7 +152,7 @@ public: class GetErrorMessage : public Message { MESSAGE_CLASS_DECLARATION public: - GetErrorMessage(unsigned int subsystemIndex) : + explicit GetErrorMessage(unsigned int subsystemIndex) : m_subsystemIndex(subsystemIndex) {} void setErrorMessage(const QString& text) { m_errorMessage = text; } @@ -204,7 +204,7 @@ public: int m_index; }; - enum State { + enum class State { StNotStarted, //!< engine is before initialization StIdle, //!< engine is idle StReady, //!< engine is ready to run @@ -244,7 +244,7 @@ public: } else if (subsystemIndex == 1) { return m_stateTx; } else { - return StNotStarted; + return State::StNotStarted; } } @@ -256,13 +256,13 @@ public: private: struct SourceCorrection { - bool m_dcOffsetCorrection; - bool m_iqImbalanceCorrection; - double m_iOffset; - double m_qOffset; - int m_iRange; - int m_qRange; - int m_imbalance; + bool m_dcOffsetCorrection = false; + bool m_iqImbalanceCorrection = false; + double m_iOffset = 0; + double m_qOffset = 0; + int m_iRange = 1 << 16; + int m_qRange = 1 << 16; + int m_imbalance = 65536; MovingAverageUtil m_iBeta; MovingAverageUtil m_qBeta; #if IMBALANCE_INT @@ -284,13 +284,6 @@ private: #endif SourceCorrection() { - m_dcOffsetCorrection = false; - m_iqImbalanceCorrection = false; - m_iOffset = 0; - m_qOffset = 0; - m_iRange = 1 << 16; - m_qRange = 1 << 16; - m_imbalance = 65536; m_iBeta.reset(); m_qBeta.reset(); m_avgAmp.reset(); @@ -317,17 +310,17 @@ private: MessageQueue m_inputMessageQueue; // BasebandSampleSinks; + using BasebandSampleSinks = std::list; std::vector m_basebandSampleSinks; //!< ancillary sample sinks on main thread (per input stream) std::map m_rxRealElseComplex; //!< map of real else complex indicators for device sources (by input stream) - typedef std::list BasebandSampleSources; + using BasebandSampleSources = std::list; std::vector m_basebandSampleSources; //!< channel sample sources (per output stream) std::map m_txRealElseComplex; //!< map of real else complex indicators for device sinks (by input stream) std::vector> m_sourceSampleBuffers; std::vector> m_sourceZeroBuffers; unsigned int m_sumIndex; //!< channel index when summing channels - typedef std::list MIMOChannels; + using MIMOChannels = std::list; MIMOChannels m_mimoChannels; //!< MIMO channels std::vector m_sourcesCorrections; diff --git a/sdrbase/dsp/dspdevicesinkengine.cpp b/sdrbase/dsp/dspdevicesinkengine.cpp index 70090a1e3..0f3d8fd07 100644 --- a/sdrbase/dsp/dspdevicesinkengine.cpp +++ b/sdrbase/dsp/dspdevicesinkengine.cpp @@ -30,7 +30,7 @@ DSPDeviceSinkEngine::DSPDeviceSinkEngine(uint32_t uid, QObject* parent) : QObject(parent), m_uid(uid), - m_state(StNotStarted), + m_state(State::StNotStarted), m_deviceSampleSink(nullptr), m_sampleSinkSequence(0), m_basebandSampleSources(), @@ -39,7 +39,7 @@ DSPDeviceSinkEngine::DSPDeviceSinkEngine(uint32_t uid, QObject* parent) : m_centerFrequency(0), m_realElseComplex(false) { - setState(StIdle); + setState(State::StIdle); connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()), Qt::QueuedConnection); } @@ -121,13 +121,13 @@ void DSPDeviceSinkEngine::removeSpectrumSink(BasebandSampleSink* spectrumSink) getInputMessageQueue()->push(cmd); } -QString DSPDeviceSinkEngine::errorMessage() +QString DSPDeviceSinkEngine::errorMessage() const { qDebug() << "DSPDeviceSinkEngine::errorMessage"; return m_errorMessage; } -QString DSPDeviceSinkEngine::sinkDeviceDescription() +QString DSPDeviceSinkEngine::sinkDeviceDescription() const { qDebug() << "DSPDeviceSinkEngine::sinkDeviceDescription"; return m_deviceDescription; @@ -202,7 +202,7 @@ void DSPDeviceSinkEngine::workSamples(SampleVector& data, unsigned int iBegin, u sBegin + nbSamples, data.begin() + iBegin, data.begin() + iBegin, - [this](Sample& a, const Sample& b) -> Sample { + [this](const Sample& a, const Sample& b) -> Sample { FixReal den = m_sumIndex + 1; // at each stage scale sum by n/n+1 and input by 1/n+1 FixReal nom = m_sumIndex; // so that final sum is scaled by N (number of channels) FixReal x = a.real()/den + nom*(b.real()/den); @@ -228,20 +228,20 @@ DSPDeviceSinkEngine::State DSPDeviceSinkEngine::gotoIdle() qDebug() << "DSPDeviceSinkEngine::gotoIdle"; switch(m_state) { - case StNotStarted: - return StNotStarted; + case State::StNotStarted: + return State::StNotStarted; - case StIdle: - case StError: - return StIdle; + case State::StIdle: + case State::StError: + return State::StIdle; - case StReady: - case StRunning: + case State::StReady: + case State::StRunning: break; } if (!m_deviceSampleSink) { - return StIdle; + return State::StIdle; } // stop everything @@ -256,23 +256,23 @@ DSPDeviceSinkEngine::State DSPDeviceSinkEngine::gotoIdle() m_deviceDescription.clear(); m_sampleRate = 0; - return StIdle; + return State::StIdle; } DSPDeviceSinkEngine::State DSPDeviceSinkEngine::gotoInit() { switch(m_state) { - case StNotStarted: - return StNotStarted; + case State::StNotStarted: + return State::StNotStarted; - case StRunning: // FIXME: assumes it goes first through idle state. Could we get back to init from running directly? - return StRunning; + case State::StRunning: + return State::StRunning; - case StReady: - return StReady; + case State::StReady: + return State::StReady; - case StIdle: - case StError: + case State::StIdle: + case State::StError: break; } @@ -310,7 +310,7 @@ DSPDeviceSinkEngine::State DSPDeviceSinkEngine::gotoInit() m_deviceSampleSink->getMessageQueueToGUI()->push(rep); } - return StReady; + return State::StReady; } DSPDeviceSinkEngine::State DSPDeviceSinkEngine::gotoRunning() @@ -319,17 +319,17 @@ DSPDeviceSinkEngine::State DSPDeviceSinkEngine::gotoRunning() switch(m_state) { - case StNotStarted: - return StNotStarted; + case State::StNotStarted: + return State::StNotStarted; - case StIdle: - return StIdle; + case State::StIdle: + return State::StIdle; - case StRunning: - return StRunning; + case State::StRunning: + return State::StRunning; - case StReady: - case StError: + case State::StReady: + case State::StError: break; } @@ -358,7 +358,7 @@ DSPDeviceSinkEngine::State DSPDeviceSinkEngine::gotoRunning() qDebug() << "DSPDeviceSinkEngine::gotoRunning: input message queue pending: " << m_inputMessageQueue.size(); - return StRunning; + return State::StRunning; } DSPDeviceSinkEngine::State DSPDeviceSinkEngine::gotoError(const QString& errorMessage) @@ -367,11 +367,11 @@ DSPDeviceSinkEngine::State DSPDeviceSinkEngine::gotoError(const QString& errorMe m_errorMessage = errorMessage; m_deviceDescription.clear(); - setState(StError); - return StError; + setState(State::StError); + return State::StError; } -void DSPDeviceSinkEngine::handleSetSink(DeviceSampleSink*) +void DSPDeviceSinkEngine::handleSetSink(const DeviceSampleSink*) { if (!m_deviceSampleSink) { // Early leave return; @@ -390,7 +390,7 @@ void DSPDeviceSinkEngine::handleSetSink(DeviceSampleSink*) void DSPDeviceSinkEngine::handleData() { - if (m_state == StRunning) { + if (m_state == State::StRunning) { workSampleFifo(); } } @@ -441,7 +441,7 @@ bool DSPDeviceSinkEngine::handleMessage(const Message& message) { setState(gotoIdle()); - if(m_state == StIdle) { + if(m_state == State::StIdle) { setState(gotoInit()); // State goes ready if init is performed } @@ -449,7 +449,7 @@ bool DSPDeviceSinkEngine::handleMessage(const Message& message) } else if (DSPGenerationStart::match(message)) { - if(m_state == StReady) { + if(m_state == State::StReady) { setState(gotoRunning()); } @@ -462,7 +462,7 @@ bool DSPDeviceSinkEngine::handleMessage(const Message& message) } else if (DSPSetSink::match(message)) { - const DSPSetSink& cmd = (const DSPSetSink&) message; + const auto& cmd = (const DSPSetSink&) message; handleSetSink(cmd.getSampleSink()); return true; } @@ -471,7 +471,7 @@ bool DSPDeviceSinkEngine::handleMessage(const Message& message) auto& cmd = (const DSPRemoveSpectrumSink&) message; BasebandSampleSink* spectrumSink = cmd.getSampleSink(); - if(m_state == StRunning) { + if(m_state == State::StRunning) { spectrumSink->stop(); } @@ -486,7 +486,7 @@ bool DSPDeviceSinkEngine::handleMessage(const Message& message) auto *notif = new DSPSignalNotification(m_sampleRate, m_centerFrequency); source->pushMessage(notif); - if (m_state == StRunning) { + if (m_state == State::StRunning) { source->start(); } @@ -497,7 +497,7 @@ bool DSPDeviceSinkEngine::handleMessage(const Message& message) auto& cmd = (const DSPRemoveBasebandSampleSource&) message; BasebandSampleSource* source = cmd.getSampleSource(); - if(m_state == StRunning) { + if(m_state == State::StRunning) { source->stop(); } diff --git a/sdrbase/dsp/dspdevicesinkengine.h b/sdrbase/dsp/dspdevicesinkengine.h index db190782d..7917e49ae 100644 --- a/sdrbase/dsp/dspdevicesinkengine.h +++ b/sdrbase/dsp/dspdevicesinkengine.h @@ -44,7 +44,7 @@ class SDRBASE_API DSPDeviceSinkEngine : public QObject { Q_OBJECT public: - enum State { + enum class State { StNotStarted, //!< engine is before initialization StIdle, //!< engine is idle StReady, //!< engine is ready to run @@ -53,7 +53,7 @@ public: }; DSPDeviceSinkEngine(uint32_t uid, QObject* parent = nullptr); - ~DSPDeviceSinkEngine(); + ~DSPDeviceSinkEngine() final; uint32_t getUID() const { return m_uid; } @@ -75,8 +75,8 @@ public: State state() const { return m_state; } //!< Return DSP engine current state - QString errorMessage(); //!< Return the current error message - QString sinkDeviceDescription(); //!< Return the sink device description + QString errorMessage() const; //!< Return the current error message + QString sinkDeviceDescription() const; //!< Return the sink device description private: uint32_t m_uid; //!< unique ID @@ -91,7 +91,7 @@ private: DeviceSampleSink* m_deviceSampleSink; int m_sampleSinkSequence; - typedef std::list BasebandSampleSources; + using BasebandSampleSources = std::list; BasebandSampleSources m_basebandSampleSources; //!< baseband sample sources within main thread (usually file input) BasebandSampleSink *m_spectrumSink; @@ -112,7 +112,7 @@ private: State gotoError(const QString& errorMsg); //!< Go to an error state void setState(State state); - void handleSetSink(DeviceSampleSink* sink); //!< Manage sink setting + void handleSetSink(const DeviceSampleSink* sink); //!< Manage sink setting bool handleMessage(const Message& cmd); private slots: diff --git a/sdrbase/dsp/dspdevicesourceengine.cpp b/sdrbase/dsp/dspdevicesourceengine.cpp index afaf18ee7..d6899f13d 100644 --- a/sdrbase/dsp/dspdevicesourceengine.cpp +++ b/sdrbase/dsp/dspdevicesourceengine.cpp @@ -31,7 +31,7 @@ DSPDeviceSourceEngine::DSPDeviceSourceEngine(uint uid, QObject* parent) : QObject(parent), m_uid(uid), - m_state(StNotStarted), + m_state(State::StNotStarted), m_deviceSampleSource(nullptr), m_sampleSourceSequence(0), m_basebandSampleSinks(), @@ -46,7 +46,7 @@ DSPDeviceSourceEngine::DSPDeviceSourceEngine(uint uid, QObject* parent) : m_qRange(1 << 16), m_imbalance(65536) { - setState(StIdle); + setState(State::StIdle); connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()), Qt::QueuedConnection); } @@ -64,7 +64,7 @@ void DSPDeviceSourceEngine::setState(State state) } } -bool DSPDeviceSourceEngine::initAcquisition() +bool DSPDeviceSourceEngine::initAcquisition() const { qDebug("DSPDeviceSourceEngine::initAcquisition (dummy)"); return true; @@ -195,8 +195,8 @@ void DSPDeviceSourceEngine::iqCorrections(SampleVector::iterator begin, SampleVe m_avgPhi(m_avgIQ.asDouble()/m_avgII.asDouble()); } - float& yi = xi; // the in phase remains the reference - float yq = xq - m_avgPhi.asDouble()*xi; + const float& yi = xi; // the in phase remains the reference + float yq = xq - (float) m_avgPhi.asDouble()*xi; // amplitude I/Q imbalance m_avgII2(yi*yi); // @@ -207,12 +207,12 @@ void DSPDeviceSourceEngine::iqCorrections(SampleVector::iterator begin, SampleVe } // final correction - float& zi = yi; // the in phase remains the reference - float zq = m_avgAmp.asDouble() * yq; + const float& zi = yi; // the in phase remains the reference + auto zq = (float) (m_avgAmp.asDouble() * yq); // convert and store - it->m_real = zi * SDR_RX_SCALEF; - it->m_imag = zq * SDR_RX_SCALEF; + it->m_real = (FixReal) (zi * SDR_RX_SCALEF); + it->m_imag = (FixReal) (zq * SDR_RX_SCALEF); #endif } else @@ -345,20 +345,20 @@ DSPDeviceSourceEngine::State DSPDeviceSourceEngine::gotoIdle() qDebug("DSPDeviceSourceEngine::gotoIdle"); switch(m_state) { - case StNotStarted: - return StNotStarted; + case State::StNotStarted: + return State::StNotStarted; - case StIdle: - case StError: - return StIdle; + case State::StIdle: + case State::StError: + return State::StIdle; - case StReady: - case StRunning: + case State::StReady: + case State::StRunning: break; } if (!m_deviceSampleSource) { - return StIdle; + return State::StIdle; } // stop everything @@ -372,23 +372,23 @@ DSPDeviceSourceEngine::State DSPDeviceSourceEngine::gotoIdle() m_deviceDescription.clear(); m_sampleRate = 0; - return StIdle; + return State::StIdle; } DSPDeviceSourceEngine::State DSPDeviceSourceEngine::gotoInit() { switch(m_state) { - case StNotStarted: - return StNotStarted; + case State::StNotStarted: + return State::StNotStarted; - case StRunning: // FIXME: assumes it goes first through idle state. Could we get back to init from running directly? - return StRunning; + case State::StRunning: + return State::StRunning; - case StReady: - return StReady; + case State::StReady: + return State::StReady; - case StIdle: - case StError: + case State::StIdle: + case State::StError: break; } @@ -427,7 +427,7 @@ DSPDeviceSourceEngine::State DSPDeviceSourceEngine::gotoInit() m_deviceSampleSource->getMessageQueueToGUI()->push(rep); } - return StReady; + return State::StReady; } DSPDeviceSourceEngine::State DSPDeviceSourceEngine::gotoRunning() @@ -436,17 +436,17 @@ DSPDeviceSourceEngine::State DSPDeviceSourceEngine::gotoRunning() switch(m_state) { - case StNotStarted: - return StNotStarted; + case State::StNotStarted: + return State::StNotStarted; - case StIdle: - return StIdle; + case State::StIdle: + return State::StIdle; - case StRunning: - return StRunning; + case State::StRunning: + return State::StRunning; - case StReady: - case StError: + case State::StReady: + case State::StError: break; } @@ -470,7 +470,7 @@ DSPDeviceSourceEngine::State DSPDeviceSourceEngine::gotoRunning() qDebug() << "DSPDeviceSourceEngine::gotoRunning:input message queue pending: " << m_inputMessageQueue.size(); - return StRunning; + return State::StRunning; } DSPDeviceSourceEngine::State DSPDeviceSourceEngine::gotoError(const QString& errorMessage) @@ -479,8 +479,8 @@ DSPDeviceSourceEngine::State DSPDeviceSourceEngine::gotoError(const QString& err m_errorMessage = errorMessage; m_deviceDescription.clear(); - setState(StError); - return StError; + setState(State::StError); + return State::StError; } void DSPDeviceSourceEngine::handleSetSource(DeviceSampleSource* source) @@ -502,7 +502,7 @@ void DSPDeviceSourceEngine::handleSetSource(DeviceSampleSource* source) void DSPDeviceSourceEngine::handleData() { - if(m_state == StRunning) + if(m_state == State::StRunning) { work(); } @@ -588,11 +588,11 @@ bool DSPDeviceSourceEngine::handleMessage(const Message& message) { setState(gotoIdle()); - if(m_state == StIdle) { + if(m_state == State::StIdle) { setState(gotoInit()); // State goes ready if init is performed } - if(m_state == StReady) { + if(m_state == State::StReady) { setState(gotoRunning()); } @@ -617,7 +617,7 @@ bool DSPDeviceSourceEngine::handleMessage(const Message& message) auto *msg = new DSPSignalNotification(m_sampleRate, m_centerFrequency); sink->pushMessage(msg); // start the sink: - if(m_state == StRunning) { + if(m_state == State::StRunning) { sink->start(); } } @@ -626,7 +626,7 @@ bool DSPDeviceSourceEngine::handleMessage(const Message& message) auto cmd = (const DSPRemoveBasebandSampleSink&) message; BasebandSampleSink* sink = cmd.getSampleSink(); - if(m_state == StRunning) { + if(m_state == State::StRunning) { sink->stop(); } diff --git a/sdrbase/dsp/dspdevicesourceengine.h b/sdrbase/dsp/dspdevicesourceengine.h index ba5b839ac..cd440d7c0 100644 --- a/sdrbase/dsp/dspdevicesourceengine.h +++ b/sdrbase/dsp/dspdevicesourceengine.h @@ -38,7 +38,7 @@ class SDRBASE_API DSPDeviceSourceEngine : public QObject { Q_OBJECT public: - enum State { + enum class State { StNotStarted, //!< engine is before initialization StIdle, //!< engine is idle StReady, //!< engine is ready to run @@ -47,13 +47,13 @@ public: }; DSPDeviceSourceEngine(uint uid, QObject* parent = nullptr); - ~DSPDeviceSourceEngine(); + ~DSPDeviceSourceEngine() final; uint getUID() const { return m_uid; } MessageQueue* getInputMessageQueue() { return &m_inputMessageQueue; } - bool initAcquisition(); //!< Initialize acquisition sequence + bool initAcquisition() const; //!< Initialize acquisition sequence bool startAcquisition(); //!< Start acquisition sequence void stopAcquistion(); //!< Stop acquisition sequence diff --git a/sdrbase/plugin/plugininterface.h b/sdrbase/plugin/plugininterface.h index 72ce5a6ff..50b83c7af 100644 --- a/sdrbase/plugin/plugininterface.h +++ b/sdrbase/plugin/plugininterface.h @@ -84,8 +84,8 @@ public: StreamType streamType; //!< This is the type of stream supported int deviceNbItems; //!< Number of items (or streams) in the device. >1 for composite devices. int deviceItemIndex; //!< For composite devices this is the Rx or Tx stream index. -1 if not initialized - int claimed; //!< This is the device set index if claimed else -1 - bool removed; //!< Set if device has been removed + int claimed = -1; //!< This is the device set index if claimed else -1 + bool removed = false; //!< Set if device has been removed SamplingDevice(const QString& _displayedName, const QString& _hardwareId, @@ -104,9 +104,7 @@ public: type(_type), streamType(_streamType), deviceNbItems(_deviceNbItems), - deviceItemIndex(_deviceItemIndex), - claimed(-1), - removed(false) + deviceItemIndex(_deviceItemIndex) { } bool operator==(const SamplingDevice& rhs) const @@ -117,7 +115,7 @@ public: && serial == rhs.serial; } }; - typedef QList SamplingDevices; + using SamplingDevices = QList; /** This is the device from which the sampling devices are derived. For physical devices this represents * a single physical unit (a LimeSDR, HackRF, BladeRF, RTL-SDR dongle, ...) that is enumerated once and @@ -148,9 +146,9 @@ public: nbTxStreams(_nbTxStreams) {} }; - typedef QList OriginDevices; + using OriginDevices = QList; - virtual ~PluginInterface() { } + virtual ~PluginInterface() = default; virtual const PluginDescriptor& getPluginDescriptor() const = 0; virtual void initPlugin(PluginAPI* pluginAPI) = 0; diff --git a/sdrgui/device/deviceuiset.cpp b/sdrgui/device/deviceuiset.cpp index d56a46cfb..3c83f1dac 100644 --- a/sdrgui/device/deviceuiset.cpp +++ b/sdrgui/device/deviceuiset.cpp @@ -78,10 +78,7 @@ DeviceUISet::DeviceUISet(int deviceSetIndex, DeviceSet *deviceSet) DeviceUISet::~DeviceUISet() { - // delete m_channelWindow; delete m_mainSpectrumGUI; - // delete m_spectrumGUI; // done above - // delete m_spectrum; } void DeviceUISet::setIndex(int deviceSetIndex) @@ -119,7 +116,7 @@ void DeviceUISet::registerRxChannelInstance(ChannelAPI *channelAPI, ChannelGUI* channelGUI, &ChannelGUI::closing, this, - [=](){ this->handleChannelGUIClosing(channelGUI); }, + [this, channelGUI](){ this->handleChannelGUIClosing(channelGUI); }, Qt::QueuedConnection ); } @@ -132,7 +129,7 @@ void DeviceUISet::registerTxChannelInstance(ChannelAPI *channelAPI, ChannelGUI* channelGUI, &ChannelGUI::closing, this, - [=](){ this->handleChannelGUIClosing(channelGUI); }, + [this, channelGUI](){ this->handleChannelGUIClosing(channelGUI); }, Qt::QueuedConnection ); } @@ -145,7 +142,7 @@ void DeviceUISet::registerChannelInstance(ChannelAPI *channelAPI, ChannelGUI* ch channelGUI, &ChannelGUI::closing, this, - [=](){ this->handleChannelGUIClosing(channelGUI); }, + [this, channelGUI](){ this->handleChannelGUIClosing(channelGUI); }, Qt::QueuedConnection ); } @@ -226,14 +223,14 @@ bool DeviceUISet::deserialize(const QByteArray& data) if (d.getVersion() == 1) { - QByteArray data; + QByteArray bdata; - d.readBlob(1, &data); - m_deviceAPI->deserialize(data); - d.readBlob(2, &data); - m_deviceGUI->deserialize(data); - d.readBlob(3, &data); - m_spectrumGUI->deserialize(data); + d.readBlob(1, &bdata); + m_deviceAPI->deserialize(bdata); + d.readBlob(2, &bdata); + m_deviceGUI->deserialize(bdata); + d.readBlob(3, &bdata); + m_spectrumGUI->deserialize(bdata); return true; } @@ -331,9 +328,9 @@ void DeviceUISet::loadRxChannelSettings(const Preset *preset, PluginAPI *pluginA m_deviceSet->clearChannels(); qDebug("DeviceUISet::loadRxChannelSettings: %d channel(s) in preset", preset->getChannelCount()); - for (int i = 0; i < preset->getChannelCount(); i++) + for (int j = 0; j < preset->getChannelCount(); j++) { - const Preset::ChannelConfig& channelConfig = preset->getChannelConfig(i); + const Preset::ChannelConfig& channelConfig = preset->getChannelConfig(j); ChannelGUI *rxChannelGUI = nullptr; ChannelAPI *channelAPI = nullptr; @@ -348,7 +345,7 @@ void DeviceUISet::loadRxChannelSettings(const Preset *preset, PluginAPI *pluginA qPrintable((*channelRegistrations)[i].m_channelIdURI), qPrintable(channelConfig.m_channelIdURI)); BasebandSampleSink *rxChannel = nullptr; - PluginInterface *pluginInterface = (*channelRegistrations)[i].m_plugin; + const PluginInterface *pluginInterface = (*channelRegistrations)[i].m_plugin; pluginInterface->createRxChannel(m_deviceAPI, &rxChannel, &channelAPI); rxChannelGUI = pluginInterface->createRxChannelGUI(this, rxChannel); rxChannelGUI->setDisplayedame(pluginInterface->getPluginDescriptor().displayedName); @@ -357,7 +354,7 @@ void DeviceUISet::loadRxChannelSettings(const Preset *preset, PluginAPI *pluginA rxChannelGUI, &ChannelGUI::closing, this, - [=](){ this->handleChannelGUIClosing(rxChannelGUI); }, + [this, rxChannelGUI](){ this->handleChannelGUIClosing(rxChannelGUI); }, Qt::QueuedConnection ); break; @@ -370,7 +367,7 @@ void DeviceUISet::loadRxChannelSettings(const Preset *preset, PluginAPI *pluginA rxChannelGUI->deserialize(channelConfig.m_config); int originalWorkspaceIndex = rxChannelGUI->getWorkspaceIndex(); - if (workspaces && (workspaces->size() > 0) && (originalWorkspaceIndex < workspaces->size())) // restore in original workspace + if (workspaces && (!workspaces->empty()) && (originalWorkspaceIndex < workspaces->size())) // restore in original workspace { (*workspaces)[originalWorkspaceIndex]->addToMdiArea((QMdiSubWindow*) rxChannelGUI); } @@ -395,19 +392,19 @@ void DeviceUISet::loadRxChannelSettings(const Preset *preset, PluginAPI *pluginA rxChannelGUI, &ChannelGUI::moveToWorkspace, this, - [=](int wsIndexDest){ MainWindow::getInstance()->channelMove(rxChannelGUI, wsIndexDest); } + [rxChannelGUI](int wsIndexDest){ MainWindow::getInstance()->channelMove(rxChannelGUI, wsIndexDest); } ); QObject::connect( rxChannelGUI, &ChannelGUI::duplicateChannelEmitted, this, - [=](){ MainWindow::getInstance()->channelDuplicate(rxChannelGUI); } + [rxChannelGUI](){ MainWindow::getInstance()->channelDuplicate(rxChannelGUI); } ); QObject::connect( rxChannelGUI, &ChannelGUI::moveToDeviceSet, this, - [=](int dsIndexDest){ MainWindow::getInstance()->channelMoveToDeviceSet(rxChannelGUI, dsIndexDest); } + [rxChannelGUI](int dsIndexDest){ MainWindow::getInstance()->channelMoveToDeviceSet(rxChannelGUI, dsIndexDest); } ); } } @@ -460,9 +457,9 @@ void DeviceUISet::loadTxChannelSettings(const Preset *preset, PluginAPI *pluginA m_deviceSet->clearChannels(); qDebug("DeviceUISet::loadTxChannelSettings: %d channel(s) in preset", preset->getChannelCount()); - for (int i = 0; i < preset->getChannelCount(); i++) + for (int j = 0; j < preset->getChannelCount(); j++) { - const Preset::ChannelConfig& channelConfig = preset->getChannelConfig(i); + const Preset::ChannelConfig& channelConfig = preset->getChannelConfig(j); ChannelGUI *txChannelGUI = nullptr; ChannelAPI *channelAPI = nullptr; @@ -475,8 +472,8 @@ void DeviceUISet::loadTxChannelSettings(const Preset *preset, PluginAPI *pluginA qDebug("DeviceUISet::loadTxChannelSettings: creating new channel [%s] from config [%s]", qPrintable((*channelRegistrations)[i].m_channelIdURI), qPrintable(channelConfig.m_channelIdURI)); - BasebandSampleSource *txChannel; - PluginInterface *pluginInterface = (*channelRegistrations)[i].m_plugin; + BasebandSampleSource *txChannel = nullptr; + const PluginInterface *pluginInterface = (*channelRegistrations)[i].m_plugin; pluginInterface->createTxChannel(m_deviceAPI, &txChannel, &channelAPI); txChannelGUI = pluginInterface->createTxChannelGUI(this, txChannel); txChannelGUI->setDisplayedame(pluginInterface->getPluginDescriptor().displayedName); @@ -485,7 +482,7 @@ void DeviceUISet::loadTxChannelSettings(const Preset *preset, PluginAPI *pluginA txChannelGUI, &ChannelGUI::closing, this, - [=](){ this->handleChannelGUIClosing(txChannelGUI); }, + [this, txChannelGUI](){ this->handleChannelGUIClosing(txChannelGUI); }, Qt::QueuedConnection ); break; @@ -498,7 +495,7 @@ void DeviceUISet::loadTxChannelSettings(const Preset *preset, PluginAPI *pluginA txChannelGUI->deserialize(channelConfig.m_config); int originalWorkspaceIndex = txChannelGUI->getWorkspaceIndex(); - if (workspaces && (workspaces->size() > 0) && (originalWorkspaceIndex < workspaces->size())) // restore in original workspace + if (workspaces && (!workspaces->empty()) && (originalWorkspaceIndex < workspaces->size())) // restore in original workspace { (*workspaces)[originalWorkspaceIndex]->addToMdiArea((QMdiSubWindow*) txChannelGUI); } @@ -523,19 +520,19 @@ void DeviceUISet::loadTxChannelSettings(const Preset *preset, PluginAPI *pluginA txChannelGUI, &ChannelGUI::moveToWorkspace, this, - [=](int wsIndexDest){ MainWindow::getInstance()->channelMove(txChannelGUI, wsIndexDest); } + [txChannelGUI](int wsIndexDest){ MainWindow::getInstance()->channelMove(txChannelGUI, wsIndexDest); } ); QObject::connect( txChannelGUI, &ChannelGUI::duplicateChannelEmitted, this, - [=](){ MainWindow::getInstance()->channelDuplicate(txChannelGUI); } + [txChannelGUI](){ MainWindow::getInstance()->channelDuplicate(txChannelGUI); } ); QObject::connect( txChannelGUI, &ChannelGUI::moveToDeviceSet, this, - [=](int dsIndexDest){ MainWindow::getInstance()->channelMoveToDeviceSet(txChannelGUI, dsIndexDest); } + [txChannelGUI](int dsIndexDest){ MainWindow::getInstance()->channelMoveToDeviceSet(txChannelGUI, dsIndexDest); } ); } } @@ -586,9 +583,9 @@ void DeviceUISet::loadMIMOChannelSettings(const Preset *preset, PluginAPI *plugi m_deviceSet->clearChannels(); qDebug("DeviceUISet::loadMIMOChannelSettings: %d channel(s) in preset", preset->getChannelCount()); - for (int i = 0; i < preset->getChannelCount(); i++) + for (int j = 0; j < preset->getChannelCount(); j++) { - const Preset::ChannelConfig& channelConfig = preset->getChannelConfig(i); + const Preset::ChannelConfig& channelConfig = preset->getChannelConfig(j); ChannelGUI *channelGUI = nullptr; ChannelAPI *channelAPI = nullptr; @@ -602,8 +599,8 @@ void DeviceUISet::loadMIMOChannelSettings(const Preset *preset, PluginAPI *plugi qDebug("DeviceUISet::loadMIMOChannelSettings: creating new MIMO channel [%s] from config [%s]", qPrintable((*channelMIMORegistrations)[i].m_channelIdURI), qPrintable(channelConfig.m_channelIdURI)); - MIMOChannel *mimoChannel; - PluginInterface *pluginInterface = (*channelMIMORegistrations)[i].m_plugin; + MIMOChannel *mimoChannel = nullptr; + const PluginInterface *pluginInterface = (*channelMIMORegistrations)[i].m_plugin; pluginInterface->createMIMOChannel(m_deviceAPI, &mimoChannel, &channelAPI); channelGUI = pluginInterface->createMIMOChannelGUI(this, mimoChannel); channelGUI->setDisplayedame(pluginInterface->getPluginDescriptor().displayedName); @@ -612,7 +609,7 @@ void DeviceUISet::loadMIMOChannelSettings(const Preset *preset, PluginAPI *plugi channelGUI, &ChannelGUI::closing, this, - [=](){ this->handleChannelGUIClosing(channelGUI); }, + [this, channelGUI](){ this->handleChannelGUIClosing(channelGUI); }, Qt::QueuedConnection ); break; @@ -629,8 +626,8 @@ void DeviceUISet::loadMIMOChannelSettings(const Preset *preset, PluginAPI *plugi qDebug("DeviceUISet::loadMIMOChannelSettings: creating new Rx channel [%s] from config [%s]", qPrintable((*channelRxRegistrations)[i].m_channelIdURI), qPrintable(channelConfig.m_channelIdURI)); - BasebandSampleSink *rxChannel; - PluginInterface *pluginInterface = (*channelRxRegistrations)[i].m_plugin; + BasebandSampleSink *rxChannel = nullptr; + const PluginInterface *pluginInterface = (*channelRxRegistrations)[i].m_plugin; pluginInterface->createRxChannel(m_deviceAPI, &rxChannel, &channelAPI); channelGUI = pluginInterface->createRxChannelGUI(this, rxChannel); channelGUI->setDisplayedame(pluginInterface->getPluginDescriptor().displayedName); @@ -639,7 +636,7 @@ void DeviceUISet::loadMIMOChannelSettings(const Preset *preset, PluginAPI *plugi channelGUI, &ChannelGUI::closing, this, - [=](){ this->handleChannelGUIClosing(channelGUI); }, + [this, channelGUI](){ this->handleChannelGUIClosing(channelGUI); }, Qt::QueuedConnection ); break; @@ -656,8 +653,8 @@ void DeviceUISet::loadMIMOChannelSettings(const Preset *preset, PluginAPI *plugi qDebug("DeviceUISet::loadMIMOChannelSettings: creating new Tx channel [%s] from config [%s]", qPrintable((*channelTxRegistrations)[i].m_channelIdURI), qPrintable(channelConfig.m_channelIdURI)); - BasebandSampleSource *txChannel; - PluginInterface *pluginInterface = (*channelTxRegistrations)[i].m_plugin; + BasebandSampleSource *txChannel = nullptr; + const PluginInterface *pluginInterface = (*channelTxRegistrations)[i].m_plugin; pluginInterface->createTxChannel(m_deviceAPI, &txChannel, &channelAPI); channelGUI = pluginInterface->createTxChannelGUI(this, txChannel); channelGUI->setDisplayedame(pluginInterface->getPluginDescriptor().displayedName); @@ -672,7 +669,7 @@ void DeviceUISet::loadMIMOChannelSettings(const Preset *preset, PluginAPI *plugi channelGUI->deserialize(channelConfig.m_config); int originalWorkspaceIndex = channelGUI->getWorkspaceIndex(); - if (workspaces && (workspaces->size() > 0) && (originalWorkspaceIndex < workspaces->size())) // restore in original workspace + if (workspaces && (!workspaces->empty()) && (originalWorkspaceIndex < workspaces->size())) // restore in original workspace { (*workspaces)[originalWorkspaceIndex]->addToMdiArea((QMdiSubWindow*) channelGUI); } @@ -697,26 +694,26 @@ void DeviceUISet::loadMIMOChannelSettings(const Preset *preset, PluginAPI *plugi channelGUI, &ChannelGUI::closing, this, - [=](){ this->handleChannelGUIClosing(channelGUI); }, + [this, channelGUI](){ this->handleChannelGUIClosing(channelGUI); }, Qt::QueuedConnection ); QObject::connect( channelGUI, &ChannelGUI::moveToWorkspace, this, - [=](int wsIndexDest){ MainWindow::getInstance()->channelMove(channelGUI, wsIndexDest); } + [channelGUI](int wsIndexDest){ MainWindow::getInstance()->channelMove(channelGUI, wsIndexDest); } ); QObject::connect( channelGUI, &ChannelGUI::duplicateChannelEmitted, this, - [=](){ MainWindow::getInstance()->channelDuplicate(channelGUI); } + [channelGUI](){ MainWindow::getInstance()->channelDuplicate(channelGUI); } ); QObject::connect( channelGUI, &ChannelGUI::moveToDeviceSet, this, - [=](int dsIndexDest){ MainWindow::getInstance()->channelMoveToDeviceSet(channelGUI, dsIndexDest); } + [channelGUI](int dsIndexDest){ MainWindow::getInstance()->channelMoveToDeviceSet(channelGUI, dsIndexDest); } ); } } @@ -766,11 +763,11 @@ bool DeviceUISet::ChannelInstanceRegistration::operator<(const ChannelInstanceRe } } -void DeviceUISet::handleChannelGUIClosing(ChannelGUI* channelGUI) +void DeviceUISet::handleChannelGUIClosing(const ChannelGUI* channelGUI) { qDebug("DeviceUISet::handleChannelGUIClosing: %s: %d", qPrintable(channelGUI->getTitle()), channelGUI->getIndex()); - for (ChannelInstanceRegistrations::iterator it = m_channelInstanceRegistrations.begin(); it != m_channelInstanceRegistrations.end(); ++it) + for (auto it = m_channelInstanceRegistrations.begin(); it != m_channelInstanceRegistrations.end(); ++it) { if (it->m_gui == channelGUI) { @@ -793,7 +790,7 @@ void DeviceUISet::handleChannelGUIClosing(ChannelGUI* channelGUI) } } -void DeviceUISet::handleDeleteChannel(ChannelAPI *channelAPI) +void DeviceUISet::handleDeleteChannel(ChannelAPI *channelAPI) const { channelAPI->destroy(); } diff --git a/sdrgui/device/deviceuiset.h b/sdrgui/device/deviceuiset.h index f195364fd..558db2128 100644 --- a/sdrgui/device/deviceuiset.h +++ b/sdrgui/device/deviceuiset.h @@ -33,7 +33,6 @@ class SpectrumVis; class GLSpectrum; class GLSpectrumGUI; class MainSpectrumGUI; -// class ChannelWindow; class DeviceAPI; class DeviceSet; class DSPDeviceSourceEngine; @@ -61,7 +60,6 @@ public: GLSpectrum *m_spectrum; GLSpectrumGUI *m_spectrumGUI; MainSpectrumGUI *m_mainSpectrumGUI; - // ChannelWindow *m_channelWindow; DeviceAPI *m_deviceAPI; DeviceGUI *m_deviceGUI; DSPDeviceSourceEngine *m_deviceSourceEngine; @@ -74,7 +72,7 @@ public: int m_selectedDeviceItemImdex; DeviceUISet(int deviceSetIndex, DeviceSet *deviceSet); - ~DeviceUISet(); + ~DeviceUISet() final; void setIndex(int deviceSetIndex); int getIndex() const { return m_deviceSetIndex; } @@ -146,10 +144,8 @@ private: bool operator<(const ChannelInstanceRegistration& other) const; }; - typedef QList ChannelInstanceRegistrations; + using ChannelInstanceRegistrations = QList; - // ChannelInstanceRegistrations m_rxChannelInstanceRegistrations; - // ChannelInstanceRegistrations m_txChannelInstanceRegistrations; ChannelInstanceRegistrations m_channelInstanceRegistrations; int m_deviceSetIndex; DeviceSet *m_deviceSet; @@ -165,8 +161,8 @@ private: void saveMIMOChannelSettings(Preset* preset) const; private slots: - void handleChannelGUIClosing(ChannelGUI* channelGUI); - void handleDeleteChannel(ChannelAPI *channelAPI); + void handleChannelGUIClosing(const ChannelGUI* channelGUI); + void handleDeleteChannel(ChannelAPI *channelAPI) const; void onTimeSelected(int deviceSetIndex, float time); }; diff --git a/sdrgui/mainwindow.cpp b/sdrgui/mainwindow.cpp index e0386a05e..570eb51be 100644 --- a/sdrgui/mainwindow.cpp +++ b/sdrgui/mainwindow.cpp @@ -119,7 +119,7 @@ #include "gui/accessiblevaluedial.h" #include "gui/accessiblevaluedialz.h" -MainWindow *MainWindow::m_instance = 0; +MainWindow *MainWindow::m_instance = nullptr; MainWindow::MainWindow(qtwebapp::LoggerWithFile *logger, const MainParser& parser, QWidget* parent) : QMainWindow(parent), @@ -160,7 +160,7 @@ MainWindow::MainWindow(qtwebapp::LoggerWithFile *logger, const MainParser& parse qApp->setFont(font); QPixmap logoPixmap(":/sdrangel_logo.png"); - SDRangelSplash *splash = new SDRangelSplash(logoPixmap); + auto *splash = new SDRangelSplash(logoPixmap); splash->setMessageRect(QRect(10, 80, 350, 16)); splash->show(); splash->showStatusMessage("starting...", Qt::white); @@ -193,9 +193,9 @@ MainWindow::MainWindow(qtwebapp::LoggerWithFile *logger, const MainParser& parse connect(screen(), &QScreen::orientationChanged, this, &MainWindow::orientationChanged); #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) screen()->setOrientationUpdateMask(Qt::PortraitOrientation - | Qt::LandscapeOrientation - | Qt::InvertedPortraitOrientation - | Qt::InvertedLandscapeOrientation); + | Qt::LandscapeOrientation + | Qt::InvertedPortraitOrientation + | Qt::InvertedLandscapeOrientation); #endif connect(&m_statusTimer, SIGNAL(timeout()), this, SLOT(updateStatus())); @@ -217,7 +217,7 @@ MainWindow::MainWindow(qtwebapp::LoggerWithFile *logger, const MainParser& parse QString filePath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); filePath += QDir::separator(); filePath += "fftw-wisdom"; - QFileInfo fileInfo = QFileInfo(filePath); + auto fileInfo = QFileInfo(filePath); if (fileInfo.exists()) { m_dspEngine->createFFTFactory(filePath); @@ -256,13 +256,13 @@ MainWindow::MainWindow(qtwebapp::LoggerWithFile *logger, const MainParser& parse qDebug() << "MainWindow::MainWindow: load current configuration..."; loadConfiguration(m_mainCore->m_settings.getWorkingConfiguration()); - if (m_workspaces.size() == 0) + if (m_workspaces.empty()) { qDebug() << "MainWindow::MainWindow: no or empty current configuration, creating empty workspace..."; addWorkspace(); // If no configurations, load some basic examples - if (m_mainCore->m_settings.getConfigurations()->size() == 0) { + if (m_mainCore->m_settings.getConfigurations()->empty()) { loadDefaultConfigurations(); } } @@ -289,7 +289,7 @@ MainWindow::MainWindow(qtwebapp::LoggerWithFile *logger, const MainParser& parse m_requestMapper->setAdapter(m_apiAdapter); m_apiHost = parser.getServerAddress(); m_apiPort = parser.getServerPort(); - m_apiServer = new WebAPIServer(m_apiHost, m_apiPort, m_requestMapper); + m_apiServer = new WebAPIServer(m_apiHost, (uint16_t) m_apiPort, m_requestMapper); m_apiServer->start(); m_dspEngine->setMIMOSupport(true); @@ -344,12 +344,7 @@ void MainWindow::sampleSourceAdd(Workspace *deviceWorkspace, Workspace *spectrum { DSPDeviceSourceEngine *dspDeviceSourceEngine = m_dspEngine->addDeviceSourceEngine(); - uint dspDeviceSourceEngineUID = dspDeviceSourceEngine->getUID(); - char uidCStr[16]; - sprintf(uidCStr, "UID:%d", dspDeviceSourceEngineUID); - - int deviceSetIndex = m_deviceUIs.size(); - + auto deviceSetIndex = (int) m_deviceUIs.size(); m_mainCore->appendDeviceSet(0); m_deviceUIs.push_back(new DeviceUISet(deviceSetIndex, m_mainCore->m_deviceSets.back())); m_deviceUIs.back()->m_deviceSourceEngine = dspDeviceSourceEngine; @@ -359,7 +354,7 @@ void MainWindow::sampleSourceAdd(Workspace *deviceWorkspace, Workspace *spectrum m_deviceUIs.back()->m_deviceMIMOEngine = nullptr; m_mainCore->m_deviceSets.back()->m_deviceMIMOEngine = nullptr; - DeviceAPI *deviceAPI = new DeviceAPI(DeviceAPI::StreamSingleRx, deviceSetIndex, dspDeviceSourceEngine, nullptr, nullptr); + auto *deviceAPI = new DeviceAPI(DeviceAPI::StreamSingleRx, deviceSetIndex, dspDeviceSourceEngine, nullptr, nullptr); m_deviceUIs.back()->m_deviceAPI = deviceAPI; m_mainCore->m_deviceSets.back()->m_deviceAPI = deviceAPI; @@ -383,14 +378,14 @@ void MainWindow::sampleSourceAdd(Workspace *deviceWorkspace, Workspace *spectrum mainSpectrumGUI, &MainSpectrumGUI::moveToWorkspace, this, - [=](int wsIndexDest){ this->mainSpectrumMove(mainSpectrumGUI, wsIndexDest); } + [this, mainSpectrumGUI](int wsIndexDest){ this->mainSpectrumMove(mainSpectrumGUI, wsIndexDest); } ); QObject::connect( m_deviceUIs.back()->m_deviceGUI, &DeviceGUI::addChannelEmitted, this, - [=](int channelPluginIndex){ this->channelAddClicked(deviceWorkspace, deviceSetIndex, channelPluginIndex); } + [this, deviceWorkspace, deviceSetIndex](int channelPluginIndex){ this->channelAddClicked(deviceWorkspace, deviceSetIndex, channelPluginIndex); } ); QObject::connect( @@ -469,19 +464,17 @@ void MainWindow::sampleSourceCreate( } // add to buddies list - std::vector::iterator it = m_deviceUIs.begin(); + auto it = m_deviceUIs.begin(); int nbOfBuddies = 0; for (; it != m_deviceUIs.end(); ++it) { - if (*it != deviceUISet) // do not add to itself + if ((*it != deviceUISet) && // do not add to itself + (deviceUISet->m_deviceAPI->getHardwareId() == (*it)->m_deviceAPI->getHardwareId()) && + (deviceUISet->m_deviceAPI->getSamplingDeviceSerial() == (*it)->m_deviceAPI->getSamplingDeviceSerial())) { - if ((deviceUISet->m_deviceAPI->getHardwareId() == (*it)->m_deviceAPI->getHardwareId()) && - (deviceUISet->m_deviceAPI->getSamplingDeviceSerial() == (*it)->m_deviceAPI->getSamplingDeviceSerial())) - { - (*it)->m_deviceAPI->addBuddy(deviceUISet->m_deviceAPI); - nbOfBuddies++; - } + (*it)->m_deviceAPI->addBuddy(deviceUISet->m_deviceAPI); + nbOfBuddies++; } } @@ -489,8 +482,6 @@ void MainWindow::sampleSourceCreate( deviceUISet->m_deviceAPI->setBuddyLeader(true); } - // DeviceGUI *oldDeviceGUI = deviceUISet->m_deviceGUI; // store old GUI pointer for later - // constructs new GUI and input object DeviceSampleSource *source = deviceAPI->getPluginInterface()->createSampleSourcePluginInstance( deviceAPI->getSamplingDeviceId(), deviceAPI); @@ -505,13 +496,13 @@ void MainWindow::sampleSourceCreate( deviceGUI, &DeviceGUI::moveToWorkspace, this, - [=](int wsIndexDest){ this->deviceMove(deviceGUI, wsIndexDest); } + [this, deviceGUI](int wsIndexDest){ this->deviceMove(deviceGUI, wsIndexDest); } ); QObject::connect( deviceGUI, &DeviceGUI::deviceChange, this, - [=](int newDeviceIndex){ this->samplingDeviceChangeHandler(deviceGUI, newDeviceIndex); } + [this, deviceGUI](int newDeviceIndex){ this->samplingDeviceChangeHandler(deviceGUI, newDeviceIndex); } ); QObject::connect( deviceGUI, @@ -529,7 +520,7 @@ void MainWindow::sampleSourceCreate( deviceGUI, &DeviceGUI::closing, this, - [=](){ this->removeDeviceSet(deviceGUI->getIndex()); } + [this, deviceGUI](){ this->removeDeviceSet(deviceGUI->getIndex()); } ); QObject::connect( deviceGUI, @@ -565,13 +556,7 @@ void MainWindow::sampleSourceCreate( void MainWindow::sampleSinkAdd(Workspace *deviceWorkspace, Workspace *spectrumWorkspace, int deviceIndex) { DSPDeviceSinkEngine *dspDeviceSinkEngine = m_dspEngine->addDeviceSinkEngine(); - - uint dspDeviceSinkEngineUID = dspDeviceSinkEngine->getUID(); - char uidCStr[16]; - sprintf(uidCStr, "UID:%d", dspDeviceSinkEngineUID); - - int deviceSetIndex = m_deviceUIs.size(); - + auto deviceSetIndex = (int) m_deviceUIs.size(); m_mainCore->appendDeviceSet(1); m_deviceUIs.push_back(new DeviceUISet(deviceSetIndex, m_mainCore->m_deviceSets.back())); m_deviceUIs.back()->m_deviceSourceEngine = nullptr; @@ -581,7 +566,7 @@ void MainWindow::sampleSinkAdd(Workspace *deviceWorkspace, Workspace *spectrumWo m_deviceUIs.back()->m_deviceMIMOEngine = nullptr; m_mainCore->m_deviceSets.back()->m_deviceMIMOEngine = nullptr; - DeviceAPI *deviceAPI = new DeviceAPI(DeviceAPI::StreamSingleTx, deviceSetIndex, nullptr, dspDeviceSinkEngine, nullptr); + auto *deviceAPI = new DeviceAPI(DeviceAPI::StreamSingleTx, deviceSetIndex, nullptr, dspDeviceSinkEngine, nullptr); m_deviceUIs.back()->m_deviceAPI = deviceAPI; m_mainCore->m_deviceSets.back()->m_deviceAPI = deviceAPI; @@ -605,14 +590,14 @@ void MainWindow::sampleSinkAdd(Workspace *deviceWorkspace, Workspace *spectrumWo mainSpectrumGUI, &MainSpectrumGUI::moveToWorkspace, this, - [=](int wsIndexDest){ this->mainSpectrumMove(mainSpectrumGUI, wsIndexDest); } + [this, mainSpectrumGUI](int wsIndexDest){ this->mainSpectrumMove(mainSpectrumGUI, wsIndexDest); } ); QObject::connect( m_deviceUIs.back()->m_deviceGUI, &DeviceGUI::addChannelEmitted, this, - [=](int channelPluginIndex){ this->channelAddClicked(deviceWorkspace, deviceSetIndex, channelPluginIndex); } + [this, deviceWorkspace, deviceSetIndex](int channelPluginIndex){ this->channelAddClicked(deviceWorkspace, deviceSetIndex, channelPluginIndex); } ); QObject::connect( @@ -668,7 +653,7 @@ void MainWindow::sampleSinkCreate( qDebug("MainWindow::sampleSinkCreate: non existent device replaced by File Sink"); int fileSinkDeviceIndex = DeviceEnumerator::instance()->getFileOutputDeviceIndex(); selectedDeviceIndex = fileSinkDeviceIndex; - const PluginInterface::SamplingDevice *samplingDevice = DeviceEnumerator::instance()->getTxSamplingDevice(fileSinkDeviceIndex); + samplingDevice = DeviceEnumerator::instance()->getTxSamplingDevice(fileSinkDeviceIndex); deviceAPI->setSamplingDeviceSequence(samplingDevice->sequence); deviceAPI->setDeviceNbItems(samplingDevice->deviceNbItems); deviceAPI->setDeviceItemIndex(samplingDevice->deviceItemIndex); @@ -686,19 +671,17 @@ void MainWindow::sampleSinkCreate( } // add to buddies list - std::vector::iterator it = m_deviceUIs.begin(); + auto it = m_deviceUIs.begin(); int nbOfBuddies = 0; for (; it != m_deviceUIs.end(); ++it) { - if (*it != deviceUISet) // do not add to itself + if ((*it != deviceUISet) && // do not add to itself + (deviceAPI->getHardwareId() == (*it)->m_deviceAPI->getHardwareId()) && + (deviceAPI->getSamplingDeviceSerial() == (*it)->m_deviceAPI->getSamplingDeviceSerial())) { - if ((deviceAPI->getHardwareId() == (*it)->m_deviceAPI->getHardwareId()) && - (deviceAPI->getSamplingDeviceSerial() == (*it)->m_deviceAPI->getSamplingDeviceSerial())) - { - (*it)->m_deviceAPI->addBuddy(deviceAPI); - nbOfBuddies++; - } + (*it)->m_deviceAPI->addBuddy(deviceAPI); + nbOfBuddies++; } } @@ -706,8 +689,6 @@ void MainWindow::sampleSinkCreate( deviceAPI->setBuddyLeader(true); } - // DeviceGUI *oldDeviceGUI = deviceUISet->m_deviceGUI; // store old GUI pointer for later - // constructs new GUI and output object DeviceSampleSink *sink = deviceAPI->getPluginInterface()->createSampleSinkPluginInstance( deviceAPI->getSamplingDeviceId(), deviceAPI); @@ -722,13 +703,13 @@ void MainWindow::sampleSinkCreate( deviceGUI, &DeviceGUI::moveToWorkspace, this, - [=](int wsIndexDest){ this->deviceMove(deviceGUI, wsIndexDest); } + [this, deviceGUI](int wsIndexDest){ this->deviceMove(deviceGUI, wsIndexDest); } ); QObject::connect( deviceGUI, &DeviceGUI::deviceChange, this, - [=](int newDeviceIndex){ this->samplingDeviceChangeHandler(deviceGUI, newDeviceIndex); } + [this, deviceGUI](int newDeviceIndex){ this->samplingDeviceChangeHandler(deviceGUI, newDeviceIndex); } ); QObject::connect( deviceGUI, @@ -746,7 +727,7 @@ void MainWindow::sampleSinkCreate( deviceGUI, &DeviceGUI::closing, this, - [=](){ this->removeDeviceSet(deviceGUI->getIndex()); } + [this, deviceGUI](){ this->removeDeviceSet(deviceGUI->getIndex()); } ); QObject::connect( deviceGUI, @@ -783,12 +764,7 @@ void MainWindow::sampleMIMOAdd(Workspace *deviceWorkspace, Workspace *spectrumWo { DSPDeviceMIMOEngine *dspDeviceMIMOEngine = m_dspEngine->addDeviceMIMOEngine(); - uint dspDeviceMIMOEngineUID = dspDeviceMIMOEngine->getUID(); - char uidCStr[16]; - sprintf(uidCStr, "UID:%d", dspDeviceMIMOEngineUID); - - int deviceSetIndex = m_deviceUIs.size(); - + auto deviceSetIndex = (int) m_deviceUIs.size(); m_mainCore->appendDeviceSet(2); m_deviceUIs.push_back(new DeviceUISet(deviceSetIndex, m_mainCore->m_deviceSets.back())); m_deviceUIs.back()->m_deviceSourceEngine = nullptr; @@ -798,7 +774,7 @@ void MainWindow::sampleMIMOAdd(Workspace *deviceWorkspace, Workspace *spectrumWo m_deviceUIs.back()->m_deviceMIMOEngine = dspDeviceMIMOEngine; m_mainCore->m_deviceSets.back()->m_deviceMIMOEngine = dspDeviceMIMOEngine; - DeviceAPI *deviceAPI = new DeviceAPI(DeviceAPI::StreamMIMO, deviceSetIndex, nullptr, nullptr, dspDeviceMIMOEngine); + auto *deviceAPI = new DeviceAPI(DeviceAPI::StreamMIMO, deviceSetIndex, nullptr, nullptr, dspDeviceMIMOEngine); m_deviceUIs.back()->m_deviceAPI = deviceAPI; m_mainCore->m_deviceSets.back()->m_deviceAPI = deviceAPI; @@ -830,14 +806,14 @@ void MainWindow::sampleMIMOAdd(Workspace *deviceWorkspace, Workspace *spectrumWo mainSpectrumGUI, &MainSpectrumGUI::moveToWorkspace, this, - [=](int wsIndexDest){ this->mainSpectrumMove(mainSpectrumGUI, wsIndexDest); } + [this, mainSpectrumGUI](int wsIndexDest){ this->mainSpectrumMove(mainSpectrumGUI, wsIndexDest); } ); QObject::connect( m_deviceUIs.back()->m_deviceGUI, &DeviceGUI::addChannelEmitted, this, - [=](int channelPluginIndex){ this->channelAddClicked(deviceWorkspace, deviceSetIndex, channelPluginIndex); } + [this, deviceWorkspace, deviceSetIndex](int channelPluginIndex){ this->channelAddClicked(deviceWorkspace, deviceSetIndex, channelPluginIndex); } ); QObject::connect( @@ -886,7 +862,7 @@ void MainWindow::sampleMIMOCreate( qDebug("MainWindow::sampleMIMOCreate: non existent device replaced by Test MIMO"); int testMIMODeviceIndex = DeviceEnumerator::instance()->getTestMIMODeviceIndex(); selectedDeviceIndex = testMIMODeviceIndex; - const PluginInterface::SamplingDevice *samplingDevice = DeviceEnumerator::instance()->getMIMOSamplingDevice(testMIMODeviceIndex); + samplingDevice = DeviceEnumerator::instance()->getMIMOSamplingDevice(testMIMODeviceIndex); deviceAPI->setSamplingDeviceSequence(samplingDevice->sequence); deviceAPI->setDeviceNbItems(samplingDevice->deviceNbItems); deviceAPI->setDeviceItemIndex(samplingDevice->deviceItemIndex); @@ -903,8 +879,6 @@ void MainWindow::sampleMIMOCreate( deviceAPI->setHardwareUserArguments(userArgs); } - // DeviceGUI *oldDeviceGUI = deviceUISet->m_deviceGUI; // store old GUI pointer for later - // constructs new GUI and output object DeviceSampleMIMO *mimo = deviceAPI->getPluginInterface()->createSampleMIMOPluginInstance( deviceAPI->getSamplingDeviceId(), deviceAPI); @@ -919,13 +893,13 @@ void MainWindow::sampleMIMOCreate( deviceGUI, &DeviceGUI::moveToWorkspace, this, - [=](int wsIndexDest){ this->deviceMove(deviceGUI, wsIndexDest); } + [this, deviceGUI](int wsIndexDest){ this->deviceMove(deviceGUI, wsIndexDest); } ); QObject::connect( deviceGUI, &DeviceGUI::deviceChange, this, - [=](int newDeviceIndex){ this->samplingDeviceChangeHandler(deviceGUI, newDeviceIndex); } + [this, deviceGUI](int newDeviceIndex){ this->samplingDeviceChangeHandler(deviceGUI, newDeviceIndex); } ); QObject::connect( deviceGUI, @@ -943,7 +917,7 @@ void MainWindow::sampleMIMOCreate( deviceGUI, &DeviceGUI::closing, this, - [=](){ this->removeDeviceSet(deviceGUI->getIndex()); } + [this, deviceGUI](){ this->removeDeviceSet(deviceGUI->getIndex()); } ); QObject::connect( deviceGUI, @@ -966,7 +940,8 @@ void MainWindow::sampleMIMOCreate( deviceGUI->setToolTip(samplingDevice->displayedName); deviceGUI->setTitle(samplingDevice->displayedName.split(" ")[0]); deviceGUI->setCurrentDeviceIndex(selectedDeviceIndex); - QStringList channelNames, tmpChannelNames; + QStringList channelNames; + QStringList tmpChannelNames; m_pluginManager->listMIMOChannels(channelNames); m_pluginManager->listRxChannels(tmpChannelNames); channelNames.append(tmpChannelNames); @@ -1058,9 +1033,9 @@ void MainWindow::removeDeviceSet(int deviceSetIndex) // Renumerate for (int i = 0; i < (int) m_deviceUIs.size(); i++) { - DeviceUISet *deviceUISet = m_deviceUIs[i]; - deviceUISet->setIndex(i); - DeviceGUI *deviceGUI = m_deviceUIs[i]->m_deviceGUI; + DeviceUISet *xDeviceUISet = m_deviceUIs[i]; + xDeviceUISet->setIndex(i); + const DeviceGUI *deviceGUI = m_deviceUIs[i]->m_deviceGUI; Workspace *deviceWorkspace = m_workspaces[deviceGUI->getWorkspaceIndex()]; QObject::disconnect( @@ -1073,7 +1048,7 @@ void MainWindow::removeDeviceSet(int deviceSetIndex) deviceGUI, &DeviceGUI::addChannelEmitted, this, - [=](int channelPluginIndex){ this->channelAddClicked(deviceWorkspace, i, channelPluginIndex); } + [this, deviceWorkspace, i](int channelPluginIndex){ this->channelAddClicked(deviceWorkspace, i, channelPluginIndex); } ); } @@ -1083,7 +1058,7 @@ void MainWindow::removeDeviceSet(int deviceSetIndex) void MainWindow::removeLastDeviceSet() { qDebug("MainWindow::removeLastDeviceSet: %s", qPrintable(m_deviceUIs.back()->m_deviceAPI->getHardwareId())); - int removedDeviceSetIndex = m_deviceUIs.size() - 1; + auto removedDeviceSetIndex = (int) (m_deviceUIs.size() - 1); if (m_deviceUIs.back()->m_deviceSourceEngine) // source tab { @@ -1149,7 +1124,7 @@ void MainWindow::removeLastDeviceSet() void MainWindow::addFeatureSet() { - int newFeatureSetIndex = m_featureUIs.size(); + auto newFeatureSetIndex = (int) m_featureUIs.size(); if (newFeatureSetIndex != 0) { @@ -1175,7 +1150,7 @@ void MainWindow::removeFeatureSet(unsigned int tabIndex) void MainWindow::removeAllFeatureSets() { - while (m_featureUIs.size() > 0) + while (!m_featureUIs.empty()) { delete m_featureUIs.back(); m_featureUIs.pop_back(); @@ -1215,13 +1190,6 @@ void MainWindow::loadDeviceSetPresetSettings(const Preset* preset, int deviceSet DeviceUISet *deviceUISet = m_deviceUIs[deviceSetIndex]; deviceUISet->loadDeviceSetSettings(preset, m_pluginManager->getPluginAPI(), &m_workspaces, nullptr); } - - // m_spectrumToggleViewAction->setChecked(preset->getShowSpectrum()); - - // // has to be last step - // if (!preset->getLayout().isEmpty()) { - // restoreState(preset->getLayout()); - // } } void MainWindow::saveDeviceSetPresetSettings(Preset* preset, int deviceSetIndex) @@ -1232,10 +1200,8 @@ void MainWindow::saveDeviceSetPresetSettings(Preset* preset, int deviceSetIndex) // Save from currently selected source tab //int currentSourceTabIndex = ui->tabInputsView->currentIndex(); - DeviceUISet *deviceUISet = m_deviceUIs[deviceSetIndex]; + const DeviceUISet *deviceUISet = m_deviceUIs[deviceSetIndex]; deviceUISet->saveDeviceSetSettings(preset); - // preset->setShowSpectrum(m_spectrumToggleViewAction->isChecked()); - // preset->setLayout(saveState()); } void MainWindow::loadFeatureSetPresetSettings(const FeatureSetPreset* preset, int featureSetIndex, Workspace *workspace) @@ -1266,7 +1232,7 @@ void MainWindow::saveFeatureSetPresetSettings(FeatureSetPreset* preset, int feat featureUI->saveFeatureSetSettings(preset); } -void MainWindow::loadDefaultConfigurations() +void MainWindow::loadDefaultConfigurations() const { QDirIterator configurationsIt(":configurations", QDirIterator::Subdirectories); while (configurationsIt.hasNext()) @@ -1350,7 +1316,7 @@ void MainWindow::loadConfiguration(const Configuration *configuration, bool from QApplication::processEvents(); } // Device sets - while (m_deviceUIs.size() > 0) { + while (!m_deviceUIs.empty()) { removeLastDeviceSet(); } // Features @@ -1451,7 +1417,7 @@ void MainWindow::loadConfiguration(const Configuration *configuration, bool from qDebug() << "MainWindow::loadConfiguration: Unknown preset type: " << deviceSetPreset.getPresetType(); } - if (m_deviceUIs.size() > 0) + if (!m_deviceUIs.empty()) { MDIUtils::restoreMDIGeometry(m_deviceUIs.back()->m_deviceGUI, deviceSetPreset.getDeviceGeometry()); MDIUtils::restoreMDIGeometry(m_deviceUIs.back()->m_mainSpectrumGUI, deviceSetPreset.getSpectrumGeometry()); @@ -1488,7 +1454,7 @@ void MainWindow::loadConfiguration(const Configuration *configuration, bool from gui, &FeatureGUI::moveToWorkspace, this, - [=](int wsIndexDest){ this->featureMove(gui, wsIndexDest); } + [this, gui](int wsIndexDest){ this->featureMove(gui, wsIndexDest); } ); } @@ -1553,9 +1519,9 @@ void MainWindow::saveConfiguration(Configuration *configuration) } } -QString MainWindow::openGLVersion() +QString MainWindow::openGLVersion() const { - QOpenGLContext *glCurrentContext = QOpenGLContext::globalShareContext(); + const QOpenGLContext *glCurrentContext = QOpenGLContext::globalShareContext(); if (glCurrentContext) { if (glCurrentContext->isValid()) @@ -1581,9 +1547,13 @@ QString MainWindow::openGLVersion() } } -void MainWindow::createMenuBar(QToolButton *button) +void MainWindow::createMenuBar(QToolButton *button) const { - QMenu *fileMenu, *viewMenu, *workspacesMenu, *preferencesMenu, *helpMenu; + QMenu *fileMenu; + QMenu *viewMenu; + QMenu *workspacesMenu; + QMenu *preferencesMenu; + QMenu *helpMenu; if (button == nullptr) { @@ -1596,7 +1566,7 @@ void MainWindow::createMenuBar(QToolButton *button) } else { - QMenu *menu = new QMenu(); + auto *menu = new QMenu(); fileMenu = new QMenu("&File"); menu->addMenu(fileMenu); viewMenu = new QMenu("&View"); @@ -1717,7 +1687,7 @@ void MainWindow::closeEvent(QCloseEvent *closeEvent) saveConfiguration(m_mainCore->m_settings.getWorkingConfiguration()); m_mainCore->m_settings.save(); - while (m_deviceUIs.size() > 0) { + while (!m_deviceUIs.empty()) { removeLastDeviceSet(); } @@ -1733,26 +1703,6 @@ void MainWindow::applySettings() loadConfiguration(m_mainCore->m_settings.getWorkingConfiguration()); m_mainCore->m_settings.sortPresets(); - // int middleIndex = m_mainCore->m_settings.getPresetCount() / 2; - // QTreeWidgetItem *treeItem; - // ui->presetTree->clear(); - - // for (int i = 0; i < m_mainCore->m_settings.getPresetCount(); ++i) - // { - // treeItem = addPresetToTree(m_mainCore->m_settings.getPreset(i)); - - // if (i == middleIndex) { - // ui->presetTree->setCurrentItem(treeItem); - // } - // } - - // m_mainCore->m_settings.sortCommands(); - // ui->commandTree->clear(); - - // for (int i = 0; i < m_mainCore->m_settings.getCommandCount(); ++i) { - // treeItem = addCommandToTree(m_mainCore->m_settings.getCommand(i)); - // } - m_mainCore->setLoggingOptions(); } @@ -1760,7 +1710,7 @@ bool MainWindow::handleMessage(const Message& cmd) { if (MainCore::MsgLoadPreset::match(cmd)) { - MainCore::MsgLoadPreset& notif = (MainCore::MsgLoadPreset&) cmd; + auto& notif = (const MainCore::MsgLoadPreset&) cmd; int deviceSetIndex = notif.getDeviceSetIndex(); const Preset *preset = notif.getPreset(); @@ -1774,7 +1724,7 @@ bool MainWindow::handleMessage(const Message& cmd) } else if (MainCore::MsgSavePreset::match(cmd)) { - MainCore::MsgSavePreset& notif = (MainCore::MsgSavePreset&) cmd; + auto& notif = (const MainCore::MsgSavePreset&) cmd; saveDeviceSetPresetSettings(notif.getPreset(), notif.getDeviceSetIndex()); m_mainCore->m_settings.sortPresets(); m_mainCore->m_settings.save(); @@ -1782,9 +1732,9 @@ bool MainWindow::handleMessage(const Message& cmd) } else if (MainCore::MsgLoadFeatureSetPreset::match(cmd)) { - if (m_workspaces.size() > 0) + if (!m_workspaces.empty()) { - MainCore::MsgLoadFeatureSetPreset& notif = (MainCore::MsgLoadFeatureSetPreset&) cmd; + auto& notif = (const MainCore::MsgLoadFeatureSetPreset&) cmd; loadFeatureSetPresetSettings(notif.getPreset(), notif.getFeatureSetIndex(), m_workspaces[0]); } @@ -1792,7 +1742,7 @@ bool MainWindow::handleMessage(const Message& cmd) } else if (MainCore::MsgSaveFeatureSetPreset::match(cmd)) { - MainCore::MsgSaveFeatureSetPreset& notif = (MainCore::MsgSaveFeatureSetPreset&) cmd; + auto& notif = (const MainCore::MsgSaveFeatureSetPreset&) cmd; saveFeatureSetPresetSettings(notif.getPreset(), notif.getFeatureSetIndex()); m_mainCore->m_settings.sortFeatureSetPresets(); m_mainCore->m_settings.save(); @@ -1800,7 +1750,7 @@ bool MainWindow::handleMessage(const Message& cmd) } else if (MainCore::MsgDeletePreset::match(cmd)) { - MainCore::MsgDeletePreset& notif = (MainCore::MsgDeletePreset&) cmd; + auto& notif = (const MainCore::MsgDeletePreset&) cmd; const Preset *presetToDelete = notif.getPreset(); // remove preset from settings m_mainCore->m_settings.deletePreset(presetToDelete); @@ -1808,21 +1758,21 @@ bool MainWindow::handleMessage(const Message& cmd) } else if (MainCore::MsgLoadConfiguration::match(cmd)) { - MainCore::MsgLoadConfiguration& notif = (MainCore::MsgLoadConfiguration&) cmd; + auto& notif = (const MainCore::MsgLoadConfiguration&) cmd; const Configuration *configuration = notif.getConfiguration(); loadConfiguration(configuration, false); return true; } else if (MainCore::MsgSaveConfiguration::match(cmd)) { - MainCore::MsgSaveConfiguration& notif = (MainCore::MsgSaveConfiguration&) cmd; + auto& notif = (const MainCore::MsgSaveConfiguration&) cmd; Configuration *configuration = notif.getConfiguration(); saveConfiguration(configuration); return true; } else if (MainCore::MsgDeleteConfiguration::match(cmd)) { - MainCore::MsgDeleteConfiguration& notif = (MainCore::MsgDeleteConfiguration&) cmd; + auto& notif = (const MainCore::MsgDeleteConfiguration&) cmd; const Configuration *configurationToDelete = notif.getConfiguration(); // remove configuration from settings m_mainCore->m_settings.deleteConfiguration(configurationToDelete); @@ -1840,7 +1790,7 @@ bool MainWindow::handleMessage(const Message& cmd) } else if (MainCore::MsgDeleteFeatureSetPreset::match(cmd)) { - MainCore::MsgDeleteFeatureSetPreset& notif = (MainCore::MsgDeleteFeatureSetPreset&) cmd; + auto& notif = (const MainCore::MsgDeleteFeatureSetPreset&) cmd; const FeatureSetPreset *presetToDelete = notif.getPreset(); // remove preset from settings m_mainCore->m_settings.deleteFeatureSetPreset(presetToDelete); @@ -1848,10 +1798,10 @@ bool MainWindow::handleMessage(const Message& cmd) } else if (MainCore::MsgAddDeviceSet::match(cmd)) { - MainCore::MsgAddDeviceSet& notif = (MainCore::MsgAddDeviceSet&) cmd; + auto& notif = (const MainCore::MsgAddDeviceSet&) cmd; int direction = notif.getDirection(); - if (m_workspaces.size() > 0) + if (!m_workspaces.empty()) { if (direction == 1) { // Single stream Tx sampleSinkAdd(m_workspaces[0], m_workspaces[0], -1); // create with file output device by default @@ -1866,7 +1816,7 @@ bool MainWindow::handleMessage(const Message& cmd) } else if (MainCore::MsgRemoveLastDeviceSet::match(cmd)) { - if (m_deviceUIs.size() > 0) { + if (!m_deviceUIs.empty()) { removeLastDeviceSet(); } @@ -1874,7 +1824,7 @@ bool MainWindow::handleMessage(const Message& cmd) } else if (MainCore::MsgSetDevice::match(cmd)) { - MainCore::MsgSetDevice& notif = (MainCore::MsgSetDevice&) cmd; + auto& notif = (const MainCore::MsgSetDevice&) cmd; int deviceSetIndex = notif.getDeviceSetIndex(); if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_deviceUIs.size())) @@ -1887,12 +1837,12 @@ bool MainWindow::handleMessage(const Message& cmd) } else if (MainCore::MsgAddChannel::match(cmd)) { - MainCore::MsgAddChannel& notif = (MainCore::MsgAddChannel&) cmd; + auto& notif = (const MainCore::MsgAddChannel&) cmd; int deviceSetIndex = notif.getDeviceSetIndex(); if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_deviceUIs.size())) { - DeviceUISet *deviceUISet = m_deviceUIs[deviceSetIndex]; + const DeviceUISet *deviceUISet = m_deviceUIs[deviceSetIndex]; int deviceWorkspaceIndex = deviceUISet->m_deviceGUI->getWorkspaceIndex(); deviceWorkspaceIndex = deviceWorkspaceIndex < m_workspaces.size() ? deviceWorkspaceIndex : 0; int channelRegistrationIndex; @@ -1923,15 +1873,15 @@ bool MainWindow::handleMessage(const Message& cmd) } else if (MainCore::MsgDeleteChannel::match(cmd)) { - MainCore::MsgDeleteChannel& notif = (MainCore::MsgDeleteChannel&) cmd; + auto& notif = (const MainCore::MsgDeleteChannel&) cmd; deleteChannel(notif.getDeviceSetIndex(), notif.getChannelIndex()); return true; } else if (MainCore::MsgAddFeature::match(cmd)) { - MainCore::MsgAddFeature& notif = (MainCore::MsgAddFeature&) cmd; + auto& notif = (const MainCore::MsgAddFeature&) cmd; - if (m_workspaces.size() > 0) { + if (!m_workspaces.empty()) { featureAddClicked(m_workspaces[0], notif.getFeatureRegistrationIndex()); } @@ -1939,13 +1889,13 @@ bool MainWindow::handleMessage(const Message& cmd) } else if (MainCore::MsgDeleteFeature::match(cmd)) { - MainCore::MsgDeleteFeature& notif = (MainCore::MsgDeleteFeature&) cmd; + auto& notif = (const MainCore::MsgDeleteFeature&) cmd; deleteFeature(0, notif.getFeatureIndex()); return true; } else if (MainCore::MsgMoveDeviceUIToWorkspace::match(cmd)) { - MainCore::MsgMoveDeviceUIToWorkspace& notif = (MainCore::MsgMoveDeviceUIToWorkspace&) cmd; + auto& notif = (const MainCore::MsgMoveDeviceUIToWorkspace&) cmd; int deviceSetIndex = notif.getDeviceSetIndex(); if (deviceSetIndex < (int) m_deviceUIs.size()) @@ -1959,7 +1909,7 @@ bool MainWindow::handleMessage(const Message& cmd) } else if (MainCore::MsgMoveMainSpectrumUIToWorkspace::match(cmd)) { - MainCore::MsgMoveMainSpectrumUIToWorkspace& notif = (MainCore::MsgMoveMainSpectrumUIToWorkspace&) cmd; + auto& notif = (const MainCore::MsgMoveMainSpectrumUIToWorkspace&) cmd; int deviceSetIndex = notif.getDeviceSetIndex(); if (deviceSetIndex < (int) m_deviceUIs.size()) @@ -1973,10 +1923,10 @@ bool MainWindow::handleMessage(const Message& cmd) } else if (MainCore::MsgMoveFeatureUIToWorkspace::match(cmd)) { - MainCore::MsgMoveFeatureUIToWorkspace& notif = (MainCore::MsgMoveFeatureUIToWorkspace&) cmd; + auto& notif = (const MainCore::MsgMoveFeatureUIToWorkspace&) cmd; int featureIndex = notif.getFeatureIndex(); - if (featureIndex < (int) m_featureUIs[0]->getNumberOfFeatures()) + if (featureIndex < m_featureUIs[0]->getNumberOfFeatures()) { FeatureGUI *gui = m_featureUIs[0]->getFeatureGuiAt(featureIndex); featureMove(gui, notif.getWorkspaceIndex()); @@ -1986,7 +1936,7 @@ bool MainWindow::handleMessage(const Message& cmd) } else if (MainCore::MsgMoveChannelUIToWorkspace::match(cmd)) { - MainCore::MsgMoveChannelUIToWorkspace& notif = (MainCore::MsgMoveChannelUIToWorkspace&) cmd; + auto& notif = (const MainCore::MsgMoveChannelUIToWorkspace&) cmd; int deviceSetIndex = notif.getDeviceSetIndex(); if (deviceSetIndex < (int) m_deviceUIs.size()) @@ -2010,8 +1960,6 @@ bool MainWindow::handleMessage(const Message& cmd) } else if (MainCore::MsgDVSerial::match(cmd)) { - // MainCore::MsgDVSerial& notif = (MainCore::MsgDVSerial&) cmd; - // ui->action_DV_Serial->setChecked(notif.getActive()); return true; } @@ -2022,7 +1970,7 @@ void MainWindow::handleMessages() { Message* message; - while ((message = m_inputMessageQueue.pop()) != 0) + while ((message = m_inputMessageQueue.pop()) != nullptr) { qDebug("MainWindow::handleMessages: message: %s", message->getIdentifier()); handleMessage(*message); @@ -2040,7 +1988,7 @@ void MainWindow::handleWorkspaceVisibility(Workspace *workspace, bool visibility void MainWindow::addWorkspace() { int workspaceIndex = m_workspaces.size(); - Workspace *workspace = new Workspace(workspaceIndex); + auto *workspace = new Workspace(workspaceIndex); m_workspaces.push_back(workspace); if (workspace->getMenuButton()) { createMenuBar(workspace->getMenuButton()); @@ -2054,21 +2002,21 @@ void MainWindow::addWorkspace() m_workspaces.back(), &Workspace::addRxDevice, this, - [=](Workspace *inWorkspace, int deviceIndex) { this->sampleSourceAdd(inWorkspace, inWorkspace, deviceIndex); } + [this](Workspace *inWorkspace, int deviceIndex) { this->sampleSourceAdd(inWorkspace, inWorkspace, deviceIndex); } ); QObject::connect( m_workspaces.back(), &Workspace::addTxDevice, this, - [=](Workspace *inWorkspace, int deviceIndex) { this->sampleSinkAdd(inWorkspace, inWorkspace, deviceIndex); } + [this](Workspace *inWorkspace, int deviceIndex) { this->sampleSinkAdd(inWorkspace, inWorkspace, deviceIndex); } ); QObject::connect( m_workspaces.back(), &Workspace::addMIMODevice, this, - [=](Workspace *inWorkspace, int deviceIndex) { this->sampleMIMOAdd(inWorkspace, inWorkspace, deviceIndex); } + [this](Workspace *inWorkspace, int deviceIndex) { this->sampleMIMOAdd(inWorkspace, inWorkspace, deviceIndex); } ); QObject::connect( @@ -2114,15 +2062,10 @@ void MainWindow::addWorkspace() m_workspaces.back()->show(); m_workspaces.back()->raise(); - // QList tabBars = findChildren(); - - // if (tabBars.size() > 0) { - // tabBars.back()->setStyleSheet("QTabBar::tab:selected { background: rgb(128,70,0); }"); // change text color so it is visible - // } } } -void MainWindow::viewAllWorkspaces() +void MainWindow::viewAllWorkspaces() const { for (const auto& workspace : m_workspaces) { @@ -2134,7 +2077,7 @@ void MainWindow::viewAllWorkspaces() void MainWindow::removeEmptyWorkspaces() { - QList::iterator it = m_workspaces.begin(); + auto it = m_workspaces.begin(); while (it != m_workspaces.end()) { @@ -2215,7 +2158,7 @@ void MainWindow::on_action_Profile_triggered() m_profileDialog->raise(); } -void MainWindow::commandKeysConnect(QObject *object, const char *slot) +void MainWindow::commandKeysConnect(const QObject *object, const char *slot) { setFocus(); connect( @@ -2226,7 +2169,7 @@ void MainWindow::commandKeysConnect(QObject *object, const char *slot) ); } -void MainWindow::commandKeysDisconnect(QObject *object, const char *slot) +void MainWindow::commandKeysDisconnect(const QObject *object, const char *slot) const { disconnect( m_commandKeyReceiver, @@ -2243,12 +2186,12 @@ void MainWindow::on_action_saveAll_triggered() QMessageBox::information(this, tr("Done"), tr("All current settings saved")); } -void MainWindow::on_action_Quick_Start_triggered() +void MainWindow::on_action_Quick_Start_triggered() const { QDesktopServices::openUrl(QUrl("https://github.com/f4exb/sdrangel/wiki/Quick-start")); } -void MainWindow::on_action_Main_Window_triggered() +void MainWindow::on_action_Main_Window_triggered() const { QDesktopServices::openUrl(QUrl("https://github.com/f4exb/sdrangel/blob/master/sdrgui/readme.md")); } @@ -2279,7 +2222,7 @@ void MainWindow::openConfigurationDialog(bool openOnly) &dialog, &ConfigurationsDialog::loadConfiguration, this, - [=](const Configuration* configuration) { this->loadConfiguration(configuration, true); } + [this](const Configuration* configuration) { this->loadConfiguration(configuration, true); } ); new DialogPositioner(&dialog, true); dialog.exec(); @@ -2394,9 +2337,9 @@ void MainWindow::fftWisdomProcessFinished(int exitCode, QProcess::ExitStatus exi m_fftWisdomProcess = nullptr; } -void MainWindow::samplingDeviceChangeHandler(DeviceGUI *deviceGUI, int newDeviceIndex) +void MainWindow::samplingDeviceChangeHandler(const DeviceGUI *deviceGUI, int newDeviceIndex) { - int deviceType = (int) deviceGUI->getDeviceType(); + auto deviceType = (int) deviceGUI->getDeviceType(); int deviceSetIndex = deviceGUI->getIndex(); Workspace *workspace = m_workspaces[deviceGUI->getWorkspaceIndex()]; sampleDeviceChange(deviceType, deviceSetIndex, newDeviceIndex, workspace); @@ -2425,7 +2368,6 @@ void MainWindow::sampleSourceChange(int deviceSetIndex, int newDeviceIndex, Work DeviceUISet *deviceUISet = m_deviceUIs[deviceSetIndex]; QPoint p = deviceUISet->m_deviceGUI->pos(); workspace->removeFromMdiArea(deviceUISet->m_deviceGUI); - // deviceUI->m_deviceAPI->saveSamplingDeviceSettings(m_mainCore->m_settings.getWorkingPreset()); // save old API settings deviceUISet->m_deviceAPI->stopDeviceEngine(); // deletes old UI and input object @@ -2445,7 +2387,7 @@ void MainWindow::sampleSourceChange(int deviceSetIndex, int newDeviceIndex, Work deviceUISet->m_deviceGUI, &DeviceGUI::addChannelEmitted, this, - [=](int channelPluginIndex){ this->channelAddClicked(workspace, deviceSetIndex, channelPluginIndex); } + [this, workspace, deviceSetIndex](int channelPluginIndex){ this->channelAddClicked(workspace, deviceSetIndex, channelPluginIndex); } ); } } @@ -2477,7 +2419,7 @@ void MainWindow::sampleSinkChange(int deviceSetIndex, int newDeviceIndex, Worksp deviceUISet->m_deviceGUI, &DeviceGUI::addChannelEmitted, this, - [=](int channelPluginIndex){ this->channelAddClicked(workspace, deviceSetIndex, channelPluginIndex); } + [this, workspace, deviceSetIndex](int channelPluginIndex){ this->channelAddClicked(workspace, deviceSetIndex, channelPluginIndex); } ); } } @@ -2508,7 +2450,7 @@ void MainWindow::sampleMIMOChange(int deviceSetIndex, int newDeviceIndex, Worksp deviceUISet->m_deviceGUI, &DeviceGUI::addChannelEmitted, this, - [=](int channelPluginIndex){ this->channelAddClicked(workspace, deviceSetIndex, channelPluginIndex); } + [this, workspace, deviceSetIndex](int channelPluginIndex){ this->channelAddClicked(workspace, deviceSetIndex, channelPluginIndex); } ); } } @@ -2550,12 +2492,12 @@ void MainWindow::channelMoveToDeviceSet(ChannelGUI *gui, int dsIndexDestination) } } -void MainWindow::channelDuplicate(ChannelGUI *sourceChannelGUI) +void MainWindow::channelDuplicate(const ChannelGUI *sourceChannelGUI) { channelDuplicateToDeviceSet(sourceChannelGUI, sourceChannelGUI->getDeviceSetIndex()); // Duplicate in same device set } -void MainWindow::channelDuplicateToDeviceSet(ChannelGUI *sourceChannelGUI, int dsIndexDestination) +void MainWindow::channelDuplicateToDeviceSet(const ChannelGUI *sourceChannelGUI, int dsIndexDestination) { int dsIndexSource = sourceChannelGUI->getDeviceSetIndex(); int sourceChannelIndex = sourceChannelGUI->getIndex(); @@ -2566,14 +2508,14 @@ void MainWindow::channelDuplicateToDeviceSet(ChannelGUI *sourceChannelGUI, int d if ((dsIndexSource < (int) m_deviceUIs.size()) && (dsIndexDestination < (int) m_deviceUIs.size())) { DeviceUISet *sourceDeviceUI = m_deviceUIs[dsIndexSource]; - ChannelAPI *sourceChannelAPI = sourceDeviceUI->getChannelAt(sourceChannelIndex); + const ChannelAPI *sourceChannelAPI = sourceDeviceUI->getChannelAt(sourceChannelIndex); ChannelGUI *destChannelGUI = nullptr; DeviceUISet *destDeviceUI = m_deviceUIs[dsIndexDestination]; if (destDeviceUI->m_deviceSourceEngine) // source device => Rx channels { - PluginAPI::ChannelRegistrations *channelRegistrations = m_pluginManager->getRxChannelRegistrations(); - PluginInterface *pluginInterface = nullptr; + const PluginAPI::ChannelRegistrations *channelRegistrations = m_pluginManager->getRxChannelRegistrations(); + const PluginInterface *pluginInterface = nullptr; for (const auto& channelRegistration : *channelRegistrations) { @@ -2586,8 +2528,8 @@ void MainWindow::channelDuplicateToDeviceSet(ChannelGUI *sourceChannelGUI, int d if (pluginInterface) { - ChannelAPI *channelAPI; - BasebandSampleSink *rxChannel; + ChannelAPI *channelAPI = nullptr; + BasebandSampleSink *rxChannel = nullptr; pluginInterface->createRxChannel(destDeviceUI->m_deviceAPI, &rxChannel, &channelAPI); destChannelGUI = pluginInterface->createRxChannelGUI(destDeviceUI, rxChannel); destDeviceUI->registerRxChannelInstance(channelAPI, destChannelGUI); @@ -2599,8 +2541,8 @@ void MainWindow::channelDuplicateToDeviceSet(ChannelGUI *sourceChannelGUI, int d } else if (destDeviceUI->m_deviceSinkEngine) // sink device => Tx channels { - PluginAPI::ChannelRegistrations *channelRegistrations = m_pluginManager->getTxChannelRegistrations(); // Available channel plugins - PluginInterface *pluginInterface = nullptr; + const PluginAPI::ChannelRegistrations *channelRegistrations = m_pluginManager->getTxChannelRegistrations(); // Available channel plugins + const PluginInterface *pluginInterface = nullptr; for (const auto& channelRegistration : *channelRegistrations) { @@ -2614,7 +2556,7 @@ void MainWindow::channelDuplicateToDeviceSet(ChannelGUI *sourceChannelGUI, int d if (pluginInterface) { ChannelAPI *channelAPI; - BasebandSampleSource *txChannel; + BasebandSampleSource *txChannel = nullptr; pluginInterface->createTxChannel(destDeviceUI->m_deviceAPI, &txChannel, &channelAPI); destChannelGUI = pluginInterface->createTxChannelGUI(destDeviceUI, txChannel); destDeviceUI->registerTxChannelInstance(channelAPI, destChannelGUI); @@ -2626,10 +2568,10 @@ void MainWindow::channelDuplicateToDeviceSet(ChannelGUI *sourceChannelGUI, int d } else if (destDeviceUI->m_deviceMIMOEngine) // MIMO device => Any type of channel is possible { - PluginAPI::ChannelRegistrations *rxChannelRegistrations = m_pluginManager->getRxChannelRegistrations(); - PluginAPI::ChannelRegistrations *txChannelRegistrations = m_pluginManager->getTxChannelRegistrations(); - PluginAPI::ChannelRegistrations *mimoChannelRegistrations = m_pluginManager->getMIMOChannelRegistrations(); - PluginInterface *pluginInterface = nullptr; + const PluginAPI::ChannelRegistrations *rxChannelRegistrations = m_pluginManager->getRxChannelRegistrations(); + const PluginAPI::ChannelRegistrations *txChannelRegistrations = m_pluginManager->getTxChannelRegistrations(); + const PluginAPI::ChannelRegistrations *mimoChannelRegistrations = m_pluginManager->getMIMOChannelRegistrations(); + const PluginInterface *pluginInterface = nullptr; for (const auto& channelRegistration : *rxChannelRegistrations) { @@ -2643,7 +2585,7 @@ void MainWindow::channelDuplicateToDeviceSet(ChannelGUI *sourceChannelGUI, int d if (pluginInterface) // Rx channel { ChannelAPI *channelAPI; - BasebandSampleSink *rxChannel; + BasebandSampleSink *rxChannel = nullptr; pluginInterface->createRxChannel(destDeviceUI->m_deviceAPI, &rxChannel, &channelAPI); destChannelGUI = pluginInterface->createRxChannelGUI(destDeviceUI, rxChannel); destDeviceUI->registerRxChannelInstance(channelAPI, destChannelGUI); @@ -2666,7 +2608,7 @@ void MainWindow::channelDuplicateToDeviceSet(ChannelGUI *sourceChannelGUI, int d if (pluginInterface) // Tx channel { ChannelAPI *channelAPI; - BasebandSampleSource *txChannel; + BasebandSampleSource *txChannel = nullptr; pluginInterface->createTxChannel(destDeviceUI->m_deviceAPI, &txChannel, &channelAPI); destChannelGUI = pluginInterface->createTxChannelGUI(destDeviceUI, txChannel); destDeviceUI->registerTxChannelInstance(channelAPI, destChannelGUI); @@ -2689,7 +2631,7 @@ void MainWindow::channelDuplicateToDeviceSet(ChannelGUI *sourceChannelGUI, int d if (pluginInterface) { ChannelAPI *channelAPI; - MIMOChannel *mimoChannel; + MIMOChannel *mimoChannel = nullptr; pluginInterface->createMIMOChannel(destDeviceUI->m_deviceAPI, &mimoChannel, &channelAPI); destChannelGUI = pluginInterface->createMIMOChannelGUI(destDeviceUI, mimoChannel); destDeviceUI->registerChannelInstance(channelAPI, destChannelGUI); @@ -2702,7 +2644,7 @@ void MainWindow::channelDuplicateToDeviceSet(ChannelGUI *sourceChannelGUI, int d } } - DeviceAPI *destDeviceAPI = destDeviceUI->m_deviceAPI; + const DeviceAPI *destDeviceAPI = destDeviceUI->m_deviceAPI; int workspaceIndex = sourceChannelGUI->getWorkspaceIndex(); Workspace *workspace = workspaceIndex < m_workspaces.size() ? m_workspaces[sourceChannelGUI->getWorkspaceIndex()] : nullptr; @@ -2712,19 +2654,19 @@ void MainWindow::channelDuplicateToDeviceSet(ChannelGUI *sourceChannelGUI, int d destChannelGUI, &ChannelGUI::moveToWorkspace, this, - [=](int wsIndexDest){ this->channelMove(destChannelGUI, wsIndexDest); } + [this, destChannelGUI](int wsIndexDest){ this->channelMove(destChannelGUI, wsIndexDest); } ); QObject::connect( destChannelGUI, &ChannelGUI::duplicateChannelEmitted, this, - [=](){ this->channelDuplicate(destChannelGUI); } + [this, destChannelGUI](){ this->channelDuplicate(destChannelGUI); } ); QObject::connect( destChannelGUI, &ChannelGUI::moveToDeviceSet, this, - [=](int dsIndexDest){ this->channelMoveToDeviceSet(destChannelGUI, dsIndexDest); } + [this, destChannelGUI](int dsIndexDest){ this->channelMoveToDeviceSet(destChannelGUI, dsIndexDest); } ); destChannelGUI->setDeviceSetIndex(dsIndexDestination); @@ -2742,15 +2684,15 @@ void MainWindow::channelAddClicked(Workspace *workspace, int deviceSetIndex, int if (deviceSetIndex < (int) m_deviceUIs.size()) { DeviceUISet *deviceUI = m_deviceUIs[deviceSetIndex]; - ChannelGUI *gui = nullptr; + ChannelGUI *gui; ChannelAPI *channelAPI; - DeviceAPI *deviceAPI = deviceUI->m_deviceAPI; + const DeviceAPI *deviceAPI = deviceUI->m_deviceAPI; if (deviceUI->m_deviceSourceEngine) // source device => Rx channels { PluginAPI::ChannelRegistrations *channelRegistrations = m_pluginManager->getRxChannelRegistrations(); // Available channel plugins - PluginInterface *pluginInterface = (*channelRegistrations)[channelPluginIndex].m_plugin; - BasebandSampleSink *rxChannel; + const PluginInterface *pluginInterface = (*channelRegistrations)[channelPluginIndex].m_plugin; + BasebandSampleSink *rxChannel = nullptr; pluginInterface->createRxChannel(deviceUI->m_deviceAPI, &rxChannel, &channelAPI); gui = pluginInterface->createRxChannelGUI(deviceUI, rxChannel); deviceUI->registerRxChannelInstance(channelAPI, gui); @@ -2761,8 +2703,8 @@ void MainWindow::channelAddClicked(Workspace *workspace, int deviceSetIndex, int else if (deviceUI->m_deviceSinkEngine) // sink device => Tx channels { PluginAPI::ChannelRegistrations *channelRegistrations = m_pluginManager->getTxChannelRegistrations(); // Available channel plugins - PluginInterface *pluginInterface = (*channelRegistrations)[channelPluginIndex].m_plugin; - BasebandSampleSource *txChannel; + const PluginInterface *pluginInterface = (*channelRegistrations)[channelPluginIndex].m_plugin; + BasebandSampleSource *txChannel = nullptr; pluginInterface->createTxChannel(deviceUI->m_deviceAPI, &txChannel, &channelAPI); gui = pluginInterface->createTxChannelGUI(deviceUI, txChannel); deviceUI->registerTxChannelInstance(channelAPI, gui); @@ -2781,8 +2723,8 @@ void MainWindow::channelAddClicked(Workspace *workspace, int deviceSetIndex, int if (channelPluginIndex < nbMIMOChannels) { PluginAPI::ChannelRegistrations *channelRegistrations = m_pluginManager->getMIMOChannelRegistrations(); // Available channel plugins - PluginInterface *pluginInterface = (*channelRegistrations)[channelPluginIndex].m_plugin; - MIMOChannel *mimoChannel; + const PluginInterface *pluginInterface = (*channelRegistrations)[channelPluginIndex].m_plugin; + MIMOChannel *mimoChannel = nullptr; pluginInterface->createMIMOChannel(deviceUI->m_deviceAPI, &mimoChannel, &channelAPI); gui = pluginInterface->createMIMOChannelGUI(deviceUI, mimoChannel); deviceUI->registerChannelInstance(channelAPI, gui); @@ -2792,8 +2734,8 @@ void MainWindow::channelAddClicked(Workspace *workspace, int deviceSetIndex, int else if (channelPluginIndex < nbMIMOChannels + nbRxChannels) // Rx { PluginAPI::ChannelRegistrations *channelRegistrations = m_pluginManager->getRxChannelRegistrations(); // Available channel plugins - PluginInterface *pluginInterface = (*channelRegistrations)[channelPluginIndex - nbMIMOChannels].m_plugin; - BasebandSampleSink *rxChannel; + const PluginInterface *pluginInterface = (*channelRegistrations)[channelPluginIndex - nbMIMOChannels].m_plugin; + BasebandSampleSink *rxChannel = nullptr; pluginInterface->createRxChannel(deviceUI->m_deviceAPI, &rxChannel, &channelAPI); gui = pluginInterface->createRxChannelGUI(deviceUI, rxChannel); deviceUI->registerRxChannelInstance(channelAPI, gui); @@ -2803,17 +2745,25 @@ void MainWindow::channelAddClicked(Workspace *workspace, int deviceSetIndex, int else if (channelPluginIndex < nbMIMOChannels + nbRxChannels + nbTxChannels) { PluginAPI::ChannelRegistrations *channelRegistrations = m_pluginManager->getTxChannelRegistrations(); // Available channel plugins - PluginInterface *pluginInterface = (*channelRegistrations)[channelPluginIndex - nbMIMOChannels - nbRxChannels].m_plugin; - BasebandSampleSource *txChannel; + const PluginInterface *pluginInterface = (*channelRegistrations)[channelPluginIndex - nbMIMOChannels - nbRxChannels].m_plugin; + BasebandSampleSource *txChannel = nullptr; pluginInterface->createTxChannel(deviceUI->m_deviceAPI, &txChannel, &channelAPI); gui = pluginInterface->createTxChannelGUI(deviceUI, txChannel); deviceUI->registerTxChannelInstance(channelAPI, gui); gui->setIndex(channelAPI->getIndexInDeviceSet()); gui->setDisplayedame(pluginInterface->getPluginDescriptor().displayedName); } + else + { + return; + } gui->setDeviceType(ChannelGUI::DeviceMIMO); } + else + { + return; + } if (gui) { @@ -2821,19 +2771,19 @@ void MainWindow::channelAddClicked(Workspace *workspace, int deviceSetIndex, int gui, &ChannelGUI::moveToWorkspace, this, - [=](int wsIndexDest){ this->channelMove(gui, wsIndexDest); } + [this, gui](int wsIndexDest){ this->channelMove(gui, wsIndexDest); } ); QObject::connect( gui, &ChannelGUI::duplicateChannelEmitted, this, - [=](){ this->channelDuplicate(gui); } + [this, gui](){ this->channelDuplicate(gui); } ); QObject::connect( gui, &ChannelGUI::moveToDeviceSet, this, - [=](int dsIndexDest){ this->channelMoveToDeviceSet(gui, dsIndexDest); } + [this, gui](int dsIndexDest){ this->channelMoveToDeviceSet(gui, dsIndexDest); } ); gui->setDeviceSetIndex(deviceSetIndex); @@ -2842,7 +2792,6 @@ void MainWindow::channelAddClicked(Workspace *workspace, int deviceSetIndex, int qDebug("MainWindow::channelAddClicked: adding %s to workspace #%d", qPrintable(gui->getTitle()), workspace->getIndex()); workspace->addToMdiArea((QMdiSubWindow*) gui); - //gui->restoreGeometry(gui->getGeometryBytes()); loadDefaultPreset(channelAPI->getURI(), gui); } } @@ -2856,7 +2805,7 @@ void MainWindow::featureAddClicked(Workspace *workspace, int featureIndex) FeatureUISet *featureUISet = m_featureUIs[currentFeatureSetIndex]; qDebug("MainWindow::featureAddClicked: m_apiAdapter: %p", m_apiAdapter); PluginAPI::FeatureRegistrations *featureRegistrations = m_pluginManager->getFeatureRegistrations(); // Available feature plugins - PluginInterface *pluginInterface = (*featureRegistrations)[featureIndex].m_plugin; + const PluginInterface *pluginInterface = (*featureRegistrations)[featureIndex].m_plugin; Feature *feature = pluginInterface->createFeature(m_apiAdapter); FeatureGUI *gui = pluginInterface->createFeatureGUI(featureUISet, feature); featureUISet->registerFeatureInstance(gui, feature); @@ -2870,7 +2819,7 @@ void MainWindow::featureAddClicked(Workspace *workspace, int featureIndex) gui, &FeatureGUI::moveToWorkspace, this, - [=](int wsIndexDest){ this->featureMove(gui, wsIndexDest); } + [this, gui](int wsIndexDest){ this->featureMove(gui, wsIndexDest); } ); } @@ -2962,7 +2911,7 @@ void MainWindow::showAllChannels(int deviceSetIndex) } // Start all devices in the workspace -void MainWindow::startAllDevices(Workspace *workspace) +void MainWindow::startAllDevices(const Workspace *workspace) const { int workspaceIndex = workspace->getIndex(); for (auto deviceUI : m_deviceUIs) @@ -2978,7 +2927,7 @@ void MainWindow::startAllDevices(Workspace *workspace) } // Stop all devices in the workspace -void MainWindow::stopAllDevices(Workspace *workspace) +void MainWindow::stopAllDevices(const Workspace *workspace) const { int workspaceIndex = workspace->getIndex(); for (auto deviceUI : m_deviceUIs) @@ -3019,13 +2968,13 @@ void MainWindow::openFeaturePresetsDialog(QPoint p, Workspace *workspace) gui, &FeatureGUI::moveToWorkspace, this, - [=](int wsIndexDest){ this->featureMove(gui, wsIndexDest); } + [this, gui](int wsIndexDest){ this->featureMove(gui, wsIndexDest); } ); } } } -void MainWindow::openDeviceSetPresetsDialog(QPoint p, DeviceGUI *deviceGUI) +void MainWindow::openDeviceSetPresetsDialog(QPoint p, const DeviceGUI *deviceGUI) { Workspace *workspace = m_workspaces[deviceGUI->getWorkspaceIndex()]; DeviceUISet *deviceUISet = m_deviceUIs[deviceGUI->getIndex()]; @@ -3054,7 +3003,7 @@ void MainWindow::deleteFeature(int featureSetIndex, int featureIndex) // Look for and load a preset named Defaults/Default for the given plugin id void MainWindow::loadDefaultPreset(const QString& pluginId, SerializableInterface *serializableInterface) { - QList* presets = m_mainCore->m_settings.getPluginPresets(); + const QList* presets = m_mainCore->m_settings.getPluginPresets(); for (const auto preset : *presets) { @@ -3081,7 +3030,7 @@ void MainWindow::updateStatus() } } -void MainWindow::commandKeyPressed(Qt::Key key, Qt::KeyboardModifiers keyModifiers, bool release) +void MainWindow::commandKeyPressed(Qt::Key key, Qt::KeyboardModifiers keyModifiers, bool release) const { qDebug("MainWindow::commandKeyPressed: key: %x mod: %x %s", (int) key, (int) keyModifiers, release ? "release" : "press"); int currentDeviceSetIndex = 0; @@ -3095,7 +3044,7 @@ void MainWindow::commandKeyPressed(Qt::Key key, Qt::KeyboardModifiers keyModifie && (command->getKey() == key) && (command->getKeyModifiers() == keyModifiers)) { - Command* command_mod = const_cast(command); + auto* command_mod = const_cast(command); command_mod->run(m_apiServer->getHost(), m_apiServer->getPort(), currentDeviceSetIndex); } } @@ -3116,7 +3065,7 @@ void MainWindow::keyPressEvent(QKeyEvent* event) } } -void MainWindow::orientationChanged(Qt::ScreenOrientation orientation) +void MainWindow::orientationChanged(Qt::ScreenOrientation orientation) const { #ifdef ANDROID // Adjust workspace tab position, to leave max space for MDI windows diff --git a/sdrgui/mainwindow.h b/sdrgui/mainwindow.h index 27605b4ed..edbf94f89 100644 --- a/sdrgui/mainwindow.h +++ b/sdrgui/mainwindow.h @@ -69,27 +69,23 @@ class SerializableInterface; class QMenuBar; class Workspace; -// namespace Ui { -// class MainWindow; -// } - class SDRGUI_API MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(qtwebapp::LoggerWithFile *logger, const MainParser& parser, QWidget* parent = nullptr); - ~MainWindow(); + ~MainWindow() final; static MainWindow *getInstance() { return m_instance; } // Main Window is de facto a singleton so this just returns its reference MessageQueue* getInputMessageQueue() { return &m_inputMessageQueue; } const PluginManager *getPluginManager() const { return m_pluginManager; } std::vector& getDeviceUISets() { return m_deviceUIs; } - void commandKeysConnect(QObject *object, const char *slot); - void commandKeysDisconnect(QObject *object, const char *slot); + void commandKeysConnect(const QObject *object, const char *slot); + void commandKeysDisconnect(const QObject *object, const char *slot) const; int getNumberOfWorkspaces() const { return m_workspaces.size(); } public slots: void channelMove(ChannelGUI *gui, int wsIndexDestination); - void channelDuplicate(ChannelGUI *gui); + void channelDuplicate(const ChannelGUI *gui); void channelMoveToDeviceSet(ChannelGUI *gui, int dsIndexDestination); private: @@ -101,14 +97,13 @@ private: struct DeviceWidgetTabData { QWidget *gui; - QString displayName; - QString tabName; + QString displayName; + QString tabName; }; static MainWindow *m_instance; QList m_workspaces; Workspace *m_currentWorkspace; - // Ui::MainWindow* ui; MessageQueue m_inputMessageQueue; MainCore *m_mainCore; std::vector m_deviceUIs; @@ -143,10 +138,10 @@ private: void loadFeatureSetPresetSettings(const FeatureSetPreset* preset, int featureSetIndex, Workspace *workspace); void saveFeatureSetPresetSettings(FeatureSetPreset* preset, int featureSetIndex); - QString openGLVersion(); - void createMenuBar(QToolButton *button); + QString openGLVersion() const; + void createMenuBar(QToolButton *button) const; void createStatusBar(); - void closeEvent(QCloseEvent*); + void closeEvent(QCloseEvent*) final; void applySettings(); void removeDeviceSet(int deviceSetIndex); @@ -155,7 +150,7 @@ private: void removeFeatureSet(unsigned int featureSetIndex); void removeAllFeatureSets(); void deleteChannel(int deviceSetIndex, int channelIndex); - void channelDuplicateToDeviceSet(ChannelGUI *sourceChannelGUI, int dsIndexDestination); + void channelDuplicateToDeviceSet(const ChannelGUI *sourceChannelGUI, int dsIndexDestination); void sampleDeviceChange(int deviceType, int deviceSetIndex, int newDeviceIndex, Workspace *workspace); void sampleSourceChange(int deviceSetIndex, int newDeviceIndex, Workspace *workspace); void sampleSinkChange(int deviceSetIndex, int newDeviceIndex, Workspace *workspace); @@ -181,7 +176,7 @@ private: bool handleMessage(const Message& cmd); protected: - virtual void keyPressEvent(QKeyEvent* event) override; + void keyPressEvent(QKeyEvent* event) override; private slots: void handleMessages(); @@ -202,39 +197,39 @@ private slots: void on_action_My_Position_triggered(); void on_action_DeviceUserArguments_triggered(); void on_action_commands_triggered(); - void on_action_Quick_Start_triggered(); - void on_action_Main_Window_triggered(); + void on_action_Quick_Start_triggered() const; + void on_action_Main_Window_triggered() const; void on_action_Loaded_Plugins_triggered(); void on_action_About_triggered(); void updateStatus(); void addWorkspace(); - void viewAllWorkspaces(); + void viewAllWorkspaces() const; void removeEmptyWorkspaces(); void openConfigurationDialog(bool openOnly); - void loadDefaultConfigurations(); + void loadDefaultConfigurations() const; void loadConfiguration(const Configuration *configuration, bool fromDialog = false); void saveConfiguration(Configuration *configuration); void sampleSourceAdd(Workspace *deviceWorkspace, Workspace *spectrumWorkspace, int deviceIndex); void sampleSinkAdd(Workspace *workspace, Workspace *spectrumWorkspace, int deviceIndex); void sampleMIMOAdd(Workspace *workspace, Workspace *spectrumWorkspace, int deviceIndex); - void samplingDeviceChangeHandler(DeviceGUI *deviceGUI, int newDeviceIndex); + void samplingDeviceChangeHandler(const DeviceGUI *deviceGUI, int newDeviceIndex); void channelAddClicked(Workspace *workspace, int deviceSetIndex, int channelPluginIndex); void featureAddClicked(Workspace *workspace, int featureIndex); void featureMove(FeatureGUI *gui, int wsIndexDestnation); void deviceStateChanged(DeviceAPI *deviceAPI); void openFeaturePresetsDialog(QPoint p, Workspace *workspace); - void startAllDevices(Workspace *workspace); - void stopAllDevices(Workspace *workspace); + void startAllDevices(const Workspace *workspace) const; + void stopAllDevices(const Workspace *workspace) const; void deviceMove(DeviceGUI *gui, int wsIndexDestnation); void mainSpectrumMove(MainSpectrumGUI *gui, int wsIndexDestnation); void mainSpectrumShow(int deviceSetIndex); void mainSpectrumRequestDeviceCenterFrequency(int deviceSetIndex, qint64 deviceCenterFrequency); void showAllChannels(int deviceSetIndex); - void openDeviceSetPresetsDialog(QPoint p, DeviceGUI *deviceGUI); - void commandKeyPressed(Qt::Key key, Qt::KeyboardModifiers keyModifiers, bool release); + void openDeviceSetPresetsDialog(QPoint p, const DeviceGUI *deviceGUI); + void commandKeyPressed(Qt::Key key, Qt::KeyboardModifiers keyModifiers, bool release) const; void fftWisdomProcessFinished(int exitCode, QProcess::ExitStatus exitStatus); - void orientationChanged(Qt::ScreenOrientation orientation); + void orientationChanged(Qt::ScreenOrientation orientation) const; }; #endif // INCLUDE_MAINWINDOW_H diff --git a/sdrsrv/mainserver.cpp b/sdrsrv/mainserver.cpp index da49095cd..ae6ed5e0e 100644 --- a/sdrsrv/mainserver.cpp +++ b/sdrsrv/mainserver.cpp @@ -43,7 +43,7 @@ #include "mainparser.h" #include "mainserver.h" -MainServer *MainServer::m_instance = 0; +MainServer *MainServer::m_instance = nullptr; MainServer::MainServer(qtwebapp::LoggerWithFile *logger, const MainParser& parser, QObject *parent) : QObject(parent), @@ -74,7 +74,7 @@ MainServer::MainServer(qtwebapp::LoggerWithFile *logger, const MainParser& parse loadSettings(); qDebug() << "MainServer::MainServer: finishing..."; - QString applicationDirPath = QCoreApplication::instance()->applicationDirPath(); + QString applicationDirPath = QCoreApplication::applicationDirPath(); m_apiAdapter = new WebAPIAdapter(); m_requestMapper = new WebAPIRequestMapper(this); @@ -89,7 +89,7 @@ MainServer::MainServer(qtwebapp::LoggerWithFile *logger, const MainParser& parse MainServer::~MainServer() { - while (m_mainCore->m_deviceSets.size() > 0) { + while (!m_mainCore->m_deviceSets.empty()) { removeLastDevice(); } @@ -108,7 +108,7 @@ bool MainServer::handleMessage(const Message& cmd) { if (MainCore::MsgDeleteInstance::match(cmd)) { - while (m_mainCore->m_deviceSets.size() > 0) + while (!m_mainCore->m_deviceSets.empty()) { removeLastDevice(); } @@ -118,13 +118,13 @@ bool MainServer::handleMessage(const Message& cmd) } else if (MainCore::MsgLoadPreset::match(cmd)) { - MainCore::MsgLoadPreset& notif = (MainCore::MsgLoadPreset&) cmd; + auto& notif = (const MainCore::MsgLoadPreset&) cmd; loadPresetSettings(notif.getPreset(), notif.getDeviceSetIndex()); return true; } else if (MainCore::MsgSavePreset::match(cmd)) { - MainCore::MsgSavePreset& notif = (MainCore::MsgSavePreset&) cmd; + auto& notif = (const MainCore::MsgSavePreset&) cmd; savePresetSettings(notif.getPreset(), notif.getDeviceSetIndex()); m_mainCore->m_settings.sortPresets(); m_mainCore->m_settings.save(); @@ -132,7 +132,7 @@ bool MainServer::handleMessage(const Message& cmd) } else if (MainCore::MsgDeletePreset::match(cmd)) { - MainCore::MsgDeletePreset& notif = (MainCore::MsgDeletePreset&) cmd; + auto& notif = (const MainCore::MsgDeletePreset&) cmd; const Preset *presetToDelete = notif.getPreset(); // remove preset from settings m_mainCore->m_settings.deletePreset(presetToDelete); @@ -140,7 +140,7 @@ bool MainServer::handleMessage(const Message& cmd) } else if (MainCore::MsgDeleteConfiguration::match(cmd)) { - MainCore::MsgDeleteConfiguration& notif = (MainCore::MsgDeleteConfiguration&) cmd; + auto& notif = (const MainCore::MsgDeleteConfiguration&) cmd; const Configuration *configuationToDelete = notif.getConfiguration(); // remove configuration from settings m_mainCore->m_settings.deleteConfiguration(configuationToDelete); @@ -148,13 +148,13 @@ bool MainServer::handleMessage(const Message& cmd) } else if (MainCore::MsgLoadFeatureSetPreset::match(cmd)) { - MainCore::MsgLoadFeatureSetPreset& notif = (MainCore::MsgLoadFeatureSetPreset&) cmd; + auto& notif = (const MainCore::MsgLoadFeatureSetPreset&) cmd; loadFeatureSetPresetSettings(notif.getPreset(), notif.getFeatureSetIndex()); return true; } else if (MainCore::MsgSaveFeatureSetPreset::match(cmd)) { - MainCore::MsgSaveFeatureSetPreset& notif = (MainCore::MsgSaveFeatureSetPreset&) cmd; + auto& notif = (const MainCore::MsgSaveFeatureSetPreset&) cmd; saveFeatureSetPresetSettings(notif.getPreset(), notif.getFeatureSetIndex()); m_mainCore->m_settings.sortPresets(); m_mainCore->m_settings.save(); @@ -162,7 +162,7 @@ bool MainServer::handleMessage(const Message& cmd) } else if (MainCore::MsgDeleteFeatureSetPreset::match(cmd)) { - MainCore::MsgDeleteFeatureSetPreset& notif = (MainCore::MsgDeleteFeatureSetPreset&) cmd; + auto& notif = (const MainCore::MsgDeleteFeatureSetPreset&) cmd; const FeatureSetPreset *presetToDelete = notif.getPreset(); // remove preset from settings m_mainCore->m_settings.deleteFeatureSetPreset(presetToDelete); @@ -170,7 +170,7 @@ bool MainServer::handleMessage(const Message& cmd) } else if (MainCore::MsgAddDeviceSet::match(cmd)) { - MainCore::MsgAddDeviceSet& notif = (MainCore::MsgAddDeviceSet&) cmd; + auto& notif = (const MainCore::MsgAddDeviceSet&) cmd; int direction = notif.getDirection(); if (direction == 1) { // Single stream Tx @@ -185,7 +185,7 @@ bool MainServer::handleMessage(const Message& cmd) } else if (MainCore::MsgRemoveLastDeviceSet::match(cmd)) { - if (m_mainCore->m_deviceSets.size() > 0) { + if (!m_mainCore->m_deviceSets.empty()) { removeLastDevice(); } @@ -193,7 +193,7 @@ bool MainServer::handleMessage(const Message& cmd) } else if (MainCore::MsgSetDevice::match(cmd)) { - MainCore::MsgSetDevice& notif = (MainCore::MsgSetDevice&) cmd; + auto& notif = (const MainCore::MsgSetDevice&) cmd; if (notif.getDeviceType() == 1) { changeSampleSink(notif.getDeviceSetIndex(), notif.getDeviceIndex()); @@ -206,26 +206,26 @@ bool MainServer::handleMessage(const Message& cmd) } else if (MainCore::MsgAddChannel::match(cmd)) { - MainCore::MsgAddChannel& notif = (MainCore::MsgAddChannel&) cmd; + auto& notif = (const MainCore::MsgAddChannel&) cmd; addChannel(notif.getDeviceSetIndex(), notif.getChannelRegistrationIndex()); return true; } else if (MainCore::MsgDeleteChannel::match(cmd)) { - MainCore::MsgDeleteChannel& notif = (MainCore::MsgDeleteChannel&) cmd; + auto& notif = (const MainCore::MsgDeleteChannel&) cmd; deleteChannel(notif.getDeviceSetIndex(), notif.getChannelIndex()); return true; } else if (MainCore::MsgAddFeature::match(cmd)) { - MainCore::MsgAddFeature& notif = (MainCore::MsgAddFeature&) cmd; + auto& notif = (const MainCore::MsgAddFeature&) cmd; addFeature(0, notif.getFeatureRegistrationIndex()); return true; } else if (MainCore::MsgDeleteFeature::match(cmd)) { - MainCore::MsgDeleteFeature& notif = (MainCore::MsgDeleteFeature&) cmd; + auto& notif = (const MainCore::MsgDeleteFeature&) cmd; deleteFeature(0, notif.getFeatureIndex()); return true; } @@ -244,7 +244,7 @@ void MainServer::handleMessages() { Message* message; - while ((message = m_inputMessageQueue.pop()) != 0) + while ((message = m_inputMessageQueue.pop()) != nullptr) { qDebug("MainServer::handleMessages: message: %s", message->getIdentifier()); handleMessage(*message); @@ -271,21 +271,14 @@ void MainServer::addSinkDevice() { DSPDeviceSinkEngine *dspDeviceSinkEngine = m_dspEngine->addDeviceSinkEngine(); - uint dspDeviceSinkEngineUID = dspDeviceSinkEngine->getUID(); - char uidCStr[16]; - sprintf(uidCStr, "UID:%d", dspDeviceSinkEngineUID); - - int deviceTabIndex = m_mainCore->m_deviceSets.size(); + auto deviceTabIndex = (int) m_mainCore->m_deviceSets.size(); m_mainCore->m_deviceSets.push_back(new DeviceSet(deviceTabIndex, 1)); m_mainCore->m_deviceSets.back()->m_deviceSourceEngine = nullptr; m_mainCore->m_deviceSets.back()->m_deviceSinkEngine = dspDeviceSinkEngine; m_mainCore->m_deviceSets.back()->m_deviceMIMOEngine = nullptr; dspDeviceSinkEngine->addSpectrumSink(m_mainCore->m_deviceSets.back()->m_spectrumVis); - char tabNameCStr[16]; - sprintf(tabNameCStr, "T%d", deviceTabIndex); - - DeviceAPI *deviceAPI = new DeviceAPI(DeviceAPI::StreamSingleTx, deviceTabIndex, nullptr, dspDeviceSinkEngine, nullptr); + auto *deviceAPI = new DeviceAPI(DeviceAPI::StreamSingleTx, deviceTabIndex, nullptr, dspDeviceSinkEngine, nullptr); m_mainCore->m_deviceSets.back()->m_deviceAPI = deviceAPI; QList channelNames; @@ -318,14 +311,14 @@ void MainServer::addSourceDevice() { DSPDeviceSourceEngine *dspDeviceSourceEngine = m_dspEngine->addDeviceSourceEngine(); - int deviceTabIndex = m_mainCore->m_deviceSets.size(); + auto deviceTabIndex = (int) m_mainCore->m_deviceSets.size(); m_mainCore->m_deviceSets.push_back(new DeviceSet(deviceTabIndex, 0)); m_mainCore->m_deviceSets.back()->m_deviceSourceEngine = dspDeviceSourceEngine; m_mainCore->m_deviceSets.back()->m_deviceSinkEngine = nullptr; m_mainCore->m_deviceSets.back()->m_deviceMIMOEngine = nullptr; dspDeviceSourceEngine->addSink(m_mainCore->m_deviceSets.back()->m_spectrumVis); - DeviceAPI *deviceAPI = new DeviceAPI(DeviceAPI::StreamSingleRx, deviceTabIndex, dspDeviceSourceEngine, nullptr, nullptr); + auto *deviceAPI = new DeviceAPI(DeviceAPI::StreamSingleRx, deviceTabIndex, dspDeviceSourceEngine, nullptr, nullptr); m_mainCore->m_deviceSets.back()->m_deviceAPI = deviceAPI; @@ -357,14 +350,14 @@ void MainServer::addMIMODevice() { DSPDeviceMIMOEngine *dspDeviceMIMOEngine = m_dspEngine->addDeviceMIMOEngine(); - int deviceTabIndex = m_mainCore->m_deviceSets.size(); + auto deviceTabIndex = (int) m_mainCore->m_deviceSets.size(); m_mainCore->m_deviceSets.push_back(new DeviceSet(deviceTabIndex, 2)); m_mainCore->m_deviceSets.back()->m_deviceSourceEngine = nullptr; m_mainCore->m_deviceSets.back()->m_deviceSinkEngine = nullptr; m_mainCore->m_deviceSets.back()->m_deviceMIMOEngine = dspDeviceMIMOEngine; dspDeviceMIMOEngine->addSpectrumSink(m_mainCore->m_deviceSets.back()->m_spectrumVis); - DeviceAPI *deviceAPI = new DeviceAPI(DeviceAPI::StreamMIMO, deviceTabIndex, nullptr, nullptr, dspDeviceMIMOEngine); + auto *deviceAPI = new DeviceAPI(DeviceAPI::StreamMIMO, deviceTabIndex, nullptr, nullptr, dspDeviceMIMOEngine); // create a test MIMO by default int testMIMODeviceIndex = DeviceEnumerator::instance()->getTestMIMODeviceIndex(); @@ -392,12 +385,10 @@ void MainServer::addMIMODevice() void MainServer::removeLastDevice() { - int removedTabIndex = m_mainCore->m_deviceSets.size() - 1; + auto removedTabIndex = (int) (m_mainCore->m_deviceSets.size() - 1); if (m_mainCore->m_deviceSets.back()->m_deviceSourceEngine) // source set { - DSPDeviceSourceEngine *lastDeviceEngine = m_mainCore->m_deviceSets.back()->m_deviceSourceEngine; - // deletes old UI and input object m_mainCore->m_deviceSets.back()->freeChannels(); // destroys the channel instances m_mainCore->m_deviceSets.back()->m_deviceAPI->resetSamplingDeviceId(); @@ -412,8 +403,6 @@ void MainServer::removeLastDevice() } else if (m_mainCore->m_deviceSets.back()->m_deviceSinkEngine) // sink set { - DSPDeviceSinkEngine *lastDeviceEngine = m_mainCore->m_deviceSets.back()->m_deviceSinkEngine; - // deletes old UI and output object m_mainCore->m_deviceSets.back()->freeChannels(); m_mainCore->m_deviceSets.back()->m_deviceAPI->resetSamplingDeviceId(); @@ -428,8 +417,6 @@ void MainServer::removeLastDevice() } else if (m_mainCore->m_deviceSets.back()->m_deviceMIMOEngine) // MIMO set { - DSPDeviceMIMOEngine *lastDeviceEngine = m_mainCore->m_deviceSets.back()->m_deviceMIMOEngine; - m_mainCore->m_deviceSets.back()->freeChannels(); m_mainCore->m_deviceSets.back()->m_deviceAPI->resetSamplingDeviceId(); @@ -486,19 +473,17 @@ void MainServer::changeSampleSource(int deviceSetIndex, int selectedDeviceIndex) } // add to buddies list - std::vector::iterator it = m_mainCore->m_deviceSets.begin(); + auto it = m_mainCore->m_deviceSets.begin(); int nbOfBuddies = 0; for (; it != m_mainCore->m_deviceSets.end(); ++it) { - if (*it != deviceSet) // do not add to itself + if ((*it != deviceSet) && // do not add to itself + (deviceSet->m_deviceAPI->getHardwareId() == (*it)->m_deviceAPI->getHardwareId()) && + (deviceSet->m_deviceAPI->getSamplingDeviceSerial() == (*it)->m_deviceAPI->getSamplingDeviceSerial())) { - if ((deviceSet->m_deviceAPI->getHardwareId() == (*it)->m_deviceAPI->getHardwareId()) && - (deviceSet->m_deviceAPI->getSamplingDeviceSerial() == (*it)->m_deviceAPI->getSamplingDeviceSerial())) - { - (*it)->m_deviceAPI->addBuddy(deviceSet->m_deviceAPI); - nbOfBuddies++; - } + (*it)->m_deviceAPI->addBuddy(deviceSet->m_deviceAPI); + nbOfBuddies++; } } @@ -547,7 +532,7 @@ void MainServer::changeSampleSink(int deviceSetIndex, int selectedDeviceIndex) { qDebug("MainServer::changeSampleSink: non existent device replaced by File Sink"); int fileSinkDeviceIndex = DeviceEnumerator::instance()->getFileOutputDeviceIndex(); - const PluginInterface::SamplingDevice *samplingDevice = DeviceEnumerator::instance()->getTxSamplingDevice(fileSinkDeviceIndex); + samplingDevice = DeviceEnumerator::instance()->getTxSamplingDevice(fileSinkDeviceIndex); deviceSet->m_deviceAPI->setSamplingDeviceSequence(samplingDevice->sequence); deviceSet->m_deviceAPI->setDeviceNbItems(samplingDevice->deviceNbItems); deviceSet->m_deviceAPI->setDeviceItemIndex(samplingDevice->deviceItemIndex); @@ -559,19 +544,17 @@ void MainServer::changeSampleSink(int deviceSetIndex, int selectedDeviceIndex) } // add to buddies list - std::vector::iterator it = m_mainCore->m_deviceSets.begin(); + auto it = m_mainCore->m_deviceSets.begin(); int nbOfBuddies = 0; for (; it != m_mainCore->m_deviceSets.end(); ++it) { - if (*it != deviceSet) // do not add to itself + if ((deviceSet->m_deviceAPI->getHardwareId() == (*it)->m_deviceAPI->getHardwareId()) && + (deviceSet->m_deviceAPI->getSamplingDeviceSerial() == (*it)->m_deviceAPI->getSamplingDeviceSerial()) && + (*it != deviceSet)) // do not add to itself { - if ((deviceSet->m_deviceAPI->getHardwareId() == (*it)->m_deviceAPI->getHardwareId()) && - (deviceSet->m_deviceAPI->getSamplingDeviceSerial() == (*it)->m_deviceAPI->getSamplingDeviceSerial())) - { - (*it)->m_deviceAPI->addBuddy(deviceSet->m_deviceAPI); - nbOfBuddies++; - } + (*it)->m_deviceAPI->addBuddy(deviceSet->m_deviceAPI); + nbOfBuddies++; } } @@ -616,7 +599,7 @@ void MainServer::changeSampleMIMO(int deviceSetIndex, int selectedDeviceIndex) { qDebug("MainServer::changeSampleMIMO: non existent device replaced by Test MIMO"); int testMIMODeviceIndex = DeviceEnumerator::instance()->getTestMIMODeviceIndex(); - const PluginInterface::SamplingDevice *samplingDevice = DeviceEnumerator::instance()->getMIMOSamplingDevice(testMIMODeviceIndex); + samplingDevice = DeviceEnumerator::instance()->getMIMOSamplingDevice(testMIMODeviceIndex); deviceSet->m_deviceAPI->setSamplingDeviceSequence(samplingDevice->sequence); deviceSet->m_deviceAPI->setDeviceNbItems(samplingDevice->deviceNbItems); deviceSet->m_deviceAPI->setDeviceItemIndex(samplingDevice->deviceItemIndex); @@ -671,7 +654,7 @@ void MainServer::deleteChannel(int deviceSetIndex, int channelIndex) void MainServer::addFeatureSet() { m_mainCore->appendFeatureSet(); - emit m_mainCore->featureSetAdded(m_mainCore->getFeatureeSets().size() - 1); + emit m_mainCore->featureSetAdded((int) (m_mainCore->getFeatureeSets().size() - 1)); } void MainServer::removeFeatureSet(unsigned int featureSetIndex) From a014491e61362fa26162c3aca4962b52ef266e00 Mon Sep 17 00:00:00 2001 From: f4exb Date: Sun, 25 Aug 2024 00:41:39 +0200 Subject: [PATCH 15/16] Removed the destroy method from ChannelGUI interface --- sdrgui/channel/channelgui.h | 5 ++--- sdrgui/device/deviceuiset.cpp | 10 +++++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/sdrgui/channel/channelgui.h b/sdrgui/channel/channelgui.h index bd733c7ee..037133262 100644 --- a/sdrgui/channel/channelgui.h +++ b/sdrgui/channel/channelgui.h @@ -56,9 +56,8 @@ public: ContextMenuChannelSettings }; - ChannelGUI(QWidget *parent = nullptr); - virtual ~ChannelGUI(); - virtual void destroy() = 0; + explicit ChannelGUI(QWidget *parent = nullptr); + ~ChannelGUI() override; virtual void resetToDefaults() = 0; // Data saved in the derived settings diff --git a/sdrgui/device/deviceuiset.cpp b/sdrgui/device/deviceuiset.cpp index 3c83f1dac..b5a12705a 100644 --- a/sdrgui/device/deviceuiset.cpp +++ b/sdrgui/device/deviceuiset.cpp @@ -166,7 +166,7 @@ void DeviceUISet::freeChannels() for(int i = 0; i < m_channelInstanceRegistrations.count(); i++) { qDebug("DeviceUISet::freeChannels: destroying channel [%s]", qPrintable(m_channelInstanceRegistrations[i].m_channelAPI->getURI())); - m_channelInstanceRegistrations[i].m_gui->destroy(); + delete m_channelInstanceRegistrations[i].m_gui; delete m_channelInstanceRegistrations[i].m_channelAPI; } @@ -181,7 +181,7 @@ void DeviceUISet::deleteChannel(int channelIndex) qDebug("DeviceUISet::deleteChannel: delete channel [%s] at %d", qPrintable(m_channelInstanceRegistrations[channelIndex].m_channelAPI->getURI()), channelIndex); - m_channelInstanceRegistrations[channelIndex].m_gui->destroy(); + delete m_channelInstanceRegistrations[channelIndex].m_gui; delete m_channelInstanceRegistrations[channelIndex].m_channelAPI; m_channelInstanceRegistrations.removeAt(channelIndex); } @@ -320,7 +320,7 @@ void DeviceUISet::loadRxChannelSettings(const Preset *preset, PluginAPI *pluginA qDebug("DeviceUISet::loadRxChannelSettings: destroying old channel [%s]", qPrintable(m_channelInstanceRegistrations[i].m_channelAPI->getURI())); m_channelInstanceRegistrations[i].m_channelAPI->setMessageQueueToGUI(nullptr); // have channel stop sending messages to its GUI - m_channelInstanceRegistrations[i].m_gui->destroy(); + delete m_channelInstanceRegistrations[i].m_gui; delete m_channelInstanceRegistrations[i].m_channelAPI; } @@ -449,7 +449,7 @@ void DeviceUISet::loadTxChannelSettings(const Preset *preset, PluginAPI *pluginA qDebug("DeviceUISet::loadTxChannelSettings: destroying old channel [%s]", qPrintable(m_channelInstanceRegistrations[i].m_channelAPI->getURI())); m_channelInstanceRegistrations[i].m_channelAPI->setMessageQueueToGUI(nullptr); // have channel stop sending messages to its GUI - m_channelInstanceRegistrations[i].m_gui->destroy(); + delete m_channelInstanceRegistrations[i].m_gui; delete m_channelInstanceRegistrations[i].m_channelAPI; } @@ -575,7 +575,7 @@ void DeviceUISet::loadMIMOChannelSettings(const Preset *preset, PluginAPI *plugi { qDebug("DeviceUISet::loadMIMOChannelSettings: destroying old channel [%s]", qPrintable(m_channelInstanceRegistrations[i].m_channelAPI->getURI())); - m_channelInstanceRegistrations[i].m_gui->destroy(); // stop GUI first (issue #1427) + delete m_channelInstanceRegistrations[i].m_gui; // stop GUI first (issue #1427) delete m_channelInstanceRegistrations[i].m_channelAPI; // stop channel before (issue #860) } From b3215ce3d6767bd4df4e3015d3a8dd75a595da68 Mon Sep 17 00:00:00 2001 From: f4exb Date: Sun, 25 Aug 2024 23:36:46 +0200 Subject: [PATCH 16/16] Removed destroy method leftovers and Sonar lint --- .../beamsteeringcwmod/beamsteeringcwmod.cpp | 49 ++++---- .../beamsteeringcwmod/beamsteeringcwmod.h | 97 ++++++++------- .../beamsteeringcwmodgui.cpp | 29 ++--- .../beamsteeringcwmod/beamsteeringcwmodgui.h | 41 ++++--- plugins/channelmimo/doa2/doa2.cpp | 92 +++++++-------- plugins/channelmimo/doa2/doa2.h | 111 +++++++++--------- plugins/channelmimo/doa2/doa2baseband.h | 14 +-- plugins/channelmimo/doa2/doa2gui.cpp | 47 ++++---- plugins/channelmimo/doa2/doa2gui.h | 41 ++++--- .../interferometer/interferometer.cpp | 54 ++++----- .../interferometer/interferometer.h | 90 +++++++------- .../interferometer/interferometergui.cpp | 40 +++---- .../interferometer/interferometergui.h | 43 ++++--- .../channelrx/chanalyzer/chanalyzergui.cpp | 2 +- plugins/channelrx/channelpower/channelpower.h | 5 - .../channelpower/channelpowergui.cpp | 2 +- plugins/channelrx/demodadsb/adsbdemod.h | 2 +- plugins/channelrx/demodadsb/adsbdemodgui.cpp | 2 +- plugins/channelrx/demodais/aisdemod.h | 4 - plugins/channelrx/demodais/aisdemodgui.cpp | 2 +- plugins/channelrx/demodam/amdemodgui.cpp | 2 +- plugins/channelrx/demodapt/aptdemodgui.cpp | 2 +- plugins/channelrx/demodatv/atvdemodgui.cpp | 2 +- plugins/channelrx/demodbfm/bfmdemodgui.cpp | 2 +- .../demodchirpchat/chirpchatdemodgui.cpp | 2 +- plugins/channelrx/demoddab/dabdemod.h | 4 - plugins/channelrx/demoddab/dabdemodgui.cpp | 2 +- plugins/channelrx/demoddatv/datvdemodgui.cpp | 2 +- plugins/channelrx/demoddsc/dscdemod.h | 4 - plugins/channelrx/demoddsc/dscdemodgui.cpp | 2 +- plugins/channelrx/demoddsd/dsddemodgui.cpp | 2 +- .../demodendoftrain/endoftraindemod.h | 4 - .../demodendoftrain/endoftraindemodgui.cpp | 2 +- .../channelrx/demodfreedv/freedvdemodgui.cpp | 2 +- plugins/channelrx/demodft8/ft8demod.h | 2 +- plugins/channelrx/demodft8/ft8demodgui.cpp | 2 +- plugins/channelrx/demodils/ilsdemod.h | 4 - plugins/channelrx/demodils/ilsdemodgui.cpp | 2 +- plugins/channelrx/demodm17/m17demodgui.cpp | 2 +- plugins/channelrx/demodnavtex/navtexdemod.h | 4 - .../channelrx/demodnavtex/navtexdemodgui.cpp | 2 +- plugins/channelrx/demodnfm/nfmdemod.h | 1 - plugins/channelrx/demodnfm/nfmdemodgui.cpp | 2 +- plugins/channelrx/demodpacket/packetdemod.h | 4 - .../channelrx/demodpacket/packetdemodgui.cpp | 2 +- plugins/channelrx/demodpager/pagerdemod.h | 4 - .../channelrx/demodpager/pagerdemodgui.cpp | 2 +- .../demodradiosonde/radiosondedemodgui.cpp | 2 +- plugins/channelrx/demodrtty/rttydemod.h | 4 - plugins/channelrx/demodrtty/rttydemodgui.cpp | 2 +- plugins/channelrx/demodssb/ssbdemod.h | 2 +- plugins/channelrx/demodssb/ssbdemodgui.cpp | 2 +- plugins/channelrx/demodvor/vordemodgui.cpp | 2 +- plugins/channelrx/demodvormc/vordemodmc.h | 2 +- .../channelrx/demodvormc/vordemodmcgui.cpp | 2 +- plugins/channelrx/demodwfm/wfmdemodgui.cpp | 2 +- plugins/channelrx/filesink/filesink.h | 2 +- plugins/channelrx/filesink/filesinkgui.cpp | 2 +- plugins/channelrx/freqscanner/freqscanner.h | 2 +- .../channelrx/freqscanner/freqscannergui.cpp | 2 +- .../channelrx/freqtracker/freqtrackergui.cpp | 2 +- plugins/channelrx/heatmap/heatmap.h | 5 - plugins/channelrx/heatmap/heatmapgui.cpp | 2 +- plugins/channelrx/localsink/localsinkgui.cpp | 2 +- .../channelrx/noisefigure/noisefiguregui.cpp | 2 +- .../channelrx/radioastronomy/radioastronomy.h | 4 - .../radioastronomy/radioastronomygui.cpp | 2 +- .../channelrx/radioclock/radioclockgui.cpp | 2 +- .../channelrx/remotesink/remotesinkgui.cpp | 2 +- .../channelrx/remotetcpsink/remotetcpsink.h | 2 +- .../remotetcpsink/remotetcpsinkgui.cpp | 2 +- .../channelrx/sigmffilesink/sigmffilesink.h | 2 +- .../sigmffilesink/sigmffilesinkgui.cpp | 2 +- plugins/channelrx/udpsink/udpsinkgui.cpp | 2 +- plugins/channelrx/wdsprx/wdsprx.h | 2 +- plugins/channelrx/wdsprx/wdsprxgui.cpp | 2 +- plugins/channeltx/filesource/filesource.h | 2 +- .../channeltx/filesource/filesourcegui.cpp | 2 +- .../channeltx/localsource/localsourcegui.cpp | 2 +- .../mod802.15.4/ieee_802_15_4_modgui.cpp | 2 +- plugins/channeltx/modais/aismodgui.cpp | 2 +- plugins/channeltx/modam/ammodgui.cpp | 2 +- plugins/channeltx/modatv/atvmod.h | 2 +- plugins/channeltx/modatv/atvmodgui.cpp | 2 +- .../modchirpchat/chirpchatmodgui.cpp | 2 +- plugins/channeltx/moddatv/datvmod.h | 2 +- plugins/channeltx/moddatv/datvmodgui.cpp | 2 +- plugins/channeltx/modfreedv/freedvmodgui.cpp | 2 +- plugins/channeltx/modm17/m17modgui.cpp | 2 +- plugins/channeltx/modnfm/nfmmodgui.cpp | 2 +- plugins/channeltx/modpacket/packetmodgui.cpp | 2 +- plugins/channeltx/modpsk31/psk31mod.h | 2 +- plugins/channeltx/modpsk31/psk31modgui.cpp | 2 +- plugins/channeltx/modrtty/rttymod.h | 2 +- plugins/channeltx/modrtty/rttymodgui.cpp | 2 +- plugins/channeltx/modssb/ssbmodgui.cpp | 2 +- plugins/channeltx/modwfm/wfmmodgui.cpp | 2 +- .../remotesource/remotesourcegui.cpp | 2 +- plugins/channeltx/udpsource/udpsourcegui.cpp | 2 +- plugins/feature/afc/afcgui.cpp | 2 +- plugins/feature/ais/aisgui.cpp | 2 +- plugins/feature/ambe/ambegui.cpp | 2 +- .../feature/antennatools/antennatoolsgui.cpp | 2 +- plugins/feature/aprs/aprsgui.cpp | 2 +- .../demodanalyzer/demodanalyzergui.cpp | 2 +- .../gs232controller/gs232controllergui.cpp | 2 +- .../jogdialcontrollergui.cpp | 2 +- plugins/feature/limerfe/limerfegui.cpp | 2 +- plugins/feature/map/mapgui.cpp | 2 +- .../feature/morsedecoder/morsedecodergui.cpp | 2 +- plugins/feature/pertester/pertestergui.cpp | 2 +- plugins/feature/radiosonde/radiosondegui.cpp | 2 +- .../remotecontrol/remotecontrolgui.cpp | 2 +- .../feature/rigctlserver/rigctlservergui.cpp | 2 +- .../satellitetracker/satellitetrackergui.cpp | 2 +- plugins/feature/sid/sidgui.cpp | 2 +- plugins/feature/simpleptt/simplepttgui.cpp | 2 +- plugins/feature/skymap/skymapgui.cpp | 4 +- .../feature/startracker/startrackergui.cpp | 2 +- .../feature/vorlocalizer/vorlocalizergui.cpp | 2 +- .../samplesink/remoteoutput/remoteoutput.cpp | 15 +-- .../samplesink/remoteoutput/remoteoutput.h | 26 ++-- .../sigmffileinput/sigmffileinput.cpp | 3 +- .../sigmffileinput/sigmffileinput.h | 2 +- sdrbase/channel/channelapi.cpp | 3 +- sdrbase/channel/channelapi.h | 2 +- sdrbase/dsp/devicesamplemimo.cpp | 8 +- sdrgui/channel/channelgui.cpp | 34 ++---- sdrgui/channel/channelgui.h | 33 +++--- sdrgui/device/deviceuiset.cpp | 6 +- sdrgui/mainwindow.cpp | 18 +-- 131 files changed, 518 insertions(+), 621 deletions(-) diff --git a/plugins/channelmimo/beamsteeringcwmod/beamsteeringcwmod.cpp b/plugins/channelmimo/beamsteeringcwmod/beamsteeringcwmod.cpp index 7bd4f8ab4..cf976e5e7 100644 --- a/plugins/channelmimo/beamsteeringcwmod/beamsteeringcwmod.cpp +++ b/plugins/channelmimo/beamsteeringcwmod/beamsteeringcwmod.cpp @@ -46,7 +46,6 @@ BeamSteeringCWMod::BeamSteeringCWMod(DeviceAPI *deviceAPI) : m_thread(nullptr), m_basebandSource(nullptr), m_running(false), - m_guiMessageQueue(nullptr), m_frequencyOffset(0), m_basebandSampleRate(48000) { @@ -62,7 +61,7 @@ BeamSteeringCWMod::BeamSteeringCWMod(DeviceAPI *deviceAPI) : this, &BeamSteeringCWMod::networkManagerFinished ); - startSources(); + BeamSteeringCWMod::startSources(); } BeamSteeringCWMod::~BeamSteeringCWMod() @@ -77,7 +76,7 @@ BeamSteeringCWMod::~BeamSteeringCWMod() m_deviceAPI->removeChannelSinkAPI(this); m_deviceAPI->removeMIMOChannel(this); - stopSources(); + BeamSteeringCWMod::stopSources(); } void BeamSteeringCWMod::setDeviceAPI(DeviceAPI *deviceAPI) @@ -194,7 +193,7 @@ void BeamSteeringCWMod::applySettings(const BeamSteeringCWModSettings& settings, QList pipes; MainCore::instance()->getMessagePipes().getMessagePipes(this, "settings", pipes); - if (pipes.size() > 0) { + if (!pipes.empty()) { sendChannelSettings(pipes, reverseAPIKeys, settings, force); } @@ -205,7 +204,7 @@ void BeamSteeringCWMod::handleInputMessages() { Message* message; - while ((message = m_inputMessageQueue.pop()) != 0) + while ((message = m_inputMessageQueue.pop()) != nullptr) { if (handleMessage(*message)) { @@ -218,14 +217,14 @@ bool BeamSteeringCWMod::handleMessage(const Message& cmd) { if (MsgConfigureBeamSteeringCWMod::match(cmd)) { - MsgConfigureBeamSteeringCWMod& cfg = (MsgConfigureBeamSteeringCWMod&) cmd; + auto& cfg = (const MsgConfigureBeamSteeringCWMod&) cmd; qDebug() << "BeamSteeringCWMod::handleMessage: MsgConfigureBeamSteeringCWMod"; applySettings(cfg.getSettings(), cfg.getForce()); return true; } else if (DSPMIMOSignalNotification::match(cmd)) { - DSPMIMOSignalNotification& notif = (DSPMIMOSignalNotification&) cmd; + auto& notif = (const DSPMIMOSignalNotification&) cmd; qDebug() << "BeamSteeringCWMod::handleMessage: DSPMIMOSignalNotification:" << " basebandSampleRate: " << notif.getSampleRate() @@ -301,7 +300,7 @@ void BeamSteeringCWMod::validateFilterChainHash(BeamSteeringCWModSettings& setti void BeamSteeringCWMod::calculateFrequencyOffset() { double shiftFactor = HBFilterChainConverter::getShiftFactor(m_settings.m_log2Interp, m_settings.m_filterChainHash); - m_frequencyOffset = m_basebandSampleRate * shiftFactor; + m_frequencyOffset = (int64_t) (m_basebandSampleRate * shiftFactor); } int BeamSteeringCWMod::webapiSettingsGet( @@ -380,13 +379,13 @@ void BeamSteeringCWMod::webapiUpdateChannelSettings( settings.m_reverseAPIAddress = *response.getBeamSteeringCwModSettings()->getReverseApiAddress(); } if (channelSettingsKeys.contains("reverseAPIPort")) { - settings.m_reverseAPIPort = response.getBeamSteeringCwModSettings()->getReverseApiPort(); + settings.m_reverseAPIPort = (uint16_t) response.getBeamSteeringCwModSettings()->getReverseApiPort(); } if (channelSettingsKeys.contains("reverseAPIDeviceIndex")) { - settings.m_reverseAPIDeviceIndex = response.getBeamSteeringCwModSettings()->getReverseApiDeviceIndex(); + settings.m_reverseAPIDeviceIndex = (uint16_t) response.getBeamSteeringCwModSettings()->getReverseApiDeviceIndex(); } if (channelSettingsKeys.contains("reverseAPIChannelIndex")) { - settings.m_reverseAPIChannelIndex = response.getBeamSteeringCwModSettings()->getReverseApiChannelIndex(); + settings.m_reverseAPIChannelIndex = (uint16_t) response.getBeamSteeringCwModSettings()->getReverseApiChannelIndex(); } if (settings.m_channelMarker && channelSettingsKeys.contains("channelMarker")) { settings.m_channelMarker->updateFrom(channelSettingsKeys, response.getBeamSteeringCwModSettings()->getChannelMarker()); @@ -429,7 +428,7 @@ void BeamSteeringCWMod::webapiFormatChannelSettings(SWGSDRangel::SWGChannelSetti } else { - SWGSDRangel::SWGChannelMarker *swgChannelMarker = new SWGSDRangel::SWGChannelMarker(); + auto *swgChannelMarker = new SWGSDRangel::SWGChannelMarker(); settings.m_channelMarker->formatTo(swgChannelMarker); response.getBeamSteeringCwModSettings()->setChannelMarker(swgChannelMarker); } @@ -443,16 +442,16 @@ void BeamSteeringCWMod::webapiFormatChannelSettings(SWGSDRangel::SWGChannelSetti } else { - SWGSDRangel::SWGRollupState *swgRollupState = new SWGSDRangel::SWGRollupState(); + auto *swgRollupState = new SWGSDRangel::SWGRollupState(); settings.m_rollupState->formatTo(swgRollupState); response.getBeamSteeringCwModSettings()->setRollupState(swgRollupState); } } } -void BeamSteeringCWMod::webapiReverseSendSettings(QList& channelSettingsKeys, const BeamSteeringCWModSettings& settings, bool force) +void BeamSteeringCWMod::webapiReverseSendSettings(const QList& channelSettingsKeys, const BeamSteeringCWModSettings& settings, bool force) { - SWGSDRangel::SWGChannelSettings *swgChannelSettings = new SWGSDRangel::SWGChannelSettings(); + auto *swgChannelSettings = new SWGSDRangel::SWGChannelSettings(); webapiFormatChannelSettings(channelSettingsKeys, swgChannelSettings, settings, force); QString channelSettingsURL = QString("http://%1:%2/sdrangel/deviceset/%3/channel/%4/settings") @@ -463,8 +462,8 @@ void BeamSteeringCWMod::webapiReverseSendSettings(QList& channelSetting m_networkRequest.setUrl(QUrl(channelSettingsURL)); m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); - QBuffer *buffer = new QBuffer(); - buffer->open((QBuffer::ReadWrite)); + auto *buffer = new QBuffer(); + buffer->open(QBuffer::ReadWrite); buffer->write(swgChannelSettings->asJson().toUtf8()); buffer->seek(0); @@ -477,9 +476,9 @@ void BeamSteeringCWMod::webapiReverseSendSettings(QList& channelSetting void BeamSteeringCWMod::sendChannelSettings( const QList& pipes, - QList& channelSettingsKeys, + const QList& channelSettingsKeys, const BeamSteeringCWModSettings& settings, - bool force) + bool force) const { for (const auto& pipe : pipes) { @@ -487,7 +486,7 @@ void BeamSteeringCWMod::sendChannelSettings( if (messageQueue) { - SWGSDRangel::SWGChannelSettings *swgChannelSettings = new SWGSDRangel::SWGChannelSettings(); + auto *swgChannelSettings = new SWGSDRangel::SWGChannelSettings(); webapiFormatChannelSettings(channelSettingsKeys, swgChannelSettings, settings, force); MainCore::MsgChannelSettings *msg = MainCore::MsgChannelSettings::create( this, @@ -501,11 +500,11 @@ void BeamSteeringCWMod::sendChannelSettings( } void BeamSteeringCWMod::webapiFormatChannelSettings( - QList& channelSettingsKeys, + const QList& channelSettingsKeys, SWGSDRangel::SWGChannelSettings *swgChannelSettings, const BeamSteeringCWModSettings& settings, bool force -) +) const { swgChannelSettings->setDirection(2); // MIMO sink swgChannelSettings->setOriginatorChannelIndex(getIndexInDeviceSet()); @@ -534,20 +533,20 @@ void BeamSteeringCWMod::webapiFormatChannelSettings( if (settings.m_channelMarker && (channelSettingsKeys.contains("channelMarker") || force)) { - SWGSDRangel::SWGChannelMarker *swgChannelMarker = new SWGSDRangel::SWGChannelMarker(); + auto *swgChannelMarker = new SWGSDRangel::SWGChannelMarker(); settings.m_channelMarker->formatTo(swgChannelMarker); swgBeamSteeringCWSettings->setChannelMarker(swgChannelMarker); } if (settings.m_rollupState && (channelSettingsKeys.contains("rollupState") || force)) { - SWGSDRangel::SWGRollupState *swgRollupState = new SWGSDRangel::SWGRollupState(); + auto *swgRollupState = new SWGSDRangel::SWGRollupState(); settings.m_rollupState->formatTo(swgRollupState); swgBeamSteeringCWSettings->setRollupState(swgRollupState); } } -void BeamSteeringCWMod::networkManagerFinished(QNetworkReply *reply) +void BeamSteeringCWMod::networkManagerFinished(QNetworkReply *reply) const { QNetworkReply::NetworkError replyError = reply->error(); diff --git a/plugins/channelmimo/beamsteeringcwmod/beamsteeringcwmod.h b/plugins/channelmimo/beamsteeringcwmod/beamsteeringcwmod.h index fa2c614b3..0c7375d90 100644 --- a/plugins/channelmimo/beamsteeringcwmod/beamsteeringcwmod.h +++ b/plugins/channelmimo/beamsteeringcwmod/beamsteeringcwmod.h @@ -86,67 +86,64 @@ public: qint64 m_centerFrequency; }; - BeamSteeringCWMod(DeviceAPI *deviceAPI); - virtual ~BeamSteeringCWMod(); - virtual void destroy() { delete this; } - virtual void setDeviceAPI(DeviceAPI *deviceAPI); - virtual DeviceAPI *getDeviceAPI() { return m_deviceAPI; } + explicit BeamSteeringCWMod(DeviceAPI *deviceAPI); + ~BeamSteeringCWMod() final; + void destroy() final { delete this; } + void setDeviceAPI(DeviceAPI *deviceAPI) final; + DeviceAPI *getDeviceAPI() final { return m_deviceAPI; } - virtual void startSinks() {} - virtual void stopSinks() {} - virtual void startSources(); //!< thread start() - virtual void stopSources(); //!< thread exit() and wait() - virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, unsigned int sinkIndex); - virtual void pull(SampleVector::iterator& begin, unsigned int nbSamples, unsigned int sourceIndex); - virtual void pushMessage(Message *msg) { m_inputMessageQueue.push(msg); } - virtual QString getMIMOName() { return objectName(); } + void startSinks() final { /* Not used for MIMO */ } + void stopSinks() final { /* Not used for MIMO */ } + void startSources( /* Not used for MIMO */ ) final; //!< thread start() + void stopSources( /* Not used for MIMO */ ) final; //!< thread exit() and wait() + void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, unsigned int sinkIndex) final; + void pull(SampleVector::iterator& begin, unsigned int nbSamples, unsigned int sourceIndex) final; + void pushMessage(Message *msg) final { m_inputMessageQueue.push(msg); } + QString getMIMOName() final { return objectName(); } - virtual void getIdentifier(QString& id) { id = objectName(); } - virtual QString getIdentifier() const { return objectName(); } - virtual void getTitle(QString& title) { title = "BeamSteeringCWMod"; } - virtual qint64 getCenterFrequency() const { return m_frequencyOffset; } - virtual void setCenterFrequency(qint64) {} + void getIdentifier(QString& id) final { id = objectName(); } + QString getIdentifier() const final { return objectName(); } + void getTitle(QString& title) final { title = "BeamSteeringCWMod"; } + qint64 getCenterFrequency() const final { return m_frequencyOffset; } + void setCenterFrequency(qint64) final { /* Not used for MIMO */ } uint32_t getBasebandSampleRate() const { return m_basebandSampleRate; } - virtual QByteArray serialize() const; - virtual bool deserialize(const QByteArray& data); + QByteArray serialize() const final; + bool deserialize(const QByteArray& data) final; - virtual int getNbSinkStreams() const { return 0; } - virtual int getNbSourceStreams() const { return 2; } - virtual int getStreamIndex() const { return -1; } + int getNbSinkStreams() const final { return 0; } + int getNbSourceStreams() const final { return 2; } + int getStreamIndex() const final { return -1; } - virtual qint64 getStreamCenterFrequency(int streamIndex, bool sinkElseSource) const + qint64 getStreamCenterFrequency(int streamIndex, bool sinkElseSource) const final { (void) streamIndex; (void) sinkElseSource; return m_frequencyOffset; } - virtual void setMessageQueueToGUI(MessageQueue *queue) { m_guiMessageQueue = queue; } - MessageQueue *getMessageQueueToGUI() { return m_guiMessageQueue; } + int webapiSettingsGet( + SWGSDRangel::SWGChannelSettings& response, + QString& errorMessage) final; - virtual int webapiSettingsGet( - SWGSDRangel::SWGChannelSettings& response, - QString& errorMessage); + int webapiSettingsPutPatch( + bool force, + const QStringList& channelSettingsKeys, + SWGSDRangel::SWGChannelSettings& response, + QString& errorMessage) final; - virtual int webapiSettingsPutPatch( - bool force, - const QStringList& channelSettingsKeys, - SWGSDRangel::SWGChannelSettings& response, - QString& errorMessage); - - virtual int webapiWorkspaceGet( - SWGSDRangel::SWGWorkspaceInfo& query, - QString& errorMessage); + int webapiWorkspaceGet( + SWGSDRangel::SWGWorkspaceInfo& query, + QString& errorMessage) final; static void webapiFormatChannelSettings( SWGSDRangel::SWGChannelSettings& response, const BeamSteeringCWModSettings& settings); static void webapiUpdateChannelSettings( - BeamSteeringCWModSettings& settings, - const QStringList& channelSettingsKeys, - SWGSDRangel::SWGChannelSettings& response); + BeamSteeringCWModSettings& settings, + const QStringList& channelSettingsKeys, + SWGSDRangel::SWGChannelSettings& response); static const char* const m_channelIdURI; static const char* const m_channelId; @@ -161,36 +158,36 @@ private: BasebandSampleSink* m_spectrumSink; BasebandSampleSink* m_scopeSink; BeamSteeringCWModSettings m_settings; - MessageQueue *m_guiMessageQueue; //!< Input message queue to the GUI QNetworkAccessManager *m_networkManager; QNetworkRequest m_networkRequest; int64_t m_frequencyOffset; uint32_t m_basebandSampleRate; - int m_count0, m_count1; + int m_count0; + int m_count1; - virtual bool handleMessage(const Message& cmd); //!< Processing of a message. Returns true if message has actually been processed + bool handleMessage(const Message& cmd) final; //!< Processing of a message. Returns true if message has actually been processed void applySettings(const BeamSteeringCWModSettings& settings, bool force = false); static void validateFilterChainHash(BeamSteeringCWModSettings& settings); void calculateFrequencyOffset(); - void webapiReverseSendSettings(QList& channelSettingsKeys, const BeamSteeringCWModSettings& settings, bool force); + void webapiReverseSendSettings(const QList& channelSettingsKeys, const BeamSteeringCWModSettings& settings, bool force); void sendChannelSettings( const QList& pipes, - QList& channelSettingsKeys, + const QList& channelSettingsKeys, const BeamSteeringCWModSettings& settings, bool force - ); + ) const; void webapiFormatChannelSettings( - QList& channelSettingsKeys, + const QList& channelSettingsKeys, SWGSDRangel::SWGChannelSettings *swgChannelSettings, const BeamSteeringCWModSettings& settings, bool force - ); + ) const; private slots: void handleInputMessages(); - void networkManagerFinished(QNetworkReply *reply); + void networkManagerFinished(QNetworkReply *reply) const; }; #endif // INCLUDE_BEAMSTEERINGCWSOURCE_H diff --git a/plugins/channelmimo/beamsteeringcwmod/beamsteeringcwmodgui.cpp b/plugins/channelmimo/beamsteeringcwmod/beamsteeringcwmodgui.cpp index 9ab94de53..1ead0427e 100644 --- a/plugins/channelmimo/beamsteeringcwmod/beamsteeringcwmodgui.cpp +++ b/plugins/channelmimo/beamsteeringcwmod/beamsteeringcwmodgui.cpp @@ -30,15 +30,10 @@ BeamSteeringCWModGUI* BeamSteeringCWModGUI::create(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, MIMOChannel *mimoChannel) { - BeamSteeringCWModGUI* gui = new BeamSteeringCWModGUI(pluginAPI, deviceUISet, mimoChannel); + auto* gui = new BeamSteeringCWModGUI(pluginAPI, deviceUISet, mimoChannel); return gui; } -void BeamSteeringCWModGUI::destroy() -{ - delete this; -} - void BeamSteeringCWModGUI::resetToDefaults() { m_settings.resetToDefaults(); @@ -67,7 +62,7 @@ bool BeamSteeringCWModGUI::handleMessage(const Message& message) { if (BeamSteeringCWMod::MsgBasebandNotification::match(message)) { - BeamSteeringCWMod::MsgBasebandNotification& notif = (BeamSteeringCWMod::MsgBasebandNotification&) message; + auto& notif = (const BeamSteeringCWMod::MsgBasebandNotification&) message; m_basebandSampleRate = notif.getSampleRate(); m_centerFrequency = notif.getCenterFrequency(); displayRateAndShift(); @@ -76,7 +71,7 @@ bool BeamSteeringCWModGUI::handleMessage(const Message& message) } else if (BeamSteeringCWMod::MsgConfigureBeamSteeringCWMod::match(message)) { - const BeamSteeringCWMod::MsgConfigureBeamSteeringCWMod& cfg = (BeamSteeringCWMod::MsgConfigureBeamSteeringCWMod&) message; + auto& cfg = (const BeamSteeringCWMod::MsgConfigureBeamSteeringCWMod&) message; m_settings = cfg.getSettings(); blockApplySettings(true); m_channelMarker.updateSettings(static_cast(m_settings.m_channelMarker)); @@ -109,7 +104,7 @@ BeamSteeringCWModGUI::BeamSteeringCWModGUI(PluginAPI* pluginAPI, DeviceUISet *de connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(onMenuDialogCalled(const QPoint &))); m_bsCWSource = (BeamSteeringCWMod*) mimoChannel; - m_bsCWSource->setMessageQueueToGUI(getInputMessageQueue()); + m_bsCWSource->setMessageQueueToGUI(BeamSteeringCWModGUI::getInputMessageQueue()); m_basebandSampleRate = m_bsCWSource->getBasebandSampleRate(); connect(&MainCore::instance()->getMasterTimer(), SIGNAL(timeout()), this, SLOT(tick())); @@ -128,7 +123,7 @@ BeamSteeringCWModGUI::BeamSteeringCWModGUI(PluginAPI* pluginAPI, DeviceUISet *de m_deviceUISet->addChannelMarker(&m_channelMarker); - connect(getInputMessageQueue(), SIGNAL(messageEnqueued()), this, SLOT(handleSourceMessages())); + connect(BeamSteeringCWModGUI::getInputMessageQueue(), SIGNAL(messageEnqueued()), this, SLOT(handleSourceMessages())); displaySettings(); makeUIConnections(); @@ -183,13 +178,13 @@ void BeamSteeringCWModGUI::displaySettings() void BeamSteeringCWModGUI::displayRateAndShift() { - int shift = m_shiftFrequencyFactor * m_basebandSampleRate; + auto shift = (int) (m_shiftFrequencyFactor * m_basebandSampleRate); double channelSampleRate = ((double) m_basebandSampleRate) / (1<offsetFrequencyText->setText(tr("%1 Hz").arg(loc.toString(shift))); ui->channelRateText->setText(tr("%1k").arg(QString::number(channelSampleRate / 1000.0, 'g', 5))); m_channelMarker.setCenterFrequency(shift); - m_channelMarker.setBandwidth(channelSampleRate); + m_channelMarker.setBandwidth((int) channelSampleRate); } void BeamSteeringCWModGUI::leaveEvent(QEvent*) @@ -206,7 +201,7 @@ void BeamSteeringCWModGUI::handleSourceMessages() { Message* message; - while ((message = getInputMessageQueue()->pop()) != 0) + while ((message = getInputMessageQueue()->pop()) != nullptr) { if (handleMessage(*message)) { @@ -215,7 +210,7 @@ void BeamSteeringCWModGUI::handleSourceMessages() } } -void BeamSteeringCWModGUI::onWidgetRolled(QWidget* widget, bool rollDown) +void BeamSteeringCWModGUI::onWidgetRolled(const QWidget* widget, bool rollDown) { (void) widget; (void) rollDown; @@ -226,7 +221,7 @@ void BeamSteeringCWModGUI::onWidgetRolled(QWidget* widget, bool rollDown) void BeamSteeringCWModGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); @@ -316,7 +311,7 @@ void BeamSteeringCWModGUI::tick() } } -void BeamSteeringCWModGUI::makeUIConnections() +void BeamSteeringCWModGUI::makeUIConnections() const { QObject::connect(ui->channelOutput, QOverload::of(&QComboBox::currentIndexChanged), this, &BeamSteeringCWModGUI::on_channelOutput_currentIndexChanged); QObject::connect(ui->interpolationFactor, QOverload::of(&QComboBox::currentIndexChanged), this, &BeamSteeringCWModGUI::on_interpolationFactor_currentIndexChanged); @@ -326,5 +321,5 @@ void BeamSteeringCWModGUI::makeUIConnections() void BeamSteeringCWModGUI::updateAbsoluteCenterFrequency() { - setStatusFrequency(m_centerFrequency + m_shiftFrequencyFactor * m_basebandSampleRate); + setStatusFrequency(m_centerFrequency + (qint64) (m_shiftFrequencyFactor * m_basebandSampleRate)); } diff --git a/plugins/channelmimo/beamsteeringcwmod/beamsteeringcwmodgui.h b/plugins/channelmimo/beamsteeringcwmod/beamsteeringcwmodgui.h index 4670821ba..643e66e2f 100644 --- a/plugins/channelmimo/beamsteeringcwmod/beamsteeringcwmodgui.h +++ b/plugins/channelmimo/beamsteeringcwmod/beamsteeringcwmodgui.h @@ -47,22 +47,21 @@ class BeamSteeringCWModGUI : public ChannelGUI { public: static BeamSteeringCWModGUI* create(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, MIMOChannel *mimoChannel); - virtual void destroy(); - virtual void resetToDefaults(); - QByteArray serialize() const; - bool deserialize(const QByteArray& data); - virtual MessageQueue *getInputMessageQueue() { return &m_inputMessageQueue; } - virtual void setWorkspaceIndex(int index) { m_settings.m_workspaceIndex = index; }; - virtual int getWorkspaceIndex() const { return m_settings.m_workspaceIndex; }; - virtual void setGeometryBytes(const QByteArray& blob) { m_settings.m_geometryBytes = blob; }; - virtual QByteArray getGeometryBytes() const { return m_settings.m_geometryBytes; }; - virtual QString getTitle() const { return m_settings.m_title; }; - virtual QColor getTitleColor() const { return m_settings.m_rgbColor; }; - virtual void zetHidden(bool hidden) { m_settings.m_hidden = hidden; } - virtual bool getHidden() const { return m_settings.m_hidden; } - virtual ChannelMarker& getChannelMarker() { return m_channelMarker; } - virtual int getStreamIndex() const { return -1; } - virtual void setStreamIndex(int streamIndex) { (void) streamIndex; } + void resetToDefaults() final; + QByteArray serialize() const final; + bool deserialize(const QByteArray& data) final; + MessageQueue *getInputMessageQueue() final { return &m_inputMessageQueue; } + void setWorkspaceIndex(int index) final { m_settings.m_workspaceIndex = index; }; + int getWorkspaceIndex() const final { return m_settings.m_workspaceIndex; }; + void setGeometryBytes(const QByteArray& blob) final { m_settings.m_geometryBytes = blob; }; + QByteArray getGeometryBytes() const final { return m_settings.m_geometryBytes; }; + QString getTitle() const final { return m_settings.m_title; }; + QColor getTitleColor() const final { return m_settings.m_rgbColor; }; + void zetHidden(bool hidden) final { m_settings.m_hidden = hidden; } + bool getHidden() const final { return m_settings.m_hidden; } + ChannelMarker& getChannelMarker() final { return m_channelMarker; } + int getStreamIndex() const final { return -1; } + void setStreamIndex(int streamIndex) final { (void) streamIndex; } private: Ui::BeamSteeringCWModGUI* ui; @@ -82,18 +81,18 @@ private: uint32_t m_tickCount; explicit BeamSteeringCWModGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, MIMOChannel *mimoChannel, QWidget* parent = nullptr); - virtual ~BeamSteeringCWModGUI(); + ~BeamSteeringCWModGUI() final; void blockApplySettings(bool block); void applySettings(bool force = false); void displaySettings(); void displayRateAndShift(); bool handleMessage(const Message& message); - void makeUIConnections(); + void makeUIConnections() const; void updateAbsoluteCenterFrequency(); - void leaveEvent(QEvent*); - void enterEvent(EnterEventType*); + void leaveEvent(QEvent*) final; + void enterEvent(EnterEventType*) final; void applyInterpolation(); void applyPosition(); @@ -104,7 +103,7 @@ private slots: void on_interpolationFactor_currentIndexChanged(int index); void on_position_valueChanged(int value); void on_steeringDegrees_valueChanged(int value); - void onWidgetRolled(QWidget* widget, bool rollDown); + void onWidgetRolled(const QWidget* widget, bool rollDown); void onMenuDialogCalled(const QPoint& p); void tick(); }; diff --git a/plugins/channelmimo/doa2/doa2.cpp b/plugins/channelmimo/doa2/doa2.cpp index 6ff653772..ed3704f1a 100644 --- a/plugins/channelmimo/doa2/doa2.cpp +++ b/plugins/channelmimo/doa2/doa2.cpp @@ -48,7 +48,6 @@ DOA2::DOA2(DeviceAPI *deviceAPI) : m_thread(nullptr), m_basebandSink(nullptr), m_running(false), - m_guiMessageQueue(nullptr), m_frequencyOffset(0), m_deviceSampleRate(48000), m_deviceCenterFrequency(435000000) @@ -65,7 +64,7 @@ DOA2::DOA2(DeviceAPI *deviceAPI) : this, &DOA2::networkManagerFinished ); - startSinks(); + DOA2::startSinks(); } DOA2::~DOA2() @@ -80,7 +79,7 @@ DOA2::~DOA2() m_deviceAPI->removeChannelSinkAPI(this); m_deviceAPI->removeMIMOChannel(this); - stopSinks(); + DOA2::stopSinks(); } void DOA2::setDeviceAPI(DeviceAPI *deviceAPI) @@ -203,7 +202,7 @@ void DOA2::applySettings(const DOA2Settings& settings, bool force) reverseAPIKeys.append("squelchdB"); if (m_running) { - m_basebandSink->setMagThreshold(CalcDb::powerFromdB(settings.m_squelchdB)); + m_basebandSink->setMagThreshold((float) CalcDb::powerFromdB(settings.m_squelchdB)); } } @@ -217,7 +216,7 @@ void DOA2::applySettings(const DOA2Settings& settings, bool force) } if (m_running && ((m_settings.m_log2Decim != settings.m_log2Decim) - || (m_settings.m_filterChainHash != settings.m_filterChainHash) || force)) + || (m_settings.m_filterChainHash != settings.m_filterChainHash) || force)) { DOA2Baseband::MsgConfigureChannelizer *msg = DOA2Baseband::MsgConfigureChannelizer::create( settings.m_log2Decim, settings.m_filterChainHash); @@ -238,7 +237,7 @@ void DOA2::applySettings(const DOA2Settings& settings, bool force) QList pipes; MainCore::instance()->getMessagePipes().getMessagePipes(this, "settings", pipes); - if (pipes.size() > 0) { + if (!pipes.empty()) { sendChannelSettings(pipes, reverseAPIKeys, settings, force); } @@ -249,7 +248,7 @@ void DOA2::handleInputMessages() { Message* message; - while ((message = m_inputMessageQueue.pop()) != 0) + while ((message = m_inputMessageQueue.pop()) != nullptr) { if (handleMessage(*message)) { @@ -262,14 +261,14 @@ bool DOA2::handleMessage(const Message& cmd) { if (MsgConfigureDOA2::match(cmd)) { - MsgConfigureDOA2& cfg = (MsgConfigureDOA2&) cmd; + auto& cfg = (const MsgConfigureDOA2&) cmd; qDebug() << "DOA2::handleMessage: MsgConfigureDOA2"; applySettings(cfg.getSettings(), cfg.getForce()); return true; } else if (DSPMIMOSignalNotification::match(cmd)) { - DSPMIMOSignalNotification& notif = (DSPMIMOSignalNotification&) cmd; + auto& notif = (const DSPMIMOSignalNotification&) cmd; qDebug() << "DOA2::handleMessage: DSPMIMOSignalNotification:" << " inputSampleRate: " << notif.getSampleRate() @@ -347,7 +346,7 @@ void DOA2::validateFilterChainHash(DOA2Settings& settings) void DOA2::calculateFrequencyOffset() { double shiftFactor = HBFilterChainConverter::getShiftFactor(m_settings.m_log2Decim, m_settings.m_filterChainHash); - m_frequencyOffset = m_deviceSampleRate * shiftFactor; + m_frequencyOffset = (int64_t) (m_deviceSampleRate * shiftFactor); } void DOA2::applyChannelSettings(uint32_t log2Decim, uint32_t filterChainHash) @@ -360,12 +359,12 @@ void DOA2::applyChannelSettings(uint32_t log2Decim, uint32_t filterChainHash) m_basebandSink->getInputMessageQueue()->push(msg); } -float DOA2::getPhi() const +double DOA2::getPhi() const { - return m_basebandSink ? m_basebandSink->getPhi() : 0.0f; + return m_basebandSink ? m_basebandSink->getPhi() : 0.0; } -float DOA2::getPositiveDOA() const +double DOA2::getPositiveDOA() const { return std::acos(getPhi()/M_PI)*(180/M_PI); } @@ -469,13 +468,13 @@ void DOA2::webapiUpdateChannelSettings( settings.m_reverseAPIAddress = *response.getDoa2Settings()->getReverseApiAddress(); } if (channelSettingsKeys.contains("reverseAPIPort")) { - settings.m_reverseAPIPort = response.getDoa2Settings()->getReverseApiPort(); + settings.m_reverseAPIPort = (uint16_t) response.getDoa2Settings()->getReverseApiPort(); } if (channelSettingsKeys.contains("reverseAPIDeviceIndex")) { - settings.m_reverseAPIDeviceIndex = response.getDoa2Settings()->getReverseApiDeviceIndex(); + settings.m_reverseAPIDeviceIndex = (uint16_t) response.getDoa2Settings()->getReverseApiDeviceIndex(); } if (channelSettingsKeys.contains("reverseAPIChannelIndex")) { - settings.m_reverseAPIChannelIndex = response.getDoa2Settings()->getReverseApiChannelIndex(); + settings.m_reverseAPIChannelIndex = (uint16_t) response.getDoa2Settings()->getReverseApiChannelIndex(); } if (settings.m_scopeGUI && channelSettingsKeys.contains("scopeConfig")) { settings.m_scopeGUI->updateFrom(channelSettingsKeys, response.getDoa2Settings()->getScopeConfig()); @@ -525,7 +524,7 @@ void DOA2::webapiFormatChannelSettings(SWGSDRangel::SWGChannelSettings& response } else { - SWGSDRangel::SWGGLScope *swgGLScope = new SWGSDRangel::SWGGLScope(); + auto *swgGLScope = new SWGSDRangel::SWGGLScope(); settings.m_scopeGUI->formatTo(swgGLScope); response.getDoa2Settings()->setScopeConfig(swgGLScope); } @@ -539,7 +538,7 @@ void DOA2::webapiFormatChannelSettings(SWGSDRangel::SWGChannelSettings& response } else { - SWGSDRangel::SWGChannelMarker *swgChannelMarker = new SWGSDRangel::SWGChannelMarker(); + auto *swgChannelMarker = new SWGSDRangel::SWGChannelMarker(); settings.m_channelMarker->formatTo(swgChannelMarker); response.getDoa2Settings()->setChannelMarker(swgChannelMarker); } @@ -553,39 +552,39 @@ void DOA2::webapiFormatChannelSettings(SWGSDRangel::SWGChannelSettings& response } else { - SWGSDRangel::SWGRollupState *swgRollupState = new SWGSDRangel::SWGRollupState(); + auto *swgRollupState = new SWGSDRangel::SWGRollupState(); settings.m_rollupState->formatTo(swgRollupState); response.getDoa2Settings()->setRollupState(swgRollupState); } } } -void DOA2::webapiFormatChannelReport(SWGSDRangel::SWGChannelReport& response) +void DOA2::webapiFormatChannelReport(SWGSDRangel::SWGChannelReport& response) const { - float phi = normalizeAngle(getPhi() * (180/M_PI), 180.0f); - response.getDoa2Report()->setPhi(phi); + double phi = normalizeAngle(getPhi() * (180.0/M_PI), 180.0); + response.getDoa2Report()->setPhi((qint32) phi); - float hwl = 1.5e8 / (m_deviceCenterFrequency + m_frequencyOffset); - float cosTheta = (getPhi()/M_PI) * ((hwl * 1000.0) / m_settings.m_basebandDistance); - float blindAngle = (m_settings.m_basebandDistance > hwl * 1000.0) ? + double hwl = 1.5e8 / (double) (m_deviceCenterFrequency + m_frequencyOffset); + double cosTheta = (getPhi()/M_PI) * ((hwl * 1000.0) / m_settings.m_basebandDistance); + double blindAngle = (m_settings.m_basebandDistance > hwl * 1000.0) ? std::acos((hwl * 1000.0) / m_settings.m_basebandDistance) * (180/M_PI) : 0; response.getDoa2Report()->setBlindAngle((int) blindAngle); - float doaAngle = std::acos(cosTheta < -1.0 ? -1.0 : cosTheta > 1.0 ? 1.0 : cosTheta) * (180/M_PI); + double doaAngle = std::acos(cosTheta < -1.0 ? -1.0 : cosTheta > 1.0 ? 1.0 : cosTheta) * (180.0/M_PI); qDebug("DOA2::webapiFormatChannelReport: phi: %f cosT: %f DOAngle: %f", getPhi(), cosTheta, doaAngle); - float posAngle = normalizeAngle(m_settings.m_antennaAz - doaAngle, 360.0f); // DOA angles are trigonometric but displayed angles are clockwise - float negAngle = normalizeAngle(m_settings.m_antennaAz + doaAngle, 360.0f); - response.getDoa2Report()->setPosAz(posAngle); - response.getDoa2Report()->setNegAz(negAngle); + double posAngle = normalizeAngle(m_settings.m_antennaAz - doaAngle, 360.0); // DOA angles are trigonometric but displayed angles are clockwise + double negAngle = normalizeAngle(m_settings.m_antennaAz + doaAngle, 360.0); + response.getDoa2Report()->setPosAz((qint32) posAngle); + response.getDoa2Report()->setNegAz((qint32) negAngle); response.getDoa2Report()->setFftSize(m_fftSize); int channelSampleRate = m_deviceSampleRate / (1<setChannelSampleRate(channelSampleRate); } -void DOA2::webapiReverseSendSettings(QList& channelSettingsKeys, const DOA2Settings& settings, bool force) +void DOA2::webapiReverseSendSettings(const QList& channelSettingsKeys, const DOA2Settings& settings, bool force) { - SWGSDRangel::SWGChannelSettings *swgChannelSettings = new SWGSDRangel::SWGChannelSettings(); + auto *swgChannelSettings = new SWGSDRangel::SWGChannelSettings(); webapiFormatChannelSettings(channelSettingsKeys, swgChannelSettings, settings, force); QString channelSettingsURL = QString("http://%1:%2/sdrangel/deviceset/%3/channel/%4/settings") @@ -596,8 +595,8 @@ void DOA2::webapiReverseSendSettings(QList& channelSettingsKeys, const m_networkRequest.setUrl(QUrl(channelSettingsURL)); m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); - QBuffer *buffer = new QBuffer(); - buffer->open((QBuffer::ReadWrite)); + auto *buffer = new QBuffer(); + buffer->open(QBuffer::ReadWrite); buffer->write(swgChannelSettings->asJson().toUtf8()); buffer->seek(0); @@ -610,9 +609,9 @@ void DOA2::webapiReverseSendSettings(QList& channelSettingsKeys, const void DOA2::sendChannelSettings( const QList& pipes, - QList& channelSettingsKeys, + const QList& channelSettingsKeys, const DOA2Settings& settings, - bool force) + bool force) const { for (const auto& pipe : pipes) { @@ -620,7 +619,7 @@ void DOA2::sendChannelSettings( if (messageQueue) { - SWGSDRangel::SWGChannelSettings *swgChannelSettings = new SWGSDRangel::SWGChannelSettings(); + auto *swgChannelSettings = new SWGSDRangel::SWGChannelSettings(); webapiFormatChannelSettings(channelSettingsKeys, swgChannelSettings, settings, force); MainCore::MsgChannelSettings *msg = MainCore::MsgChannelSettings::create( this, @@ -634,11 +633,11 @@ void DOA2::sendChannelSettings( } void DOA2::webapiFormatChannelSettings( - QList& channelSettingsKeys, + const QList& channelSettingsKeys, SWGSDRangel::SWGChannelSettings *swgChannelSettings, const DOA2Settings& settings, bool force -) +) const { swgChannelSettings->setDirection(2); // MIMO sink swgChannelSettings->setOriginatorChannelIndex(getIndexInDeviceSet()); @@ -677,29 +676,26 @@ void DOA2::webapiFormatChannelSettings( swgDOA2Settings->setFftAveragingValue(DOA2Settings::getAveragingValue(settings.m_fftAveragingIndex)); } - if (settings.m_scopeGUI) - { - if (channelSettingsKeys.contains("scopeConfig") || force) { - settings.m_scopeGUI->formatTo(swgDOA2Settings->getScopeConfig()); - } + if ((settings.m_scopeGUI) && (channelSettingsKeys.contains("scopeConfig") || force)) { + settings.m_scopeGUI->formatTo(swgDOA2Settings->getScopeConfig()); } if (settings.m_channelMarker && (channelSettingsKeys.contains("channelMarker") || force)) { - SWGSDRangel::SWGChannelMarker *swgChannelMarker = new SWGSDRangel::SWGChannelMarker(); + auto *swgChannelMarker = new SWGSDRangel::SWGChannelMarker(); settings.m_channelMarker->formatTo(swgChannelMarker); swgDOA2Settings->setChannelMarker(swgChannelMarker); } if (settings.m_rollupState && (channelSettingsKeys.contains("rollupState") || force)) { - SWGSDRangel::SWGRollupState *swgRollupState = new SWGSDRangel::SWGRollupState(); + auto *swgRollupState = new SWGSDRangel::SWGRollupState(); settings.m_rollupState->formatTo(swgRollupState); swgDOA2Settings->setRollupState(swgRollupState); } } -void DOA2::networkManagerFinished(QNetworkReply *reply) +void DOA2::networkManagerFinished(QNetworkReply *reply) const { QNetworkReply::NetworkError replyError = reply->error(); @@ -720,7 +716,7 @@ void DOA2::networkManagerFinished(QNetworkReply *reply) reply->deleteLater(); } -float DOA2::normalizeAngle(float angle, float max) +double DOA2::normalizeAngle(double angle, double max) { if (angle < 0) { return max + angle; } if (angle > max) { return angle - max; } diff --git a/plugins/channelmimo/doa2/doa2.h b/plugins/channelmimo/doa2/doa2.h index 236f90b29..391dcb7a3 100644 --- a/plugins/channelmimo/doa2/doa2.h +++ b/plugins/channelmimo/doa2/doa2.h @@ -86,76 +86,73 @@ public: qint64 m_centerFrequency; }; - DOA2(DeviceAPI *deviceAPI); - virtual ~DOA2(); - virtual void destroy() { delete this; } - virtual void setDeviceAPI(DeviceAPI *deviceAPI); - virtual DeviceAPI *getDeviceAPI() { return m_deviceAPI; } + explicit DOA2(DeviceAPI *deviceAPI); + ~DOA2() final; + void destroy() final { delete this; } + void setDeviceAPI(DeviceAPI *deviceAPI) final; + DeviceAPI *getDeviceAPI() final { return m_deviceAPI; } - virtual void startSinks(); //!< thread start() - virtual void stopSinks(); //!< thread exit() and wait() - virtual void startSources() {} - virtual void stopSources() {} - virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, unsigned int sinkIndex); - virtual void pull(SampleVector::iterator& begin, unsigned int nbSamples, unsigned int sourceIndex); - virtual void pushMessage(Message *msg) { m_inputMessageQueue.push(msg); } - virtual QString getMIMOName() { return objectName(); } + void startSinks() final; //!< thread start() + void stopSinks() final; //!< thread exit() and wait() + void startSources() final { /* Not for MIMO */ } + void stopSources() final { /* Not for MIMO */ } + void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, unsigned int sinkIndex) final; + void pull(SampleVector::iterator& begin, unsigned int nbSamples, unsigned int sourceIndex) final; + void pushMessage(Message *msg) final { m_inputMessageQueue.push(msg); } + QString getMIMOName() final { return objectName(); } - virtual void getIdentifier(QString& id) { id = objectName(); } - virtual QString getIdentifier() const { return objectName(); } - virtual void getTitle(QString& title) { title = "DOA 2 sources"; } - virtual qint64 getCenterFrequency() const { return m_frequencyOffset; } - virtual void setCenterFrequency(qint64) {} + void getIdentifier(QString& id) final { id = objectName(); } + QString getIdentifier() const final { return objectName(); } + void getTitle(QString& title) final { title = "DOA 2 sources"; } + qint64 getCenterFrequency() const final { return m_frequencyOffset; } + void setCenterFrequency(qint64) final { /* Not for MIMO */ } uint32_t getDeviceSampleRate() const { return m_deviceSampleRate; } - virtual QByteArray serialize() const; - virtual bool deserialize(const QByteArray& data); + QByteArray serialize() const final; + bool deserialize(const QByteArray& data) final; - virtual int getNbSinkStreams() const { return 2; } - virtual int getNbSourceStreams() const { return 0; } - virtual int getStreamIndex() const { return -1; } + int getNbSinkStreams() const final { return 2; } + int getNbSourceStreams() const final { return 0; } + int getStreamIndex() const final { return -1; } - virtual qint64 getStreamCenterFrequency(int streamIndex, bool sinkElseSource) const + qint64 getStreamCenterFrequency(int streamIndex, bool sinkElseSource) const final { (void) streamIndex; (void) sinkElseSource; return m_frequencyOffset; } - virtual void setMessageQueueToGUI(MessageQueue *queue) { m_guiMessageQueue = queue; } - MessageQueue *getMessageQueueToGUI() { return m_guiMessageQueue; } - ScopeVis *getScopeVis() { return &m_scopeSink; } void applyChannelSettings(uint32_t log2Decim, uint32_t filterChainHash); - float getPhi() const; - float getPositiveDOA() const; + double getPhi() const; + double getPositiveDOA() const; - virtual int webapiSettingsGet( - SWGSDRangel::SWGChannelSettings& response, - QString& errorMessage); + int webapiSettingsGet( + SWGSDRangel::SWGChannelSettings& response, + QString& errorMessage) final; - virtual int webapiSettingsPutPatch( - bool force, - const QStringList& channelSettingsKeys, - SWGSDRangel::SWGChannelSettings& response, - QString& errorMessage); + int webapiSettingsPutPatch( + bool force, + const QStringList& channelSettingsKeys, + SWGSDRangel::SWGChannelSettings& response, + QString& errorMessage) final; - virtual int webapiReportGet( - SWGSDRangel::SWGChannelReport& response, - QString& errorMessage); + int webapiReportGet( + SWGSDRangel::SWGChannelReport& response, + QString& errorMessage) final; - virtual int webapiWorkspaceGet( - SWGSDRangel::SWGWorkspaceInfo& query, - QString& errorMessage); + int webapiWorkspaceGet( + SWGSDRangel::SWGWorkspaceInfo& query, + QString& errorMessage) final; static void webapiFormatChannelSettings( SWGSDRangel::SWGChannelSettings& response, const DOA2Settings& settings); static void webapiUpdateChannelSettings( - DOA2Settings& settings, - const QStringList& channelSettingsKeys, - SWGSDRangel::SWGChannelSettings& response); + DOA2Settings& settings, + const QStringList& channelSettingsKeys, + SWGSDRangel::SWGChannelSettings& response); static const char* const m_channelIdURI; static const char* const m_channelId; @@ -169,7 +166,6 @@ private: QMutex m_mutex; bool m_running; DOA2Settings m_settings; - MessageQueue *m_guiMessageQueue; //!< Input message queue to the GUI QNetworkAccessManager *m_networkManager; QNetworkRequest m_networkRequest; @@ -177,31 +173,32 @@ private: int64_t m_frequencyOffset; uint32_t m_deviceSampleRate; qint64 m_deviceCenterFrequency; - int m_count0, m_count1; + int m_count0; + int m_count1; - virtual bool handleMessage(const Message& cmd); //!< Processing of a message. Returns true if message has actually been processed + bool handleMessage(const Message& cmd) final; //!< Processing of a message. Returns true if message has actually been processed void applySettings(const DOA2Settings& settings, bool force = false); static void validateFilterChainHash(DOA2Settings& settings); void calculateFrequencyOffset(); - void webapiFormatChannelReport(SWGSDRangel::SWGChannelReport& response); - void webapiReverseSendSettings(QList& channelSettingsKeys, const DOA2Settings& settings, bool force); + void webapiFormatChannelReport(SWGSDRangel::SWGChannelReport& response) const; + void webapiReverseSendSettings(const QList& channelSettingsKeys, const DOA2Settings& settings, bool force); void sendChannelSettings( const QList& pipes, - QList& channelSettingsKeys, + const QList& channelSettingsKeys, const DOA2Settings& settings, bool force - ); + ) const; void webapiFormatChannelSettings( - QList& channelSettingsKeys, + const QList& channelSettingsKeys, SWGSDRangel::SWGChannelSettings *swgChannelSettings, const DOA2Settings& settings, bool force - ); - static float normalizeAngle(float angle, float max); + ) const; + static double normalizeAngle(double angle, double max); private slots: void handleInputMessages(); - void networkManagerFinished(QNetworkReply *reply); + void networkManagerFinished(QNetworkReply *reply) const; }; #endif // INCLUDE_DOA2_H diff --git a/plugins/channelmimo/doa2/doa2baseband.h b/plugins/channelmimo/doa2/doa2baseband.h index b00518bf0..9ee669efb 100644 --- a/plugins/channelmimo/doa2/doa2baseband.h +++ b/plugins/channelmimo/doa2/doa2baseband.h @@ -73,7 +73,7 @@ public: private: DOA2Settings::CorrelationType m_correlationType; - MsgConfigureCorrelation(DOA2Settings::CorrelationType correlationType) : + explicit MsgConfigureCorrelation(DOA2Settings::CorrelationType correlationType) : Message(), m_correlationType(correlationType) {} @@ -103,8 +103,8 @@ public: { } }; - DOA2Baseband(int fftSize); - ~DOA2Baseband(); + explicit DOA2Baseband(int fftSize); + ~DOA2Baseband() final; void reset(); MessageQueue *getInputMessageQueue() { return &m_inputMessageQueue; } //!< Get the queue for asynchronous inbound communication @@ -114,7 +114,7 @@ public: void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, unsigned int streamIndex); void setBasebandSampleRate(unsigned int sampleRate); - float getPhi() const { return m_phi; } + double getPhi() const { return m_phi; } void setMagThreshold(float threshold) { m_magThreshold = threshold * SDR_RX_SCALED * SDR_RX_SCALED; } void setFFTAveraging(int nbFFT); @@ -128,9 +128,9 @@ private: DOA2Settings::CorrelationType m_correlationType; int m_fftSize; int m_samplesCount; //!< Number of samples processed by DOA - float m_magSum; //!< Squared magnitudes accumulator - float m_wphSum; //!< Phase difference accumulator (averaging weighted by squared magnitude) - float m_phi; //!< Resulting calculated phase difference + double m_magSum; //!< Squared magnitudes accumulator + double m_wphSum; //!< Phase difference accumulator (averaging weighted by squared magnitude) + double m_phi; //!< Resulting calculated phase difference double m_magThreshold; //!< Squared magnitude scaled threshold int m_fftAvg; //!< Average over a certain number of FFTs int m_fftAvgCount; //!< FFT averaging counter diff --git a/plugins/channelmimo/doa2/doa2gui.cpp b/plugins/channelmimo/doa2/doa2gui.cpp index 75f6b6fa0..972491b61 100644 --- a/plugins/channelmimo/doa2/doa2gui.cpp +++ b/plugins/channelmimo/doa2/doa2gui.cpp @@ -33,15 +33,10 @@ DOA2GUI* DOA2GUI::create(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, MIMOChannel *channelMIMO) { - DOA2GUI* gui = new DOA2GUI(pluginAPI, deviceUISet, channelMIMO); + auto* gui = new DOA2GUI(pluginAPI, deviceUISet, channelMIMO); return gui; } -void DOA2GUI::destroy() -{ - delete this; -} - void DOA2GUI::resetToDefaults() { m_settings.resetToDefaults(); @@ -78,7 +73,7 @@ bool DOA2GUI::handleMessage(const Message& message) { if (DOA2::MsgBasebandNotification::match(message)) { - DOA2::MsgBasebandNotification& notif = (DOA2::MsgBasebandNotification&) message; + auto& notif = (const DOA2::MsgBasebandNotification&) message; m_sampleRate = notif.getSampleRate(); m_centerFrequency = notif.getCenterFrequency(); displayRateAndShift(); @@ -88,7 +83,7 @@ bool DOA2GUI::handleMessage(const Message& message) } else if (DOA2::MsgConfigureDOA2::match(message)) { - const DOA2::MsgConfigureDOA2& notif = (const DOA2::MsgConfigureDOA2&) message; + auto& notif = (const DOA2::MsgConfigureDOA2&) message; m_settings = notif.getSettings(); ui->scopeGUI->updateSettings(); m_channelMarker.updateSettings(static_cast(m_settings.m_channelMarker)); @@ -122,7 +117,7 @@ DOA2GUI::DOA2GUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, MIMOChannel *ch m_doa2 = (DOA2*) channelMIMO; m_scopeVis = m_doa2->getScopeVis(); m_scopeVis->setGLScope(ui->glScope); - m_doa2->setMessageQueueToGUI(getInputMessageQueue()); + m_doa2->setMessageQueueToGUI(DOA2GUI::getInputMessageQueue()); m_sampleRate = m_doa2->getDeviceSampleRate(); ui->glScope->setTraceModulo(DOA2::m_fftSize); @@ -150,7 +145,7 @@ DOA2GUI::DOA2GUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, MIMOChannel *ch ui->scopeGUI->traceLengthChange(); ui->compass->setBlindAngleBorder(true); - connect(getInputMessageQueue(), SIGNAL(messageEnqueued()), this, SLOT(handleSourceMessages())); + connect(DOA2GUI::getInputMessageQueue(), SIGNAL(messageEnqueued()), this, SLOT(handleSourceMessages())); displaySettings(); makeUIConnections(); @@ -221,20 +216,20 @@ void DOA2GUI::displaySettings() void DOA2GUI::displayRateAndShift() { - int shift = m_shiftFrequencyFactor * m_sampleRate; + auto shift = (int) (m_shiftFrequencyFactor * m_sampleRate); double channelSampleRate = ((double) m_sampleRate) / (1<offsetFrequencyText->setText(tr("%1 Hz").arg(loc.toString(shift))); ui->channelRateText->setText(tr("%1k").arg(QString::number(channelSampleRate / 1000.0, 'g', 5))); m_channelMarker.setCenterFrequency(shift); - m_channelMarker.setBandwidth(channelSampleRate); - m_scopeVis->setLiveRate(channelSampleRate); + m_channelMarker.setBandwidth((int) channelSampleRate); + m_scopeVis->setLiveRate((int) channelSampleRate); } void DOA2GUI::setFFTAveragingTooltip() { - float channelSampleRate = ((float) m_sampleRate) / (1<pop()) != 0) + while ((message = getInputMessageQueue()->pop()) != nullptr) { if (handleMessage(*message)) { @@ -283,7 +278,7 @@ void DOA2GUI::handleSourceMessages() } } -void DOA2GUI::onWidgetRolled(QWidget* widget, bool rollDown) +void DOA2GUI::onWidgetRolled(const QWidget* widget, bool rollDown) { (void) widget; (void) rollDown; @@ -294,7 +289,7 @@ void DOA2GUI::onWidgetRolled(QWidget* widget, bool rollDown) void DOA2GUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); @@ -434,7 +429,7 @@ void DOA2GUI::tick() } } -void DOA2GUI::makeUIConnections() +void DOA2GUI::makeUIConnections() const { QObject::connect(ui->decimationFactor, QOverload::of(&QComboBox::currentIndexChanged), this, &DOA2GUI::on_decimationFactor_currentIndexChanged); QObject::connect(ui->position, &QSlider::valueChanged, this, &DOA2GUI::on_position_valueChanged); @@ -449,9 +444,9 @@ void DOA2GUI::makeUIConnections() void DOA2GUI::updateAbsoluteCenterFrequency() { - qint64 cf = m_centerFrequency + m_shiftFrequencyFactor * m_sampleRate; + auto cf = (qint64) ((double) m_centerFrequency + m_shiftFrequencyFactor * m_sampleRate); setStatusFrequency(cf); - m_hwl = 1.5e+8 / cf; + m_hwl = 1.5e+8 / (double) cf; ui->halfWLText->setText(tr("%1").arg(m_hwl*1000, 5, 'f', 0)); updateScopeFScale(); } @@ -470,14 +465,14 @@ void DOA2GUI::updateScopeFScale() void DOA2GUI::updateDOA() { - float cosTheta = (m_doa2->getPhi()/M_PI) * ((m_hwl * 1000.0) / m_settings.m_basebandDistance); - float blindAngle = (m_settings.m_basebandDistance > m_hwl * 1000.0) ? + double cosTheta = (m_doa2->getPhi()/M_PI) * ((m_hwl * 1000.0) / m_settings.m_basebandDistance); + double blindAngle = (m_settings.m_basebandDistance > m_hwl * 1000.0) ? std::acos((m_hwl * 1000.0) / m_settings.m_basebandDistance) * (180/M_PI) : 0; ui->compass->setBlindAngle(blindAngle); - float doaAngle = std::acos(cosTheta < -1.0 ? -1.0 : cosTheta > 1.0 ? 1.0 : cosTheta) * (180/M_PI); - float posAngle = ui->antAz->value() - doaAngle; // DOA angles are trigonometric but displayed angles are clockwise - float negAngle = ui->antAz->value() + doaAngle; + double doaAngle = std::acos(cosTheta < -1.0 ? -1.0 : cosTheta > 1.0 ? 1.0 : cosTheta) * (180/M_PI); + double posAngle = ui->antAz->value() - doaAngle; // DOA angles are trigonometric but displayed angles are clockwise + double negAngle = ui->antAz->value() + doaAngle; ui->compass->setAzPos(posAngle); ui->compass->setAzNeg(negAngle); ui->posText->setText(tr("%1").arg(ui->compass->getAzPos(), 3, 'f', 0, QLatin1Char('0'))); diff --git a/plugins/channelmimo/doa2/doa2gui.h b/plugins/channelmimo/doa2/doa2gui.h index 3cd559c6f..f0d669f3c 100644 --- a/plugins/channelmimo/doa2/doa2gui.h +++ b/plugins/channelmimo/doa2/doa2gui.h @@ -46,22 +46,21 @@ class DOA2GUI : public ChannelGUI { public: static DOA2GUI* create(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, MIMOChannel *mimoChannel); - virtual void destroy(); - virtual void resetToDefaults(); - virtual QByteArray serialize() const; - virtual bool deserialize(const QByteArray& data); - virtual MessageQueue* getInputMessageQueue(); - virtual void setWorkspaceIndex(int index) { m_settings.m_workspaceIndex = index; }; - virtual int getWorkspaceIndex() const { return m_settings.m_workspaceIndex; }; - virtual void setGeometryBytes(const QByteArray& blob) { m_settings.m_geometryBytes = blob; }; - virtual QByteArray getGeometryBytes() const { return m_settings.m_geometryBytes; }; - virtual QString getTitle() const { return m_settings.m_title; }; - virtual QColor getTitleColor() const { return m_settings.m_rgbColor; }; - virtual void zetHidden(bool hidden) { m_settings.m_hidden = hidden; } - virtual bool getHidden() const { return m_settings.m_hidden; } - virtual ChannelMarker& getChannelMarker() { return m_channelMarker; } - virtual int getStreamIndex() const { return -1; } - virtual void setStreamIndex(int streamIndex) { (void) streamIndex; } + void resetToDefaults() final; + QByteArray serialize() const final; + bool deserialize(const QByteArray& data) final; + MessageQueue* getInputMessageQueue() final; + void setWorkspaceIndex(int index) final { m_settings.m_workspaceIndex = index; }; + int getWorkspaceIndex() const final { return m_settings.m_workspaceIndex; }; + void setGeometryBytes(const QByteArray& blob) final { m_settings.m_geometryBytes = blob; }; + QByteArray getGeometryBytes() const final { return m_settings.m_geometryBytes; }; + QString getTitle() const final { return m_settings.m_title; }; + QColor getTitleColor() const final { return m_settings.m_rgbColor; }; + void zetHidden(bool hidden) final { m_settings.m_hidden = hidden; } + bool getHidden() const final { return m_settings.m_hidden; } + ChannelMarker& getChannelMarker() final { return m_channelMarker; } + int getStreamIndex() const final { return -1; } + void setStreamIndex(int streamIndex) final { (void) streamIndex; } private: Ui::DOA2GUI* ui; @@ -82,7 +81,7 @@ private: double m_hwl; //!< Half wavelength at center frequency explicit DOA2GUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, MIMOChannel *rxChannel, QWidget* parent = nullptr); - virtual ~DOA2GUI(); + ~DOA2GUI() final; void blockApplySettings(bool block); void applySettings(bool force = false); @@ -93,13 +92,13 @@ private: void setFFTAveragingTooltip(); static void setNumberStr(float v, int decimalPlaces, QString& s); bool handleMessage(const Message& message); - void makeUIConnections(); + void makeUIConnections() const; void updateAbsoluteCenterFrequency(); void updateScopeFScale(); void updateDOA(); - void leaveEvent(QEvent*); - void enterEvent(EnterEventType*); + void leaveEvent(QEvent*) final; + void enterEvent(EnterEventType*) final; private slots: void handleSourceMessages(); @@ -112,7 +111,7 @@ private slots: void on_squelch_valueChanged(int value); void on_fftAveraging_currentIndexChanged(int index); void on_centerPosition_clicked(); - void onWidgetRolled(QWidget* widget, bool rollDown); + void onWidgetRolled(const QWidget* widget, bool rollDown); void onMenuDialogCalled(const QPoint& p); void tick(); }; diff --git a/plugins/channelmimo/interferometer/interferometer.cpp b/plugins/channelmimo/interferometer/interferometer.cpp index 1330edbf2..808e6503c 100644 --- a/plugins/channelmimo/interferometer/interferometer.cpp +++ b/plugins/channelmimo/interferometer/interferometer.cpp @@ -83,7 +83,7 @@ Interferometer::Interferometer(DeviceAPI *deviceAPI) : &Interferometer::updateDeviceSetList ); updateDeviceSetList(); - startSinks(); + Interferometer::startSinks(); } Interferometer::~Interferometer() @@ -98,7 +98,7 @@ Interferometer::~Interferometer() m_deviceAPI->removeChannelSinkAPI(this); m_deviceAPI->removeMIMOChannel(this); - stopSinks(); + Interferometer::stopSinks(); } void Interferometer::setDeviceAPI(DeviceAPI *deviceAPI) @@ -229,7 +229,7 @@ void Interferometer::applySettings(const InterferometerSettings& settings, const QList pipes; MainCore::instance()->getMessagePipes().getMessagePipes(this, "settings", pipes); - if (pipes.size() > 0) { + if (!pipes.empty()) { sendChannelSettings(pipes, settingsKeys, settings, force); } @@ -254,7 +254,7 @@ void Interferometer::handleInputMessages() { Message* message; - while ((message = m_inputMessageQueue.pop()) != 0) + while ((message = m_inputMessageQueue.pop()) != nullptr) { if (handleMessage(*message)) { @@ -267,14 +267,14 @@ bool Interferometer::handleMessage(const Message& cmd) { if (MsgConfigureInterferometer::match(cmd)) { - MsgConfigureInterferometer& cfg = (MsgConfigureInterferometer&) cmd; + auto& cfg = (const MsgConfigureInterferometer&) cmd; qDebug() << "Interferometer::handleMessage: MsgConfigureInterferometer"; applySettings(cfg.getSettings(), cfg.getSettingsKeys(), cfg.getForce()); return true; } else if (DSPMIMOSignalNotification::match(cmd)) { - DSPMIMOSignalNotification& notif = (DSPMIMOSignalNotification&) cmd; + auto& notif = (const DSPMIMOSignalNotification&) cmd; qDebug() << "Interferometer::handleMessage: DSPMIMOSignalNotification:" << " inputSampleRate: " << notif.getSampleRate() @@ -355,7 +355,7 @@ void Interferometer::validateFilterChainHash(InterferometerSettings& settings) void Interferometer::calculateFrequencyOffset(uint32_t log2Decim, uint32_t filterChainHash) { double shiftFactor = HBFilterChainConverter::getShiftFactor(log2Decim, filterChainHash); - m_frequencyOffset = m_deviceSampleRate * shiftFactor; + m_frequencyOffset = (int64_t) (m_deviceSampleRate * shiftFactor); } void Interferometer::applyChannelSettings(uint32_t log2Decim, uint32_t filterChainHash) @@ -383,7 +383,7 @@ void Interferometer::updateDeviceSetList() if (deviceSourceEngine) { - DeviceSampleSource *deviceSource = deviceSourceEngine->getSource(); + const DeviceSampleSource *deviceSource = deviceSourceEngine->getSource(); if (deviceSource->getDeviceDescription() == "LocalInput") { m_localInputDeviceIndexes.append(deviceSetIndex); @@ -401,7 +401,7 @@ void Interferometer::updateDeviceSetList() InterferometerSettings settings = m_settings; int newIndexInList; - if (m_localInputDeviceIndexes.size() != 0) // there are some local input devices + if (!m_localInputDeviceIndexes.empty()) // there are some local input devices { if (m_settings.m_localDeviceIndex < 0) { // not set before newIndexInList = 0; // set to first device in list @@ -574,13 +574,13 @@ void Interferometer::webapiUpdateChannelSettings( settings.m_reverseAPIAddress = *response.getInterferometerSettings()->getReverseApiAddress(); } if (channelSettingsKeys.contains("reverseAPIPort")) { - settings.m_reverseAPIPort = response.getInterferometerSettings()->getReverseApiPort(); + settings.m_reverseAPIPort = (uint16_t) response.getInterferometerSettings()->getReverseApiPort(); } if (channelSettingsKeys.contains("reverseAPIDeviceIndex")) { - settings.m_reverseAPIDeviceIndex = response.getInterferometerSettings()->getReverseApiDeviceIndex(); + settings.m_reverseAPIDeviceIndex = (uint16_t) response.getInterferometerSettings()->getReverseApiDeviceIndex(); } if (channelSettingsKeys.contains("reverseAPIChannelIndex")) { - settings.m_reverseAPIChannelIndex = response.getInterferometerSettings()->getReverseApiChannelIndex(); + settings.m_reverseAPIChannelIndex = (uint16_t) response.getInterferometerSettings()->getReverseApiChannelIndex(); } if (settings.m_spectrumGUI && channelSettingsKeys.contains("spectrumConfig")) { settings.m_spectrumGUI->updateFrom(channelSettingsKeys, response.getInterferometerSettings()->getSpectrumConfig()); @@ -632,7 +632,7 @@ void Interferometer::webapiFormatChannelSettings(SWGSDRangel::SWGChannelSettings } else { - SWGSDRangel::SWGGLSpectrum *swgGLSpectrum = new SWGSDRangel::SWGGLSpectrum(); + auto *swgGLSpectrum = new SWGSDRangel::SWGGLSpectrum(); settings.m_spectrumGUI->formatTo(swgGLSpectrum); response.getInterferometerSettings()->setSpectrumConfig(swgGLSpectrum); } @@ -646,7 +646,7 @@ void Interferometer::webapiFormatChannelSettings(SWGSDRangel::SWGChannelSettings } else { - SWGSDRangel::SWGGLScope *swgGLScope = new SWGSDRangel::SWGGLScope(); + auto *swgGLScope = new SWGSDRangel::SWGGLScope(); settings.m_scopeGUI->formatTo(swgGLScope); response.getInterferometerSettings()->setScopeConfig(swgGLScope); } @@ -660,7 +660,7 @@ void Interferometer::webapiFormatChannelSettings(SWGSDRangel::SWGChannelSettings } else { - SWGSDRangel::SWGChannelMarker *swgChannelMarker = new SWGSDRangel::SWGChannelMarker(); + auto *swgChannelMarker = new SWGSDRangel::SWGChannelMarker(); settings.m_channelMarker->formatTo(swgChannelMarker); response.getInterferometerSettings()->setChannelMarker(swgChannelMarker); } @@ -674,7 +674,7 @@ void Interferometer::webapiFormatChannelSettings(SWGSDRangel::SWGChannelSettings } else { - SWGSDRangel::SWGRollupState *swgRollupState = new SWGSDRangel::SWGRollupState(); + auto *swgRollupState = new SWGSDRangel::SWGRollupState(); settings.m_rollupState->formatTo(swgRollupState); response.getInterferometerSettings()->setRollupState(swgRollupState); } @@ -683,7 +683,7 @@ void Interferometer::webapiFormatChannelSettings(SWGSDRangel::SWGChannelSettings void Interferometer::webapiReverseSendSettings(const QList& channelSettingsKeys, const InterferometerSettings& settings, bool force) { - SWGSDRangel::SWGChannelSettings *swgChannelSettings = new SWGSDRangel::SWGChannelSettings(); + auto *swgChannelSettings = new SWGSDRangel::SWGChannelSettings(); webapiFormatChannelSettings(channelSettingsKeys, swgChannelSettings, settings, force); QString channelSettingsURL = QString("http://%1:%2/sdrangel/deviceset/%3/channel/%4/settings") @@ -694,8 +694,8 @@ void Interferometer::webapiReverseSendSettings(const QList& channelSett m_networkRequest.setUrl(QUrl(channelSettingsURL)); m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); - QBuffer *buffer = new QBuffer(); - buffer->open((QBuffer::ReadWrite)); + auto *buffer = new QBuffer(); + buffer->open(QBuffer::ReadWrite); buffer->write(swgChannelSettings->asJson().toUtf8()); buffer->seek(0); @@ -710,7 +710,7 @@ void Interferometer::sendChannelSettings( const QList& pipes, const QList& channelSettingsKeys, const InterferometerSettings& settings, - bool force) + bool force) const { for (const auto& pipe : pipes) { @@ -718,7 +718,7 @@ void Interferometer::sendChannelSettings( if (messageQueue) { - SWGSDRangel::SWGChannelSettings *swgChannelSettings = new SWGSDRangel::SWGChannelSettings(); + auto *swgChannelSettings = new SWGSDRangel::SWGChannelSettings(); webapiFormatChannelSettings(channelSettingsKeys, swgChannelSettings, settings, force); MainCore::MsgChannelSettings *msg = MainCore::MsgChannelSettings::create( this, @@ -736,7 +736,7 @@ void Interferometer::webapiFormatChannelSettings( SWGSDRangel::SWGChannelSettings *swgChannelSettings, const InterferometerSettings& settings, bool force -) +) const { swgChannelSettings->setDirection(2); // MIMO sink swgChannelSettings->setOriginatorChannelIndex(getIndexInDeviceSet()); @@ -774,34 +774,34 @@ void Interferometer::webapiFormatChannelSettings( if (settings.m_spectrumGUI && (channelSettingsKeys.contains("spectrumConfig") || force)) { - SWGSDRangel::SWGGLSpectrum *swgGLSpectrum = new SWGSDRangel::SWGGLSpectrum(); + auto *swgGLSpectrum = new SWGSDRangel::SWGGLSpectrum(); settings.m_spectrumGUI->formatTo(swgGLSpectrum); swgInterferometerSettings->setSpectrumConfig(swgGLSpectrum); } if (settings.m_scopeGUI && (channelSettingsKeys.contains("scopeConfig") || force)) { - SWGSDRangel::SWGGLScope *swgGLScope = new SWGSDRangel::SWGGLScope(); + auto *swgGLScope = new SWGSDRangel::SWGGLScope(); settings.m_scopeGUI->formatTo(swgGLScope); swgInterferometerSettings->setScopeConfig(swgGLScope); } if (settings.m_channelMarker && (channelSettingsKeys.contains("channelMarker") || force)) { - SWGSDRangel::SWGChannelMarker *swgChannelMarker = new SWGSDRangel::SWGChannelMarker(); + auto *swgChannelMarker = new SWGSDRangel::SWGChannelMarker(); settings.m_channelMarker->formatTo(swgChannelMarker); swgInterferometerSettings->setChannelMarker(swgChannelMarker); } if (settings.m_rollupState && (channelSettingsKeys.contains("rollupState") || force)) { - SWGSDRangel::SWGRollupState *swgRollupState = new SWGSDRangel::SWGRollupState(); + auto *swgRollupState = new SWGSDRangel::SWGRollupState(); settings.m_rollupState->formatTo(swgRollupState); swgInterferometerSettings->setRollupState(swgRollupState); } } -void Interferometer::networkManagerFinished(QNetworkReply *reply) +void Interferometer::networkManagerFinished(QNetworkReply *reply) const { QNetworkReply::NetworkError replyError = reply->error(); diff --git a/plugins/channelmimo/interferometer/interferometer.h b/plugins/channelmimo/interferometer/interferometer.h index 927282675..4531fb4a2 100644 --- a/plugins/channelmimo/interferometer/interferometer.h +++ b/plugins/channelmimo/interferometer/interferometer.h @@ -108,72 +108,69 @@ public: { } }; - Interferometer(DeviceAPI *deviceAPI); - virtual ~Interferometer(); - virtual void destroy() { delete this; } - virtual void setDeviceAPI(DeviceAPI *deviceAPI); - virtual DeviceAPI *getDeviceAPI() { return m_deviceAPI; } + explicit Interferometer(DeviceAPI *deviceAPI); + ~Interferometer() final; + void destroy() final { delete this; } + void setDeviceAPI(DeviceAPI *deviceAPI) final; + DeviceAPI *getDeviceAPI() final { return m_deviceAPI; } - virtual void startSinks(); //!< thread start() - virtual void stopSinks(); //!< thread exit() and wait() - virtual void startSources() {} - virtual void stopSources() {} - virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, unsigned int sinkIndex); - virtual void pull(SampleVector::iterator& begin, unsigned int nbSamples, unsigned int sourceIndex); - virtual void pushMessage(Message *msg) { m_inputMessageQueue.push(msg); } - virtual QString getMIMOName() { return objectName(); } + void startSinks() final; //!< thread start() + void stopSinks() final; //!< thread exit() and wait() + void startSources() final { /* not for MIMMO*/ } + void stopSources() final { /* not for MIMMO*/ } + void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, unsigned int sinkIndex) final; + void pull(SampleVector::iterator& begin, unsigned int nbSamples, unsigned int sourceIndex) final; + void pushMessage(Message *msg) final { m_inputMessageQueue.push(msg); } + QString getMIMOName() final { return objectName(); } - virtual void getIdentifier(QString& id) { id = objectName(); } - virtual QString getIdentifier() const { return objectName(); } - virtual void getTitle(QString& title) { title = "Interferometer"; } - virtual qint64 getCenterFrequency() const { return m_frequencyOffset; } - virtual void setCenterFrequency(qint64) {} + void getIdentifier(QString& id) final { id = objectName(); } + QString getIdentifier() const final { return objectName(); } + void getTitle(QString& title) final { title = "Interferometer"; } + qint64 getCenterFrequency() const final { return m_frequencyOffset; } + void setCenterFrequency(qint64) final { /* not for MIMMO*/ } uint32_t getDeviceSampleRate() const { return m_deviceSampleRate; } - virtual QByteArray serialize() const; - virtual bool deserialize(const QByteArray& data); + QByteArray serialize() const final; + bool deserialize(const QByteArray& data) final; - virtual int getNbSinkStreams() const { return 2; } - virtual int getNbSourceStreams() const { return 0; } - virtual int getStreamIndex() const { return -1; } + int getNbSinkStreams() const final { return 2; } + int getNbSourceStreams() const final { return 0; } + int getStreamIndex() const final { return -1; } - virtual qint64 getStreamCenterFrequency(int streamIndex, bool sinkElseSource) const + qint64 getStreamCenterFrequency(int streamIndex, bool sinkElseSource) const final { (void) streamIndex; (void) sinkElseSource; return m_frequencyOffset; } - virtual void setMessageQueueToGUI(MessageQueue *queue) { m_guiMessageQueue = queue; } - MessageQueue *getMessageQueueToGUI() { return m_guiMessageQueue; } - SpectrumVis *getSpectrumVis() { return &m_spectrumVis; } ScopeVis *getScopeVis() { return &m_scopeSink; } void applyChannelSettings(uint32_t log2Decim, uint32_t filterChainHash); const QList& getDeviceSetList() { return m_localInputDeviceIndexes; } - virtual int webapiSettingsGet( - SWGSDRangel::SWGChannelSettings& response, - QString& errorMessage); + int webapiSettingsGet( + SWGSDRangel::SWGChannelSettings& response, + QString& errorMessage) final; - virtual int webapiSettingsPutPatch( - bool force, - const QStringList& channelSettingsKeys, - SWGSDRangel::SWGChannelSettings& response, - QString& errorMessage); + int webapiSettingsPutPatch( + bool force, + const QStringList& channelSettingsKeys, + SWGSDRangel::SWGChannelSettings& response, + QString& errorMessage) final; - virtual int webapiWorkspaceGet( - SWGSDRangel::SWGWorkspaceInfo& query, - QString& errorMessage); + int webapiWorkspaceGet( + SWGSDRangel::SWGWorkspaceInfo& query, + QString& errorMessage) final; static void webapiFormatChannelSettings( SWGSDRangel::SWGChannelSettings& response, const InterferometerSettings& settings); static void webapiUpdateChannelSettings( - InterferometerSettings& settings, - const QStringList& channelSettingsKeys, - SWGSDRangel::SWGChannelSettings& response); + InterferometerSettings& settings, + const QStringList& channelSettingsKeys, + SWGSDRangel::SWGChannelSettings& response); static const char* const m_channelIdURI; static const char* const m_channelId; @@ -196,11 +193,12 @@ private: uint64_t m_centerFrequency; int64_t m_frequencyOffset; uint32_t m_deviceSampleRate; - int m_count0, m_count1; + int m_count0; + int m_count1; QList m_localInputDeviceIndexes; - virtual bool handleMessage(const Message& cmd); //!< Processing of a message. Returns true if message has actually been processed + bool handleMessage(const Message& cmd) final; //!< Processing of a message. Returns true if message has actually been processed void applySettings(const InterferometerSettings& settings, const QList& settingsKeys, bool force = false); static void validateFilterChainHash(InterferometerSettings& settings); void calculateFrequencyOffset(uint32_t log2Decim, uint32_t filterChainHash); @@ -213,17 +211,17 @@ private: const QList& channelSettingsKeys, const InterferometerSettings& settings, bool force - ); + ) const; void webapiFormatChannelSettings( const QList& channelSettingsKeys, SWGSDRangel::SWGChannelSettings *swgChannelSettings, const InterferometerSettings& settings, bool force - ); + ) const; private slots: void handleInputMessages(); - void networkManagerFinished(QNetworkReply *reply); + void networkManagerFinished(QNetworkReply *reply) const; }; #endif // INCLUDE_INTERFEROMETER_H diff --git a/plugins/channelmimo/interferometer/interferometergui.cpp b/plugins/channelmimo/interferometer/interferometergui.cpp index a4830d32c..f9f006eef 100644 --- a/plugins/channelmimo/interferometer/interferometergui.cpp +++ b/plugins/channelmimo/interferometer/interferometergui.cpp @@ -32,15 +32,10 @@ InterferometerGUI* InterferometerGUI::create(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, MIMOChannel *channelMIMO) { - InterferometerGUI* gui = new InterferometerGUI(pluginAPI, deviceUISet, channelMIMO); + auto* gui = new InterferometerGUI(pluginAPI, deviceUISet, channelMIMO); return gui; } -void InterferometerGUI::destroy() -{ - delete this; -} - void InterferometerGUI::resetToDefaults() { m_settings.resetToDefaults(); @@ -77,7 +72,7 @@ bool InterferometerGUI::handleMessage(const Message& message) { if (Interferometer::MsgBasebandNotification::match(message)) { - Interferometer::MsgBasebandNotification& notif = (Interferometer::MsgBasebandNotification&) message; + auto& notif = (const Interferometer::MsgBasebandNotification&) message; m_sampleRate = notif.getSampleRate(); m_centerFrequency = notif.getCenterFrequency(); displayRateAndShift(); @@ -86,7 +81,7 @@ bool InterferometerGUI::handleMessage(const Message& message) } else if (Interferometer::MsgConfigureInterferometer::match(message)) { - const Interferometer::MsgConfigureInterferometer& cfg = (const Interferometer::MsgConfigureInterferometer&) message; + auto& cfg = (const Interferometer::MsgConfigureInterferometer&) message; if (cfg.getForce()) { m_settings = cfg.getSettings(); @@ -102,7 +97,8 @@ bool InterferometerGUI::handleMessage(const Message& message) } else if (Interferometer::MsgReportDevices::match(message)) { - Interferometer::MsgReportDevices& report = (Interferometer::MsgReportDevices&) message; + auto& msg = const_cast(message); + auto& report = (Interferometer::MsgReportDevices&) msg; updateDeviceSetList(report.getDeviceSetIndexes()); return true; } @@ -135,7 +131,7 @@ InterferometerGUI::InterferometerGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUI m_spectrumVis->setGLSpectrum(ui->glSpectrum); m_scopeVis = m_interferometer->getScopeVis(); m_scopeVis->setGLScope(ui->glScope); - m_interferometer->setMessageQueueToGUI(getInputMessageQueue()); + m_interferometer->setMessageQueueToGUI(InterferometerGUI::getInputMessageQueue()); m_sampleRate = m_interferometer->getDeviceSampleRate(); ui->spectrumGUI->setBuddies(m_spectrumVis, ui->glSpectrum); @@ -175,7 +171,7 @@ InterferometerGUI::InterferometerGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUI m_scopeVis->setTraceChunkSize(Interferometer::m_fftSize); // Set scope trace length unit to FFT size ui->scopeGUI->traceLengthChange(); - connect(getInputMessageQueue(), SIGNAL(messageEnqueued()), this, SLOT(handleSourceMessages())); + connect(InterferometerGUI::getInputMessageQueue(), SIGNAL(messageEnqueued()), this, SLOT(handleSourceMessages())); updateDeviceSetList(m_interferometer->getDeviceSetList()); displaySettings(); @@ -243,15 +239,15 @@ void InterferometerGUI::displaySettings() void InterferometerGUI::displayRateAndShift() { - int shift = m_shiftFrequencyFactor * m_sampleRate; + auto shift = (int) (m_shiftFrequencyFactor * m_sampleRate); double channelSampleRate = ((double) m_sampleRate) / (1<offsetFrequencyText->setText(tr("%1 Hz").arg(loc.toString(shift))); ui->channelRateText->setText(tr("%1k").arg(QString::number(channelSampleRate / 1000.0, 'g', 5))); m_channelMarker.setCenterFrequency(shift); - m_channelMarker.setBandwidth(channelSampleRate); - ui->glSpectrum->setSampleRate(channelSampleRate); - m_scopeVis->setLiveRate(channelSampleRate); + m_channelMarker.setBandwidth((int) channelSampleRate); + ui->glSpectrum->setSampleRate((int) channelSampleRate); + m_scopeVis->setLiveRate((int) channelSampleRate); } void InterferometerGUI::leaveEvent(QEvent*) @@ -268,7 +264,7 @@ void InterferometerGUI::handleSourceMessages() { Message* message; - while ((message = getInputMessageQueue()->pop()) != 0) + while ((message = getInputMessageQueue()->pop()) != nullptr) { if (handleMessage(*message)) { @@ -277,7 +273,7 @@ void InterferometerGUI::handleSourceMessages() } } -void InterferometerGUI::onWidgetRolled(QWidget* widget, bool rollDown) +void InterferometerGUI::onWidgetRolled(const QWidget* widget, bool rollDown) { (void) widget; (void) rollDown; @@ -288,7 +284,7 @@ void InterferometerGUI::onWidgetRolled(QWidget* widget, bool rollDown) void InterferometerGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); @@ -330,7 +326,7 @@ void InterferometerGUI::onMenuDialogCalled(const QPoint &p) void InterferometerGUI::updateDeviceSetList(const QList& deviceSetIndexes) { - QList::const_iterator it = deviceSetIndexes.begin(); + auto it = deviceSetIndexes.begin(); ui->localDevice->blockSignals(true); @@ -343,7 +339,7 @@ void InterferometerGUI::updateDeviceSetList(const QList& deviceSetIndexes) ui->localDevice->blockSignals(false); } -int InterferometerGUI::getLocalDeviceIndexInCombo(int localDeviceIndex) +int InterferometerGUI::getLocalDeviceIndexInCombo(int localDeviceIndex) const { int index = 0; @@ -457,7 +453,7 @@ void InterferometerGUI::tick() } } -void InterferometerGUI::makeUIConnections() +void InterferometerGUI::makeUIConnections() const { QObject::connect(ui->decimationFactor, QOverload::of(&QComboBox::currentIndexChanged), this, &InterferometerGUI::on_decimationFactor_currentIndexChanged); QObject::connect(ui->position, &QSlider::valueChanged, this, &InterferometerGUI::on_position_valueChanged); @@ -472,5 +468,5 @@ void InterferometerGUI::makeUIConnections() void InterferometerGUI::updateAbsoluteCenterFrequency() { - setStatusFrequency(m_centerFrequency + m_shiftFrequencyFactor * m_sampleRate); + setStatusFrequency((qint64) ((double) m_centerFrequency + m_shiftFrequencyFactor * m_sampleRate)); } diff --git a/plugins/channelmimo/interferometer/interferometergui.h b/plugins/channelmimo/interferometer/interferometergui.h index a0d19f59d..f6fc7a37d 100644 --- a/plugins/channelmimo/interferometer/interferometergui.h +++ b/plugins/channelmimo/interferometer/interferometergui.h @@ -46,22 +46,21 @@ class InterferometerGUI : public ChannelGUI { public: static InterferometerGUI* create(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, MIMOChannel *mimoChannel); - virtual void destroy(); - virtual void resetToDefaults(); - virtual QByteArray serialize() const; - virtual bool deserialize(const QByteArray& data); - virtual MessageQueue* getInputMessageQueue(); - virtual void setWorkspaceIndex(int index) { m_settings.m_workspaceIndex = index; }; - virtual int getWorkspaceIndex() const { return m_settings.m_workspaceIndex; }; - virtual void setGeometryBytes(const QByteArray& blob) { m_settings.m_geometryBytes = blob; }; - virtual QByteArray getGeometryBytes() const { return m_settings.m_geometryBytes; }; - virtual QString getTitle() const { return m_settings.m_title; }; - virtual QColor getTitleColor() const { return m_settings.m_rgbColor; }; - virtual void zetHidden(bool hidden) { m_settings.m_hidden = hidden; } - virtual bool getHidden() const { return m_settings.m_hidden; } - virtual ChannelMarker& getChannelMarker() { return m_channelMarker; } - virtual int getStreamIndex() const { return -1; } - virtual void setStreamIndex(int streamIndex) { (void) streamIndex; } + void resetToDefaults() final; + QByteArray serialize() const final; + bool deserialize(const QByteArray& data) final; + MessageQueue* getInputMessageQueue() final; + void setWorkspaceIndex(int index) final { m_settings.m_workspaceIndex = index; }; + int getWorkspaceIndex() const final { return m_settings.m_workspaceIndex; }; + void setGeometryBytes(const QByteArray& blob) final { m_settings.m_geometryBytes = blob; }; + QByteArray getGeometryBytes() const final { return m_settings.m_geometryBytes; }; + QString getTitle() const final { return m_settings.m_title; }; + QColor getTitleColor() const final { return m_settings.m_rgbColor; }; + void zetHidden(bool hidden) final { m_settings.m_hidden = hidden; } + bool getHidden() const final { return m_settings.m_hidden; } + ChannelMarker& getChannelMarker() final { return m_channelMarker; } + int getStreamIndex() const final { return -1; } + void setStreamIndex(int streamIndex) final { (void) streamIndex; } private: Ui::InterferometerGUI* ui; @@ -83,7 +82,7 @@ private: uint32_t m_tickCount; explicit InterferometerGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, MIMOChannel *rxChannel, QWidget* parent = nullptr); - virtual ~InterferometerGUI(); + ~InterferometerGUI() final; void blockApplySettings(bool block); void applySettings(bool force = false); @@ -92,13 +91,13 @@ private: void displaySettings(); void displayRateAndShift(); bool handleMessage(const Message& message); - void makeUIConnections(); + void makeUIConnections() const; void updateAbsoluteCenterFrequency(); void updateDeviceSetList(const QList& deviceSetIndexes); - int getLocalDeviceIndexInCombo(int localDeviceIndex); + int getLocalDeviceIndexInCombo(int localDeviceIndex) const; - void leaveEvent(QEvent*); - void enterEvent(EnterEventType*); + void leaveEvent(QEvent*) final; + void enterEvent(EnterEventType*) final; private slots: void handleSourceMessages(); @@ -111,7 +110,7 @@ private slots: void on_correlationType_currentIndexChanged(int index); void on_localDevice_currentIndexChanged(int index); void on_localDevicePlay_toggled(bool checked); - void onWidgetRolled(QWidget* widget, bool rollDown); + void onWidgetRolled(const QWidget* widget, bool rollDown); void onMenuDialogCalled(const QPoint& p); void tick(); }; diff --git a/plugins/channelrx/chanalyzer/chanalyzergui.cpp b/plugins/channelrx/chanalyzer/chanalyzergui.cpp index 6de3cac8c..26b15643d 100644 --- a/plugins/channelrx/chanalyzer/chanalyzergui.cpp +++ b/plugins/channelrx/chanalyzer/chanalyzergui.cpp @@ -474,7 +474,7 @@ void ChannelAnalyzerGUI::onWidgetRolled(QWidget* widget, bool rollDown) void ChannelAnalyzerGUI::onMenuDialogCalled(const QPoint& p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); diff --git a/plugins/channelrx/channelpower/channelpower.h b/plugins/channelrx/channelpower/channelpower.h index 505c2db52..07ab73e4d 100644 --- a/plugins/channelrx/channelpower/channelpower.h +++ b/plugins/channelrx/channelpower/channelpower.h @@ -138,11 +138,6 @@ public: m_basebandSink->resetMagLevels(); } -/* void setMessageQueueToGUI(MessageQueue* queue) override { - ChannelAPI::setMessageQueueToGUI(queue); - m_basebandSink->setMessageQueueToGUI(queue); - }*/ - uint32_t getNumberOfDeviceStreams() const; static const char * const m_channelIdURI; diff --git a/plugins/channelrx/channelpower/channelpowergui.cpp b/plugins/channelrx/channelpower/channelpowergui.cpp index 5b90dcc15..f76aa829e 100644 --- a/plugins/channelrx/channelpower/channelpowergui.cpp +++ b/plugins/channelrx/channelpower/channelpowergui.cpp @@ -200,7 +200,7 @@ void ChannelPowerGUI::onWidgetRolled(QWidget* widget, bool rollDown) void ChannelPowerGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); diff --git a/plugins/channelrx/demodadsb/adsbdemod.h b/plugins/channelrx/demodadsb/adsbdemod.h index 2ded12ee9..aa514e784 100644 --- a/plugins/channelrx/demodadsb/adsbdemod.h +++ b/plugins/channelrx/demodadsb/adsbdemod.h @@ -152,7 +152,7 @@ public: SWGSDRangel::SWGChannelSettings& response); void getMagSqLevels(double& avg, double& peak, int& nbSamples) { m_basebandSink->getMagSqLevels(avg, peak, nbSamples); } - void setMessageQueueToGUI(MessageQueue* queue) override { + void setMessageQueueToGUI(MessageQueue* queue) final { ChannelAPI::setMessageQueueToGUI(queue); m_basebandSink->setMessageQueueToGUI(queue); } diff --git a/plugins/channelrx/demodadsb/adsbdemodgui.cpp b/plugins/channelrx/demodadsb/adsbdemodgui.cpp index 342e8f5c8..40f5b7528 100644 --- a/plugins/channelrx/demodadsb/adsbdemodgui.cpp +++ b/plugins/channelrx/demodadsb/adsbdemodgui.cpp @@ -3904,7 +3904,7 @@ void ADSBDemodGUI::onWidgetRolled(QWidget* widget, bool rollDown) void ADSBDemodGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); diff --git a/plugins/channelrx/demodais/aisdemod.h b/plugins/channelrx/demodais/aisdemod.h index 54b521af2..009f3be1c 100644 --- a/plugins/channelrx/demodais/aisdemod.h +++ b/plugins/channelrx/demodais/aisdemod.h @@ -163,10 +163,6 @@ public: void getMagSqLevels(double& avg, double& peak, int& nbSamples) { m_basebandSink->getMagSqLevels(avg, peak, nbSamples); } -/* void setMessageQueueToGUI(MessageQueue* queue) override { - ChannelAPI::setMessageQueueToGUI(queue); - m_basebandSink->setMessageQueueToGUI(queue); - }*/ uint32_t getNumberOfDeviceStreams() const; diff --git a/plugins/channelrx/demodais/aisdemodgui.cpp b/plugins/channelrx/demodais/aisdemodgui.cpp index b47ebbf36..2c6b877a2 100644 --- a/plugins/channelrx/demodais/aisdemodgui.cpp +++ b/plugins/channelrx/demodais/aisdemodgui.cpp @@ -667,7 +667,7 @@ void AISDemodGUI::onWidgetRolled(QWidget* widget, bool rollDown) void AISDemodGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); diff --git a/plugins/channelrx/demodam/amdemodgui.cpp b/plugins/channelrx/demodam/amdemodgui.cpp index 415a65f3e..bed687ecf 100644 --- a/plugins/channelrx/demodam/amdemodgui.cpp +++ b/plugins/channelrx/demodam/amdemodgui.cpp @@ -394,7 +394,7 @@ void AMDemodGUI::onWidgetRolled(QWidget* widget, bool rollDown) void AMDemodGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); diff --git a/plugins/channelrx/demodapt/aptdemodgui.cpp b/plugins/channelrx/demodapt/aptdemodgui.cpp index c018ae69c..cdbf3250f 100644 --- a/plugins/channelrx/demodapt/aptdemodgui.cpp +++ b/plugins/channelrx/demodapt/aptdemodgui.cpp @@ -556,7 +556,7 @@ void APTDemodGUI::onWidgetRolled(QWidget* widget, bool rollDown) void APTDemodGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); diff --git a/plugins/channelrx/demodatv/atvdemodgui.cpp b/plugins/channelrx/demodatv/atvdemodgui.cpp index d8b9f0128..cd010a55d 100644 --- a/plugins/channelrx/demodatv/atvdemodgui.cpp +++ b/plugins/channelrx/demodatv/atvdemodgui.cpp @@ -207,7 +207,7 @@ void ATVDemodGUI::handleSourceMessages() void ATVDemodGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); diff --git a/plugins/channelrx/demodbfm/bfmdemodgui.cpp b/plugins/channelrx/demodbfm/bfmdemodgui.cpp index 516132209..2ccd75900 100644 --- a/plugins/channelrx/demodbfm/bfmdemodgui.cpp +++ b/plugins/channelrx/demodbfm/bfmdemodgui.cpp @@ -332,7 +332,7 @@ void BFMDemodGUI::onWidgetRolled(QWidget* widget, bool rollDown) void BFMDemodGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); diff --git a/plugins/channelrx/demodchirpchat/chirpchatdemodgui.cpp b/plugins/channelrx/demodchirpchat/chirpchatdemodgui.cpp index 7a87afeb5..ceaada06e 100644 --- a/plugins/channelrx/demodchirpchat/chirpchatdemodgui.cpp +++ b/plugins/channelrx/demodchirpchat/chirpchatdemodgui.cpp @@ -349,7 +349,7 @@ void ChirpChatDemodGUI::onWidgetRolled(QWidget* widget, bool rollDown) void ChirpChatDemodGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); diff --git a/plugins/channelrx/demoddab/dabdemod.h b/plugins/channelrx/demoddab/dabdemod.h index 8f90cc756..bce5df35b 100644 --- a/plugins/channelrx/demoddab/dabdemod.h +++ b/plugins/channelrx/demoddab/dabdemod.h @@ -392,10 +392,6 @@ public: void getMagSqLevels(double& avg, double& peak, int& nbSamples) { m_basebandSink->getMagSqLevels(avg, peak, nbSamples); } -/* void setMessageQueueToGUI(MessageQueue* queue) override { - ChannelAPI::setMessageQueueToGUI(queue); - m_basebandSink->setMessageQueueToGUI(queue); - }*/ uint32_t getNumberOfDeviceStreams() const; int getAudioSampleRate() const { return m_basebandSink->getAudioSampleRate(); } diff --git a/plugins/channelrx/demoddab/dabdemodgui.cpp b/plugins/channelrx/demoddab/dabdemodgui.cpp index 889a41334..956632439 100644 --- a/plugins/channelrx/demoddab/dabdemodgui.cpp +++ b/plugins/channelrx/demoddab/dabdemodgui.cpp @@ -451,7 +451,7 @@ void DABDemodGUI::onWidgetRolled(QWidget* widget, bool rollDown) void DABDemodGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); diff --git a/plugins/channelrx/demoddatv/datvdemodgui.cpp b/plugins/channelrx/demoddatv/datvdemodgui.cpp index 56ef72028..cce1efe84 100644 --- a/plugins/channelrx/demoddatv/datvdemodgui.cpp +++ b/plugins/channelrx/demoddatv/datvdemodgui.cpp @@ -169,7 +169,7 @@ void DATVDemodGUI::onWidgetRolled(QWidget* widget, bool rollDown) void DATVDemodGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); diff --git a/plugins/channelrx/demoddsc/dscdemod.h b/plugins/channelrx/demoddsc/dscdemod.h index 4fd4c1201..e06b3bde5 100644 --- a/plugins/channelrx/demoddsc/dscdemod.h +++ b/plugins/channelrx/demoddsc/dscdemod.h @@ -163,10 +163,6 @@ public: void getMagSqLevels(double& avg, double& peak, int& nbSamples) { m_basebandSink->getMagSqLevels(avg, peak, nbSamples); } -/* void setMessageQueueToGUI(MessageQueue* queue) override { - ChannelAPI::setMessageQueueToGUI(queue); - m_basebandSink->setMessageQueueToGUI(queue); - }*/ uint32_t getNumberOfDeviceStreams() const; diff --git a/plugins/channelrx/demoddsc/dscdemodgui.cpp b/plugins/channelrx/demoddsc/dscdemodgui.cpp index cbade9cbd..de9f2deb6 100644 --- a/plugins/channelrx/demoddsc/dscdemodgui.cpp +++ b/plugins/channelrx/demoddsc/dscdemodgui.cpp @@ -493,7 +493,7 @@ void DSCDemodGUI::onWidgetRolled(QWidget* widget, bool rollDown) void DSCDemodGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); diff --git a/plugins/channelrx/demoddsd/dsddemodgui.cpp b/plugins/channelrx/demoddsd/dsddemodgui.cpp index fa88e0248..b6be07e02 100644 --- a/plugins/channelrx/demoddsd/dsddemodgui.cpp +++ b/plugins/channelrx/demoddsd/dsddemodgui.cpp @@ -297,7 +297,7 @@ void DSDDemodGUI::onWidgetRolled(QWidget* widget, bool rollDown) void DSDDemodGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); diff --git a/plugins/channelrx/demodendoftrain/endoftraindemod.h b/plugins/channelrx/demodendoftrain/endoftraindemod.h index a3d294403..88f2b2278 100644 --- a/plugins/channelrx/demodendoftrain/endoftraindemod.h +++ b/plugins/channelrx/demodendoftrain/endoftraindemod.h @@ -137,10 +137,6 @@ public: void getMagSqLevels(double& avg, double& peak, int& nbSamples) { m_basebandSink->getMagSqLevels(avg, peak, nbSamples); } -/* void setMessageQueueToGUI(MessageQueue* queue) override { - ChannelAPI::setMessageQueueToGUI(queue); - m_basebandSink->setMessageQueueToGUI(queue); - }*/ uint32_t getNumberOfDeviceStreams() const; diff --git a/plugins/channelrx/demodendoftrain/endoftraindemodgui.cpp b/plugins/channelrx/demodendoftrain/endoftraindemodgui.cpp index d94497b10..3d66bc991 100644 --- a/plugins/channelrx/demodendoftrain/endoftraindemodgui.cpp +++ b/plugins/channelrx/demodendoftrain/endoftraindemodgui.cpp @@ -373,7 +373,7 @@ void EndOfTrainDemodGUI::onWidgetRolled(QWidget* widget, bool rollDown) void EndOfTrainDemodGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); diff --git a/plugins/channelrx/demodfreedv/freedvdemodgui.cpp b/plugins/channelrx/demodfreedv/freedvdemodgui.cpp index 5a738215f..cd35e0633 100644 --- a/plugins/channelrx/demodfreedv/freedvdemodgui.cpp +++ b/plugins/channelrx/demodfreedv/freedvdemodgui.cpp @@ -201,7 +201,7 @@ void FreeDVDemodGUI::on_spanLog2_valueChanged(int value) void FreeDVDemodGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); diff --git a/plugins/channelrx/demodft8/ft8demod.h b/plugins/channelrx/demodft8/ft8demod.h index 8b57d2b23..7fe05bb77 100644 --- a/plugins/channelrx/demodft8/ft8demod.h +++ b/plugins/channelrx/demodft8/ft8demod.h @@ -102,7 +102,7 @@ public: } void setDeviceCenterFrequency(qint64 centerFrequency, int index); - void setMessageQueueToGUI(MessageQueue* queue) override; + void setMessageQueueToGUI(MessageQueue* queue) final; uint32_t getChannelSampleRate() const { return m_running ? m_basebandSink->getChannelSampleRate() : 0; } double getMagSq() const { return m_running ? m_basebandSink->getMagSq() : 0.0; } diff --git a/plugins/channelrx/demodft8/ft8demodgui.cpp b/plugins/channelrx/demodft8/ft8demodgui.cpp index 43f762245..2de0c60e9 100644 --- a/plugins/channelrx/demodft8/ft8demodgui.cpp +++ b/plugins/channelrx/demodft8/ft8demodgui.cpp @@ -542,7 +542,7 @@ void FT8DemodGUI::on_settings_clicked() void FT8DemodGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); diff --git a/plugins/channelrx/demodils/ilsdemod.h b/plugins/channelrx/demodils/ilsdemod.h index a636983eb..911a2d1ab 100644 --- a/plugins/channelrx/demodils/ilsdemod.h +++ b/plugins/channelrx/demodils/ilsdemod.h @@ -179,10 +179,6 @@ public: void getMagSqLevels(double& avg, double& peak, int& nbSamples) { m_basebandSink->getMagSqLevels(avg, peak, nbSamples); } -/* void setMessageQueueToGUI(MessageQueue* queue) override { - ChannelAPI::setMessageQueueToGUI(queue); - m_basebandSink->setMessageQueueToGUI(queue); - }*/ uint32_t getNumberOfDeviceStreams() const; diff --git a/plugins/channelrx/demodils/ilsdemodgui.cpp b/plugins/channelrx/demodils/ilsdemodgui.cpp index 4d8baac7c..a155a41bb 100644 --- a/plugins/channelrx/demodils/ilsdemodgui.cpp +++ b/plugins/channelrx/demodils/ilsdemodgui.cpp @@ -946,7 +946,7 @@ void ILSDemodGUI::onWidgetRolled(QWidget* widget, bool rollDown) void ILSDemodGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); diff --git a/plugins/channelrx/demodm17/m17demodgui.cpp b/plugins/channelrx/demodm17/m17demodgui.cpp index 51941bf2a..88a323d1e 100644 --- a/plugins/channelrx/demodm17/m17demodgui.cpp +++ b/plugins/channelrx/demodm17/m17demodgui.cpp @@ -349,7 +349,7 @@ void M17DemodGUI::onWidgetRolled(QWidget* widget, bool rollDown) void M17DemodGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); diff --git a/plugins/channelrx/demodnavtex/navtexdemod.h b/plugins/channelrx/demodnavtex/navtexdemod.h index a9dc61f47..205cfecce 100644 --- a/plugins/channelrx/demodnavtex/navtexdemod.h +++ b/plugins/channelrx/demodnavtex/navtexdemod.h @@ -183,10 +183,6 @@ public: void getMagSqLevels(double& avg, double& peak, int& nbSamples) { m_basebandSink->getMagSqLevels(avg, peak, nbSamples); } -/* void setMessageQueueToGUI(MessageQueue* queue) override { - ChannelAPI::setMessageQueueToGUI(queue); - m_basebandSink->setMessageQueueToGUI(queue); - }*/ uint32_t getNumberOfDeviceStreams() const; diff --git a/plugins/channelrx/demodnavtex/navtexdemodgui.cpp b/plugins/channelrx/demodnavtex/navtexdemodgui.cpp index dbf3d7127..8fbba971b 100644 --- a/plugins/channelrx/demodnavtex/navtexdemodgui.cpp +++ b/plugins/channelrx/demodnavtex/navtexdemodgui.cpp @@ -450,7 +450,7 @@ void NavtexDemodGUI::onWidgetRolled(QWidget* widget, bool rollDown) void NavtexDemodGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); diff --git a/plugins/channelrx/demodnfm/nfmdemod.h b/plugins/channelrx/demodnfm/nfmdemod.h index 8d1504795..afa003127 100644 --- a/plugins/channelrx/demodnfm/nfmdemod.h +++ b/plugins/channelrx/demodnfm/nfmdemod.h @@ -135,7 +135,6 @@ public: } } - void setMessageQueueToGUI(MessageQueue* queue) override { ChannelAPI::setMessageQueueToGUI(queue); } int getAudioSampleRate() const { return m_running ? m_basebandSink->getAudioSampleRate() : 0; } uint32_t getNumberOfDeviceStreams() const; diff --git a/plugins/channelrx/demodnfm/nfmdemodgui.cpp b/plugins/channelrx/demodnfm/nfmdemodgui.cpp index 2a09aa779..2d832894a 100644 --- a/plugins/channelrx/demodnfm/nfmdemodgui.cpp +++ b/plugins/channelrx/demodnfm/nfmdemodgui.cpp @@ -318,7 +318,7 @@ void NFMDemodGUI::onWidgetRolled(QWidget* widget, bool rollDown) void NFMDemodGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); diff --git a/plugins/channelrx/demodpacket/packetdemod.h b/plugins/channelrx/demodpacket/packetdemod.h index 1d0d1238a..29763cb08 100644 --- a/plugins/channelrx/demodpacket/packetdemod.h +++ b/plugins/channelrx/demodpacket/packetdemod.h @@ -134,10 +134,6 @@ public: void getMagSqLevels(double& avg, double& peak, int& nbSamples) { m_basebandSink->getMagSqLevels(avg, peak, nbSamples); } -/* void setMessageQueueToGUI(MessageQueue* queue) override { - ChannelAPI::setMessageQueueToGUI(queue); - m_basebandSink->setMessageQueueToGUI(queue); - }*/ uint32_t getNumberOfDeviceStreams() const; diff --git a/plugins/channelrx/demodpacket/packetdemodgui.cpp b/plugins/channelrx/demodpacket/packetdemodgui.cpp index ce8059176..9c5174f44 100644 --- a/plugins/channelrx/demodpacket/packetdemodgui.cpp +++ b/plugins/channelrx/demodpacket/packetdemodgui.cpp @@ -372,7 +372,7 @@ void PacketDemodGUI::onWidgetRolled(QWidget* widget, bool rollDown) void PacketDemodGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); diff --git a/plugins/channelrx/demodpager/pagerdemod.h b/plugins/channelrx/demodpager/pagerdemod.h index cae8e7658..c59bddbb3 100644 --- a/plugins/channelrx/demodpager/pagerdemod.h +++ b/plugins/channelrx/demodpager/pagerdemod.h @@ -190,10 +190,6 @@ public: void getMagSqLevels(double& avg, double& peak, int& nbSamples) { m_basebandSink->getMagSqLevels(avg, peak, nbSamples); } -/* void setMessageQueueToGUI(MessageQueue* queue) override { - ChannelAPI::setMessageQueueToGUI(queue); - m_basebandSink->setMessageQueueToGUI(queue); - }*/ uint32_t getNumberOfDeviceStreams() const; diff --git a/plugins/channelrx/demodpager/pagerdemodgui.cpp b/plugins/channelrx/demodpager/pagerdemodgui.cpp index 89dea3efd..e8186da80 100644 --- a/plugins/channelrx/demodpager/pagerdemodgui.cpp +++ b/plugins/channelrx/demodpager/pagerdemodgui.cpp @@ -424,7 +424,7 @@ void PagerDemodGUI::onWidgetRolled(QWidget* widget, bool rollDown) void PagerDemodGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); diff --git a/plugins/channelrx/demodradiosonde/radiosondedemodgui.cpp b/plugins/channelrx/demodradiosonde/radiosondedemodgui.cpp index 4d88bb9c1..ed9621479 100644 --- a/plugins/channelrx/demodradiosonde/radiosondedemodgui.cpp +++ b/plugins/channelrx/demodradiosonde/radiosondedemodgui.cpp @@ -501,7 +501,7 @@ void RadiosondeDemodGUI::onWidgetRolled(QWidget* widget, bool rollDown) void RadiosondeDemodGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); diff --git a/plugins/channelrx/demodrtty/rttydemod.h b/plugins/channelrx/demodrtty/rttydemod.h index aa0267a0f..849579bac 100644 --- a/plugins/channelrx/demodrtty/rttydemod.h +++ b/plugins/channelrx/demodrtty/rttydemod.h @@ -177,10 +177,6 @@ public: void getMagSqLevels(double& avg, double& peak, int& nbSamples) { m_basebandSink->getMagSqLevels(avg, peak, nbSamples); } -/* void setMessageQueueToGUI(MessageQueue* queue) override { - ChannelAPI::setMessageQueueToGUI(queue); - m_basebandSink->setMessageQueueToGUI(queue); - }*/ uint32_t getNumberOfDeviceStreams() const; diff --git a/plugins/channelrx/demodrtty/rttydemodgui.cpp b/plugins/channelrx/demodrtty/rttydemodgui.cpp index 29977f38d..baad2448e 100644 --- a/plugins/channelrx/demodrtty/rttydemodgui.cpp +++ b/plugins/channelrx/demodrtty/rttydemodgui.cpp @@ -358,7 +358,7 @@ void RttyDemodGUI::onWidgetRolled(QWidget* widget, bool rollDown) void RttyDemodGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); diff --git a/plugins/channelrx/demodssb/ssbdemod.h b/plugins/channelrx/demodssb/ssbdemod.h index 49c3aa067..c2f7e94b7 100644 --- a/plugins/channelrx/demodssb/ssbdemod.h +++ b/plugins/channelrx/demodssb/ssbdemod.h @@ -101,7 +101,7 @@ public: return m_settings.m_inputFrequencyOffset; } - void setMessageQueueToGUI(MessageQueue* queue) override; + void setMessageQueueToGUI(MessageQueue* queue) final; uint32_t getAudioSampleRate() const { return m_running ? m_basebandSink->getAudioSampleRate() : 0; } uint32_t getChannelSampleRate() const { return m_running ? m_basebandSink->getChannelSampleRate() : 0; } double getMagSq() const { return m_running ? m_basebandSink->getMagSq() : 0.0; } diff --git a/plugins/channelrx/demodssb/ssbdemodgui.cpp b/plugins/channelrx/demodssb/ssbdemodgui.cpp index a331ffdff..879022832 100644 --- a/plugins/channelrx/demodssb/ssbdemodgui.cpp +++ b/plugins/channelrx/demodssb/ssbdemodgui.cpp @@ -299,7 +299,7 @@ void SSBDemodGUI::on_filterIndex_valueChanged(int value) void SSBDemodGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); diff --git a/plugins/channelrx/demodvor/vordemodgui.cpp b/plugins/channelrx/demodvor/vordemodgui.cpp index e6bbb5841..8ea23389c 100644 --- a/plugins/channelrx/demodvor/vordemodgui.cpp +++ b/plugins/channelrx/demodvor/vordemodgui.cpp @@ -238,7 +238,7 @@ void VORDemodGUI::onWidgetRolled(QWidget* widget, bool rollDown) void VORDemodGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); diff --git a/plugins/channelrx/demodvormc/vordemodmc.h b/plugins/channelrx/demodvormc/vordemodmc.h index 20799a1d4..febc6c95e 100644 --- a/plugins/channelrx/demodvormc/vordemodmc.h +++ b/plugins/channelrx/demodvormc/vordemodmc.h @@ -125,7 +125,7 @@ public: void getMagSqLevels(double& avg, double& peak, int& nbSamples) { m_basebandSink->getMagSqLevels(avg, peak, nbSamples); } - void setMessageQueueToGUI(MessageQueue* queue) override { + void setMessageQueueToGUI(MessageQueue* queue) final { ChannelAPI::setMessageQueueToGUI(queue); m_basebandSink->setMessageQueueToGUI(queue); } diff --git a/plugins/channelrx/demodvormc/vordemodmcgui.cpp b/plugins/channelrx/demodvormc/vordemodmcgui.cpp index 93a126c3f..a06c812f7 100644 --- a/plugins/channelrx/demodvormc/vordemodmcgui.cpp +++ b/plugins/channelrx/demodvormc/vordemodmcgui.cpp @@ -1111,7 +1111,7 @@ void VORDemodMCGUI::onWidgetRolled(QWidget* widget, bool rollDown) void VORDemodMCGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); diff --git a/plugins/channelrx/demodwfm/wfmdemodgui.cpp b/plugins/channelrx/demodwfm/wfmdemodgui.cpp index b9e576411..bae2b95c4 100644 --- a/plugins/channelrx/demodwfm/wfmdemodgui.cpp +++ b/plugins/channelrx/demodwfm/wfmdemodgui.cpp @@ -180,7 +180,7 @@ void WFMDemodGUI::onWidgetRolled(QWidget* widget, bool rollDown) void WFMDemodGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); diff --git a/plugins/channelrx/filesink/filesink.h b/plugins/channelrx/filesink/filesink.h index 516bd2d23..16079ce5a 100644 --- a/plugins/channelrx/filesink/filesink.h +++ b/plugins/channelrx/filesink/filesink.h @@ -148,7 +148,7 @@ public: const QStringList& channelSettingsKeys, SWGSDRangel::SWGChannelSettings& response); - void setMessageQueueToGUI(MessageQueue* queue) override; + void setMessageQueueToGUI(MessageQueue* queue) final; void getLocalDevices(std::vector& indexes); uint32_t getNumberOfDeviceStreams() const; SpectrumVis *getSpectrumVis() { return &m_spectrumVis; } diff --git a/plugins/channelrx/filesink/filesinkgui.cpp b/plugins/channelrx/filesink/filesinkgui.cpp index 1b83569f0..5e686366a 100644 --- a/plugins/channelrx/filesink/filesinkgui.cpp +++ b/plugins/channelrx/filesink/filesinkgui.cpp @@ -363,7 +363,7 @@ void FileSinkGUI::onWidgetRolled(QWidget* widget, bool rollDown) void FileSinkGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); diff --git a/plugins/channelrx/freqscanner/freqscanner.h b/plugins/channelrx/freqscanner/freqscanner.h index a5ec4ff37..3989b00c7 100644 --- a/plugins/channelrx/freqscanner/freqscanner.h +++ b/plugins/channelrx/freqscanner/freqscanner.h @@ -355,7 +355,7 @@ public: const QStringList& channelSettingsKeys, SWGSDRangel::SWGChannelSettings& response); - void setMessageQueueToGUI(MessageQueue* queue) override { + void setMessageQueueToGUI(MessageQueue* queue) final { ChannelAPI::setMessageQueueToGUI(queue); m_basebandSink->setMessageQueueToGUI(queue); } diff --git a/plugins/channelrx/freqscanner/freqscannergui.cpp b/plugins/channelrx/freqscanner/freqscannergui.cpp index fa8287ec0..7aa5ead86 100644 --- a/plugins/channelrx/freqscanner/freqscannergui.cpp +++ b/plugins/channelrx/freqscanner/freqscannergui.cpp @@ -377,7 +377,7 @@ void FreqScannerGUI::onWidgetRolled(QWidget* widget, bool rollDown) void FreqScannerGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); diff --git a/plugins/channelrx/freqtracker/freqtrackergui.cpp b/plugins/channelrx/freqtracker/freqtrackergui.cpp index 2bb22702f..965bc6505 100644 --- a/plugins/channelrx/freqtracker/freqtrackergui.cpp +++ b/plugins/channelrx/freqtracker/freqtrackergui.cpp @@ -264,7 +264,7 @@ void FreqTrackerGUI::onWidgetRolled(QWidget* widget, bool rollDown) void FreqTrackerGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); diff --git a/plugins/channelrx/heatmap/heatmap.h b/plugins/channelrx/heatmap/heatmap.h index 91505d224..34e074f28 100644 --- a/plugins/channelrx/heatmap/heatmap.h +++ b/plugins/channelrx/heatmap/heatmap.h @@ -143,11 +143,6 @@ public: m_basebandSink->resetMagLevels(); } -/* void setMessageQueueToGUI(MessageQueue* queue) override { - ChannelAPI::setMessageQueueToGUI(queue); - m_basebandSink->setMessageQueueToGUI(queue); - }*/ - uint32_t getNumberOfDeviceStreams() const; static const char * const m_channelIdURI; diff --git a/plugins/channelrx/heatmap/heatmapgui.cpp b/plugins/channelrx/heatmap/heatmapgui.cpp index d18b3a9de..6d9fc7213 100644 --- a/plugins/channelrx/heatmap/heatmapgui.cpp +++ b/plugins/channelrx/heatmap/heatmapgui.cpp @@ -483,7 +483,7 @@ void HeatMapGUI::onWidgetRolled(QWidget* widget, bool rollDown) void HeatMapGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); diff --git a/plugins/channelrx/localsink/localsinkgui.cpp b/plugins/channelrx/localsink/localsinkgui.cpp index 002de5ac4..34a819ba9 100644 --- a/plugins/channelrx/localsink/localsinkgui.cpp +++ b/plugins/channelrx/localsink/localsinkgui.cpp @@ -333,7 +333,7 @@ void LocalSinkGUI::onWidgetRolled(QWidget* widget, bool rollDown) void LocalSinkGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); diff --git a/plugins/channelrx/noisefigure/noisefiguregui.cpp b/plugins/channelrx/noisefigure/noisefiguregui.cpp index b371b3061..8f41f7b2a 100644 --- a/plugins/channelrx/noisefigure/noisefiguregui.cpp +++ b/plugins/channelrx/noisefigure/noisefiguregui.cpp @@ -540,7 +540,7 @@ void NoiseFigureGUI::onWidgetRolled(QWidget* widget, bool rollDown) void NoiseFigureGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); diff --git a/plugins/channelrx/radioastronomy/radioastronomy.h b/plugins/channelrx/radioastronomy/radioastronomy.h index bc1679bac..db3948ba8 100644 --- a/plugins/channelrx/radioastronomy/radioastronomy.h +++ b/plugins/channelrx/radioastronomy/radioastronomy.h @@ -442,10 +442,6 @@ public: void getMagSqLevels(double& avg, double& peak, int& nbSamples) { m_basebandSink->getMagSqLevels(avg, peak, nbSamples); } -/* void setMessageQueueToGUI(MessageQueue* queue) override { - ChannelAPI::setMessageQueueToGUI(queue); - m_basebandSink->setMessageQueueToGUI(queue); - }*/ uint32_t getNumberOfDeviceStreams() const; diff --git a/plugins/channelrx/radioastronomy/radioastronomygui.cpp b/plugins/channelrx/radioastronomy/radioastronomygui.cpp index 185bfd384..89633ad55 100644 --- a/plugins/channelrx/radioastronomy/radioastronomygui.cpp +++ b/plugins/channelrx/radioastronomy/radioastronomygui.cpp @@ -1940,7 +1940,7 @@ void RadioAstronomyGUI::onWidgetRolled(QWidget* widget, bool rollDown) void RadioAstronomyGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); diff --git a/plugins/channelrx/radioclock/radioclockgui.cpp b/plugins/channelrx/radioclock/radioclockgui.cpp index e1fe6ff59..a21d19e96 100644 --- a/plugins/channelrx/radioclock/radioclockgui.cpp +++ b/plugins/channelrx/radioclock/radioclockgui.cpp @@ -282,7 +282,7 @@ void RadioClockGUI::onWidgetRolled(QWidget* widget, bool rollDown) void RadioClockGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); diff --git a/plugins/channelrx/remotesink/remotesinkgui.cpp b/plugins/channelrx/remotesink/remotesinkgui.cpp index 259b0929a..94247a47d 100644 --- a/plugins/channelrx/remotesink/remotesinkgui.cpp +++ b/plugins/channelrx/remotesink/remotesinkgui.cpp @@ -233,7 +233,7 @@ void RemoteSinkGUI::onWidgetRolled(QWidget* widget, bool rollDown) void RemoteSinkGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); diff --git a/plugins/channelrx/remotetcpsink/remotetcpsink.h b/plugins/channelrx/remotetcpsink/remotetcpsink.h index 4b5cf1108..edb4e9170 100644 --- a/plugins/channelrx/remotetcpsink/remotetcpsink.h +++ b/plugins/channelrx/remotetcpsink/remotetcpsink.h @@ -164,7 +164,7 @@ public: uint32_t getNumberOfDeviceStreams() const; int getBasebandSampleRate() const { return m_basebandSampleRate; } - void setMessageQueueToGUI(MessageQueue* queue) override { + void setMessageQueueToGUI(MessageQueue* queue) final { ChannelAPI::setMessageQueueToGUI(queue); m_basebandSink->setMessageQueueToGUI(queue); } diff --git a/plugins/channelrx/remotetcpsink/remotetcpsinkgui.cpp b/plugins/channelrx/remotetcpsink/remotetcpsinkgui.cpp index 17c1fde3f..12d6fe11f 100644 --- a/plugins/channelrx/remotetcpsink/remotetcpsinkgui.cpp +++ b/plugins/channelrx/remotetcpsink/remotetcpsinkgui.cpp @@ -318,7 +318,7 @@ void RemoteTCPSinkGUI::onWidgetRolled(QWidget* widget, bool rollDown) void RemoteTCPSinkGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); diff --git a/plugins/channelrx/sigmffilesink/sigmffilesink.h b/plugins/channelrx/sigmffilesink/sigmffilesink.h index 3a5f3e29a..9a7f5d678 100644 --- a/plugins/channelrx/sigmffilesink/sigmffilesink.h +++ b/plugins/channelrx/sigmffilesink/sigmffilesink.h @@ -148,7 +148,7 @@ public: const QStringList& channelSettingsKeys, SWGSDRangel::SWGChannelSettings& response); - void setMessageQueueToGUI(MessageQueue* queue) override; + void setMessageQueueToGUI(MessageQueue* queue) final; void getLocalDevices(std::vector& indexes); uint32_t getNumberOfDeviceStreams() const; SpectrumVis *getSpectrumVis() { return &m_spectrumVis; } diff --git a/plugins/channelrx/sigmffilesink/sigmffilesinkgui.cpp b/plugins/channelrx/sigmffilesink/sigmffilesinkgui.cpp index 4036cbef0..2604d33a2 100644 --- a/plugins/channelrx/sigmffilesink/sigmffilesinkgui.cpp +++ b/plugins/channelrx/sigmffilesink/sigmffilesinkgui.cpp @@ -357,7 +357,7 @@ void SigMFFileSinkGUI::onWidgetRolled(QWidget* widget, bool rollDown) void SigMFFileSinkGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); diff --git a/plugins/channelrx/udpsink/udpsinkgui.cpp b/plugins/channelrx/udpsink/udpsinkgui.cpp index fada6d19f..5cf7d806c 100644 --- a/plugins/channelrx/udpsink/udpsinkgui.cpp +++ b/plugins/channelrx/udpsink/udpsinkgui.cpp @@ -615,7 +615,7 @@ void UDPSinkGUI::onWidgetRolled(QWidget* widget, bool rollDown) void UDPSinkGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); diff --git a/plugins/channelrx/wdsprx/wdsprx.h b/plugins/channelrx/wdsprx/wdsprx.h index cce0f4910..cd3c5e44e 100644 --- a/plugins/channelrx/wdsprx/wdsprx.h +++ b/plugins/channelrx/wdsprx/wdsprx.h @@ -101,7 +101,7 @@ public: return m_settings.m_inputFrequencyOffset; } - void setMessageQueueToGUI(MessageQueue* queue) override; + void setMessageQueueToGUI(MessageQueue* queue) final; uint32_t getAudioSampleRate() const { return m_running ? m_basebandSink->getAudioSampleRate() : 0; } uint32_t getChannelSampleRate() const { return m_running ? m_basebandSink->getChannelSampleRate() : 0; } double getMagSq() const { return m_running ? m_basebandSink->getMagSq() : 0.0; } diff --git a/plugins/channelrx/wdsprx/wdsprxgui.cpp b/plugins/channelrx/wdsprx/wdsprxgui.cpp index 46501630d..44c1f4f6f 100644 --- a/plugins/channelrx/wdsprx/wdsprxgui.cpp +++ b/plugins/channelrx/wdsprx/wdsprxgui.cpp @@ -434,7 +434,7 @@ void WDSPRxGUI::on_demod_currentIndexChanged(int index) void WDSPRxGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); diff --git a/plugins/channeltx/filesource/filesource.h b/plugins/channeltx/filesource/filesource.h index bf89c4b69..515fce43f 100644 --- a/plugins/channeltx/filesource/filesource.h +++ b/plugins/channeltx/filesource/filesource.h @@ -219,7 +219,7 @@ public: double getMagSq() const; void getMagSqLevels(double& avg, double& peak, int& nbSamples) const; - void setMessageQueueToGUI(MessageQueue* queue) override; + void setMessageQueueToGUI(MessageQueue* queue) final; uint32_t getNumberOfDeviceStreams() const; static const char* const m_channelIdURI; diff --git a/plugins/channeltx/filesource/filesourcegui.cpp b/plugins/channeltx/filesource/filesourcegui.cpp index 9d95a09ca..617ca34f6 100644 --- a/plugins/channeltx/filesource/filesourcegui.cpp +++ b/plugins/channeltx/filesource/filesourcegui.cpp @@ -369,7 +369,7 @@ void FileSourceGUI::onWidgetRolled(QWidget* widget, bool rollDown) void FileSourceGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); diff --git a/plugins/channeltx/localsource/localsourcegui.cpp b/plugins/channeltx/localsource/localsourcegui.cpp index 62138d604..191e3ebec 100644 --- a/plugins/channeltx/localsource/localsourcegui.cpp +++ b/plugins/channeltx/localsource/localsourcegui.cpp @@ -237,7 +237,7 @@ void LocalSourceGUI::onWidgetRolled(QWidget* widget, bool rollDown) void LocalSourceGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); diff --git a/plugins/channeltx/mod802.15.4/ieee_802_15_4_modgui.cpp b/plugins/channeltx/mod802.15.4/ieee_802_15_4_modgui.cpp index b9123943c..7a10b9932 100644 --- a/plugins/channeltx/mod802.15.4/ieee_802_15_4_modgui.cpp +++ b/plugins/channeltx/mod802.15.4/ieee_802_15_4_modgui.cpp @@ -331,7 +331,7 @@ void IEEE_802_15_4_ModGUI::onWidgetRolled(QWidget* widget, bool rollDown) void IEEE_802_15_4_ModGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); diff --git a/plugins/channeltx/modais/aismodgui.cpp b/plugins/channeltx/modais/aismodgui.cpp index d41a09f86..8e2a56dfa 100644 --- a/plugins/channeltx/modais/aismodgui.cpp +++ b/plugins/channeltx/modais/aismodgui.cpp @@ -353,7 +353,7 @@ void AISModGUI::onWidgetRolled(QWidget* widget, bool rollDown) void AISModGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); diff --git a/plugins/channeltx/modam/ammodgui.cpp b/plugins/channeltx/modam/ammodgui.cpp index ee02347bd..a0d5b8022 100644 --- a/plugins/channeltx/modam/ammodgui.cpp +++ b/plugins/channeltx/modam/ammodgui.cpp @@ -296,7 +296,7 @@ void AMModGUI::onWidgetRolled(const QWidget* widget, bool rollDown) void AMModGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); diff --git a/plugins/channeltx/modatv/atvmod.h b/plugins/channeltx/modatv/atvmod.h index bc77a82fc..164b8a010 100644 --- a/plugins/channeltx/modatv/atvmod.h +++ b/plugins/channeltx/modatv/atvmod.h @@ -309,7 +309,7 @@ public: void setLevelMeter(QObject *levelMeter); int getEffectiveSampleRate() const; void getCameraNumbers(std::vector& numbers); - void setMessageQueueToGUI(MessageQueue* queue) override; + void setMessageQueueToGUI(MessageQueue* queue) final; static const char* const m_channelIdURI; static const char* const m_channelId; diff --git a/plugins/channeltx/modatv/atvmodgui.cpp b/plugins/channeltx/modatv/atvmodgui.cpp index 0c0968950..409b2e7c6 100644 --- a/plugins/channeltx/modatv/atvmodgui.cpp +++ b/plugins/channeltx/modatv/atvmodgui.cpp @@ -702,7 +702,7 @@ void ATVModGUI::onWidgetRolled(QWidget* widget, bool rollDown) void ATVModGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); diff --git a/plugins/channeltx/modchirpchat/chirpchatmodgui.cpp b/plugins/channeltx/modchirpchat/chirpchatmodgui.cpp index f177e2bb5..deb422120 100644 --- a/plugins/channeltx/modchirpchat/chirpchatmodgui.cpp +++ b/plugins/channeltx/modchirpchat/chirpchatmodgui.cpp @@ -370,7 +370,7 @@ void ChirpChatModGUI::onWidgetRolled(QWidget* widget, bool rollDown) void ChirpChatModGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); diff --git a/plugins/channeltx/moddatv/datvmod.h b/plugins/channeltx/moddatv/datvmod.h index bb259141a..5d8f49aff 100644 --- a/plugins/channeltx/moddatv/datvmod.h +++ b/plugins/channeltx/moddatv/datvmod.h @@ -262,7 +262,7 @@ public: uint32_t getNumberOfDeviceStreams() const; double getMagSq() const; int getEffectiveSampleRate() const; - void setMessageQueueToGUI(MessageQueue* queue) override; + void setMessageQueueToGUI(MessageQueue* queue) final; static const char* const m_channelIdURI; static const char* const m_channelId; diff --git a/plugins/channeltx/moddatv/datvmodgui.cpp b/plugins/channeltx/moddatv/datvmodgui.cpp index 035be57a9..8478945f7 100644 --- a/plugins/channeltx/moddatv/datvmodgui.cpp +++ b/plugins/channeltx/moddatv/datvmodgui.cpp @@ -497,7 +497,7 @@ void DATVModGUI::onWidgetRolled(QWidget* widget, bool rollDown) void DATVModGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); diff --git a/plugins/channeltx/modfreedv/freedvmodgui.cpp b/plugins/channeltx/modfreedv/freedvmodgui.cpp index 5d289d51b..c63a5c802 100644 --- a/plugins/channeltx/modfreedv/freedvmodgui.cpp +++ b/plugins/channeltx/modfreedv/freedvmodgui.cpp @@ -306,7 +306,7 @@ void FreeDVModGUI::onWidgetRolled(QWidget* widget, bool rollDown) void FreeDVModGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); diff --git a/plugins/channeltx/modm17/m17modgui.cpp b/plugins/channeltx/modm17/m17modgui.cpp index c06b59c2c..3913603da 100644 --- a/plugins/channeltx/modm17/m17modgui.cpp +++ b/plugins/channeltx/modm17/m17modgui.cpp @@ -402,7 +402,7 @@ void M17ModGUI::onWidgetRolled(QWidget* widget, bool rollDown) void M17ModGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); diff --git a/plugins/channeltx/modnfm/nfmmodgui.cpp b/plugins/channeltx/modnfm/nfmmodgui.cpp index c3b51aff0..180a5e04e 100644 --- a/plugins/channeltx/modnfm/nfmmodgui.cpp +++ b/plugins/channeltx/modnfm/nfmmodgui.cpp @@ -384,7 +384,7 @@ void NFMModGUI::onWidgetRolled(QWidget* widget, bool rollDown) void NFMModGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); diff --git a/plugins/channeltx/modpacket/packetmodgui.cpp b/plugins/channeltx/modpacket/packetmodgui.cpp index 15fbc27d3..8c281ac59 100644 --- a/plugins/channeltx/modpacket/packetmodgui.cpp +++ b/plugins/channeltx/modpacket/packetmodgui.cpp @@ -399,7 +399,7 @@ void PacketModGUI::onWidgetRolled(QWidget* widget, bool rollDown) void PacketModGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); diff --git a/plugins/channeltx/modpsk31/psk31mod.h b/plugins/channeltx/modpsk31/psk31mod.h index 4b217ab88..b1c569bf4 100644 --- a/plugins/channeltx/modpsk31/psk31mod.h +++ b/plugins/channeltx/modpsk31/psk31mod.h @@ -194,7 +194,7 @@ public: void setLevelMeter(QObject *levelMeter); uint32_t getNumberOfDeviceStreams() const; int getSourceChannelSampleRate() const; - void setMessageQueueToGUI(MessageQueue* queue) override; + void setMessageQueueToGUI(MessageQueue* queue) final; static const char* const m_channelIdURI; static const char* const m_channelId; diff --git a/plugins/channeltx/modpsk31/psk31modgui.cpp b/plugins/channeltx/modpsk31/psk31modgui.cpp index 92c9d1f0d..1bc3956f8 100644 --- a/plugins/channeltx/modpsk31/psk31modgui.cpp +++ b/plugins/channeltx/modpsk31/psk31modgui.cpp @@ -283,7 +283,7 @@ void PSK31GUI::onWidgetRolled(QWidget* widget, bool rollDown) void PSK31GUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); diff --git a/plugins/channeltx/modrtty/rttymod.h b/plugins/channeltx/modrtty/rttymod.h index ea332c678..32353e666 100644 --- a/plugins/channeltx/modrtty/rttymod.h +++ b/plugins/channeltx/modrtty/rttymod.h @@ -194,7 +194,7 @@ public: void setLevelMeter(QObject *levelMeter); uint32_t getNumberOfDeviceStreams() const; int getSourceChannelSampleRate() const; - void setMessageQueueToGUI(MessageQueue* queue) override; + void setMessageQueueToGUI(MessageQueue* queue) final; static const char* const m_channelIdURI; static const char* const m_channelId; diff --git a/plugins/channeltx/modrtty/rttymodgui.cpp b/plugins/channeltx/modrtty/rttymodgui.cpp index eeaa0ee43..da26dfc28 100644 --- a/plugins/channeltx/modrtty/rttymodgui.cpp +++ b/plugins/channeltx/modrtty/rttymodgui.cpp @@ -362,7 +362,7 @@ void RttyModGUI::onWidgetRolled(QWidget* widget, bool rollDown) void RttyModGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); diff --git a/plugins/channeltx/modssb/ssbmodgui.cpp b/plugins/channeltx/modssb/ssbmodgui.cpp index d0f9e5946..c24e9615d 100644 --- a/plugins/channeltx/modssb/ssbmodgui.cpp +++ b/plugins/channeltx/modssb/ssbmodgui.cpp @@ -371,7 +371,7 @@ void SSBModGUI::onWidgetRolled(QWidget* widget, bool rollDown) void SSBModGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); diff --git a/plugins/channeltx/modwfm/wfmmodgui.cpp b/plugins/channeltx/modwfm/wfmmodgui.cpp index 1fcb1eb58..8697e1841 100644 --- a/plugins/channeltx/modwfm/wfmmodgui.cpp +++ b/plugins/channeltx/modwfm/wfmmodgui.cpp @@ -300,7 +300,7 @@ void WFMModGUI::onWidgetRolled(QWidget* widget, bool rollDown) void WFMModGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); diff --git a/plugins/channeltx/remotesource/remotesourcegui.cpp b/plugins/channeltx/remotesource/remotesourcegui.cpp index f53676bdd..d60712bee 100644 --- a/plugins/channeltx/remotesource/remotesourcegui.cpp +++ b/plugins/channeltx/remotesource/remotesourcegui.cpp @@ -310,7 +310,7 @@ void RemoteSourceGUI::onWidgetRolled(QWidget* widget, bool rollDown) void RemoteSourceGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); diff --git a/plugins/channeltx/udpsource/udpsourcegui.cpp b/plugins/channeltx/udpsource/udpsourcegui.cpp index b93a0c687..53830689d 100644 --- a/plugins/channeltx/udpsource/udpsourcegui.cpp +++ b/plugins/channeltx/udpsource/udpsourcegui.cpp @@ -495,7 +495,7 @@ void UDPSourceGUI::onWidgetRolled(QWidget* widget, bool rollDown) void UDPSourceGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicChannelSettingsDialog dialog(&m_channelMarker, this); dialog.setUseReverseAPI(m_settings.m_useReverseAPI); diff --git a/plugins/feature/afc/afcgui.cpp b/plugins/feature/afc/afcgui.cpp index e855d605c..bff9d14f9 100644 --- a/plugins/feature/afc/afcgui.cpp +++ b/plugins/feature/afc/afcgui.cpp @@ -278,7 +278,7 @@ void AFCGUI::updateDeviceSetLists(const AFC::MsgDeviceSetListsReport& report) void AFCGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicFeatureSettingsDialog dialog(this); dialog.setTitle(m_settings.m_title); diff --git a/plugins/feature/ais/aisgui.cpp b/plugins/feature/ais/aisgui.cpp index d240c2355..e8514a27b 100644 --- a/plugins/feature/ais/aisgui.cpp +++ b/plugins/feature/ais/aisgui.cpp @@ -296,7 +296,7 @@ void AISGUI::displaySettings() void AISGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicFeatureSettingsDialog dialog(this); dialog.setTitle(m_settings.m_title); diff --git a/plugins/feature/ambe/ambegui.cpp b/plugins/feature/ambe/ambegui.cpp index b7f306eaf..f0decea86 100644 --- a/plugins/feature/ambe/ambegui.cpp +++ b/plugins/feature/ambe/ambegui.cpp @@ -115,7 +115,7 @@ void AMBEGUI::onWidgetRolled(QWidget* widget, bool rollDown) void AMBEGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicFeatureSettingsDialog dialog(this); dialog.setTitle(m_settings.m_title); diff --git a/plugins/feature/antennatools/antennatoolsgui.cpp b/plugins/feature/antennatools/antennatoolsgui.cpp index 0266590d7..3f385c28f 100644 --- a/plugins/feature/antennatools/antennatoolsgui.cpp +++ b/plugins/feature/antennatools/antennatoolsgui.cpp @@ -212,7 +212,7 @@ void AntennaToolsGUI::makeUIConnections() void AntennaToolsGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicFeatureSettingsDialog dialog(this); dialog.setTitle(m_settings.m_title); diff --git a/plugins/feature/aprs/aprsgui.cpp b/plugins/feature/aprs/aprsgui.cpp index 426581373..697db8b66 100644 --- a/plugins/feature/aprs/aprsgui.cpp +++ b/plugins/feature/aprs/aprsgui.cpp @@ -723,7 +723,7 @@ void APRSGUI::resizeEvent(QResizeEvent* event) void APRSGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicFeatureSettingsDialog dialog(this); dialog.setTitle(m_settings.m_title); diff --git a/plugins/feature/demodanalyzer/demodanalyzergui.cpp b/plugins/feature/demodanalyzer/demodanalyzergui.cpp index bd6cc65be..fec29c1b2 100644 --- a/plugins/feature/demodanalyzer/demodanalyzergui.cpp +++ b/plugins/feature/demodanalyzer/demodanalyzergui.cpp @@ -263,7 +263,7 @@ void DemodAnalyzerGUI::updateChannelList() void DemodAnalyzerGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicFeatureSettingsDialog dialog(this); dialog.setTitle(m_settings.m_title); diff --git a/plugins/feature/gs232controller/gs232controllergui.cpp b/plugins/feature/gs232controller/gs232controllergui.cpp index 5b8c544be..460a8279b 100644 --- a/plugins/feature/gs232controller/gs232controllergui.cpp +++ b/plugins/feature/gs232controller/gs232controllergui.cpp @@ -586,7 +586,7 @@ void GS232ControllerGUI::updatePipeList(const AvailableChannelOrFeatureList& sou void GS232ControllerGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicFeatureSettingsDialog dialog(this); dialog.setTitle(m_settings.m_title); diff --git a/plugins/feature/jogdialcontroller/jogdialcontrollergui.cpp b/plugins/feature/jogdialcontroller/jogdialcontrollergui.cpp index 2f1e395f5..db96ff89a 100644 --- a/plugins/feature/jogdialcontroller/jogdialcontrollergui.cpp +++ b/plugins/feature/jogdialcontroller/jogdialcontrollergui.cpp @@ -247,7 +247,7 @@ void JogdialControllerGUI::updateChannelList() void JogdialControllerGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicFeatureSettingsDialog dialog(this); dialog.setTitle(m_settings.m_title); diff --git a/plugins/feature/limerfe/limerfegui.cpp b/plugins/feature/limerfe/limerfegui.cpp index 2dcab36cc..f18bc309a 100644 --- a/plugins/feature/limerfe/limerfegui.cpp +++ b/plugins/feature/limerfe/limerfegui.cpp @@ -86,7 +86,7 @@ void LimeRFEGUI::onWidgetRolled(QWidget* widget, bool rollDown) void LimeRFEGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicFeatureSettingsDialog dialog(this); dialog.setTitle(m_settings.m_title); diff --git a/plugins/feature/map/mapgui.cpp b/plugins/feature/map/mapgui.cpp index 8714b4884..91b155e08 100644 --- a/plugins/feature/map/mapgui.cpp +++ b/plugins/feature/map/mapgui.cpp @@ -1957,7 +1957,7 @@ void MapGUI::displaySettings() void MapGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicFeatureSettingsDialog dialog(this); dialog.setTitle(m_settings.m_title); diff --git a/plugins/feature/morsedecoder/morsedecodergui.cpp b/plugins/feature/morsedecoder/morsedecodergui.cpp index 500a129b2..1a28149fc 100644 --- a/plugins/feature/morsedecoder/morsedecodergui.cpp +++ b/plugins/feature/morsedecoder/morsedecodergui.cpp @@ -285,7 +285,7 @@ void MorseDecoderGUI::updateChannelList() void MorseDecoderGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicFeatureSettingsDialog dialog(this); dialog.setTitle(m_settings.m_title); diff --git a/plugins/feature/pertester/pertestergui.cpp b/plugins/feature/pertester/pertestergui.cpp index 0acfc50e0..268f05c2a 100644 --- a/plugins/feature/pertester/pertestergui.cpp +++ b/plugins/feature/pertester/pertestergui.cpp @@ -200,7 +200,7 @@ void PERTesterGUI::displaySettings() void PERTesterGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicFeatureSettingsDialog dialog(this); dialog.setTitle(m_settings.m_title); diff --git a/plugins/feature/radiosonde/radiosondegui.cpp b/plugins/feature/radiosonde/radiosondegui.cpp index c8c1169a4..066448855 100644 --- a/plugins/feature/radiosonde/radiosondegui.cpp +++ b/plugins/feature/radiosonde/radiosondegui.cpp @@ -265,7 +265,7 @@ void RadiosondeGUI::displaySettings() void RadiosondeGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicFeatureSettingsDialog dialog(this); dialog.setTitle(m_settings.m_title); diff --git a/plugins/feature/remotecontrol/remotecontrolgui.cpp b/plugins/feature/remotecontrol/remotecontrolgui.cpp index 5b2fa27f9..5dc74b48c 100644 --- a/plugins/feature/remotecontrol/remotecontrolgui.cpp +++ b/plugins/feature/remotecontrol/remotecontrolgui.cpp @@ -191,7 +191,7 @@ void RemoteControlGUI::displaySettings() void RemoteControlGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicFeatureSettingsDialog dialog(this); dialog.setTitle(m_settings.m_title); diff --git a/plugins/feature/rigctlserver/rigctlservergui.cpp b/plugins/feature/rigctlserver/rigctlservergui.cpp index f4056cdac..6c311c1b4 100644 --- a/plugins/feature/rigctlserver/rigctlservergui.cpp +++ b/plugins/feature/rigctlserver/rigctlservergui.cpp @@ -288,7 +288,7 @@ bool RigCtlServerGUI::updateChannelList() void RigCtlServerGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicFeatureSettingsDialog dialog(this); dialog.setTitle(m_settings.m_title); diff --git a/plugins/feature/satellitetracker/satellitetrackergui.cpp b/plugins/feature/satellitetracker/satellitetrackergui.cpp index 34d02bdf4..8f3c70df7 100644 --- a/plugins/feature/satellitetracker/satellitetrackergui.cpp +++ b/plugins/feature/satellitetracker/satellitetrackergui.cpp @@ -397,7 +397,7 @@ void SatelliteTrackerGUI::displaySettings() void SatelliteTrackerGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicFeatureSettingsDialog dialog(this); dialog.setTitle(m_settings.m_title); diff --git a/plugins/feature/sid/sidgui.cpp b/plugins/feature/sid/sidgui.cpp index 6c7c0d581..f6fb0637c 100644 --- a/plugins/feature/sid/sidgui.cpp +++ b/plugins/feature/sid/sidgui.cpp @@ -415,7 +415,7 @@ void SIDGUI::setAutosaveTimer() void SIDGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicFeatureSettingsDialog dialog(this); dialog.setTitle(m_settings.m_title); diff --git a/plugins/feature/simpleptt/simplepttgui.cpp b/plugins/feature/simpleptt/simplepttgui.cpp index c5ada8a9a..89e96c944 100644 --- a/plugins/feature/simpleptt/simplepttgui.cpp +++ b/plugins/feature/simpleptt/simplepttgui.cpp @@ -365,7 +365,7 @@ void SimplePTTGUI::updateDeviceSetLists() void SimplePTTGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicFeatureSettingsDialog dialog(this); dialog.setTitle(m_settings.m_title); diff --git a/plugins/feature/skymap/skymapgui.cpp b/plugins/feature/skymap/skymapgui.cpp index f81472316..f2caef05d 100644 --- a/plugins/feature/skymap/skymapgui.cpp +++ b/plugins/feature/skymap/skymapgui.cpp @@ -426,7 +426,7 @@ void SkyMapGUI::displaySettings() void SkyMapGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicFeatureSettingsDialog dialog(this); dialog.setTitle(m_settings.m_title); @@ -1110,4 +1110,4 @@ void SkyMapGUI::handlePipeMessageQueue(MessageQueue* messageQueue) delete message; } } -} \ No newline at end of file +} diff --git a/plugins/feature/startracker/startrackergui.cpp b/plugins/feature/startracker/startrackergui.cpp index da419dfb2..87639ab65 100644 --- a/plugins/feature/startracker/startrackergui.cpp +++ b/plugins/feature/startracker/startrackergui.cpp @@ -565,7 +565,7 @@ void StarTrackerGUI::displaySettings() void StarTrackerGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicFeatureSettingsDialog dialog(this); dialog.setTitle(m_settings.m_title); diff --git a/plugins/feature/vorlocalizer/vorlocalizergui.cpp b/plugins/feature/vorlocalizer/vorlocalizergui.cpp index a1b20aa99..17734a04a 100644 --- a/plugins/feature/vorlocalizer/vorlocalizergui.cpp +++ b/plugins/feature/vorlocalizer/vorlocalizergui.cpp @@ -988,7 +988,7 @@ void VORLocalizerGUI::onWidgetRolled(QWidget* widget, bool rollDown) void VORLocalizerGUI::onMenuDialogCalled(const QPoint &p) { - if (m_contextMenuType == ContextMenuChannelSettings) + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) { BasicFeatureSettingsDialog dialog(this); dialog.setTitle(m_settings.m_title); diff --git a/plugins/samplesink/remoteoutput/remoteoutput.cpp b/plugins/samplesink/remoteoutput/remoteoutput.cpp index cbd20ca60..f3eeba7f6 100644 --- a/plugins/samplesink/remoteoutput/remoteoutput.cpp +++ b/plugins/samplesink/remoteoutput/remoteoutput.cpp @@ -47,21 +47,8 @@ MESSAGE_CLASS_DEFINITION(RemoteOutput::MsgRequestFixedData, Message) RemoteOutput::RemoteOutput(DeviceAPI *deviceAPI) : m_deviceAPI(deviceAPI), - m_running(false), m_settings(), - m_centerFrequency(435000000), - m_sampleRate(48000), - m_remoteOutputWorker(nullptr), - m_deviceDescription("RemoteOutput"), - m_startingTimeStamp(0), - m_masterTimer(deviceAPI->getMasterTimer()), - m_tickCount(0), - m_greaterTickCount(0), - m_tickMultiplier(1), - m_queueLength(0), - m_queueSize(0), - m_recoverableCount(0), - m_unrecoverableCount(0) + m_masterTimer(deviceAPI->getMasterTimer()) { m_deviceAPI->setNbSinkStreams(1); m_networkManager = new QNetworkAccessManager(); diff --git a/plugins/samplesink/remoteoutput/remoteoutput.h b/plugins/samplesink/remoteoutput/remoteoutput.h index 825215d27..544be0381 100644 --- a/plugins/samplesink/remoteoutput/remoteoutput.h +++ b/plugins/samplesink/remoteoutput/remoteoutput.h @@ -259,22 +259,22 @@ public: private: DeviceAPI *m_deviceAPI; QRecursiveMutex m_mutex; - bool m_running; + bool m_running = false; RemoteOutputSettings m_settings; - uint64_t m_centerFrequency; - int m_sampleRate; - RemoteOutputWorker* m_remoteOutputWorker; + uint64_t m_centerFrequency = 435000000; + int m_sampleRate = 48000; + RemoteOutputWorker* m_remoteOutputWorker = nullptr; QThread m_remoteOutputWorkerThread; - QString m_deviceDescription; - std::time_t m_startingTimeStamp; + QString m_deviceDescription = "RemoteOutput"; + std::time_t m_startingTimeStamp = 0; const QTimer& m_masterTimer; - uint32_t m_tickCount; // for 50 ms timer - uint32_t m_greaterTickCount; // for 1 s derived timer - uint32_t m_tickMultiplier; // for greater tick count - int m_queueLength; - int m_queueSize; - int m_recoverableCount; - int m_unrecoverableCount; + uint32_t m_tickCount = 0; // for 50 ms timer + uint32_t m_greaterTickCount = 0; // for 1 s derived timer + uint32_t m_tickMultiplier = 1; // for greater tick count + int m_queueLength = 0; + int m_queueSize = 0; + int m_recoverableCount = 0; + int m_unrecoverableCount = 0; QNetworkAccessManager *m_networkManager; QNetworkRequest m_networkRequest; diff --git a/plugins/samplesource/sigmffileinput/sigmffileinput.cpp b/plugins/samplesource/sigmffileinput/sigmffileinput.cpp index 54fcd8f3a..692eda908 100644 --- a/plugins/samplesource/sigmffileinput/sigmffileinput.cpp +++ b/plugins/samplesource/sigmffileinput/sigmffileinput.cpp @@ -61,8 +61,7 @@ MESSAGE_CLASS_DEFINITION(SigMFFileInput::MsgReportTotalSamplesCheck, Message) SigMFFileInput::SigMFFileInput(DeviceAPI *deviceAPI) : m_deviceAPI(deviceAPI), - m_settings(), - m_deviceDescription("SigMFFileInput") + m_settings() { m_sampleFifo.setLabel(m_deviceDescription); m_deviceAPI->setNbSourceStreams(1); diff --git a/plugins/samplesource/sigmffileinput/sigmffileinput.h b/plugins/samplesource/sigmffileinput/sigmffileinput.h index 872db9e85..820521f32 100644 --- a/plugins/samplesource/sigmffileinput/sigmffileinput.h +++ b/plugins/samplesource/sigmffileinput/sigmffileinput.h @@ -462,7 +462,7 @@ private: QString m_recordSummary; SigMFFileInputWorker* m_fileInputWorker = nullptr; QThread m_fileInputWorkerThread; - QString m_deviceDescription; + QString m_deviceDescription = "SigMFFileInput"; int m_sampleRate = 48000; unsigned int m_sampleBytes = 1; quint64 m_centerFrequency = 0; diff --git a/sdrbase/channel/channelapi.cpp b/sdrbase/channel/channelapi.cpp index 8141ddc4e..49eda04d0 100644 --- a/sdrbase/channel/channelapi.cpp +++ b/sdrbase/channel/channelapi.cpp @@ -21,6 +21,7 @@ /////////////////////////////////////////////////////////////////////////////////// #include "util/uid.h" +#include "util/message.h" #include "channelapi.h" ChannelAPI::ChannelAPI(const QString& uri, StreamType streamType) : @@ -39,7 +40,7 @@ void ChannelAPI::handleInputMessages() { Message* message; - while ((message = m_inputMessageQueue.pop()) != 0) + while ((message = m_inputMessageQueue.pop()) != nullptr) { if (handleMessage(*message)) { delete message; diff --git a/sdrbase/channel/channelapi.h b/sdrbase/channel/channelapi.h index 10c7a940c..9be890076 100644 --- a/sdrbase/channel/channelapi.h +++ b/sdrbase/channel/channelapi.h @@ -55,7 +55,7 @@ public: }; ChannelAPI(const QString& name, StreamType streamType); - virtual ~ChannelAPI() {} + ~ChannelAPI() override = default; virtual void destroy() = 0; virtual void setDeviceAPI(DeviceAPI*) = 0; virtual DeviceAPI *getDeviceAPI() = 0; diff --git a/sdrbase/dsp/devicesamplemimo.cpp b/sdrbase/dsp/devicesamplemimo.cpp index ec29c1608..c3de8162b 100644 --- a/sdrbase/dsp/devicesamplemimo.cpp +++ b/sdrbase/dsp/devicesamplemimo.cpp @@ -20,20 +20,18 @@ #include "devicesamplemimo.h" DeviceSampleMIMO::DeviceSampleMIMO() : - m_guiMessageQueue(0) + m_guiMessageQueue(nullptr) { connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages())); } -DeviceSampleMIMO::~DeviceSampleMIMO() -{ -} +DeviceSampleMIMO::~DeviceSampleMIMO() = default; void DeviceSampleMIMO::handleInputMessages() { Message* message; - while ((message = m_inputMessageQueue.pop()) != 0) + while ((message = m_inputMessageQueue.pop()) != nullptr) { if (handleMessage(*message)) { diff --git a/sdrgui/channel/channelgui.cpp b/sdrgui/channel/channelgui.cpp index 556857fad..af5ab6253 100644 --- a/sdrgui/channel/channelgui.cpp +++ b/sdrgui/channel/channelgui.cpp @@ -41,11 +41,11 @@ ChannelGUI::ChannelGUI(QWidget *parent) : QMdiSubWindow(parent), - m_deviceType(DeviceRx), + m_resizer(this), + m_contextMenuType(ContextMenuType::ContextMenuNone), + m_deviceType(DeviceType::DeviceRx), m_deviceSetIndex(0), m_channelIndex(0), - m_contextMenuType(ContextMenuNone), - m_resizer(this), m_drag(false), m_disableResize(false), m_mdi(nullptr) @@ -125,9 +125,6 @@ ChannelGUI::ChannelGUI(QWidget *parent) : m_moveToDeviceButton->setToolTip("Move to another device"); m_statusFrequency = new QLabel(); - // QFont font = m_statusFrequency->font(); - // font.setPointSize(8); - // m_statusFrequency->setFont(font); m_statusFrequency->setAlignment(Qt::AlignRight |Qt::AlignVCenter); m_statusFrequency->setFixedHeight(20); m_statusFrequency->setFixedWidth(90); @@ -136,7 +133,6 @@ ChannelGUI::ChannelGUI(QWidget *parent) : m_statusFrequency->setToolTip("Channel absolute frequency (Hz)"); m_statusLabel = new QLabel(); - // m_statusLabel->setText("OK"); // for future use m_statusLabel->setFixedHeight(20); m_statusLabel->setMinimumWidth(20); m_statusLabel->setContentsMargins(10, 0, 0, 0); // Add space between statusFrequency and statusLabel @@ -152,7 +148,6 @@ ChannelGUI::ChannelGUI(QWidget *parent) : m_topLayout->addWidget(m_indexLabel); m_topLayout->addWidget(m_settingsButton); m_topLayout->addWidget(m_titleLabel); - // m_topLayout->addStretch(1); m_topLayout->addWidget(m_helpButton); m_topLayout->addWidget(m_moveButton); m_topLayout->addWidget(m_shrinkButton); @@ -174,7 +169,6 @@ ChannelGUI::ChannelGUI(QWidget *parent) : m_sizeGripBottomRight = new QSizeGrip(this); m_sizeGripBottomRight->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); m_sizeGripBottomRight->setFixedHeight(20); - // m_bottomLayout->addStretch(1); m_bottomLayout->addWidget(m_sizeGripBottomRight, 0, Qt::AlignBottom | Qt::AlignRight); m_layouts->addLayout(m_topLayout); @@ -275,11 +269,11 @@ void ChannelGUI::leaveEvent(QEvent* event) void ChannelGUI::activateSettingsDialog() { QPoint p = QCursor::pos(); - m_contextMenuType = ContextMenuChannelSettings; + m_contextMenuType = ContextMenuType::ContextMenuChannelSettings; emit customContextMenuRequested(p); } -void ChannelGUI::showHelp() +void ChannelGUI::showHelp() const { if (m_helpURL.isEmpty()) { return; @@ -322,13 +316,11 @@ void ChannelGUI::onWidgetRolled(QWidget *widget, bool show) { if (show) { - // qDebug("ChannelGUI::onWidgetRolled: show: %d %d", m_rollupContents.height(), widget->height()); int dh = m_heightsMap.contains(widget) ? m_heightsMap[widget] - widget->height() : widget->minimumHeight(); resize(width(), 52 + 3 + m_rollupContents->height() + dh); } else { - // qDebug("ChannelGUI::onWidgetRolled: hide: %d %d", m_rollupContents.height(), widget->height()); m_heightsMap[widget] = widget->height(); resize(width(), 52 + 3 + m_rollupContents->height()); } @@ -517,7 +509,7 @@ void ChannelGUI::setStatusText(const QString& text) void ChannelGUI::updateIndexLabel() { - if ((m_deviceType == DeviceMIMO) && (getStreamIndex() >= 0)) { + if ((m_deviceType == DeviceType::DeviceMIMO) && (getStreamIndex() >= 0)) { m_indexLabel->setText(tr("%1%2:%3.%4").arg(getDeviceTypeTag()).arg(m_deviceSetIndex).arg(m_channelIndex).arg(getStreamIndex())); } else { @@ -525,7 +517,7 @@ void ChannelGUI::updateIndexLabel() } } -bool ChannelGUI::isOnMovingPad() +bool ChannelGUI::isOnMovingPad() const { return m_indexLabel->underMouse() || m_titleLabel->underMouse() || m_statusFrequency->underMouse() || m_statusLabel->underMouse(); } @@ -537,15 +529,15 @@ void ChannelGUI::setHighlighted(bool highlighted) .arg(palette().dark().color().darker(115).name()))); } -QString ChannelGUI::getDeviceTypeTag() +QString ChannelGUI::getDeviceTypeTag() const { switch (m_deviceType) { - case DeviceRx: + case DeviceType::DeviceRx: return "R"; - case DeviceTx: + case DeviceType::DeviceTx: return "T"; - case DeviceMIMO: + case DeviceType::DeviceMIMO: return "M"; default: return "X"; @@ -554,6 +546,6 @@ QString ChannelGUI::getDeviceTypeTag() QColor ChannelGUI::getTitleColor(const QColor& backgroundColor) { - float l = 0.2126*backgroundColor.redF() + 0.7152*backgroundColor.greenF() + 0.0722*backgroundColor.blueF(); - return l < 0.5f ? Qt::white : Qt::black; + double l = 0.2126*backgroundColor.redF() + 0.7152*backgroundColor.greenF() + 0.0722*backgroundColor.blueF(); + return l < 0.5 ? Qt::white : Qt::black; } diff --git a/sdrgui/channel/channelgui.h b/sdrgui/channel/channelgui.h index 037133262..135f00b07 100644 --- a/sdrgui/channel/channelgui.h +++ b/sdrgui/channel/channelgui.h @@ -43,14 +43,14 @@ class SDRGUI_API ChannelGUI : public QMdiSubWindow, public SerializableInterface { Q_OBJECT public: - enum DeviceType + enum class DeviceType { DeviceRx, DeviceTx, DeviceMIMO }; - enum ContextMenuType + enum class ContextMenuType { ContextMenuNone, ContextMenuChannelSettings @@ -91,35 +91,36 @@ public: void setStatusText(const QString& text); protected: + FramelessWindowResizer m_resizer; + ContextMenuType m_contextMenuType; + QString m_helpURL; + QString m_displayedName; + void closeEvent(QCloseEvent *event) override; void leaveEvent(QEvent *event) override; void mousePressEvent(QMouseEvent* event) override; void mouseReleaseEvent(QMouseEvent* event) override; void mouseMoveEvent(QMouseEvent* event) override; - void resetContextMenuType() { m_contextMenuType = ContextMenuNone; } + void resetContextMenuType() { m_contextMenuType = ContextMenuType::ContextMenuNone; } void updateIndexLabel(); int getAdditionalHeight() const { return 22 + 22; } // height of top and bottom bars void setHighlighted(bool highlighted); - int gripSize() { return m_resizer.m_gripSize; } // size in pixels of resize grip around the window - - DeviceType m_deviceType; - int m_deviceSetIndex; - int m_channelIndex; - QString m_helpURL; - RollupContents* m_rollupContents; - ContextMenuType m_contextMenuType; - QString m_displayedName; - FramelessWindowResizer m_resizer; + int gripSize() const { return m_resizer.m_gripSize; } // size in pixels of resize grip around the window protected slots: void shrinkWindow(); void maximizeWindow(); private: - bool isOnMovingPad(); - QString getDeviceTypeTag(); + bool isOnMovingPad() const; + QString getDeviceTypeTag() const; static QColor getTitleColor(const QColor& backgroundColor); + DeviceType m_deviceType; + int m_deviceSetIndex; + int m_channelIndex; + RollupContents* m_rollupContents; + QLabel *m_indexLabel; QPushButton *m_settingsButton; QLabel *m_titleLabel; @@ -146,7 +147,7 @@ private: private slots: void activateSettingsDialog(); - void showHelp(); + void showHelp() const; void openMoveToWorkspaceDialog(); void onWidgetRolled(QWidget *widget, bool show); void duplicateChannel(); diff --git a/sdrgui/device/deviceuiset.cpp b/sdrgui/device/deviceuiset.cpp index b5a12705a..85f1541ca 100644 --- a/sdrgui/device/deviceuiset.cpp +++ b/sdrgui/device/deviceuiset.cpp @@ -383,7 +383,7 @@ void DeviceUISet::loadRxChannelSettings(const Preset *preset, PluginAPI *pluginA MDIUtils::restoreMDIGeometry(rxChannelGUI, rxChannelGUI->getGeometryBytes()); rxChannelGUI->getRollupContents()->arrangeRollups(); - rxChannelGUI->setDeviceType(ChannelGUI::DeviceRx); + rxChannelGUI->setDeviceType(ChannelGUI::DeviceType::DeviceRx); rxChannelGUI->setDeviceSetIndex(m_deviceSetIndex); rxChannelGUI->setIndex(channelAPI->getIndexInDeviceSet()); rxChannelGUI->setIndexToolTip(m_deviceAPI->getSamplingDeviceDisplayName()); @@ -511,7 +511,7 @@ void DeviceUISet::loadTxChannelSettings(const Preset *preset, PluginAPI *pluginA MDIUtils::restoreMDIGeometry(txChannelGUI, txChannelGUI->getGeometryBytes()); txChannelGUI->getRollupContents()->arrangeRollups(); - txChannelGUI->setDeviceType(ChannelGUI::DeviceTx); + txChannelGUI->setDeviceType(ChannelGUI::DeviceType::DeviceTx); txChannelGUI->setDeviceSetIndex(m_deviceSetIndex); txChannelGUI->setIndex(channelAPI->getIndexInDeviceSet()); txChannelGUI->setIndexToolTip(m_deviceAPI->getSamplingDeviceDisplayName()); @@ -685,7 +685,7 @@ void DeviceUISet::loadMIMOChannelSettings(const Preset *preset, PluginAPI *plugi MDIUtils::restoreMDIGeometry(channelGUI, channelGUI->getGeometryBytes()); channelGUI->getRollupContents()->arrangeRollups(); - channelGUI->setDeviceType(ChannelGUI::DeviceMIMO); + channelGUI->setDeviceType(ChannelGUI::DeviceType::DeviceMIMO); channelGUI->setDeviceSetIndex(m_deviceSetIndex); channelGUI->setIndex(channelAPI->getIndexInDeviceSet()); channelGUI->setIndexToolTip(m_deviceAPI->getSamplingDeviceDisplayName()); diff --git a/sdrgui/mainwindow.cpp b/sdrgui/mainwindow.cpp index 570eb51be..a417a82eb 100644 --- a/sdrgui/mainwindow.cpp +++ b/sdrgui/mainwindow.cpp @@ -2528,12 +2528,12 @@ void MainWindow::channelDuplicateToDeviceSet(const ChannelGUI *sourceChannelGUI, if (pluginInterface) { - ChannelAPI *channelAPI = nullptr; + ChannelAPI *channelAPI; BasebandSampleSink *rxChannel = nullptr; pluginInterface->createRxChannel(destDeviceUI->m_deviceAPI, &rxChannel, &channelAPI); destChannelGUI = pluginInterface->createRxChannelGUI(destDeviceUI, rxChannel); destDeviceUI->registerRxChannelInstance(channelAPI, destChannelGUI); - destChannelGUI->setDeviceType(ChannelGUI::DeviceRx); + destChannelGUI->setDeviceType(ChannelGUI::DeviceType::DeviceRx); destChannelGUI->setIndex(channelAPI->getIndexInDeviceSet()); QByteArray b = sourceChannelGUI->serialize(); destChannelGUI->deserialize(b); @@ -2560,7 +2560,7 @@ void MainWindow::channelDuplicateToDeviceSet(const ChannelGUI *sourceChannelGUI, pluginInterface->createTxChannel(destDeviceUI->m_deviceAPI, &txChannel, &channelAPI); destChannelGUI = pluginInterface->createTxChannelGUI(destDeviceUI, txChannel); destDeviceUI->registerTxChannelInstance(channelAPI, destChannelGUI); - destChannelGUI->setDeviceType(ChannelGUI::DeviceTx); + destChannelGUI->setDeviceType(ChannelGUI::DeviceType::DeviceTx); destChannelGUI->setIndex(channelAPI->getIndexInDeviceSet()); QByteArray b = sourceChannelGUI->serialize(); destChannelGUI->deserialize(b); @@ -2589,7 +2589,7 @@ void MainWindow::channelDuplicateToDeviceSet(const ChannelGUI *sourceChannelGUI, pluginInterface->createRxChannel(destDeviceUI->m_deviceAPI, &rxChannel, &channelAPI); destChannelGUI = pluginInterface->createRxChannelGUI(destDeviceUI, rxChannel); destDeviceUI->registerRxChannelInstance(channelAPI, destChannelGUI); - destChannelGUI->setDeviceType(ChannelGUI::DeviceMIMO); + destChannelGUI->setDeviceType(ChannelGUI::DeviceType::DeviceMIMO); destChannelGUI->setIndex(channelAPI->getIndexInDeviceSet()); QByteArray b = sourceChannelGUI->serialize(); destChannelGUI->deserialize(b); @@ -2612,7 +2612,7 @@ void MainWindow::channelDuplicateToDeviceSet(const ChannelGUI *sourceChannelGUI, pluginInterface->createTxChannel(destDeviceUI->m_deviceAPI, &txChannel, &channelAPI); destChannelGUI = pluginInterface->createTxChannelGUI(destDeviceUI, txChannel); destDeviceUI->registerTxChannelInstance(channelAPI, destChannelGUI); - destChannelGUI->setDeviceType(ChannelGUI::DeviceMIMO); + destChannelGUI->setDeviceType(ChannelGUI::DeviceType::DeviceMIMO); destChannelGUI->setIndex(channelAPI->getIndexInDeviceSet()); QByteArray b = sourceChannelGUI->serialize(); destChannelGUI->deserialize(b); @@ -2635,7 +2635,7 @@ void MainWindow::channelDuplicateToDeviceSet(const ChannelGUI *sourceChannelGUI, pluginInterface->createMIMOChannel(destDeviceUI->m_deviceAPI, &mimoChannel, &channelAPI); destChannelGUI = pluginInterface->createMIMOChannelGUI(destDeviceUI, mimoChannel); destDeviceUI->registerChannelInstance(channelAPI, destChannelGUI); - destChannelGUI->setDeviceType(ChannelGUI::DeviceMIMO); + destChannelGUI->setDeviceType(ChannelGUI::DeviceType::DeviceMIMO); destChannelGUI->setIndex(channelAPI->getIndexInDeviceSet()); QByteArray b = sourceChannelGUI->serialize(); destChannelGUI->deserialize(b); @@ -2696,7 +2696,7 @@ void MainWindow::channelAddClicked(Workspace *workspace, int deviceSetIndex, int pluginInterface->createRxChannel(deviceUI->m_deviceAPI, &rxChannel, &channelAPI); gui = pluginInterface->createRxChannelGUI(deviceUI, rxChannel); deviceUI->registerRxChannelInstance(channelAPI, gui); - gui->setDeviceType(ChannelGUI::DeviceRx); + gui->setDeviceType(ChannelGUI::DeviceType::DeviceRx); gui->setIndex(channelAPI->getIndexInDeviceSet()); gui->setDisplayedame(pluginInterface->getPluginDescriptor().displayedName); } @@ -2708,7 +2708,7 @@ void MainWindow::channelAddClicked(Workspace *workspace, int deviceSetIndex, int pluginInterface->createTxChannel(deviceUI->m_deviceAPI, &txChannel, &channelAPI); gui = pluginInterface->createTxChannelGUI(deviceUI, txChannel); deviceUI->registerTxChannelInstance(channelAPI, gui); - gui->setDeviceType(ChannelGUI::DeviceTx); + gui->setDeviceType(ChannelGUI::DeviceType::DeviceTx); gui->setIndex(channelAPI->getIndexInDeviceSet()); gui->setDisplayedame(pluginInterface->getPluginDescriptor().displayedName); } @@ -2758,7 +2758,7 @@ void MainWindow::channelAddClicked(Workspace *workspace, int deviceSetIndex, int return; } - gui->setDeviceType(ChannelGUI::DeviceMIMO); + gui->setDeviceType(ChannelGUI::DeviceType::DeviceMIMO); } else {