From d2526cdc5bf7a6b687ce885ca877958916f9a268 Mon Sep 17 00:00:00 2001 From: srcejon Date: Mon, 2 Oct 2023 15:45:17 +0100 Subject: [PATCH] Fix loading settings. Add remove inactive button. Restart scan when sample rate changes. --- plugins/channelrx/freqscanner/freqscanner.cpp | 10 +- .../freqscanner/freqscanneraddrangedialog.cpp | 88 +++++++- .../freqscanner/freqscanneraddrangedialog.h | 5 +- .../freqscanner/freqscanneraddrangedialog.ui | 190 +++++++++++------- .../channelrx/freqscanner/freqscannergui.cpp | 45 ++++- .../channelrx/freqscanner/freqscannergui.h | 1 + .../channelrx/freqscanner/freqscannergui.ui | 20 +- plugins/channelrx/freqscanner/readme.md | 15 +- 8 files changed, 271 insertions(+), 103 deletions(-) diff --git a/plugins/channelrx/freqscanner/freqscanner.cpp b/plugins/channelrx/freqscanner/freqscanner.cpp index ef0afc145..14b00720a 100644 --- a/plugins/channelrx/freqscanner/freqscanner.cpp +++ b/plugins/channelrx/freqscanner/freqscanner.cpp @@ -225,7 +225,13 @@ bool FreqScanner::handleMessage(const Message& cmd) else if (DSPSignalNotification::match(cmd)) { DSPSignalNotification& notif = (DSPSignalNotification&) cmd; - m_basebandSampleRate = notif.getSampleRate(); + int newSampleRate = notif.getSampleRate(); + if ((newSampleRate != m_basebandSampleRate) && (m_state != IDLE)) + { + // Restart scan if sample rate changes + startScan(); + } + m_basebandSampleRate = newSampleRate; m_centerFrequency = notif.getCenterFrequency(); qDebug() << "FreqScanner::handleMessage: DSPSignalNotification"; // Forward to the sink @@ -645,7 +651,7 @@ void FreqScanner::applySettings(const FreqScannerSettings& settings, const QStri { // Restart scan if any settings change if (m_state != IDLE) { - m_state = START_SCAN; + startScan(); } } diff --git a/plugins/channelrx/freqscanner/freqscanneraddrangedialog.cpp b/plugins/channelrx/freqscanner/freqscanneraddrangedialog.cpp index c08998641..cdf24d2cb 100644 --- a/plugins/channelrx/freqscanner/freqscanneraddrangedialog.cpp +++ b/plugins/channelrx/freqscanner/freqscanneraddrangedialog.cpp @@ -29,11 +29,9 @@ FreqScannerAddRangeDialog::FreqScannerAddRangeDialog(int step, QWidget* parent) ui->stop->setColorMapper(ColorMapper(ColorMapper::GrayGold)); ui->stop->setValueRange(false, 11, 0, 99999999999); - // Airband frequency range - ui->start->setValue(118000000); - ui->stop->setValue(137000000); + on_preset_currentTextChanged("Airband"); - ui->step->setCurrentText(QString::number(step)); + //ui->step->setCurrentText(QString::number(step)); } FreqScannerAddRangeDialog::~FreqScannerAddRangeDialog() @@ -43,8 +41,84 @@ FreqScannerAddRangeDialog::~FreqScannerAddRangeDialog() void FreqScannerAddRangeDialog::accept() { - m_start = ui->start->getValue(); - m_stop = ui->stop->getValue(); - m_step = ui->step->currentText().toInt(); + if (ui->preset->currentText() == "Digital Selective Calling") + { + // From ITU M.541 + static const QList dscFreqs = { + 2177000, 2189500, + 4208000, 4208500, 4209000, + 6312500, 6313000, + 8415000, 8415500, 8416000, + 12577500, 12578000, 12578500, + 16805000, 16805500, 16806000, 18898500, 18899000, 18899500, + 22374500, 22375000, 22375500, + 25208500, 25209000, 25209500 + }; + m_frequencies.append(dscFreqs); + } + else if (ui->preset->currentText() == "DAB") + { + static const QList dabFreqs = { + 174928000, 176640000, 178352000, 180064000, + 181936000, 183648000, 185360000, 187072000, + 188928000, 190640000, 192352000, 194064000, + 195936000, 197648000, 199360000, 201072000, + 202928000, 204640000, 206352000, 208064000, + 209936000, 211648000, 213360000, 215072000, + 216928000, 218640000, 220352000, 222064000, + 223936000, 225648000, 227360000, 229072000, + 230784000, 232496000, 234208000, 235776000, + 237448000, 239200000 + }; + m_frequencies.append(dabFreqs); + } + else + { + qint64 start = ui->start->getValue(); + qint64 stop = ui->stop->getValue(); + int step = ui->step->currentText().toInt(); + + if ((start <= stop) && (step > 0)) + { + for (qint64 f = start; f <= stop; f += step) { + m_frequencies.append(f); + } + } + } + QDialog::accept(); } + +void FreqScannerAddRangeDialog::on_preset_currentTextChanged(const QString& text) +{ + bool enableManAdjust = true; + if (text == "Airband") + { + ui->start->setValue(118000000); + ui->stop->setValue(137000000); + ui->step->setCurrentText("25000"); + } + else if (text == "Broadcast FM") + { + ui->start->setValue(87500000); + ui->stop->setValue(108000000); + ui->step->setCurrentText("100000"); + } + else if (text == "DAB") + { + enableManAdjust = false; + } + else if (text == "Marine") + { + ui->start->setValue(156000000); + ui->stop->setValue(162150000); + ui->step->setCurrentText("25000"); + } + else if (text == "Digital Selective Calling") + { + enableManAdjust = false; + } + ui->start->setEnabled(enableManAdjust); + ui->stop->setEnabled(enableManAdjust); + ui->step->setEnabled(enableManAdjust); +} diff --git a/plugins/channelrx/freqscanner/freqscanneraddrangedialog.h b/plugins/channelrx/freqscanner/freqscanneraddrangedialog.h index 7cb25b076..0a9f14e36 100644 --- a/plugins/channelrx/freqscanner/freqscanneraddrangedialog.h +++ b/plugins/channelrx/freqscanner/freqscanneraddrangedialog.h @@ -30,12 +30,11 @@ public: explicit FreqScannerAddRangeDialog(int step, QWidget* parent = nullptr); ~FreqScannerAddRangeDialog(); - qint64 m_start; - qint64 m_stop; - int m_step; + QList m_frequencies; private slots: void accept(); + void on_preset_currentTextChanged(const QString& text); private: Ui::FreqScannerAddRangeDialog *ui; diff --git a/plugins/channelrx/freqscanner/freqscanneraddrangedialog.ui b/plugins/channelrx/freqscanner/freqscanneraddrangedialog.ui index 0cce5efe4..73cd0a1aa 100644 --- a/plugins/channelrx/freqscanner/freqscanneraddrangedialog.ui +++ b/plugins/channelrx/freqscanner/freqscanneraddrangedialog.ui @@ -7,7 +7,7 @@ 0 0 385 - 162 + 190 @@ -31,82 +31,21 @@ Add Frequency Range - - - - - 0 - 0 - - - - - 32 - 16 - - - - - Liberation Mono - 12 - - - - PointingHandCursor - - - Qt::StrongFocus - - - Stop frequency in Hertz - - - - - + + - Stop Frequency + Step - - - - - 90 - 0 - - - - Start Frequency - - - - - + + Hz - - - - true - - - - 25000 - - - - - 8333.3 - - - - - + @@ -137,24 +76,129 @@ - + Hz - - + + Hz - + - Step + Stop Frequency + + + + + + + + 90 + 0 + + + + Start Frequency + + + + + + + true + + + + 25000 + + + + + 8333.3 + + + + + 100000 + + + + + + + + + 0 + 0 + + + + + 32 + 16 + + + + + Liberation Mono + 12 + + + + PointingHandCursor + + + Qt::StrongFocus + + + Stop frequency in Hertz + + + + + + + Select a preset range of frequencies + + + + Airband + + + + + Broadcast FM + + + + + DAB + + + + + Digital Selective Calling + + + + + Marine + + + + + + + + Preset diff --git a/plugins/channelrx/freqscanner/freqscannergui.cpp b/plugins/channelrx/freqscanner/freqscannergui.cpp index 9cd79d20e..520d4dbbc 100644 --- a/plugins/channelrx/freqscanner/freqscannergui.cpp +++ b/plugins/channelrx/freqscanner/freqscannergui.cpp @@ -504,7 +504,6 @@ void FreqScannerGUI::displaySettings() setTitle(m_channelMarker.getTitle()); blockApplySettings(true); - int channelIndex = ui->channels->findText(m_settings.m_channel); if (channelIndex >= 0) { ui->channels->setCurrentIndex(channelIndex); @@ -524,6 +523,7 @@ void FreqScannerGUI::displaySettings() ui->mode->setCurrentIndex((int)m_settings.m_mode); ui->table->blockSignals(true); + ui->table->setRowCount(0); for (int i = 0; i < m_settings.m_frequencies.size(); i++) { addRow(m_settings.m_frequencies[i], m_settings.m_enabled[i], m_settings.m_notes[i]); @@ -618,16 +618,9 @@ void FreqScannerGUI::on_addRange_clicked() new DialogPositioner(&dialog, false); if (dialog.exec()) { - qint64 start = dialog.m_start; - qint64 stop = dialog.m_stop; - int step = dialog.m_step; - blockApplySettings(true); - if ((start <= stop) && (step > 0)) - { - for (qint64 f = start; f <= stop; f += step) { - addRow(f, true); - } + for (const auto f : dialog.m_frequencies) { + addRow(f, true); } blockApplySettings(false); QList settingsKeys({ @@ -659,6 +652,27 @@ void FreqScannerGUI::on_remove_clicked() applySettings(settingsKeys); } +void FreqScannerGUI::on_removeInactive_clicked() +{ + for (int i = ui->table->rowCount() - 1; i >= 0; i--) + { + if (ui->table->item(i, COL_ACTIVE_COUNT)->data(Qt::DisplayRole).toInt() == 0) + { + ui->table->removeRow(i); + m_settings.m_frequencies.removeAt(i); // table_cellChanged isn't called for removeRow + m_settings.m_enabled.removeAt(i); + m_settings.m_notes.removeAt(i); + } + } + QList settingsKeys({ + "frequencies", + "enabled", + "notes" + }); + applySettings(settingsKeys); +} + + static QList takeRow(QTableWidget* table, int row) { QList rowItems; @@ -805,6 +819,14 @@ void FreqScannerGUI::table_customContextMenuRequested(QPoint pos) }); tableContextMenu->addAction(copyAction); + // Remove selected rows + + QAction* removeAction = new QAction("Remove", tableContextMenu); + connect(removeAction, &QAction::triggered, this, [this]()->void { + on_remove_clicked(); + }); + tableContextMenu->addAction(removeAction); + tableContextMenu->addSeparator(); // Tune to frequency @@ -904,7 +926,7 @@ void FreqScannerGUI::resizeTable() // Fill table with a row of dummy data that will size the columns nicely int row = ui->table->rowCount(); ui->table->setRowCount(row + 1); - ui->table->setItem(row, COL_FREQUENCY, new QTableWidgetItem("999.000 MHz")); + ui->table->setItem(row, COL_FREQUENCY, new QTableWidgetItem("800,000.5 MHz")); ui->table->setItem(row, COL_ANNOTATION, new QTableWidgetItem("An annotation")); ui->table->setItem(row, COL_ENABLE, new QTableWidgetItem("Enable")); ui->table->setItem(row, COL_POWER, new QTableWidgetItem("-100.0")); @@ -931,6 +953,7 @@ void FreqScannerGUI::makeUIConnections() QObject::connect(ui->addSingle, &QToolButton::clicked, this, &FreqScannerGUI::on_addSingle_clicked); QObject::connect(ui->addRange, &QToolButton::clicked, this, &FreqScannerGUI::on_addRange_clicked); QObject::connect(ui->remove, &QToolButton::clicked, this, &FreqScannerGUI::on_remove_clicked); + QObject::connect(ui->removeInactive, &QToolButton::clicked, this, &FreqScannerGUI::on_removeInactive_clicked); QObject::connect(ui->up, &QToolButton::clicked, this, &FreqScannerGUI::on_up_clicked); QObject::connect(ui->down, &QToolButton::clicked, this, &FreqScannerGUI::on_down_clicked); QObject::connect(ui->clearActiveCount, &QToolButton::clicked, this, &FreqScannerGUI::on_clearActiveCount_clicked); diff --git a/plugins/channelrx/freqscanner/freqscannergui.h b/plugins/channelrx/freqscanner/freqscannergui.h index 35be2e571..9113fe514 100644 --- a/plugins/channelrx/freqscanner/freqscannergui.h +++ b/plugins/channelrx/freqscanner/freqscannergui.h @@ -132,6 +132,7 @@ private slots: void on_addSingle_clicked(); void on_addRange_clicked(); void on_remove_clicked(); + void on_removeInactive_clicked(); void on_up_clicked(); void on_down_clicked(); void on_clearActiveCount_clicked(); diff --git a/plugins/channelrx/freqscanner/freqscannergui.ui b/plugins/channelrx/freqscanner/freqscannergui.ui index cd887b094..a22fa5160 100644 --- a/plugins/channelrx/freqscanner/freqscannergui.ui +++ b/plugins/channelrx/freqscanner/freqscannergui.ui @@ -181,6 +181,12 @@ + + + 30 + 0 + + Active frequency power @@ -231,10 +237,10 @@ Power threshold in dB - -1400 + -1000 - 100 + 0 1 @@ -699,6 +705,16 @@ + + + + Remove rows with Active Count of 0 + + + Remove Inactive + + + diff --git a/plugins/channelrx/freqscanner/readme.md b/plugins/channelrx/freqscanner/readme.md index a6a71263a..9f2de848f 100644 --- a/plugins/channelrx/freqscanner/readme.md +++ b/plugins/channelrx/freqscanner/readme.md @@ -87,7 +87,7 @@ Displays the current status of the Frequency Scanner. The frequency table contains the list of frequencies to be scanned, along with results of a scan. The columns are: -- Freq (Hz): Specifies the channel center frequencies to be scanned. These should be spaced by integer multiples of the channel bandwidth (8). Values should be entered in Hertz. +- Freq (Hz): Specifies the channel center frequencies to be scanned. Values should be entered in Hertz. - Annotation: An annotation (description) for the frequency, that is obtained from the closest matching [annotation marker](../../../sdrgui/gui/spectrummarkers.md) in the Main Spectrum. - Enable: Determines whether the frequency will be scanned. This can be used to temporaily disable frequencies you aren't interested in. - Power (dB): Displays the measured power in decibels from the last scan. The cell will have a green background if the power was above the threshold (4). @@ -99,6 +99,7 @@ When an active frequency is found after a scan, the corresponding row in the tab Right clicking on a cell will display a popup menu: - Copy contents of cell to clipboard. +- Remove selected rows. - Tune selected channel (1) to the frequency in the row clicked on.

15: Add

@@ -112,16 +113,20 @@ The step value should typically be an integer multiple of the channel bandwidth

17: Remove

-Removes the selected rows from the frequency table (14). +Removes the selected rows from the frequency table (14). Press Ctrl-A to select all rows. -

18: Up

+

18: Remove Inactive

+ +Removes all rows with Active Count of 0. + +

19: Up

Moves the selected rows up the frequency table (14). -

19: Down

+

20: Down

Moves the selected rows the the frequency table (14). -

20: Clear Active Count

+

21: Clear Active Count

Press to reset the value in the Active Count column to 0 for all rows.