From f841eecab927218feed93cb24fb168bd179e81ca Mon Sep 17 00:00:00 2001 From: Jon Beniston Date: Mon, 20 Jan 2025 10:54:21 +0000 Subject: [PATCH] Add --start option to start all devices and features. For #2359. --- sdrbase/feature/featurewebapiutils.cpp | 30 ++++++++++++++++++++++++++ sdrbase/feature/featurewebapiutils.h | 1 + sdrbase/mainparser.cpp | 9 +++++++- sdrbase/mainparser.h | 3 +++ sdrgui/mainwindow.cpp | 28 ++++++++++++++++++++++++ sdrgui/mainwindow.h | 2 ++ 6 files changed, 72 insertions(+), 1 deletion(-) diff --git a/sdrbase/feature/featurewebapiutils.cpp b/sdrbase/feature/featurewebapiutils.cpp index 45832bb96..84303acda 100644 --- a/sdrbase/feature/featurewebapiutils.cpp +++ b/sdrbase/feature/featurewebapiutils.cpp @@ -20,12 +20,42 @@ #include "SWGFeatureActions.h" #include "SWGMapActions.h" #include "SWGPERTesterActions.h" +#include "SWGDeviceState.h" #include "maincore.h" #include "feature/featureset.h" #include "feature/feature.h" #include "featurewebapiutils.h" +// Start feature +bool FeatureWebAPIUtils::run(int featureSetIndex, int featureIndex) +{ + Feature *feature = FeatureWebAPIUtils::getFeature(featureSetIndex, featureIndex, ""); + if (feature != nullptr) + { + SWGSDRangel::SWGDeviceState runResponse; + QString errorResponse; + int httpRC; + + runResponse.setState(new QString()); + httpRC = feature->webapiRun(true, runResponse, errorResponse); + + if (httpRC/100 != 2) + { + qWarning("FeatureWebAPIUtils::run: run error %d: %s", + httpRC, qPrintable(errorResponse)); + return false; + } + + return true; + } + else + { + qWarning("FeatureWebAPIUtils::run: no feature F%d:%d", featureSetIndex, featureIndex); + return false; + } +} + // Find the specified target on the map bool FeatureWebAPIUtils::mapFind(const QString& target, int featureSetIndex, int featureIndex) { diff --git a/sdrbase/feature/featurewebapiutils.h b/sdrbase/feature/featurewebapiutils.h index d0448892c..ddad1ae82 100644 --- a/sdrbase/feature/featurewebapiutils.h +++ b/sdrbase/feature/featurewebapiutils.h @@ -47,6 +47,7 @@ private slots: class SDRBASE_API FeatureWebAPIUtils { public: + static bool run(int featureSetIndex, int featureIndex); static bool mapFind(const QString& target, int featureSetIndex=-1, int featureIndex=-1); static bool mapSetDateTime(const QDateTime& dateTime, int featureSetIndex=-1, int featureIndex=-1); static bool skyMapFind(const QString& target, int featureSetIndex=-1, int featureIndex=-1); diff --git a/sdrbase/mainparser.cpp b/sdrbase/mainparser.cpp index 3735a5103..1456b8f25 100644 --- a/sdrbase/mainparser.cpp +++ b/sdrbase/mainparser.cpp @@ -42,7 +42,8 @@ MainParser::MainParser() : m_remoteTCPSinkPortOption("remote-tcp-port", "Remote TCP Sink port (Default 1234).", "port", "1234"), m_remoteTCPSinkHWTypeOption("remote-tcp-hwtype", "Remote TCP Sink device hardware type (Optional. E.g. RTLSDR/SDRplayV3/AirspyHF).", "hwtype"), m_remoteTCPSinkSerialOption("remote-tcp-serial", "Remote TCP Sink device serial (Optional).", "serial"), - m_listDevicesOption("list-devices", "List available physical devices.") + m_listDevicesOption("list-devices", "List available physical devices."), + m_startOption("start", "Start all devices and features") { m_serverAddress = ""; // Bind to any address @@ -56,6 +57,7 @@ MainParser::MainParser() : m_remoteTCPSinkHWType = ""; m_remoteTCPSinkSerial = ""; m_listDevices = false; + m_start = false; m_parser.setApplicationDescription("Software Defined Radio application"); m_parser.addHelpOption(); @@ -72,6 +74,7 @@ MainParser::MainParser() : m_parser.addOption(m_remoteTCPSinkHWTypeOption); m_parser.addOption(m_remoteTCPSinkSerialOption); m_parser.addOption(m_listDevicesOption); + m_parser.addOption(m_startOption); } MainParser::~MainParser() @@ -154,4 +157,8 @@ void MainParser::parse(const QCoreApplication& app) qCritical() << "You must specify a device with either --remote-tcp-hwtype or --remote-tcp-serial"; exit (EXIT_FAILURE); } + + // Start devices and features + m_start = m_parser.isSet(m_startOption); + } diff --git a/sdrbase/mainparser.h b/sdrbase/mainparser.h index d38be74ba..220db95bb 100644 --- a/sdrbase/mainparser.h +++ b/sdrbase/mainparser.h @@ -45,6 +45,7 @@ public: const QString& getRemoteTCPSinkHWType() const { return m_remoteTCPSinkHWType; } const QString& getRemoteTCPSinkSerial() const { return m_remoteTCPSinkSerial; } bool getListDevices() const { return m_listDevices; } + bool getStart() const { return m_start; } private: QString m_serverAddress; @@ -58,6 +59,7 @@ private: QString m_remoteTCPSinkHWType; QString m_remoteTCPSinkSerial; bool m_listDevices; + bool m_start; QCommandLineParser m_parser; QCommandLineOption m_serverAddressOption; @@ -71,6 +73,7 @@ private: QCommandLineOption m_remoteTCPSinkHWTypeOption; QCommandLineOption m_remoteTCPSinkSerialOption; QCommandLineOption m_listDevicesOption; + QCommandLineOption m_startOption; }; diff --git a/sdrgui/mainwindow.cpp b/sdrgui/mainwindow.cpp index a3c5e9fe9..0fad8ba78 100644 --- a/sdrgui/mainwindow.cpp +++ b/sdrgui/mainwindow.cpp @@ -61,6 +61,7 @@ #include "feature/featureset.h" #include "feature/feature.h" #include "feature/featuregui.h" +#include "feature/featurewebapiutils.h" #include "mainspectrum/mainspectrumgui.h" #include "commands/commandkeyreceiver.h" #include "gui/presetitem.h" @@ -275,6 +276,9 @@ MainWindow::MainWindow(qtwebapp::LoggerWithFile *logger, const MainParser& parse InitFSM *fsm = new InitFSM(this, splash, !parser.getScratch()); connect(fsm, &InitFSM::finished, fsm, &InitFSM::deleteLater); connect(fsm, &InitFSM::finished, splash, &SDRangelSplash::deleteLater); + if (parser.getStart()) { + connect(fsm, &InitFSM::finished, this, &MainWindow::startAllAfterDelay); + } fsm->start(); qDebug() << "MainWindow::MainWindow: end"; @@ -3382,6 +3386,30 @@ void MainWindow::showAllChannels(int deviceSetIndex) } } +void MainWindow::startAllAfterDelay() +{ + // Wait a little bit before starting all devices and features, + // as some devices, such as FileSinks, can fail to start if run before initialised + // Is there a better way than this arbitrary time? + QTimer::singleShot(1000, this, &MainWindow::startAll); +} + +// Start all devices and features in all workspaces +void MainWindow::startAll() +{ + // Start all devices + for (const auto& workspace : m_workspaces) { + startAllDevices(workspace); + } + // Start all features + for (int featureSetIndex = 0; featureSetIndex < m_featureUIs.size(); featureSetIndex++) + { + for (int featureIndex = 0; featureIndex < m_featureUIs[featureSetIndex]->getNumberOfFeatures(); featureIndex++) { + FeatureWebAPIUtils::run(featureSetIndex, featureIndex); + } + } +} + // Start all devices in the workspace void MainWindow::startAllDevices(const Workspace *workspace) const { diff --git a/sdrgui/mainwindow.h b/sdrgui/mainwindow.h index 6b7baf77b..d14228fad 100644 --- a/sdrgui/mainwindow.h +++ b/sdrgui/mainwindow.h @@ -458,6 +458,8 @@ private slots: void featureMove(FeatureGUI *gui, int wsIndexDestnation); void deviceStateChanged(DeviceAPI *deviceAPI); void openFeaturePresetsDialog(QPoint p, Workspace *workspace); + void startAllAfterDelay(); + void startAll(); void startAllDevices(const Workspace *workspace) const; void stopAllDevices(const Workspace *workspace) const; void deviceMove(DeviceGUI *gui, int wsIndexDestnation);