Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Frequency scanner: Add scan results to channel report. Add run action to API. Add HF ATC. #2181

Merged
merged 4 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 56 additions & 1 deletion plugins/channelrx/freqscanner/freqscanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "SWGWorkspaceInfo.h"
#include "SWGFreqScannerSettings.h"
#include "SWGChannelReport.h"
#include "SWGChannelActions.h"

#include "device/deviceset.h"
#include "dsp/dspengine.h"
Expand Down Expand Up @@ -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();
}
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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<SWGSDRangel::SWGFreqScannerChannelState *> *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)
Expand Down
6 changes: 6 additions & 0 deletions plugins/channelrx/freqscanner/freqscanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,11 @@ class FreqScanner : public BasebandSampleSink, public ChannelAPI {
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);
Expand Down Expand Up @@ -388,6 +393,7 @@ class FreqScanner : public BasebandSampleSink, public ChannelAPI {
qint64 m_stepStartFrequency;
qint64 m_stepStopFrequency;
QList<MsgScanResult::ScanResult> m_scanResults;
QList<MsgScanResult::ScanResult> m_scanResultsForReport;

enum State {
IDLE,
Expand Down
17 changes: 17 additions & 0 deletions plugins/channelrx/freqscanner/freqscanneraddrangedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,19 @@ void FreqScannerAddRangeDialog::accept()
};
m_frequencies.append(FRS_GMRSFreqs);
}
else if (ui->preset->currentText() == "HF ATC")
{
static const QList<qint64> hfFreqs = {
2872000, 2890000, 2899000, 2971000,
3016000, 3446000, 3476000, 3491000,
4675000, 5598000, 5616000, 5649000,
6547000, 6595000, 6622000, 6667000,
8831000, 8864000, 8879000, 8891000,
8906000, 10021000, 11336000, 13291000,
13306000, 17946000
};
m_frequencies.append(hfFreqs);
}
else
{
qint64 start = ui->start->getValue();
Expand Down Expand Up @@ -151,6 +164,10 @@ void FreqScannerAddRangeDialog::on_preset_currentTextChanged(const QString& text
{
enableManAdjust = false;
}
else if (text == "HF ATC")
{
enableManAdjust = false;
}
ui->start->setEnabled(enableManAdjust);
ui->stop->setEnabled(enableManAdjust);
ui->step->setEnabled(enableManAdjust);
Expand Down
6 changes: 5 additions & 1 deletion plugins/channelrx/freqscanner/freqscanneraddrangedialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@
<string>FRS-GMRS</string>
</property>
</item>
<item>
<property name="text">
<string>HF ATC</string>
</property>
</item>
</widget>
</item>
<item row="0" column="0">
Expand Down Expand Up @@ -232,7 +237,6 @@
</customwidgets>
<resources>
<include location="../../../sdrgui/resources/res.qrc"/>
<include location="../demodapt/icons.qrc"/>
</resources>
<connections>
<connection>
Expand Down
14 changes: 12 additions & 2 deletions plugins/channelrx/freqscanner/freqscannergui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -1080,7 +1090,7 @@ void FreqScannerGUI::makeUIConnections()
QObject::connect(ui->priority, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &FreqScannerGUI::on_priority_currentIndexChanged);
QObject::connect(ui->measurement, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &FreqScannerGUI::on_measurement_currentIndexChanged);
QObject::connect(ui->mode, QOverload<int>::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);
Expand Down
2 changes: 1 addition & 1 deletion plugins/channelrx/freqscanner/freqscannergui.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
12 changes: 12 additions & 0 deletions plugins/channelrx/freqscanner/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,15 @@ Moves the selected rows the the frequency table (14).
<h3>21: Clear Active Count</h3>

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

<h2>API</h2>

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"
37 changes: 36 additions & 1 deletion sdrbase/resources/webapi/doc/html2/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3598,6 +3598,9 @@
"FileSourceActions" : {
"$ref" : "#/definitions/FileSourceActions"
},
"FreqScannerActions" : {
"$ref" : "#/definitions/FreqScannerActions"
},
"IEEE_802_15_4_ModActions" : {
"$ref" : "#/definitions/IEEE_802_15_4_ModActions"
},
Expand Down Expand Up @@ -7221,6 +7224,28 @@
}
},
"description" : "FreeDVMod"
};
defs.FreqScannerActions = {
"properties" : {
"run" : {
"type" : "integer",
"description" : "Set the plugin running state\n * 0 - idle\n * 1 - run\n"
}
},
"description" : "Frequency Scanner actions"
};
defs.FreqScannerChannelState = {
"properties" : {
"frequency" : {
"type" : "integer",
"description" : "Channel centre frequency in Hz"
},
"power" : {
"type" : "number",
"format" : "float",
"description" : "Channel power in dB"
}
}
};
defs.FreqScannerFrequency = {
"properties" : {
Expand Down Expand Up @@ -7252,6 +7277,16 @@
"properties" : {
"channelSampleRate" : {
"type" : "integer"
},
"scanState" : {
"type" : "integer",
"description" : "(IDLE=0, START_SCAN=1, SCANNING=2, WAIT_FOR_END_TX=3, WAIT_FOR_RETRANSMISSION=4)"
},
"channelState" : {
"type" : "array",
"items" : {
"$ref" : "#/definitions/FreqScannerChannelState"
}
}
},
"description" : "FreqScanner"
Expand Down Expand Up @@ -59084,7 +59119,7 @@ <h3> Status: 501 - Function not implemented </h3>
</div>
<div id="generator">
<div class="content">
Generated 2024-06-18T10:11:11.522+02:00
Generated 2024-06-21T11:03:53.536+02:00
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ ChannelActions:
$ref: "/doc/swagger/include/FileSink.yaml#/FileSinkActions"
FileSourceActions:
$ref: "/doc/swagger/include/FileSource.yaml#/FileSourceActions"
FreqScannerActions:
$ref: "/doc/swagger/include/FreqScanner.yaml#/FreqScannerActions"
IEEE_802_15_4_ModActions:
$ref: "/doc/swagger/include/IEEE_802_15_4_Mod.yaml#/IEEE_802_15_4_ModActions"
PacketModActions:
Expand Down
27 changes: 27 additions & 0 deletions sdrbase/resources/webapi/doc/swagger/include/FreqScanner.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,23 @@ FreqScannerReport:
properties:
channelSampleRate:
type: integer
scanState:
description: (IDLE=0, START_SCAN=1, SCANNING=2, WAIT_FOR_END_TX=3, WAIT_FOR_RETRANSMISSION=4)
type: integer
channelState:
type: array
items:
$ref: "/doc/swagger/include/FreqScanner.yaml#/FreqScannerChannelState"

FreqScannerChannelState:
properties:
frequency:
description: "Channel centre frequency in Hz"
type: integer
power:
description: "Channel power in dB"
type: number
format: float

FreqScannerFrequency:
properties:
Expand All @@ -77,3 +94,13 @@ FreqScannerFrequency:
type: string
squelch:
type: string

FreqScannerActions:
description: "Frequency Scanner actions"
properties:
run:
type: integer
description: >
Set the plugin running state
* 0 - idle
* 1 - run
6 changes: 6 additions & 0 deletions sdrbase/webapi/webapirequestmapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions sdrbase/webapi/webapiutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ const QMap<QString, QString> 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"},
Expand Down
2 changes: 2 additions & 0 deletions swagger/sdrangel/api/swagger/include/ChannelActions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ ChannelActions:
$ref: "http://swgserver:8081/api/swagger/include/FileSink.yaml#/FileSinkActions"
FileSourceActions:
$ref: "http://swgserver:8081/api/swagger/include/FileSource.yaml#/FileSourceActions"
FreqScannerActions:
$ref: "http://swgserver:8081/api/swagger/include/FreqScanner.yaml#/FreqScannerActions"
IEEE_802_15_4_ModActions:
$ref: "http://swgserver:8081/api/swagger/include/IEEE_802_15_4_Mod.yaml#/IEEE_802_15_4_ModActions"
PacketModActions:
Expand Down
Loading
Loading