From d9ec9f27872f84f4452eabb6ff944a3e05178d83 Mon Sep 17 00:00:00 2001 From: f4exb Date: Thu, 10 Sep 2020 02:43:28 +0200 Subject: [PATCH] RigCtrl plugin: Removed QMainWindow dependency in plugin interface. Get API URI from MainWindow. Cosmetic changes --- plugins/misc/rigctrl/CMakeLists.txt | 2 +- plugins/misc/rigctrl/rigctrl.cpp | 54 +++++++------- plugins/misc/rigctrl/rigctrl.h | 9 ++- plugins/misc/rigctrl/rigctrlgui.cpp | 2 - plugins/misc/rigctrl/rigctrlgui.ui | 90 ++++++++++-------------- plugins/misc/rigctrl/rigctrlplugin.cpp | 12 ++-- plugins/misc/rigctrl/rigctrlplugin.h | 8 +-- plugins/misc/rigctrl/rigctrlsettings.cpp | 43 ++++++----- plugins/misc/rigctrl/rigctrlsettings.h | 8 ++- sdrbase/plugin/plugininterface.h | 4 +- sdrgui/mainwindow.cpp | 2 +- sdrgui/mainwindow.h | 2 + sdrsrv/maincore.cpp | 2 + sdrsrv/maincore.h | 5 ++ 14 files changed, 119 insertions(+), 124 deletions(-) diff --git a/plugins/misc/rigctrl/CMakeLists.txt b/plugins/misc/rigctrl/CMakeLists.txt index f803c68db..d6915e987 100644 --- a/plugins/misc/rigctrl/CMakeLists.txt +++ b/plugins/misc/rigctrl/CMakeLists.txt @@ -45,7 +45,7 @@ target_link_libraries(${TARGET_NAME} Qt5::Core ${TARGET_LIB} sdrbase - ${TARGET_LIB_GUI} + ${TARGET_LIB_GUI} swagger ) diff --git a/plugins/misc/rigctrl/rigctrl.cpp b/plugins/misc/rigctrl/rigctrl.cpp index 8d3dc9759..81d9897c5 100644 --- a/plugins/misc/rigctrl/rigctrl.cpp +++ b/plugins/misc/rigctrl/rigctrl.cpp @@ -22,10 +22,10 @@ #include // Length of buffers -#define CMD_LENGTH 1024 -#define URL_LENGTH 1024 -#define RESPONSE_LENGTH 1024 -#define DATA_LENGTH 1024 +const unsigned int RigCtrl::m_CmdLength = 1024; +const unsigned int RigCtrl::m_UrlLength = 1024; +const unsigned int RigCtrl::m_ResponseLength = 1024; +const unsigned int RigCtrl::m_DataLength = 1024; // Hamlib rigctrl error codes enum rig_errcode_e { @@ -103,7 +103,7 @@ RigCtrl::RigCtrl() : m_state(idle), m_tcpServer(nullptr), m_clientConnection(nullptr) -{ +{ m_netman = new QNetworkAccessManager(this); connect(m_netman, &QNetworkAccessManager::finished, this, &RigCtrl::processAPIResponse); @@ -194,9 +194,9 @@ void RigCtrl::acceptConnection() // Get rigctrl command and start processing it void RigCtrl::getCommand() { - char cmd[CMD_LENGTH]; - char url[URL_LENGTH]; - char response[RESPONSE_LENGTH]; + char cmd[m_CmdLength]; + char url[m_UrlLength]; + char response[m_ResponseLength]; qint64 len; QNetworkRequest request; char *p; @@ -211,13 +211,13 @@ void RigCtrl::getCommand() // Set frequency m_targetFrequency = atof(cmd[0] == 'F' ? &cmd[2] : &cmd[9]); // Get current centre frequency - sprintf(url, "%s/deviceset/%d/device/settings", qUtf8Printable(m_settings.m_APIAddress), m_settings.m_deviceIndex); + sprintf(url, "%s/deviceset/%d/device/settings", qUtf8Printable(m_APIBaseURI), m_settings.m_deviceIndex); request.setUrl(QUrl(url)); m_netman->get(request); m_state = set_freq; } else if (!strncmp(cmd, "f", 1) || !strncmp(cmd, "get_freq", 8)) { // Get frequency - need to add centerFrequency and inputFrequencyOffset - sprintf(url, "%s/deviceset/%d/device/settings", qUtf8Printable(m_settings.m_APIAddress), m_settings.m_deviceIndex); + sprintf(url, "%s/deviceset/%d/device/settings", qUtf8Printable(m_APIBaseURI), m_settings.m_deviceIndex); request.setUrl(QUrl(url)); m_netman->get(request); m_state = get_freq_center; @@ -253,7 +253,7 @@ void RigCtrl::getCommand() } if (mode_map[i].modem != nullptr) { // Delete current modem - sprintf(url, "%s/deviceset/%d/channel/%d", qUtf8Printable(m_settings.m_APIAddress), m_settings.m_deviceIndex, m_settings.m_channelIndex); + sprintf(url, "%s/deviceset/%d/channel/%d", qUtf8Printable(m_APIBaseURI), m_settings.m_deviceIndex, m_settings.m_channelIndex); request.setUrl(QUrl(url)); m_netman->sendCustomRequest(request, "DELETE"); m_state = set_mode_mod; @@ -263,19 +263,19 @@ void RigCtrl::getCommand() } } else if (!strncmp(cmd, "set_powerstat 0", 15)) { // Power off radio - sprintf(url, "%s/deviceset/%d/device/run", qUtf8Printable(m_settings.m_APIAddress), m_settings.m_deviceIndex); + sprintf(url, "%s/deviceset/%d/device/run", qUtf8Printable(m_APIBaseURI), m_settings.m_deviceIndex); request.setUrl(QUrl(url)); m_netman->sendCustomRequest(request, "DELETE"); m_state = set_power_off; } else if (!strncmp(cmd, "set_powerstat 1", 15)) { // Power on radio - sprintf(url, "%s/deviceset/%d/device/run", qUtf8Printable(m_settings.m_APIAddress), m_settings.m_deviceIndex); + sprintf(url, "%s/deviceset/%d/device/run", qUtf8Printable(m_APIBaseURI), m_settings.m_deviceIndex); request.setUrl(QUrl(url)); m_netman->post(request, ""); m_state = set_power_on; } else if (!strncmp(cmd, "get_powerstat", 13)) { // Return if powered on or off - sprintf(url, "%s/deviceset/%d/device/run", qUtf8Printable(m_settings.m_APIAddress), m_settings.m_deviceIndex); + sprintf(url, "%s/deviceset/%d/device/run", qUtf8Printable(m_APIBaseURI), m_settings.m_deviceIndex); request.setUrl(QUrl(url)); m_netman->get(request); m_state = get_power; @@ -292,9 +292,9 @@ void RigCtrl::getCommand() void RigCtrl::processAPIResponse(QNetworkReply *reply) { double freq; - char response[RESPONSE_LENGTH]; - char url[URL_LENGTH]; - char data[DATA_LENGTH]; + char response[m_ResponseLength]; + char url[m_UrlLength]; + char data[m_DataLength]; QNetworkRequest request; if (reply->error() == QNetworkReply::NoError) { @@ -311,7 +311,7 @@ void RigCtrl::processAPIResponse(QNetworkReply *reply) freq = getSubObjectDouble(jsonObj, "centerFrequency"); if (freq >= 0.0) { m_targetFrequency = freq; - sprintf(url, "%s/deviceset/%d/channel/%d/settings", qUtf8Printable(m_settings.m_APIAddress), m_settings.m_deviceIndex, m_settings.m_channelIndex); + sprintf(url, "%s/deviceset/%d/channel/%d/settings", qUtf8Printable(m_APIBaseURI), m_settings.m_deviceIndex, m_settings.m_channelIndex); request.setUrl(QUrl(url)); m_netman->get(request); } else { @@ -333,7 +333,7 @@ void RigCtrl::processAPIResponse(QNetworkReply *reply) if (fabs(freq - m_targetFrequency) > m_settings.m_maxFrequencyOffset) { // Update centerFrequency setSubObjectDouble(jsonObj, "centerFrequency", m_targetFrequency); - sprintf(url, "%s/deviceset/%d/device/settings", qUtf8Printable(m_settings.m_APIAddress), m_settings.m_deviceIndex); + sprintf(url, "%s/deviceset/%d/device/settings", qUtf8Printable(m_APIBaseURI), m_settings.m_deviceIndex); request.setUrl(QUrl(url)); m_netman->sendCustomRequest(request, "PATCH", QJsonDocument(jsonObj).toJson()); m_state = set_freq_center; @@ -341,7 +341,7 @@ void RigCtrl::processAPIResponse(QNetworkReply *reply) // In range, so update inputFrequencyOffset m_targetOffset = m_targetFrequency - freq; // Get settings containg inputFrequencyOffset, so we can patch them - sprintf(url, "%s/deviceset/%d/channel/%d/settings", qUtf8Printable(m_settings.m_APIAddress), m_settings.m_deviceIndex, m_settings.m_channelIndex); + sprintf(url, "%s/deviceset/%d/channel/%d/settings", qUtf8Printable(m_APIBaseURI), m_settings.m_deviceIndex, m_settings.m_channelIndex); request.setUrl(QUrl(url)); m_netman->get(request); m_state = set_freq_set_offset; @@ -351,7 +351,7 @@ void RigCtrl::processAPIResponse(QNetworkReply *reply) case set_freq_no_offset: // Update centerFrequency, without trying to set offset setSubObjectDouble(jsonObj, "centerFrequency", m_targetFrequency); - sprintf(url, "%s/deviceset/%d/device/settings", qUtf8Printable(m_settings.m_APIAddress), m_settings.m_deviceIndex); + sprintf(url, "%s/deviceset/%d/device/settings", qUtf8Printable(m_APIBaseURI), m_settings.m_deviceIndex); request.setUrl(QUrl(url)); m_netman->sendCustomRequest(request, "PATCH", QJsonDocument(jsonObj).toJson()); m_state = set_freq_center_no_offset; @@ -363,7 +363,7 @@ void RigCtrl::processAPIResponse(QNetworkReply *reply) if (freq == m_targetFrequency) { // Set inputFrequencyOffset to 0 m_targetOffset = 0; - sprintf(url, "%s/deviceset/%d/channel/%d/settings", qUtf8Printable(m_settings.m_APIAddress), m_settings.m_deviceIndex, m_settings.m_channelIndex); + sprintf(url, "%s/deviceset/%d/channel/%d/settings", qUtf8Printable(m_APIBaseURI), m_settings.m_deviceIndex, m_settings.m_channelIndex); request.setUrl(QUrl(url)); m_netman->get(request); m_state = set_freq_set_offset; @@ -389,7 +389,7 @@ void RigCtrl::processAPIResponse(QNetworkReply *reply) case set_freq_set_offset: // Patch inputFrequencyOffset if (setSubObjectDouble(jsonObj, "inputFrequencyOffset", m_targetOffset)) { - sprintf(url, "%s/deviceset/%d/channel/%d/settings", qUtf8Printable(m_settings.m_APIAddress), m_settings.m_deviceIndex, m_settings.m_channelIndex); + sprintf(url, "%s/deviceset/%d/channel/%d/settings", qUtf8Printable(m_APIBaseURI), m_settings.m_deviceIndex, m_settings.m_channelIndex); request.setUrl(QUrl(url)); m_netman->sendCustomRequest(request, "PATCH", QJsonDocument(jsonObj).toJson()); m_state = set_freq_offset; @@ -414,7 +414,7 @@ void RigCtrl::processAPIResponse(QNetworkReply *reply) case set_mode_mod: // Create new modem - sprintf(url, "%s/deviceset/%d/channel", qUtf8Printable(m_settings.m_APIAddress), m_settings.m_deviceIndex); + sprintf(url, "%s/deviceset/%d/channel", qUtf8Printable(m_APIBaseURI), m_settings.m_deviceIndex); sprintf(data, "{ \"channelType\": \"%s\", \"direction\": 0, \"originatorDeviceSetIndex\": %d}\n", m_targetModem, m_settings.m_deviceIndex); request.setUrl(QUrl(url)); request.setHeader(QNetworkRequest::ContentTypeHeader,"application/json"); @@ -428,7 +428,7 @@ void RigCtrl::processAPIResponse(QNetworkReply *reply) case set_mode_settings: // Set modem bandwidth - sprintf(url, "%s/deviceset/%d/channel/%d/settings", qUtf8Printable(m_settings.m_APIAddress), m_settings.m_deviceIndex, m_settings.m_channelIndex); + sprintf(url, "%s/deviceset/%d/channel/%d/settings", qUtf8Printable(m_APIBaseURI), m_settings.m_deviceIndex, m_settings.m_channelIndex); sprintf(data, "{ \"channelType\": \"%s\", \"%sSettings\": {\"rfBandwidth\":%d}}\n", m_targetModem, m_targetModem, m_targetBW); request.setUrl(QUrl(url)); request.setHeader(QNetworkRequest::ContentTypeHeader,"application/json"); @@ -476,7 +476,7 @@ void RigCtrl::processAPIResponse(QNetworkReply *reply) case set_freq_set_offset: // Probably no demodulator enabled on the specified channel // Just set as center frequency - sprintf(url, "%s/deviceset/%d/device/settings", qUtf8Printable(m_settings.m_APIAddress), m_settings.m_deviceIndex); + sprintf(url, "%s/deviceset/%d/device/settings", qUtf8Printable(m_APIBaseURI), m_settings.m_deviceIndex); request.setUrl(QUrl(url)); m_netman->get(request); m_state = set_freq_no_offset; @@ -484,7 +484,7 @@ void RigCtrl::processAPIResponse(QNetworkReply *reply) case set_mode_mod: // Probably no modem on channel to delete, so continue to try to create one - sprintf(url, "%s/deviceset/%d/channel", qUtf8Printable(m_settings.m_APIAddress), m_settings.m_deviceIndex); + sprintf(url, "%s/deviceset/%d/channel", qUtf8Printable(m_APIBaseURI), m_settings.m_deviceIndex); sprintf(data, "{ \"channelType\": \"%s\", \"direction\": 0, \"originatorDeviceSetIndex\": %d}\n", m_targetModem, m_settings.m_deviceIndex); request.setUrl(QUrl(url)); request.setHeader(QNetworkRequest::ContentTypeHeader,"application/json"); diff --git a/plugins/misc/rigctrl/rigctrl.h b/plugins/misc/rigctrl/rigctrl.h index 38b61f88a..ad0391465 100644 --- a/plugins/misc/rigctrl/rigctrl.h +++ b/plugins/misc/rigctrl/rigctrl.h @@ -32,6 +32,7 @@ public: ~RigCtrl(); void getSettings(RigCtrlSettings *settings); void setSettings(RigCtrlSettings *settings); + void setAPIBaseURI(const QString& apiBaseURI) { m_APIBaseURI = apiBaseURI; } QByteArray serialize() const; bool deserialize(const QByteArray& data); @@ -40,7 +41,7 @@ private slots: void getCommand(); void processAPIResponse(QNetworkReply *reply); -protected: +private: QTcpServer *m_tcpServer; QTcpSocket *m_clientConnection; QNetworkAccessManager *m_netman; @@ -60,8 +61,14 @@ protected: double m_targetOffset; const char *m_targetModem; int m_targetBW; + QString m_APIBaseURI; //!< Base URI of own API RigCtrlSettings m_settings; + + static const unsigned int m_CmdLength; + static const unsigned int m_UrlLength; + static const unsigned int m_ResponseLength; + static const unsigned int m_DataLength; }; #endif // INCLUDE_RIGCTRL_H diff --git a/plugins/misc/rigctrl/rigctrlgui.cpp b/plugins/misc/rigctrl/rigctrlgui.cpp index da2aa38ad..357315128 100644 --- a/plugins/misc/rigctrl/rigctrlgui.cpp +++ b/plugins/misc/rigctrl/rigctrlgui.cpp @@ -27,7 +27,6 @@ RigCtrlGUI::RigCtrlGUI(RigCtrl *rigCtrl, QWidget* parent) : ui->setupUi(this); m_rigCtrl->getSettings(&m_settings); ui->enable->setChecked(m_settings.m_enabled); - ui->api->setText(QString(m_settings.m_APIAddress)); ui->rigCtrlPort->setValue(m_settings.m_rigCtrlPort); ui->maxFrequencyOffset->setValue(m_settings.m_maxFrequencyOffset); ui->deviceIndex->setValue(m_settings.m_deviceIndex); @@ -42,7 +41,6 @@ RigCtrlGUI::~RigCtrlGUI() void RigCtrlGUI::accept() { m_settings.m_enabled = ui->enable->isChecked(); - m_settings.m_APIAddress = ui->api->text(); m_settings.m_rigCtrlPort = ui->rigCtrlPort->value(); m_settings.m_maxFrequencyOffset = ui->maxFrequencyOffset->value(); m_settings.m_deviceIndex = ui->deviceIndex->value(); diff --git a/plugins/misc/rigctrl/rigctrlgui.ui b/plugins/misc/rigctrl/rigctrlgui.ui index b5c83afd7..d721794a3 100644 --- a/plugins/misc/rigctrl/rigctrlgui.ui +++ b/plugins/misc/rigctrl/rigctrlgui.ui @@ -7,7 +7,7 @@ 0 0 351 - 235 + 261 @@ -33,69 +33,35 @@ - + rigctrl Port - - - - Device Index - - - - - - - Index of the device that should be controlled by rigctrl commands. -Default is 0. - - - - - - - Index of the channel that is to be controlled by rigctrl commands. -Default is 0. - - - - - - - Channel Index - - - - - - - API Address - - - - + - URL of SDRangel API server to control. -Default is http://127.0.0.1:8091/sdrangel + TCP port to listen for rigctrl commands on. +Default is 4532. - - http://127.0.0.1:8091/sdrangel + + 1024 + + + 65536 - + Max Frequency Offset - + Controls whether the center frequency or frequency offset is adjusted when a new frequency is received via a rigctrl command. @@ -108,17 +74,33 @@ Default is 10000. - - + + + + Device Index + + + + + - TCP port to listen for rigctrl commands on. -Default is 4532. + Index of the device that should be controlled by rigctrl commands. +Default is 0. - - 1024 + + + + + + Channel Index - - 65536 + + + + + + Index of the channel that is to be controlled by rigctrl commands. +Default is 0. diff --git a/plugins/misc/rigctrl/rigctrlplugin.cpp b/plugins/misc/rigctrl/rigctrlplugin.cpp index 31aa56c71..3facb90f7 100644 --- a/plugins/misc/rigctrl/rigctrlplugin.cpp +++ b/plugins/misc/rigctrl/rigctrlplugin.cpp @@ -28,6 +28,7 @@ #include #include #include +#include "mainwindow.h" #include "rigctrlgui.h" #endif #include "rigctrlplugin.h" @@ -62,10 +63,8 @@ void RigCtrlPlugin::initPlugin(PluginAPI* pluginAPI) #ifdef SERVER_MODE bool RigCtrlPlugin::createTopLevelGUI( - QMainWindow* mainWindow ) { - (void) mainWindow; return true; } @@ -74,12 +73,11 @@ void RigCtrlPlugin::showRigCtrlUI() } #else -bool RigCtrlPlugin::createTopLevelGUI( - QMainWindow* mainWindow - ) +bool RigCtrlPlugin::createTopLevelGUI() { - m_mainWindow = mainWindow; - QMenuBar *menuBar = mainWindow->menuBar(); + m_mainWindow = MainWindow::getInstance(); + m_rigCtrl->setAPIBaseURI(QString("http://%1:%2/sdrangel").arg(m_mainWindow->getAPIHost()).arg(m_mainWindow->getAPIPort())); + QMenuBar *menuBar = m_mainWindow->menuBar(); QMenu *prefMenu = menuBar->findChild("menuPreferences", Qt::FindDirectChildrenOnly); if (prefMenu == nullptr) { diff --git a/plugins/misc/rigctrl/rigctrlplugin.h b/plugins/misc/rigctrl/rigctrlplugin.h index c8bac3c81..eca76c1b7 100644 --- a/plugins/misc/rigctrl/rigctrlplugin.h +++ b/plugins/misc/rigctrl/rigctrlplugin.h @@ -23,7 +23,7 @@ #include "rigctrl.h" class PluginAPI; -class QMainWindow; +class MainWindow; #define RIGCTRL_DEVICE_TYPE_ID "sdrangel.misc.rigctrl" @@ -33,12 +33,12 @@ class RigCtrlPlugin : public QObject, public PluginInterface { Q_PLUGIN_METADATA(IID RIGCTRL_DEVICE_TYPE_ID) public: - explicit RigCtrlPlugin(RigCtrl *rigCtrl = NULL, QObject* parent = NULL); + explicit RigCtrlPlugin(RigCtrl *rigCtrl = nullptr, QObject* parent = nullptr); const PluginDescriptor& getPluginDescriptor() const; void initPlugin(PluginAPI* pluginAPI); - virtual bool createTopLevelGUI(QMainWindow* mainWindow); + virtual bool createTopLevelGUI(); virtual QByteArray serializeGlobalSettings() const; virtual bool deserializeGlobalSettings(const QByteArray& data); @@ -47,7 +47,7 @@ private slots: private: static const PluginDescriptor m_pluginDescriptor; - QMainWindow* m_mainWindow; + MainWindow* m_mainWindow; RigCtrl *m_rigCtrl; }; diff --git a/plugins/misc/rigctrl/rigctrlsettings.cpp b/plugins/misc/rigctrl/rigctrlsettings.cpp index e9dc48d04..51f99bf4d 100644 --- a/plugins/misc/rigctrl/rigctrlsettings.cpp +++ b/plugins/misc/rigctrl/rigctrlsettings.cpp @@ -21,21 +21,20 @@ #include #include "util/simpleserializer.h" -#define ENABLED_DEFAULT false -#define API_ADDRESS_DEFAULT "http://127.0.0.1:8091/sdrangel" -#define RIG_CTRL_PORT_DEFAULT 4532 -#define MAX_FREQUENCY_OFFSET_DEFAULT 10000 -#define DEVICE_INDEX_DEFAULT 0 -#define CHANNEL_INDEX_DEFAULT 0 +const bool RigCtrlSettings::m_EnabledDefault = false; +const int RigCtrlSettings::m_RigCtrlPortDefault = 4532; +const int RigCtrlSettings::m_MaxFrequencyOffsetDefault = 10000; +const int RigCtrlSettings::m_DeviceIndexDefault = 0; +const int RigCtrlSettings::m_ChannelIndexDefault = 0; + void RigCtrlSettings::resetToDefaults() { - m_enabled = ENABLED_DEFAULT; - m_APIAddress = API_ADDRESS_DEFAULT; - m_rigCtrlPort = RIG_CTRL_PORT_DEFAULT; - m_maxFrequencyOffset = MAX_FREQUENCY_OFFSET_DEFAULT; - m_deviceIndex = DEVICE_INDEX_DEFAULT; - m_channelIndex = CHANNEL_INDEX_DEFAULT; + m_enabled = m_EnabledDefault; + m_rigCtrlPort = m_RigCtrlPortDefault; + m_maxFrequencyOffset = m_MaxFrequencyOffsetDefault; + m_deviceIndex = m_DeviceIndexDefault; + m_channelIndex = m_ChannelIndexDefault; } QByteArray RigCtrlSettings::serialize() const @@ -43,7 +42,6 @@ QByteArray RigCtrlSettings::serialize() const SimpleSerializer s(1); s.writeBool(1, m_enabled); - s.writeString(2, m_APIAddress); s.writeS32(3, m_rigCtrlPort); s.writeS32(4, m_maxFrequencyOffset); s.writeS32(5, m_deviceIndex); @@ -64,28 +62,27 @@ bool RigCtrlSettings::deserialize(const QByteArray& data) if (d.getVersion() == 1) { - d.readBool(1, &m_enabled, ENABLED_DEFAULT); - d.readString(2, &m_APIAddress, API_ADDRESS_DEFAULT); - d.readS32(3, &m_rigCtrlPort, RIG_CTRL_PORT_DEFAULT); - d.readS32(4, &m_maxFrequencyOffset, MAX_FREQUENCY_OFFSET_DEFAULT); - d.readS32(5, &m_deviceIndex, DEVICE_INDEX_DEFAULT); - d.readS32(6, &m_channelIndex, CHANNEL_INDEX_DEFAULT); + d.readBool(1, &m_enabled, m_EnabledDefault); + d.readS32(3, &m_rigCtrlPort, m_RigCtrlPortDefault); + d.readS32(4, &m_maxFrequencyOffset, m_MaxFrequencyOffsetDefault); + d.readS32(5, &m_deviceIndex, m_DeviceIndexDefault); + d.readS32(6, &m_channelIndex, m_ChannelIndexDefault); if (!((m_rigCtrlPort > 1023) && (m_rigCtrlPort < 65536))) { qDebug() << "RigCtrlSettings::deserialize invalid port number ignored"; - m_rigCtrlPort = RIG_CTRL_PORT_DEFAULT; + m_rigCtrlPort = m_RigCtrlPortDefault; } if (m_maxFrequencyOffset < 0) { qDebug() << "RigCtrlSettings::deserialize invalid max frequency offset ignored"; - m_maxFrequencyOffset = MAX_FREQUENCY_OFFSET_DEFAULT; + m_maxFrequencyOffset = m_MaxFrequencyOffsetDefault; } if (m_deviceIndex < 0) { qDebug() << "RigCtrlSettings::deserialize invalid device index ignored"; - m_deviceIndex = DEVICE_INDEX_DEFAULT; + m_deviceIndex = m_DeviceIndexDefault; } if (m_channelIndex < 0) { qDebug() << "RigCtrlSettings::deserialize invalid channel index ignored"; - m_deviceIndex = CHANNEL_INDEX_DEFAULT; + m_deviceIndex = m_ChannelIndexDefault; } return true; diff --git a/plugins/misc/rigctrl/rigctrlsettings.h b/plugins/misc/rigctrl/rigctrlsettings.h index 3784a4c81..ad6221e9e 100644 --- a/plugins/misc/rigctrl/rigctrlsettings.h +++ b/plugins/misc/rigctrl/rigctrlsettings.h @@ -24,7 +24,6 @@ struct RigCtrlSettings { bool m_enabled; - QString m_APIAddress; int m_rigCtrlPort; int m_maxFrequencyOffset; int m_deviceIndex; @@ -37,6 +36,13 @@ struct RigCtrlSettings { void resetToDefaults(); QByteArray serialize() const; bool deserialize(const QByteArray& data); + +private: + static const bool m_EnabledDefault; + static const int m_RigCtrlPortDefault; + static const int m_MaxFrequencyOffsetDefault; + static const int m_DeviceIndexDefault; + static const int m_ChannelIndexDefault; }; #endif /* INCLUDE_RIGCTRLSETTINGS_H */ diff --git a/sdrbase/plugin/plugininterface.h b/sdrbase/plugin/plugininterface.h index 793b27ce5..73816de8b 100644 --- a/sdrbase/plugin/plugininterface.h +++ b/sdrbase/plugin/plugininterface.h @@ -6,8 +6,6 @@ #include "export.h" -class QMainWindow; - struct SDRBASE_API PluginDescriptor { const QString hardwareId; // general plugin description @@ -314,7 +312,7 @@ public: virtual void deleteSampleMIMOPluginInstanceMIMO(DeviceSampleMIMO *mimo); // Callback to allow plugin to add elements to top-level GUI (such as menu items) - virtual bool createTopLevelGUI(QMainWindow* mainWindow) + virtual bool createTopLevelGUI() { return true; } diff --git a/sdrgui/mainwindow.cpp b/sdrgui/mainwindow.cpp index adee01c88..bd9f9a750 100644 --- a/sdrgui/mainwindow.cpp +++ b/sdrgui/mainwindow.cpp @@ -266,7 +266,7 @@ MainWindow::MainWindow(qtwebapp::LoggerWithFile *logger, const MainParser& parse PluginAPI::MiscPluginRegistrations *miscPluginRegistrations = m_pluginManager->getMiscPluginRegistrations(); for (int i = 0; i < miscPluginRegistrations->count(); i++) { - (*miscPluginRegistrations)[i].m_plugin->createTopLevelGUI(this); + (*miscPluginRegistrations)[i].m_plugin->createTopLevelGUI(); } qDebug() << "MainWindow::MainWindow: end"; diff --git a/sdrgui/mainwindow.h b/sdrgui/mainwindow.h index a967ab0e7..cdbdcb224 100644 --- a/sdrgui/mainwindow.h +++ b/sdrgui/mainwindow.h @@ -103,6 +103,8 @@ public: std::vector& getDeviceUISets() { return m_deviceUIs; } void commandKeysConnect(QObject *object, const char *slot); void commandKeysDisconnect(QObject *object, const char *slot); + const QString& getAPIHost() const { return m_apiHost; } + int getAPIPort() const { return m_apiPort; } friend class WebAPIAdapterGUI; diff --git a/sdrsrv/maincore.cpp b/sdrsrv/maincore.cpp index df0423925..b3ca11563 100644 --- a/sdrsrv/maincore.cpp +++ b/sdrsrv/maincore.cpp @@ -82,6 +82,8 @@ MainCore::MainCore(qtwebapp::LoggerWithFile *logger, const MainParser& parser, Q m_apiAdapter = new WebAPIAdapterSrv(*this); m_requestMapper = new WebAPIRequestMapper(this); m_requestMapper->setAdapter(m_apiAdapter); + m_apiHost = parser.getServerAddress(); + m_apiPort = parser.getServerPort(); m_apiServer = new WebAPIServer(parser.getServerAddress(), parser.getServerPort(), m_requestMapper); m_apiServer->start(); diff --git a/sdrsrv/maincore.h b/sdrsrv/maincore.h index 875e66054..f526b7916 100644 --- a/sdrsrv/maincore.h +++ b/sdrsrv/maincore.h @@ -68,6 +68,9 @@ public: void addChannel(int deviceSetIndex, int selectedChannelIndex); void deleteChannel(int deviceSetIndex, int channelIndex); + const QString& getAPIHost() const { return m_apiHost; } + int getAPIPort() const { return m_apiPort; } + friend class WebAPIAdapterSrv; signals: @@ -288,6 +291,8 @@ private: DSPEngine* m_dspEngine; int m_lastEngineState; qtwebapp::LoggerWithFile *m_logger; + QString m_apiHost; + int m_apiPort; MessageQueue m_inputMessageQueue; QTimer m_masterTimer;