From 9d27407a666daf651848f0563ad19b5b7763af2b Mon Sep 17 00:00:00 2001 From: f4exb Date: Sun, 19 Jan 2020 18:10:16 +0100 Subject: [PATCH] LimeRFE USB: implemented device set control --- sdrgui/limerfegui/limerfeusbdialog.cpp | 131 ++++++++++++++++++++-- sdrgui/limerfegui/limerfeusbdialog.h | 20 ++++ sdrgui/limerfegui/limerfeusbdialog.ui | 144 ++++++++++++++++++++----- 3 files changed, 261 insertions(+), 34 deletions(-) diff --git a/sdrgui/limerfegui/limerfeusbdialog.cpp b/sdrgui/limerfegui/limerfeusbdialog.cpp index 9cf036f45..4968cbd66 100644 --- a/sdrgui/limerfegui/limerfeusbdialog.cpp +++ b/sdrgui/limerfegui/limerfeusbdialog.cpp @@ -20,6 +20,8 @@ #include "util/serialutil.h" #include "util/db.h" #include "dsp/dspengine.h" +#include "dsp/dspdevicesourceengine.h" +#include "dsp/dspdevicesinkengine.h" #include "gui/doublevalidator.h" #include "limerfeusbdialog.h" @@ -29,7 +31,10 @@ LimeRFEUSBDialog::LimeRFEUSBDialog(LimeRFEUSBCalib& limeRFEUSBCalib, QWidget* pa m_limeRFEUSBCalib(limeRFEUSBCalib), QDialog(parent), ui(new Ui::LimeRFEUSBDialog), - m_rxTxToggle(false) + m_rxTxToggle(false), + m_currentPowerCorrection(0.0), + m_avgPower(false), + m_deviceSetSync(false) { ui->setupUi(this); ui->powerCorrValue->setValidator(new DoubleValidator(-99.9, 99.9, 1, ui->powerCorrValue)); @@ -40,8 +45,9 @@ LimeRFEUSBDialog::LimeRFEUSBDialog(LimeRFEUSBCalib& limeRFEUSBCalib, QWidget* pa ui->device->addItem(QString(it->c_str())); } + updateDeviceSetList(); displaySettings(); // default values - m_timer.setInterval(1000); + m_timer.setInterval(500); } LimeRFEUSBDialog::~LimeRFEUSBDialog() @@ -574,6 +580,11 @@ void LimeRFEUSBDialog::on_powerAutoRefresh_toggled(bool checked) } } +void LimeRFEUSBDialog::on_powerAbsAvg_clicked() +{ + m_avgPower = ui->powerAbsAvg->isChecked(); +} + void LimeRFEUSBDialog::on_powerCorrValue_textEdited(const QString &text) { bool ok; @@ -587,6 +598,77 @@ void LimeRFEUSBDialog::on_powerCorrValue_textEdited(const QString &text) } } +void LimeRFEUSBDialog::on_deviceSetRefresh_clicked() +{ + updateDeviceSetList(); +} + +void LimeRFEUSBDialog::on_deviceSetSync_clicked() +{ + m_deviceSetSync = ui->deviceSetSync->isChecked(); + + if (m_deviceSetSync) { + syncRxTx(); + } +} + +void LimeRFEUSBDialog::syncRxTx() +{ + if (!m_settings.m_txOn) { + stopStartTx(m_settings.m_txOn); + } + + stopStartRx(m_settings.m_rxOn); + + if (m_settings.m_txOn) { + stopStartTx(m_settings.m_txOn); + } +} + +void LimeRFEUSBDialog::stopStartRx(bool start) +{ + int rxDeviceSetSequence = ui->deviceSetRx->currentIndex(); + + if ((rxDeviceSetSequence < 0) || (rxDeviceSetSequence >= m_sourceEngines.size())) { + return; + } + + DSPDeviceSourceEngine *deviceSourceEngine = m_sourceEngines[rxDeviceSetSequence]; + + if (start) + { + if (deviceSourceEngine->initAcquisition()) { + deviceSourceEngine->startAcquisition(); + } + } + else + { + deviceSourceEngine->stopAcquistion(); + } +} + +void LimeRFEUSBDialog::stopStartTx(bool start) +{ + int txDeviceSetSequence = ui->deviceSetTx->currentIndex(); + + if ((txDeviceSetSequence < 0) || (txDeviceSetSequence >= m_sinkEngines.size())) { + return; + } + + DSPDeviceSinkEngine *deviceSinkEngine = m_sinkEngines[txDeviceSetSequence]; + + if (start) + { + if (deviceSinkEngine->initGeneration()) { + deviceSinkEngine->startGeneration(); + } + } + else + { + deviceSinkEngine->stopGeneration(); + } +} + void LimeRFEUSBDialog::updateAbsPower(double powerCorrDB) { bool ok; @@ -595,10 +677,39 @@ void LimeRFEUSBDialog::updateAbsPower(double powerCorrDB) if (ok) { double powerCorrected = power + powerCorrDB; - ui->powerAbsDbText->setText(QString::number(powerCorrected, 'f', 1)); - double powerMilliwatts = CalcDb::powerFromdB(powerCorrected); - powerMilliwatts = powerMilliwatts > 8000.0 ? 8000.0 : powerMilliwatts; - ui->powerAbsWText->setText(QString::number(powerMilliwatts/1000.0, 'f', 3)); + double powerDisplayed = powerCorrected; + + if (m_avgPower) + { + m_powerMovingAverage(powerCorrected); + powerDisplayed = m_powerMovingAverage.asDouble(); + } + + ui->powerAbsDbText->setText(tr("%1 dBm").arg(QString::number(powerDisplayed, 'f', 1))); + double powerWatts = CalcDb::powerFromdB(powerDisplayed - 30.0); + powerWatts = powerWatts > 8.0 ? 8.0 : powerWatts; + ui->powerAbsWText->setText(tr("%1 W").arg(QString::number(powerWatts, 'f', 3))); + } +} + +void LimeRFEUSBDialog::updateDeviceSetList() +{ + DSPEngine *dspEngine = DSPEngine::instance(); + m_sourceEngines.clear(); + m_sinkEngines.clear(); + + for (uint32_t i = 0; i < dspEngine->getDeviceSourceEnginesNumber(); i++) + { + DSPDeviceSourceEngine *deviceSourceEngine = dspEngine->getDeviceSourceEngineByIndex(i); + m_sourceEngines.push_back(deviceSourceEngine); + ui->deviceSetRx->addItem(QString("%1").arg(i)); + } + + for (uint32_t i = 0; i < dspEngine->getDeviceSinkEnginesNumber(); i++) + { + DSPDeviceSinkEngine *deviceSinkEngine = dspEngine->getDeviceSinkEngineByIndex(i); + m_sinkEngines.push_back(deviceSinkEngine); + ui->deviceSetTx->addItem(QString("%1").arg(i)); } } @@ -633,6 +744,10 @@ void LimeRFEUSBDialog::on_modeRx_toggled(bool checked) ui->statusText->setText(m_controller.getError(rc).c_str()); } + if (m_deviceSetSync) { + syncRxTx(); + } + displayMode(); } @@ -667,6 +782,10 @@ void LimeRFEUSBDialog::on_modeTx_toggled(bool checked) ui->statusText->setText(m_controller.getError(rc).c_str()); } + if (m_deviceSetSync) { + syncRxTx(); + } + displayMode(); } diff --git a/sdrgui/limerfegui/limerfeusbdialog.h b/sdrgui/limerfegui/limerfeusbdialog.h index 171e41d86..1f60d0687 100644 --- a/sdrgui/limerfegui/limerfeusbdialog.h +++ b/sdrgui/limerfegui/limerfeusbdialog.h @@ -19,13 +19,19 @@ #ifndef SDRGUI_LIMERFEGUI_LIMERFEUSBDIALOG_H_ #define SDRGUI_LIMERFEGUI_LIMERFEUSBDIALOG_H_ +#include + #include #include +#include "util/movingaverage.h" #include "limerfe/limerfecontroller.h" #include "limerfe/limerfeusbcalib.h" #include "export.h" +class DSPDeviceSourceEngine; +class DSPDeviceSinkEngine; + namespace Ui { class LimeRFEUSBDialog; } @@ -48,6 +54,10 @@ private: double getPowerCorrection(); void setPowerCorrection(double dbValue); void updateAbsPower(double powerCorrDB); + void updateDeviceSetList(); + void stopStartRx(bool start); + void stopStartTx(bool start); + void syncRxTx(); Ui::LimeRFEUSBDialog* ui; LimeRFEController m_controller; @@ -56,6 +66,13 @@ private: bool m_rxTxToggle; QTimer m_timer; double m_currentPowerCorrection; + bool m_avgPower; + MovingAverageUtil m_powerMovingAverage; + bool m_deviceSetSync; + int m_rxDeviceSetSequence; + int m_txDeviceSetSequence; + std::vector m_sourceEngines; + std::vector m_sinkEngines; private slots: void on_openDevice_clicked(); @@ -72,10 +89,13 @@ private slots: void on_powerSource_currentIndexChanged(int index); void on_powerRefresh_clicked(); void on_powerAutoRefresh_toggled(bool checked); + void on_powerAbsAvg_clicked(); void on_powerCorrValue_textEdited(const QString &text); void on_modeRx_toggled(bool checked); void on_modeTx_toggled(bool checked); void on_rxTxToggle_clicked(); + void on_deviceSetRefresh_clicked(); + void on_deviceSetSync_clicked(); void on_apply_clicked(); void tick(); }; diff --git a/sdrgui/limerfegui/limerfeusbdialog.ui b/sdrgui/limerfegui/limerfeusbdialog.ui index a4bf9e4d5..a6b7885ad 100644 --- a/sdrgui/limerfegui/limerfeusbdialog.ui +++ b/sdrgui/limerfegui/limerfeusbdialog.ui @@ -441,8 +441,8 @@ 10 350 - 51 - 27 + 50 + 25 @@ -460,8 +460,8 @@ 70 350 - 51 - 27 + 50 + 25 @@ -537,8 +537,8 @@ 130 350 - 71 - 27 + 70 + 25 @@ -805,15 +805,15 @@ 170 290 - 45 + 75 17 - Corrected forward power in dB + Corrected forward power in dBm - -00.0 + -00.0 dBm Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter @@ -822,9 +822,9 @@ - 220 + 250 290 - 45 + 65 17 @@ -832,23 +832,7 @@ Corrected forward power in Watts - 0.000 - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - 280 - 290 - 15 - 17 - - - - W + 0.000 W Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter @@ -876,6 +860,110 @@ Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + 320 + 290 + 50 + 17 + + + + Corrected power averaging + + + Avg + + + + + + 230 + 350 + 50 + 25 + + + + Sequence of Rx DeviceSet + + + + + + 310 + 350 + 50 + 25 + + + + Sequence of Tx DeviceSet + + + + + + 210 + 350 + 25 + 25 + + + + Rx + + + + + + 290 + 350 + 25 + 25 + + + + Tx + + + + + + 210 + 320 + 100 + 25 + + + + DeviceSet synchronization + + + Rx/Tx Sync + + + + + + 370 + 350 + 24 + 24 + + + + Refresh DeviceSet indexes + + + + + + + :/recycle.png:/recycle.png + +