Skip to content

Commit

Permalink
Add --start option to start all devices and features. For f4exb#2359.
Browse files Browse the repository at this point in the history
  • Loading branch information
srcejon committed Jan 20, 2025
1 parent 83b36c6 commit f841eec
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 1 deletion.
30 changes: 30 additions & 0 deletions sdrbase/feature/featurewebapiutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions sdrbase/feature/featurewebapiutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 8 additions & 1 deletion sdrbase/mainparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
Expand All @@ -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()
Expand Down Expand Up @@ -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);

}
3 changes: 3 additions & 0 deletions sdrbase/mainparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class SDRBASE_API MainParser
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;
Expand All @@ -58,6 +59,7 @@ class SDRBASE_API MainParser
QString m_remoteTCPSinkHWType;
QString m_remoteTCPSinkSerial;
bool m_listDevices;
bool m_start;

QCommandLineParser m_parser;
QCommandLineOption m_serverAddressOption;
Expand All @@ -71,6 +73,7 @@ class SDRBASE_API MainParser
QCommandLineOption m_remoteTCPSinkHWTypeOption;
QCommandLineOption m_remoteTCPSinkSerialOption;
QCommandLineOption m_listDevicesOption;
QCommandLineOption m_startOption;
};


Expand Down
28 changes: 28 additions & 0 deletions sdrgui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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
{
Expand Down
2 changes: 2 additions & 0 deletions sdrgui/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit f841eec

Please sign in to comment.