From 28cc7c3f31d058c4614183a972097115a12c4694 Mon Sep 17 00:00:00 2001 From: srcejon Date: Fri, 21 Jun 2024 10:24:16 +0100 Subject: [PATCH] FreqScanner: Add API action to run scan. Add scan results to channel report. --- plugins/channelrx/freqscanner/freqscanner.cpp | 57 ++++++++++++++++++- plugins/channelrx/freqscanner/freqscanner.h | 6 ++ .../channelrx/freqscanner/freqscannergui.cpp | 14 ++++- .../channelrx/freqscanner/freqscannergui.h | 2 +- plugins/channelrx/freqscanner/readme.md | 12 ++++ sdrbase/webapi/webapirequestmapper.cpp | 6 ++ sdrbase/webapi/webapiutils.cpp | 1 + 7 files changed, 94 insertions(+), 4 deletions(-) diff --git a/plugins/channelrx/freqscanner/freqscanner.cpp b/plugins/channelrx/freqscanner/freqscanner.cpp index 54afdd639..04432245c 100644 --- a/plugins/channelrx/freqscanner/freqscanner.cpp +++ b/plugins/channelrx/freqscanner/freqscanner.cpp @@ -31,6 +31,7 @@ #include "SWGWorkspaceInfo.h" #include "SWGFreqScannerSettings.h" #include "SWGChannelReport.h" +#include "SWGChannelActions.h" #include "device/deviceset.h" #include "dsp/dspengine.h" @@ -550,7 +551,9 @@ void FreqScanner::processScanResults(const QDateTime& fftStartTime, const QList< setDeviceCenterFrequency(nextCenterFrequency); } - if (complete) { + if (complete) + { + m_scanResultsForReport = m_scanResults; m_scanResults.clear(); } } @@ -815,6 +818,47 @@ int FreqScanner::webapiReportGet( return 200; } +int FreqScanner::webapiActionsPost( + const QStringList& channelActionsKeys, + SWGSDRangel::SWGChannelActions& query, + QString& errorMessage) +{ + SWGSDRangel::SWGFreqScannerActions *swgFreqScannerActions = query.getFreqScannerActions(); + + if (swgFreqScannerActions) + { + if (channelActionsKeys.contains("run")) + { + bool run = swgFreqScannerActions->getRun() != 0; + if (run) + { + MsgStartScan *start = MsgStartScan::create(); + if (getMessageQueueToGUI()) { + getMessageQueueToGUI()->push(start); + } else { + getInputMessageQueue()->push(start); + } + } + else + { + MsgStopScan *stop = MsgStopScan::create(); + if (getMessageQueueToGUI()) { + getMessageQueueToGUI()->push(stop); + } else { + getInputMessageQueue()->push(stop); + } + } + } + + return 202; + } + else + { + errorMessage = "Missing FreqScannerActions in query"; + return 400; + } +} + void FreqScanner::webapiUpdateChannelSettings( FreqScannerSettings& settings, const QStringList& channelSettingsKeys, @@ -984,6 +1028,17 @@ void FreqScanner::webapiFormatChannelSettings(SWGSDRangel::SWGChannelSettings& r void FreqScanner::webapiFormatChannelReport(SWGSDRangel::SWGChannelReport& response) { response.getFreqScannerReport()->setChannelSampleRate(m_basebandSink->getChannelSampleRate()); + response.getFreqScannerReport()->setScanState((int) m_state); + + QList *list = response.getFreqScannerReport()->getChannelState(); + + for (int i = 0; i < m_scanResultsForReport.size(); i++) + { + SWGSDRangel::SWGFreqScannerChannelState *channelState = new SWGSDRangel::SWGFreqScannerChannelState(); + channelState->setFrequency(m_scanResultsForReport[i].m_frequency); + channelState->setPower(m_scanResultsForReport[i].m_power); + list->append(channelState); + } } void FreqScanner::webapiReverseSendSettings(const QStringList& channelSettingsKeys, const FreqScannerSettings& settings, bool force) diff --git a/plugins/channelrx/freqscanner/freqscanner.h b/plugins/channelrx/freqscanner/freqscanner.h index 40f1fc84d..a5ec4ff37 100644 --- a/plugins/channelrx/freqscanner/freqscanner.h +++ b/plugins/channelrx/freqscanner/freqscanner.h @@ -341,6 +341,11 @@ public: SWGSDRangel::SWGChannelReport& response, QString& errorMessage); + virtual int webapiActionsPost( + const QStringList& channelActionsKeys, + SWGSDRangel::SWGChannelActions& query, + QString& errorMessage); + static void webapiFormatChannelSettings( SWGSDRangel::SWGChannelSettings& response, const FreqScannerSettings& settings); @@ -388,6 +393,7 @@ private: qint64 m_stepStartFrequency; qint64 m_stepStopFrequency; QList m_scanResults; + QList m_scanResultsForReport; enum State { IDLE, diff --git a/plugins/channelrx/freqscanner/freqscannergui.cpp b/plugins/channelrx/freqscanner/freqscannergui.cpp index 9660542c2..fa8287ec0 100644 --- a/plugins/channelrx/freqscanner/freqscannergui.cpp +++ b/plugins/channelrx/freqscanner/freqscannergui.cpp @@ -204,6 +204,16 @@ bool FreqScannerGUI::handleMessage(const Message& message) return true; } + else if (FreqScanner::MsgStartScan::match(message)) + { + ui->startStop->doToggle(true); + return true; + } + else if (FreqScanner::MsgStopScan::match(message)) + { + ui->startStop->doToggle(false); + return true; + } return false; } @@ -609,7 +619,7 @@ void FreqScannerGUI::enterEvent(EnterEventType* event) ChannelGUI::enterEvent(event); } -void FreqScannerGUI::on_startStop_clicked(bool checked) +void FreqScannerGUI::on_startStop_toggled(bool checked) { if (checked) { @@ -1080,7 +1090,7 @@ void FreqScannerGUI::makeUIConnections() QObject::connect(ui->priority, QOverload::of(&QComboBox::currentIndexChanged), this, &FreqScannerGUI::on_priority_currentIndexChanged); QObject::connect(ui->measurement, QOverload::of(&QComboBox::currentIndexChanged), this, &FreqScannerGUI::on_measurement_currentIndexChanged); QObject::connect(ui->mode, QOverload::of(&QComboBox::currentIndexChanged), this, &FreqScannerGUI::on_mode_currentIndexChanged); - QObject::connect(ui->startStop, &ButtonSwitch::clicked, this, &FreqScannerGUI::on_startStop_clicked); + QObject::connect(ui->startStop, &ButtonSwitch::toggled, this, &FreqScannerGUI::on_startStop_toggled); QObject::connect(ui->table, &QTableWidget::cellChanged, this, &FreqScannerGUI::on_table_cellChanged); QObject::connect(ui->addSingle, &QToolButton::clicked, this, &FreqScannerGUI::on_addSingle_clicked); QObject::connect(ui->addRange, &QToolButton::clicked, this, &FreqScannerGUI::on_addRange_clicked); diff --git a/plugins/channelrx/freqscanner/freqscannergui.h b/plugins/channelrx/freqscanner/freqscannergui.h index 4dc9dd484..ebff8c522 100644 --- a/plugins/channelrx/freqscanner/freqscannergui.h +++ b/plugins/channelrx/freqscanner/freqscannergui.h @@ -140,7 +140,7 @@ private slots: void table_sectionResized(int logicalIndex, int oldSize, int newSize); void columnSelectMenu(QPoint pos); void columnSelectMenuChecked(bool checked = false); - void on_startStop_clicked(bool checked = false); + void on_startStop_toggled(bool checked = false); void on_addSingle_clicked(); void on_addRange_clicked(); void on_remove_clicked(); diff --git a/plugins/channelrx/freqscanner/readme.md b/plugins/channelrx/freqscanner/readme.md index 0636c0683..7bd676b98 100644 --- a/plugins/channelrx/freqscanner/readme.md +++ b/plugins/channelrx/freqscanner/readme.md @@ -140,3 +140,15 @@ Moves the selected rows the the frequency table (14).

