From d981912eeefa6c52e9acc18b3788e28466467443 Mon Sep 17 00:00:00 2001 From: f4exb Date: Sat, 25 Dec 2021 12:54:33 +0100 Subject: [PATCH] Remote input: removed API calls from GUI --- .../samplesource/remoteinput/remoteinput.cpp | 71 +++++++++- .../samplesource/remoteinput/remoteinput.h | 63 +++++++++ .../remoteinput/remoteinputgui.cpp | 129 ++++++------------ .../samplesource/remoteinput/remoteinputgui.h | 7 +- 4 files changed, 171 insertions(+), 99 deletions(-) diff --git a/plugins/samplesource/remoteinput/remoteinput.cpp b/plugins/samplesource/remoteinput/remoteinput.cpp index 09465341b..7cbcca41d 100644 --- a/plugins/samplesource/remoteinput/remoteinput.cpp +++ b/plugins/samplesource/remoteinput/remoteinput.cpp @@ -44,6 +44,9 @@ MESSAGE_CLASS_DEFINITION(RemoteInput::MsgReportRemoteInputStreamData, Message) MESSAGE_CLASS_DEFINITION(RemoteInput::MsgReportRemoteInputStreamTiming, Message) MESSAGE_CLASS_DEFINITION(RemoteInput::MsgConfigureRemoteChannel, Message) MESSAGE_CLASS_DEFINITION(RemoteInput::MsgStartStop, Message) +MESSAGE_CLASS_DEFINITION(RemoteInput::MsgReportRemoteFixedData, Message) +MESSAGE_CLASS_DEFINITION(RemoteInput::MsgReportRemoteAPIError, Message) +MESSAGE_CLASS_DEFINITION(RemoteInput::MsgRequestFixedData, Message) RemoteInput::RemoteInput(DeviceAPI *deviceAPI) : m_deviceAPI(deviceAPI), @@ -213,6 +216,19 @@ bool RemoteInput::handleMessage(const Message& message) applyRemoteChannelSettings(conf.getSettings()); return true; } + else if (MsgRequestFixedData::match(message)) + { + QString reportURL; + + reportURL = QString("http://%1:%2/sdrangel") + .arg(m_settings.m_apiAddress) + .arg(m_settings.m_apiPort); + + m_networkRequest.setUrl(QUrl(reportURL)); + m_networkManager->get(m_networkRequest); + + return true; + } else { return false; @@ -597,6 +613,12 @@ void RemoteInput::networkManagerFinished(QNetworkReply *reply) << " error(" << (int) replyError << "): " << replyError << ": " << reply->errorString(); + + if (m_guiMessageQueue) + { + MsgReportRemoteAPIError *msg = MsgReportRemoteAPIError::create(reply->errorString()); + m_guiMessageQueue->push(msg); + } } else { @@ -610,8 +632,23 @@ void RemoteInput::networkManagerFinished(QNetworkReply *reply) if (error.error == QJsonParseError::NoError) { - if (doc.object().contains("RemoteSinkSettings")) { - analyzeRemoteChannelSettingsReply(doc.object()); + const QJsonObject&jsonObject = doc.object(); + + if (jsonObject.contains("RemoteSinkSettings")) { + analyzeRemoteChannelSettingsReply(jsonObject); + } else if (jsonObject.contains("version")) { + analyzeInstanceSummaryReply(jsonObject); + } + } + else + { + QString errorMsg = QString("Reply JSON error: ") + error.errorString() + QString(" at offset ") + QString::number(error.offset); + qInfo().noquote() << "RemoteInputGui::networkManagerFinished: " << errorMsg; + + if (m_guiMessageQueue) + { + MsgReportRemoteAPIError *msg = MsgReportRemoteAPIError::create(errorMsg); + m_guiMessageQueue->push(msg); } } } @@ -619,6 +656,36 @@ void RemoteInput::networkManagerFinished(QNetworkReply *reply) reply->deleteLater(); } +void RemoteInput::analyzeInstanceSummaryReply(const QJsonObject& jsonObject) +{ + MsgReportRemoteFixedData::RemoteData msgRemoteFixedData; + msgRemoteFixedData.m_version = jsonObject["version"].toString(); + + if (jsonObject.contains("qtVersion")) { + msgRemoteFixedData.m_qtVersion = jsonObject["qtVersion"].toString(); + } + + if (jsonObject.contains("architecture")) { + msgRemoteFixedData.m_architecture = jsonObject["architecture"].toString(); + } + + if (jsonObject.contains("os")) { + msgRemoteFixedData.m_os = jsonObject["os"].toString(); + } + + if (jsonObject.contains("dspRxBits") && jsonObject.contains("dspTxBits")) + { + msgRemoteFixedData.m_rxBits = jsonObject["dspRxBits"].toInt(); + msgRemoteFixedData.m_txBits = jsonObject["dspTxBits"].toInt(); + } + + if (m_guiMessageQueue) + { + MsgReportRemoteFixedData *msg = MsgReportRemoteFixedData::create(msgRemoteFixedData); + m_guiMessageQueue->push(msg); + } +} + void RemoteInput::analyzeRemoteChannelSettingsReply(const QJsonObject& jsonObject) { QJsonObject settings = jsonObject["RemoteSinkSettings"].toObject(); diff --git a/plugins/samplesource/remoteinput/remoteinput.h b/plugins/samplesource/remoteinput/remoteinput.h index 314527a14..f9250b947 100644 --- a/plugins/samplesource/remoteinput/remoteinput.h +++ b/plugins/samplesource/remoteinput/remoteinput.h @@ -284,6 +284,68 @@ public: { } }; + class MsgReportRemoteFixedData : public Message { + MESSAGE_CLASS_DECLARATION + + public: + struct RemoteData + { + QString m_version; //!< Remote SDRangel version + QString m_qtVersion; //!< Remote Qt version used to build SDRangel + QString m_architecture; //!< Remote CPU architecture + QString m_os; //!< Remote O/S + int m_rxBits; //!< Number of bits used for I or Q sample on Rx side + int m_txBits; //!< Number of bits used for I or Q sample on Tx side + }; + + const RemoteData& getData() const { return m_remoteData; } + + static MsgReportRemoteFixedData* create(const RemoteData& remoteData) { + return new MsgReportRemoteFixedData(remoteData); + } + + private: + RemoteData m_remoteData; + + MsgReportRemoteFixedData(const RemoteData& remoteData) : + Message(), + m_remoteData(remoteData) + {} + }; + + class MsgReportRemoteAPIError : public Message { + MESSAGE_CLASS_DECLARATION + + public: + const QString& getMessage() const { return m_message; } + + static MsgReportRemoteAPIError* create(const QString& message) { + return new MsgReportRemoteAPIError(message); + } + + private: + QString m_message; + + MsgReportRemoteAPIError(const QString& message) : + Message(), + m_message(message) + {} + }; + + class MsgRequestFixedData : public Message { + MESSAGE_CLASS_DECLARATION + + public: + static MsgRequestFixedData* create() { + return new MsgRequestFixedData(); + } + + private: + MsgRequestFixedData() : + Message() + {} + }; + RemoteInput(DeviceAPI *deviceAPI); virtual ~RemoteInput(); virtual void destroy(); @@ -359,6 +421,7 @@ private: void webapiReverseSendStartStop(bool start); void getRemoteChannelSettings(); void analyzeRemoteChannelSettingsReply(const QJsonObject& jsonObject); + void analyzeInstanceSummaryReply(const QJsonObject& jsonObject); private slots: void networkManagerFinished(QNetworkReply *reply); diff --git a/plugins/samplesource/remoteinput/remoteinputgui.cpp b/plugins/samplesource/remoteinput/remoteinputgui.cpp index f780cc63e..db3d9540f 100644 --- a/plugins/samplesource/remoteinput/remoteinputgui.cpp +++ b/plugins/samplesource/remoteinput/remoteinputgui.cpp @@ -25,10 +25,6 @@ #include #include #include -#include -#include -#include -#include #include "ui_remoteinputgui.h" #include "gui/colormapper.h" @@ -94,9 +90,6 @@ RemoteInputGui::RemoteInputGui(DeviceUISet *deviceUISet, QWidget* parent) : connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()), Qt::QueuedConnection); m_sampleSource->setMessageQueueToGUI(&m_inputMessageQueue); - m_networkManager = new QNetworkAccessManager(); - connect(m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkManagerFinished(QNetworkReply*))); - m_eventsTime.start(); displayEventCounts(); displayEventTimer(); @@ -107,8 +100,6 @@ RemoteInputGui::RemoteInputGui(DeviceUISet *deviceUISet, QWidget* parent) : RemoteInputGui::~RemoteInputGui() { - disconnect(m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkManagerFinished(QNetworkReply*))); - delete m_networkManager; delete ui; } @@ -222,7 +213,20 @@ bool RemoteInputGui::handleMessage(const Message& message) blockApplySettings(true); ui->startStop->setChecked(notif.getStartStop()); blockApplySettings(false); - + return true; + } + else if (RemoteInput::MsgReportRemoteFixedData::match(message)) + { + ui->apiAddressLabel->setStyleSheet("QLabel { background-color : green; }"); + const RemoteInput::MsgReportRemoteFixedData& report = (const RemoteInput::MsgReportRemoteFixedData&) message; + displayRemoteFixedData(report.getData()); + return true; + } + else if (RemoteInput::MsgReportRemoteAPIError::match(message)) + { + ui->apiAddressLabel->setStyleSheet("QLabel { background:rgb(79,79,79); }"); + const RemoteInput::MsgReportRemoteAPIError& report = (const RemoteInput::MsgReportRemoteAPIError&) message; + ui->statusText->setText(QString(report.getMessage())); return true; } else @@ -394,9 +398,9 @@ void RemoteInputGui::on_apiApplyButton_clicked(bool checked) sendSettings(); - QString infoURL = QString("http://%1:%2/sdrangel").arg(m_settings.m_apiAddress).arg(m_settings.m_apiPort); - m_networkRequest.setUrl(QUrl(infoURL)); - m_networkManager->get(m_networkRequest); + ui->apiAddressLabel->setStyleSheet("QLabel { background:rgb(79,79,79); }"); + RemoteInput::MsgRequestFixedData *msg = RemoteInput::MsgRequestFixedData::create(); + m_sampleSource->getInputMessageQueue()->push(msg); } void RemoteInputGui::on_dataApplyButton_clicked(bool checked) @@ -413,9 +417,9 @@ void RemoteInputGui::on_apiAddress_editingFinished() { m_settings.m_apiAddress = ui->apiAddress->text(); - QString infoURL = QString("http://%1:%2/sdrangel").arg(m_settings.m_apiAddress).arg(m_settings.m_apiPort); - m_networkRequest.setUrl(QUrl(infoURL)); - m_networkManager->get(m_networkRequest); + ui->apiAddressLabel->setStyleSheet("QLabel { background:rgb(79,79,79); }"); + RemoteInput::MsgRequestFixedData *msg = RemoteInput::MsgRequestFixedData::create(); + m_sampleSource->getInputMessageQueue()->push(msg); sendSettings(); } @@ -470,9 +474,9 @@ void RemoteInputGui::on_apiPort_editingFinished() { m_settings.m_apiPort = udpApiPort; - QString infoURL = QString("http://%1:%2/sdrangel").arg(m_settings.m_apiAddress).arg(m_settings.m_apiPort); - m_networkRequest.setUrl(QUrl(infoURL)); - m_networkManager->get(m_networkRequest); + ui->apiAddressLabel->setStyleSheet("QLabel { background:rgb(79,79,79); }"); + RemoteInput::MsgRequestFixedData *msg = RemoteInput::MsgRequestFixedData::create(); + m_sampleSource->getInputMessageQueue()->push(msg); sendSettings(); } @@ -526,6 +530,21 @@ void RemoteInputGui::displayEventTimer() ui->eventCountsTimeText->setText(s_time); } +void RemoteInputGui::displayRemoteFixedData(const RemoteInput::MsgReportRemoteFixedData::RemoteData& remoteData) +{ + QString infoLine; + + infoLine = remoteData.m_version; + infoLine += " Qt" + remoteData.m_qtVersion; + infoLine += " " + remoteData.m_architecture; + infoLine += " " + remoteData.m_os; + infoLine += QString(" %1/%2b").arg(remoteData.m_rxBits).arg(remoteData.m_txBits); + + if (infoLine.size() > 0) { + ui->infoText->setText(infoLine); + } +} + void RemoteInputGui::updateWithAcquisition() { } @@ -636,78 +655,6 @@ void RemoteInputGui::updateStatus() } } -void RemoteInputGui::networkManagerFinished(QNetworkReply *reply) -{ - if (reply->error()) - { - ui->apiAddressLabel->setStyleSheet("QLabel { background:rgb(79,79,79); }"); - ui->statusText->setText(reply->errorString()); - } - else - { - QString answer = reply->readAll(); - - try - { - QByteArray jsonBytes(answer.toStdString().c_str()); - QJsonParseError error; - QJsonDocument doc = QJsonDocument::fromJson(jsonBytes, &error); - - if (error.error == QJsonParseError::NoError) - { - ui->apiAddressLabel->setStyleSheet("QLabel { background-color : green; }"); - ui->statusText->setText(QString("API OK")); - analyzeApiReply(doc.object()); - } - else - { - ui->apiAddressLabel->setStyleSheet("QLabel { background:rgb(79,79,79); }"); - QString errorMsg = QString("Reply JSON error: ") + error.errorString() + QString(" at offset ") + QString::number(error.offset); - ui->statusText->setText(QString("JSON error. See log")); - qInfo().noquote() << "RemoteInputGui::networkManagerFinished" << errorMsg; - } - } - catch (const std::exception& ex) - { - ui->apiAddressLabel->setStyleSheet("QLabel { background:rgb(79,79,79); }"); - QString errorMsg = QString("Error parsing request: ") + ex.what(); - ui->statusText->setText("Error parsing request. See log for details"); - qInfo().noquote() << "RemoteInputGui::networkManagerFinished" << errorMsg; - } - } - - reply->deleteLater(); -} - -void RemoteInputGui::analyzeApiReply(const QJsonObject& jsonObject) -{ - QString infoLine; - - if (jsonObject.contains("version")) { - infoLine = jsonObject["version"].toString(); - } - - if (jsonObject.contains("qtVersion")) { - infoLine += " Qt" + jsonObject["qtVersion"].toString(); - } - - if (jsonObject.contains("architecture")) { - infoLine += " " + jsonObject["architecture"].toString(); - } - - if (jsonObject.contains("os")) { - infoLine += " " + jsonObject["os"].toString(); - } - - if (jsonObject.contains("dspRxBits") && jsonObject.contains("dspTxBits")) { - infoLine += QString(" %1/%2b").arg(jsonObject["dspRxBits"].toInt()).arg(jsonObject["dspTxBits"].toInt()); - } - - if (infoLine.size() > 0) { - ui->infoText->setText(infoLine); - } -} - void RemoteInputGui::openDeviceSettingsDialog(const QPoint& p) { BasicDeviceSettingsDialog dialog(this); diff --git a/plugins/samplesource/remoteinput/remoteinputgui.h b/plugins/samplesource/remoteinput/remoteinputgui.h index eeaad908d..bfd1e91d0 100644 --- a/plugins/samplesource/remoteinput/remoteinputgui.h +++ b/plugins/samplesource/remoteinput/remoteinputgui.h @@ -21,7 +21,6 @@ #include #include #include -#include #include "device/devicegui.h" #include "util/messagequeue.h" @@ -100,14 +99,12 @@ private: QPalette m_paletteGreenText; QPalette m_paletteWhiteText; - QNetworkAccessManager *m_networkManager; - QNetworkRequest m_networkRequest; - void blockApplySettings(bool block); void displaySettings(); void displayRemoteSettings(); void displayRemoteShift(); void displayTime(); + void displayRemoteFixedData(const RemoteInput::MsgReportRemoteFixedData::RemoteData& remoteData); void sendSettings(); void updateWithAcquisition(); void updateWithStreamTime(); @@ -117,7 +114,6 @@ private: void applyDecimation(); void applyPosition(); void applyRemoteSettings(); - void analyzeApiReply(const QJsonObject& jsonObject); bool handleMessage(const Message& message); private slots: @@ -139,7 +135,6 @@ private slots: void on_eventCountsReset_clicked(bool checked); void updateHardware(); void updateStatus(); - void networkManagerFinished(QNetworkReply *reply); void openDeviceSettingsDialog(const QPoint& p); };