1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-22 08:04:49 -05:00

Remote input: removed API calls from GUI

This commit is contained in:
f4exb 2021-12-25 12:54:33 +01:00
parent 9bb3a273b3
commit d981912eee
4 changed files with 171 additions and 99 deletions

View File

@ -44,6 +44,9 @@ MESSAGE_CLASS_DEFINITION(RemoteInput::MsgReportRemoteInputStreamData, Message)
MESSAGE_CLASS_DEFINITION(RemoteInput::MsgReportRemoteInputStreamTiming, Message) MESSAGE_CLASS_DEFINITION(RemoteInput::MsgReportRemoteInputStreamTiming, Message)
MESSAGE_CLASS_DEFINITION(RemoteInput::MsgConfigureRemoteChannel, Message) MESSAGE_CLASS_DEFINITION(RemoteInput::MsgConfigureRemoteChannel, Message)
MESSAGE_CLASS_DEFINITION(RemoteInput::MsgStartStop, 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) : RemoteInput::RemoteInput(DeviceAPI *deviceAPI) :
m_deviceAPI(deviceAPI), m_deviceAPI(deviceAPI),
@ -213,6 +216,19 @@ bool RemoteInput::handleMessage(const Message& message)
applyRemoteChannelSettings(conf.getSettings()); applyRemoteChannelSettings(conf.getSettings());
return true; 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 else
{ {
return false; return false;
@ -597,6 +613,12 @@ void RemoteInput::networkManagerFinished(QNetworkReply *reply)
<< " error(" << (int) replyError << " error(" << (int) replyError
<< "): " << replyError << "): " << replyError
<< ": " << reply->errorString(); << ": " << reply->errorString();
if (m_guiMessageQueue)
{
MsgReportRemoteAPIError *msg = MsgReportRemoteAPIError::create(reply->errorString());
m_guiMessageQueue->push(msg);
}
} }
else else
{ {
@ -610,8 +632,23 @@ void RemoteInput::networkManagerFinished(QNetworkReply *reply)
if (error.error == QJsonParseError::NoError) if (error.error == QJsonParseError::NoError)
{ {
if (doc.object().contains("RemoteSinkSettings")) { const QJsonObject&jsonObject = doc.object();
analyzeRemoteChannelSettingsReply(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(); 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) void RemoteInput::analyzeRemoteChannelSettingsReply(const QJsonObject& jsonObject)
{ {
QJsonObject settings = jsonObject["RemoteSinkSettings"].toObject(); QJsonObject settings = jsonObject["RemoteSinkSettings"].toObject();

View File

@ -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); RemoteInput(DeviceAPI *deviceAPI);
virtual ~RemoteInput(); virtual ~RemoteInput();
virtual void destroy(); virtual void destroy();
@ -359,6 +421,7 @@ private:
void webapiReverseSendStartStop(bool start); void webapiReverseSendStartStop(bool start);
void getRemoteChannelSettings(); void getRemoteChannelSettings();
void analyzeRemoteChannelSettingsReply(const QJsonObject& jsonObject); void analyzeRemoteChannelSettingsReply(const QJsonObject& jsonObject);
void analyzeInstanceSummaryReply(const QJsonObject& jsonObject);
private slots: private slots:
void networkManagerFinished(QNetworkReply *reply); void networkManagerFinished(QNetworkReply *reply);

View File

@ -25,10 +25,6 @@
#include <QTime> #include <QTime>
#include <QDateTime> #include <QDateTime>
#include <QString> #include <QString>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QJsonParseError>
#include <QJsonObject>
#include "ui_remoteinputgui.h" #include "ui_remoteinputgui.h"
#include "gui/colormapper.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); connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()), Qt::QueuedConnection);
m_sampleSource->setMessageQueueToGUI(&m_inputMessageQueue); m_sampleSource->setMessageQueueToGUI(&m_inputMessageQueue);
m_networkManager = new QNetworkAccessManager();
connect(m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkManagerFinished(QNetworkReply*)));
m_eventsTime.start(); m_eventsTime.start();
displayEventCounts(); displayEventCounts();
displayEventTimer(); displayEventTimer();
@ -107,8 +100,6 @@ RemoteInputGui::RemoteInputGui(DeviceUISet *deviceUISet, QWidget* parent) :
RemoteInputGui::~RemoteInputGui() RemoteInputGui::~RemoteInputGui()
{ {
disconnect(m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkManagerFinished(QNetworkReply*)));
delete m_networkManager;
delete ui; delete ui;
} }
@ -222,7 +213,20 @@ bool RemoteInputGui::handleMessage(const Message& message)
blockApplySettings(true); blockApplySettings(true);
ui->startStop->setChecked(notif.getStartStop()); ui->startStop->setChecked(notif.getStartStop());
blockApplySettings(false); 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; return true;
} }
else else
@ -394,9 +398,9 @@ void RemoteInputGui::on_apiApplyButton_clicked(bool checked)
sendSettings(); sendSettings();
QString infoURL = QString("http://%1:%2/sdrangel").arg(m_settings.m_apiAddress).arg(m_settings.m_apiPort); ui->apiAddressLabel->setStyleSheet("QLabel { background:rgb(79,79,79); }");
m_networkRequest.setUrl(QUrl(infoURL)); RemoteInput::MsgRequestFixedData *msg = RemoteInput::MsgRequestFixedData::create();
m_networkManager->get(m_networkRequest); m_sampleSource->getInputMessageQueue()->push(msg);
} }
void RemoteInputGui::on_dataApplyButton_clicked(bool checked) void RemoteInputGui::on_dataApplyButton_clicked(bool checked)
@ -413,9 +417,9 @@ void RemoteInputGui::on_apiAddress_editingFinished()
{ {
m_settings.m_apiAddress = ui->apiAddress->text(); m_settings.m_apiAddress = ui->apiAddress->text();
QString infoURL = QString("http://%1:%2/sdrangel").arg(m_settings.m_apiAddress).arg(m_settings.m_apiPort); ui->apiAddressLabel->setStyleSheet("QLabel { background:rgb(79,79,79); }");
m_networkRequest.setUrl(QUrl(infoURL)); RemoteInput::MsgRequestFixedData *msg = RemoteInput::MsgRequestFixedData::create();
m_networkManager->get(m_networkRequest); m_sampleSource->getInputMessageQueue()->push(msg);
sendSettings(); sendSettings();
} }
@ -470,9 +474,9 @@ void RemoteInputGui::on_apiPort_editingFinished()
{ {
m_settings.m_apiPort = udpApiPort; m_settings.m_apiPort = udpApiPort;
QString infoURL = QString("http://%1:%2/sdrangel").arg(m_settings.m_apiAddress).arg(m_settings.m_apiPort); ui->apiAddressLabel->setStyleSheet("QLabel { background:rgb(79,79,79); }");
m_networkRequest.setUrl(QUrl(infoURL)); RemoteInput::MsgRequestFixedData *msg = RemoteInput::MsgRequestFixedData::create();
m_networkManager->get(m_networkRequest); m_sampleSource->getInputMessageQueue()->push(msg);
sendSettings(); sendSettings();
} }
@ -526,6 +530,21 @@ void RemoteInputGui::displayEventTimer()
ui->eventCountsTimeText->setText(s_time); 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() 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) void RemoteInputGui::openDeviceSettingsDialog(const QPoint& p)
{ {
BasicDeviceSettingsDialog dialog(this); BasicDeviceSettingsDialog dialog(this);

View File

@ -21,7 +21,6 @@
#include <QTimer> #include <QTimer>
#include <QElapsedTimer> #include <QElapsedTimer>
#include <QWidget> #include <QWidget>
#include <QNetworkRequest>
#include "device/devicegui.h" #include "device/devicegui.h"
#include "util/messagequeue.h" #include "util/messagequeue.h"
@ -100,14 +99,12 @@ private:
QPalette m_paletteGreenText; QPalette m_paletteGreenText;
QPalette m_paletteWhiteText; QPalette m_paletteWhiteText;
QNetworkAccessManager *m_networkManager;
QNetworkRequest m_networkRequest;
void blockApplySettings(bool block); void blockApplySettings(bool block);
void displaySettings(); void displaySettings();
void displayRemoteSettings(); void displayRemoteSettings();
void displayRemoteShift(); void displayRemoteShift();
void displayTime(); void displayTime();
void displayRemoteFixedData(const RemoteInput::MsgReportRemoteFixedData::RemoteData& remoteData);
void sendSettings(); void sendSettings();
void updateWithAcquisition(); void updateWithAcquisition();
void updateWithStreamTime(); void updateWithStreamTime();
@ -117,7 +114,6 @@ private:
void applyDecimation(); void applyDecimation();
void applyPosition(); void applyPosition();
void applyRemoteSettings(); void applyRemoteSettings();
void analyzeApiReply(const QJsonObject& jsonObject);
bool handleMessage(const Message& message); bool handleMessage(const Message& message);
private slots: private slots:
@ -139,7 +135,6 @@ private slots:
void on_eventCountsReset_clicked(bool checked); void on_eventCountsReset_clicked(bool checked);
void updateHardware(); void updateHardware();
void updateStatus(); void updateStatus();
void networkManagerFinished(QNetworkReply *reply);
void openDeviceSettingsDialog(const QPoint& p); void openDeviceSettingsDialog(const QPoint& p);
}; };