21: Clear Active Count

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

API

+ +Full details of the API can be found in the Swagger documentation. Below are a few examples. + +To run a frequency scan: + + curl -X POST "http://127.0.0.1:8091/sdrangel/deviceset/0/channel/0/actions" -d '{ "channelType": "FreqScanner", "direction": 0, "originatorDeviceSetIndex": 0, "originatorChannelIndex": 0, "FreqScannerActions": { "run": 1 }}' + +To get the results of the last scan: + + curl -X GET "http://127.0.0.1:8091/sdrangel/deviceset/0/channel/0/report" diff --git a/sdrbase/webapi/webapirequestmapper.cpp b/sdrbase/webapi/webapirequestmapper.cpp index b424b61d0..4eced1e82 100644 --- a/sdrbase/webapi/webapirequestmapper.cpp +++ b/sdrbase/webapi/webapirequestmapper.cpp @@ -4821,6 +4821,11 @@ bool WebAPIRequestMapper::getChannelActions( channelActions->setFileSourceActions(new SWGSDRangel::SWGFileSourceActions()); channelActions->getFileSourceActions()->fromJsonObject(actionsJsonObject); } + else if (channelActionsKey == "FreqScannerActions") + { + channelActions->setFreqScannerActions(new SWGSDRangel::SWGFreqScannerActions()); + channelActions->getFreqScannerActions()->fromJsonObject(actionsJsonObject); + } else if (channelActionsKey == "IEEE_802_15_4_ModActions") { channelActions->setIeee802154ModActions(new SWGSDRangel::SWGIEEE_802_15_4_ModActions()); @@ -5629,6 +5634,7 @@ void WebAPIRequestMapper::resetChannelActions(SWGSDRangel::SWGChannelActions& ch channelActions.setAptDemodActions(nullptr); channelActions.setChannelType(nullptr); channelActions.setFileSourceActions(nullptr); + channelActions.setFreqScannerActions(nullptr); channelActions.setIeee802154ModActions(nullptr); channelActions.setPacketModActions(nullptr); channelActions.setPsk31ModActions(nullptr); diff --git a/sdrbase/webapi/webapiutils.cpp b/sdrbase/webapi/webapiutils.cpp index a89989fbe..7873fd125 100644 --- a/sdrbase/webapi/webapiutils.cpp +++ b/sdrbase/webapi/webapiutils.cpp @@ -216,6 +216,7 @@ const QMap WebAPIUtils::m_channelTypeToActionsKey = { {"APTDemod", "APTDemodActions"}, {"FileSink", "FileSinkActions"}, {"FileSource", "FileSourceActions"}, + {"FreqScanner", "FreqScannerActions"}, {"SigMFFileSink", "SigMFFileSinkActions"}, {"IEEE_802_15_4_Mod", "IEEE_802_15_4_ModActions"}, {"RadioAstronomy", "RadioAstronomyActions"},