diff --git a/plugins/channelrx/wdsprx/wdsprxbaseband.cpp b/plugins/channelrx/wdsprx/wdsprxbaseband.cpp index b079bd566e..f0a1e176d0 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 ee1ca96dec..8f3543c5bc 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 c89c3cc154..3f2b59da3d 100644 --- a/plugins/channelrx/wdsprx/wdsprxgui.h +++ b/plugins/channelrx/wdsprx/wdsprxgui.h @@ -58,21 +58,21 @@ class WDSPRxGUI : public ChannelGUI { 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 @@ public slots: 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 39430c63bf..6647816bc9 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 28fdc65532..bf1be19eed 100644 --- a/plugins/channeltx/modam/ammod.h +++ b/plugins/channeltx/modam/ammod.h @@ -251,7 +251,7 @@ class AMMod : public BasebandSampleSource, public ChannelAPI { DeviceAPI* m_deviceAPI; QThread *m_thread; - bool m_running; + bool m_running = false; AMModBaseband* m_basebandSource; AMModSettings m_settings; @@ -260,38 +260,38 @@ class AMMod : public BasebandSampleSource, public ChannelAPI { 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 5a0cfd7914..ee02347bde 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 7c4220c526..1ee214775e 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 @@ class AMModGUI : public ChannelGUI { 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 @@ public slots: int m_basebandSampleRate; bool m_doApplySettings; + CRightClickEnabler *m_audioMuteRightClickEnabler; + CRightClickEnabler *m_feedbackRightClickEnabler; + AMMod* m_amMod; MovingAverageUtil m_channelPowerDbAvg; @@ -88,8 +92,8 @@ public slots: 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 @@ public slots: 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 669f539285..dcb20f7c10 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 25feb8fe3a..d3acb5a6d7 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 01921618c0..5277c145f4 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 a032ff7749..bcec5d7b2d 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 @@ class AMModSource : public QObject, public ChannelSampleSource 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 @@ class AMModSource : public QObject, public ChannelSampleSource 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 @@ class AMModSource : public QObject, public ChannelSampleSource 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 dc4b0d5494..2a2dbb94b6 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 de0ad0c8b8..44300800ba 100644 --- a/plugins/channeltx/modnfm/nfmmod.h +++ b/plugins/channeltx/modnfm/nfmmod.h @@ -82,7 +82,7 @@ class NFMMod : public BasebandSampleSource, public ChannelAPI { private: QString m_fileName; - MsgConfigureFileSourceName(const QString& fileName) : + explicit MsgConfigureFileSourceName(const QString& fileName) : Message(), m_fileName(fileName) { } @@ -100,10 +100,10 @@ class NFMMod : public BasebandSampleSource, public ChannelAPI { 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 @@ class NFMMod : public BasebandSampleSource, public ChannelAPI { 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 @@ class NFMMod : public BasebandSampleSource, public ChannelAPI { return new MsgReportFileSourceStreamData(sampleRate, recordLength); } - protected: + private: int m_sampleRate; quint32 m_recordLength; @@ -174,55 +174,55 @@ class NFMMod : public BasebandSampleSource, public ChannelAPI { //================================================================= - 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 @@ class NFMMod : public BasebandSampleSource, public ChannelAPI { DeviceAPI* m_deviceAPI; QThread *m_thread; - bool m_running; + bool m_running = false; NFMModBaseband* m_basebandSource; NFMModSettings m_settings; @@ -260,39 +260,39 @@ class NFMMod : public BasebandSampleSource, public ChannelAPI { 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 39d758f1b1..ff37ccfb77 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 9a6d31ed98..8aad901af2 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 @@ class NFMModSource : public QObject, public ChannelSampleSource 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 @@ class NFMModSource : public QObject, public ChannelSampleSource 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 @@ class NFMModSource : public QObject, public ChannelSampleSource 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 @@ class NFMModSource : public QObject, public ChannelSampleSource 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 @@ class NFMModSource : public QObject, public ChannelSampleSource 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 9ae2b047ae..7fd668786c 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 166086428e..fc962d32ef 100644 --- a/plugins/channeltx/modssb/ssbmod.h +++ b/plugins/channeltx/modssb/ssbmod.h @@ -83,7 +83,7 @@ class SSBMod : public BasebandSampleSource, public ChannelAPI { private: QString m_fileName; - MsgConfigureFileSourceName(const QString& fileName) : + explicit MsgConfigureFileSourceName(const QString& fileName) : Message(), m_fileName(fileName) { } @@ -101,10 +101,10 @@ class SSBMod : public BasebandSampleSource, public ChannelAPI { 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 @@ class SSBMod : public BasebandSampleSource, public ChannelAPI { 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 @@ class SSBMod : public BasebandSampleSource, public ChannelAPI { return new MsgReportFileSourceStreamData(sampleRate, recordLength); } - protected: + private: int m_sampleRate; quint32 m_recordLength; @@ -175,55 +175,55 @@ class SSBMod : public BasebandSampleSource, public ChannelAPI { //================================================================= - 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 @@ class SSBMod : public BasebandSampleSource, public ChannelAPI { 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 @@ class SSBMod : public BasebandSampleSource, public ChannelAPI { 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 b829b3701d..c2e1f9df22 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 (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); - - 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++; - } - - if (n_out > 0) - { + 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; + } + + 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; + } + + sample = m_SSBFilterBuffer[m_SSBFilterBufferIndex]; + m_SSBFilterBufferIndex++; + } + + 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 1eb4cb3485..20fed05b5f 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 @@ class SSBModSource : public QObject, public ChannelSampleSource 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 @@ class SSBModSource : public QObject, public ChannelSampleSource 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 @@ class SSBModSource : public QObject, public ChannelSampleSource 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 @@ class SSBModSource : public QObject, public ChannelSampleSource 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 @@ class SSBModSource : public QObject, public ChannelSampleSource 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 df7a634eeb..9d03add8e1 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 (!m_deviceAPI->getSourceBuddies().empty()) + { + DeviceAPI *buddy = m_deviceAPI->getSourceBuddies()[0]; - if (buddy->getDeviceSourceEngine()->state() == DSPDeviceSourceEngine::StRunning) { // Tx side running - changeSettings = false; - } else { - changeSettings = true; - } - } - else // No Rx open - { + if (buddy->getDeviceSourceEngine()->state() == DSPDeviceSourceEngine::State::StRunning) { // Tx side running + changeSettings = false; + } else { changeSettings = true; } + } + else // No Rx open + { + changeSettings = true; + } - if (changeSettings) + if (changeSettings) + { + if (settings.m_xb200) { - 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"; - } + 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"; - } + } + 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; } + + 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_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_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 (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_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 (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 (settingsKeys.contains("bandwidth") || force) + if ((m_dev != nullptr) && (settingsKeys.contains("bandwidth") || force)) { - if (m_dev != 0) - { - 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; - } - } + 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 e1d7969717..480b3fa4f5 100644 --- a/plugins/samplesink/bladerf1output/bladerf1output.h +++ b/plugins/samplesink/bladerf1output/bladerf1output.h @@ -74,10 +74,10 @@ class Bladerf1Output : public DeviceSampleSink { return new MsgStartStop(startStop); } - protected: + private: bool m_startStop; - MsgStartStop(bool startStop) : + explicit MsgStartStop(bool startStop) : Message(), m_startStop(startStop) { } @@ -100,57 +100,57 @@ class Bladerf1Output : public DeviceSampleSink { { } }; - 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 @@ class Bladerf1Output : public DeviceSampleSink { 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 83034f8a35..d00c38f666 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 8c4847d964..7c405d8881 100644 --- a/plugins/samplesink/fileoutput/fileoutput.h +++ b/plugins/samplesink/fileoutput/fileoutput.h @@ -76,10 +76,10 @@ class FileOutput : public DeviceSampleSink { return new MsgStartStop(startStop); } - protected: + private: bool m_startStop; - MsgStartStop(bool startStop) : + explicit MsgStartStop(bool startStop) : Message(), m_startStop(startStop) { } @@ -99,7 +99,7 @@ class FileOutput : public DeviceSampleSink { private: QString m_fileName; - MsgConfigureFileOutputName(const QString& fileName) : + explicit MsgConfigureFileOutputName(const QString& fileName) : Message(), m_fileName(fileName) { } @@ -119,7 +119,7 @@ class FileOutput : public DeviceSampleSink { private: bool m_working; - MsgConfigureFileOutputWork(bool working) : + explicit MsgConfigureFileOutputWork(bool working) : Message(), m_working(working) { } @@ -153,10 +153,10 @@ class FileOutput : public DeviceSampleSink { return new MsgReportFileOutputGeneration(acquisition); } - protected: + private: bool m_acquisition; - MsgReportFileOutputGeneration(bool acquisition) : + explicit MsgReportFileOutputGeneration(bool acquisition) : Message(), m_acquisition(acquisition) { } @@ -173,54 +173,54 @@ class FileOutput : public DeviceSampleSink { 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 @@ class FileOutput : public DeviceSampleSink { 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 @@ class FileOutput : public DeviceSampleSink { 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 6bffe0e5c6..cbd20ca606 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 434e2916d3..825215d27d 100644 --- a/plugins/samplesink/remoteoutput/remoteoutput.h +++ b/plugins/samplesink/remoteoutput/remoteoutput.h @@ -83,7 +83,7 @@ class RemoteOutput : public DeviceSampleSink { private: bool m_working; - MsgConfigureRemoteOutputWork(bool working) : + explicit MsgConfigureRemoteOutputWork(bool working) : Message(), m_working(working) { } @@ -99,10 +99,10 @@ class RemoteOutput : public DeviceSampleSink { return new MsgStartStop(startStop); } - protected: + private: bool m_startStop; - MsgStartStop(bool startStop) : + explicit MsgStartStop(bool startStop) : Message(), m_startStop(startStop) { } @@ -122,7 +122,7 @@ class RemoteOutput : public DeviceSampleSink { private: int m_chunkCorrection; - MsgConfigureRemoteOutputChunkCorrection(int chunkCorrection) : + explicit MsgConfigureRemoteOutputChunkCorrection(int chunkCorrection) : Message(), m_chunkCorrection(chunkCorrection) { } @@ -153,7 +153,7 @@ class RemoteOutput : public DeviceSampleSink { private: RemoteData m_remoteData; - MsgReportRemoteData(const RemoteData& remoteData) : + explicit MsgReportRemoteData(const RemoteData& remoteData) : Message(), m_remoteData(remoteData) {} @@ -182,7 +182,7 @@ class RemoteOutput : public DeviceSampleSink { private: RemoteData m_remoteData; - MsgReportRemoteFixedData(const RemoteData& remoteData) : + explicit MsgReportRemoteFixedData(const RemoteData& remoteData) : Message(), m_remoteData(remoteData) {} @@ -203,58 +203,58 @@ class RemoteOutput : public DeviceSampleSink { }; - 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 @@ class RemoteOutput : public DeviceSampleSink { 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 8d4e24b916..aa8c82bdeb 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; - - if (m_deviceAPI->getSinkBuddies().size() > 0) - { - DeviceAPI *buddy = m_deviceAPI->getSinkBuddies()[0]; - - if (buddy->getDeviceSinkEngine()->state() == DSPDeviceSinkEngine::StRunning) { // Tx side running - changeSettings = false; - } else { - changeSettings = true; - } - } - else // No Tx open - { + bool changeSettings; + + if (!m_deviceAPI->getSinkBuddies().empty()) + { + DeviceAPI *buddy = m_deviceAPI->getSinkBuddies()[0]; + + if (buddy->getDeviceSinkEngine()->state() == DSPDeviceSinkEngine::State::StRunning) { // Tx side running + changeSettings = false; + } else { 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"; - } - } - - m_sharedParams.m_xb200Attached = settings.m_xb200; - } - } + } + } + 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"; + } + } + + 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 3b20bd16cd..d0a34653eb 100644 --- a/plugins/samplesource/bladerf1input/bladerf1input.h +++ b/plugins/samplesource/bladerf1input/bladerf1input.h @@ -76,62 +76,62 @@ class Bladerf1Input : public DeviceSampleSource { 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 @@ class Bladerf1Input : public DeviceSampleSource { 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 aade8c16ae..54fcd8f3a1 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 f612b31bfe..872db9e85f 100644 --- a/plugins/samplesource/sigmffileinput/sigmffileinput.h +++ b/plugins/samplesource/sigmffileinput/sigmffileinput.h @@ -86,7 +86,7 @@ class SigMFFileInput : public DeviceSampleSource { private: bool m_working; - MsgConfigureTrackWork(bool working) : + explicit MsgConfigureTrackWork(bool working) : Message(), m_working(working) { } @@ -109,7 +109,7 @@ class SigMFFileInput : public DeviceSampleSource { private: bool m_working; - MsgConfigureFileWork(bool working) : + explicit MsgConfigureFileWork(bool working) : Message(), m_working(working) { } @@ -132,7 +132,7 @@ class SigMFFileInput : public DeviceSampleSource { private: int m_trackIndex; - MsgConfigureTrackIndex(int trackIndex) : + explicit MsgConfigureTrackIndex(int trackIndex) : Message(), m_trackIndex(trackIndex) { } @@ -152,10 +152,10 @@ class SigMFFileInput : public DeviceSampleSource { 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 @@ class SigMFFileInput : public DeviceSampleSource { 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 @@ class SigMFFileInput : public DeviceSampleSource { return new MsgStartStop(startStop); } - protected: + private: bool m_startStop; - MsgStartStop(bool startStop) : + explicit MsgStartStop(bool startStop) : Message(), m_startStop(startStop) { } @@ -240,10 +240,10 @@ class SigMFFileInput : public DeviceSampleSource { return new MsgReportStartStop(startStop); } - protected: + private: bool m_startStop; - MsgReportStartStop(bool startStop) : + explicit MsgReportStartStop(bool startStop) : Message(), m_startStop(startStop) { } @@ -257,13 +257,13 @@ class SigMFFileInput : public DeviceSampleSource { 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 @@ class SigMFFileInput : public DeviceSampleSource { private: int m_trackIndex; - MsgReportTrackChange(int trackIndex) : + explicit MsgReportTrackChange(int trackIndex) : Message(), m_trackIndex(trackIndex) { } @@ -321,7 +321,7 @@ class SigMFFileInput : public DeviceSampleSource { ); } - protected: + private: quint64 m_samplesCount; quint64 m_trackSamplesCount; quint64 m_trackTimeStart; @@ -354,10 +354,10 @@ class SigMFFileInput : public DeviceSampleSource { return new MsgReportCRC(ok); } - protected: + private: bool m_ok; - MsgReportCRC(bool ok) : + explicit MsgReportCRC(bool ok) : Message(), m_ok(ok) { } @@ -376,98 +376,98 @@ class SigMFFileInput : public DeviceSampleSource { 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 @@ class SigMFFileInput : public DeviceSampleSource { 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 65bd305291..fce595cb1b 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 351816c9e8..5544952766 100644 --- a/sdrbase/device/deviceapi.h +++ b/sdrbase/device/deviceapi.h @@ -65,7 +65,7 @@ class SDRBASE_API DeviceAPI : public QObject, public SerializableInterface { 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 @@ class SDRBASE_API DeviceAPI : public QObject, public SerializableInterface { 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 @@ class SDRBASE_API DeviceAPI : public QObject, public SerializableInterface { 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 @@ class SDRBASE_API DeviceAPI : public QObject, public SerializableInterface { 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 @@ class SDRBASE_API DeviceAPI : public QObject, public SerializableInterface { const QTimer& getMasterTimer() const { return m_masterTimer; } //!< This is the DSPEngine master timer -protected: +private: // common StreamType m_streamType; @@ -217,7 +213,6 @@ class SDRBASE_API DeviceAPI : public QObject, public SerializableInterface { DSPDeviceMIMOEngine *m_deviceMIMOEngine; QList m_mimoChannelAPIs; -private: void renumerateChannels(); private slots: diff --git a/sdrbase/dsp/dspdevicemimoengine.cpp b/sdrbase/dsp/dspdevicemimoengine.cpp index 7fd4997ae1..0cf3cd7d9c 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 57968680cb..191b95c25e 100644 --- a/sdrbase/dsp/dspdevicemimoengine.h +++ b/sdrbase/dsp/dspdevicemimoengine.h @@ -40,7 +40,7 @@ class SDRBASE_API DSPDeviceMIMOEngine : public QObject { 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 @@ class SDRBASE_API DSPDeviceMIMOEngine : public QObject { class AddMIMOChannel : public Message { MESSAGE_CLASS_DECLARATION public: - AddMIMOChannel(MIMOChannel* channel) : + explicit AddMIMOChannel(MIMOChannel* channel) : Message(), m_channel(channel) { } @@ -92,7 +92,7 @@ class SDRBASE_API DSPDeviceMIMOEngine : public QObject { class RemoveMIMOChannel : public Message { MESSAGE_CLASS_DECLARATION public: - RemoveMIMOChannel(MIMOChannel* channel) : + explicit RemoveMIMOChannel(MIMOChannel* channel) : Message(), m_channel(channel) { } @@ -134,7 +134,7 @@ class SDRBASE_API DSPDeviceMIMOEngine : public QObject { 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 @@ class SDRBASE_API DSPDeviceMIMOEngine : public QObject { 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 @@ class SDRBASE_API DSPDeviceMIMOEngine : public QObject { 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 @@ class SDRBASE_API DSPDeviceMIMOEngine : public QObject { 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 @@ class SDRBASE_API DSPDeviceMIMOEngine : public QObject { } else if (subsystemIndex == 1) { return m_stateTx; } else { - return StNotStarted; + return State::StNotStarted; } } @@ -256,13 +256,13 @@ class SDRBASE_API DSPDeviceMIMOEngine : public QObject { 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 @@ class SDRBASE_API DSPDeviceMIMOEngine : public QObject { #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 @@ class SDRBASE_API DSPDeviceMIMOEngine : public QObject { 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 70090a1e3c..0f3d8fd07c 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 db190782d2..7917e49aef 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 @@ class SDRBASE_API DSPDeviceSinkEngine : public QObject { }; DSPDeviceSinkEngine(uint32_t uid, QObject* parent = nullptr); - ~DSPDeviceSinkEngine(); + ~DSPDeviceSinkEngine() final; uint32_t getUID() const { return m_uid; } @@ -75,8 +75,8 @@ class SDRBASE_API DSPDeviceSinkEngine : public QObject { 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 @@ class SDRBASE_API DSPDeviceSinkEngine : public QObject { 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 @@ class SDRBASE_API DSPDeviceSinkEngine : public QObject { 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 afaf18ee74..d6899f13d1 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 ba5b839ac3..cd440d7c04 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 @@ class SDRBASE_API DSPDeviceSourceEngine : public QObject { }; 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 72ce5a6ffe..50b83c7af8 100644 --- a/sdrbase/plugin/plugininterface.h +++ b/sdrbase/plugin/plugininterface.h @@ -84,8 +84,8 @@ class SDRBASE_API PluginInterface { 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 @@ class SDRBASE_API PluginInterface { type(_type), streamType(_streamType), deviceNbItems(_deviceNbItems), - deviceItemIndex(_deviceItemIndex), - claimed(-1), - removed(false) + deviceItemIndex(_deviceItemIndex) { } bool operator==(const SamplingDevice& rhs) const @@ -117,7 +115,7 @@ class SDRBASE_API PluginInterface { && 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 @@ class SDRBASE_API PluginInterface { 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 d56a46cfb7..3c83f1dacb 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 f195364fd2..558db21284 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 @@ class SDRGUI_API DeviceUISet : public QObject, public SerializableInterface 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 @@ class SDRGUI_API DeviceUISet : public QObject, public SerializableInterface 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 @@ class SDRGUI_API DeviceUISet : public QObject, public SerializableInterface 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 @@ class SDRGUI_API DeviceUISet : public QObject, public SerializableInterface 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 e0386a05e7..570eb51be4 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 27605b4ed4..edbf94f892 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 @@ public slots: 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 @@ public slots: 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 @@ public slots: 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 @@ public slots: 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 da49095cd9..ae6ed5e0e3 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)