From 86388722f63ec01dbec45089ece52362f4d85dfa Mon Sep 17 00:00:00 2001 From: manjaro Date: Tue, 19 Jan 2021 20:50:01 +0000 Subject: [PATCH] Add channel selection --- specwidget.cpp | 61 ++++++++++++++++++++++++++----- specwidget.h | 5 +++ specwidget.ui | 97 +++++++++++++++++++++++++++++++++++-------------- uhd_device.cpp | 2 +- uhdspectrum.pro | 2 +- 5 files changed, 128 insertions(+), 39 deletions(-) diff --git a/specwidget.cpp b/specwidget.cpp index 6629f7e..8090b02 100644 --- a/specwidget.cpp +++ b/specwidget.cpp @@ -5,7 +5,8 @@ specWidget::specWidget(QWidget *parent) : QWidget(parent), ui(new Ui::specWidget), - m_runth(new uhd_io_thread(this)) + m_runth(new uhd_io_thread(this)), + m_attenMod(new QStandardItemModel(this)) { ui->setupUi(this); Bookmarks::create(); @@ -20,13 +21,15 @@ specWidget::specWidget(QWidget *parent) : //选择带宽 ui->plotter->setFilterBoxEnabled(true); - //中心频率 - //ui->plotter->setCenterFreq(101700000); - //选择频率 - //ui->plotter->setDemodCenterFreq(102300000); + ui->plotter->setTooltipsEnabled(true); ui->plotter->setPeakDetection(false,128.0); + m_attenMod->appendRow(new QStandardItem("TX/RX")); + m_attenMod->appendRow(new QStandardItem("RX2")); + m_attenMod->appendRow(new QStandardItem("RX")); + m_attenMod->appendRow(new QStandardItem("TX")); + ui->comboBox_atn->setModel(m_attenMod); //连接 //connect (ui->plotter,&CPlotter::newDemodFreq,ui->freqCtrl,&CFreqCtrl::setFrequency); @@ -199,8 +202,22 @@ bool specWidget::saveWaterfall(const QString & filename) void specWidget::on_pushButton_reset_clicked() { saveSettings(); - loadSettings(); - resetFFT(); + if (m_runth->isRunning()) + { + if (m_nTimerID>=0) + killTimer(m_nTimerID); + + if (usrp) + { + close_device(); + } + ui->pushButton_reset->setText(tr("Start")); + } + else + { + loadSettings(); + resetFFT(); + } } void specWidget::loadSettings() @@ -286,6 +303,8 @@ void specWidget::freeFFT() } void specWidget::resetFFT() { + ui->pushButton_reset->setText(tr("Start")); + m_channel = ui->spinBox_chan->value(); freeFFT(); m_pFFTIn = (fftw_complex *) fftw_malloc(sizeof(fftw_complex) * m_nFFTSize); m_pFFTOut = (fftw_complex *) fftw_malloc(sizeof(fftw_complex) * m_nFFTSize); @@ -312,7 +331,9 @@ void specWidget::resetFFT() setSampleRate(getSampleRate()); setCenterFreq(ui->plotter->getCenterFreq()); - + QString atn = ui->comboBox_atn->currentText(); + if (atn.size()) + usrp->set_rx_antenna(atn.toStdString(),m_channel); if (m_runth->isRunning()) { stop_signal_called = true; @@ -324,7 +345,7 @@ void specWidget::resetFFT() }); m_runth->start(); m_nTimerID = startTimer(updateIntelv); - + ui->pushButton_reset->setText(tr("Stop")); } void specWidget::appendWavComplex(const double (* pWav)[2], const int count, double voltage_ref) @@ -390,7 +411,15 @@ void specWidget::timerEvent(QTimerEvent * e) ui->sMeter->setLevel(m_dFFTAmp[m_nCurrentCenter]); //ui->sMeter->setSqlLevel(m_dFFTAmp[m_nCurrentCenter]); } + static int ccct = 0; + if (++ccct % 10==0) + { + if (!m_runth->isRunning()) + ui->pushButton_reset->setText(tr("Start")); + else + ui->pushButton_reset->setText(tr("Stop")); + } } } @@ -437,3 +466,17 @@ void specWidget::on_doubleSpinBox_range_min_valueChanged(double arg1) { ui->plotter->setWaterfallRange(ui->doubleSpinBox_range_min->value(),ui->doubleSpinBox_range_max->value()); } + +void specWidget::on_comboBox_atn_currentIndexChanged(const QString &arg1) +{ + if (arg1.size()) + { + if (usrp) + usrp->set_rx_antenna(arg1.toStdString(),m_channel); + } +} + +void specWidget::on_spinBox_chan_valueChanged(int arg1) +{ + m_channel = arg1; +} diff --git a/specwidget.h b/specwidget.h index ec36fac..5123783 100644 --- a/specwidget.h +++ b/specwidget.h @@ -103,6 +103,10 @@ private slots: void on_doubleSpinBox_range_min_valueChanged(double arg1); + void on_comboBox_atn_currentIndexChanged(const QString &arg1); + + void on_spinBox_chan_valueChanged(int arg1); + private: void loadSettings(); void saveSettings(); @@ -110,6 +114,7 @@ private: void freeFFT(); private: Ui::specWidget *ui = nullptr; + QStandardItemModel * m_attenMod = nullptr; private: int m_nFFTSize = 16384; std::vector m_dHammingWnd; diff --git a/specwidget.ui b/specwidget.ui index 0e52d9e..54f956b 100644 --- a/specwidget.ui +++ b/specwidget.ui @@ -6,7 +6,7 @@ 0 0 - 738 + 787 466 @@ -33,7 +33,7 @@ - Apply + Start @@ -241,14 +241,14 @@ 0 0 310 - 380 + 348 Radio - + Qt::Vertical @@ -261,7 +261,26 @@ - + + + + + + + 6 + + + 0.000001000000000 + + + 1024.000000000000000 + + + 10.000000000000000 + + + + 6 @@ -277,36 +296,41 @@ - - + + + + Gain + + + + + + + + + + 1 + + - + - Center Freq(Mhz) + Channel - + Sample Rate(Mhz) - - - - 6 - - - 0.000001000000000 - - - 1024.000000000000000 - - - 10.000000000000000 + + + + Center Freq(Mhz) @@ -317,15 +341,19 @@ - - + + - Gain + Antenna - - + + + + false + + @@ -493,6 +521,19 @@ + + + + 0 + 0 + 310 + 348 + + + + Save + + diff --git a/uhd_device.cpp b/uhd_device.cpp index 9363469..8a53ba9 100644 --- a/uhd_device.cpp +++ b/uhd_device.cpp @@ -108,7 +108,7 @@ void uhd_device::run_IO() { //创建流对象实例 uhd::stream_args_t stream_args_rx("sc16", "sc16"); - stream_args_rx.channels.push_back(0); + stream_args_rx.channels.push_back(m_channel); rx_streamer::sptr rx_stream = usrp->get_rx_stream(stream_args_rx); rx_count = 0; diff --git a/uhdspectrum.pro b/uhdspectrum.pro index 00dfb7c..c1f2f2d 100644 --- a/uhdspectrum.pro +++ b/uhdspectrum.pro @@ -3,7 +3,7 @@ QT += core gui network greaterThan(QT_MAJOR_VERSION, 4): QT += widgets CONFIG += c++11 - +CONFIG += console # The following define makes your compiler emit warnings if you use # any Qt feature that has been marked deprecated (the exact warnings # depend on your compiler). Please consult the documentation of the -- GitLab