mirror of
https://github.com/f4exb/sdrangel.git
synced 2025-05-28 13:12:24 -04:00
SDRDaemonSink: use SDRdaemon REST API to get channel source information
This commit is contained in:
parent
1f7720e8f9
commit
e20e14ac75
@ -20,6 +20,9 @@
|
|||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
#include <QNetworkAccessManager>
|
||||||
|
#include <QNetworkReply>
|
||||||
|
#include <QJsonParseError>
|
||||||
|
|
||||||
#include <boost/algorithm/string.hpp>
|
#include <boost/algorithm/string.hpp>
|
||||||
#include <boost/lexical_cast.hpp>
|
#include <boost/lexical_cast.hpp>
|
||||||
@ -74,6 +77,9 @@ SDRdaemonSinkGui::SDRdaemonSinkGui(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_networkManager = new QNetworkAccessManager();
|
||||||
|
connect(m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkManagerFinished(QNetworkReply*)));
|
||||||
|
|
||||||
m_time.start();
|
m_time.start();
|
||||||
displayEventCounts();
|
displayEventCounts();
|
||||||
displayEventTimer();
|
displayEventTimer();
|
||||||
@ -84,6 +90,7 @@ SDRdaemonSinkGui::SDRdaemonSinkGui(DeviceUISet *deviceUISet, QWidget* parent) :
|
|||||||
|
|
||||||
SDRdaemonSinkGui::~SDRdaemonSinkGui()
|
SDRdaemonSinkGui::~SDRdaemonSinkGui()
|
||||||
{
|
{
|
||||||
|
delete m_networkManager;
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -451,9 +458,60 @@ void SDRdaemonSinkGui::tick()
|
|||||||
{
|
{
|
||||||
if ((++m_tickCount & 0xf) == 0) // 16*50ms ~800ms
|
if ((++m_tickCount & 0xf) == 0) // 16*50ms ~800ms
|
||||||
{
|
{
|
||||||
SDRdaemonSinkOutput::MsgConfigureSDRdaemonSinkStreamTiming* message = SDRdaemonSinkOutput::MsgConfigureSDRdaemonSinkStreamTiming::create();
|
QString reportURL = QString("http://%1:%2/sdrdaemon/channel/report").arg(m_settings.m_apiAddress).arg(m_settings.m_apiPort);
|
||||||
m_deviceSampleSink->getInputMessageQueue()->push(message);
|
m_networkRequest.setUrl(QUrl(reportURL));
|
||||||
|
m_networkManager->get(m_networkRequest);
|
||||||
|
|
||||||
|
// SDRdaemonSinkOutput::MsgConfigureSDRdaemonSinkStreamTiming* message = SDRdaemonSinkOutput::MsgConfigureSDRdaemonSinkStreamTiming::create();
|
||||||
|
// m_deviceSampleSink->getInputMessageQueue()->push(message);
|
||||||
|
|
||||||
displayEventTimer();
|
displayEventTimer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SDRdaemonSinkGui::networkManagerFinished(QNetworkReply *reply)
|
||||||
|
{
|
||||||
|
if (reply->error())
|
||||||
|
{
|
||||||
|
qDebug() << "SDRdaemonSinkGui::networkManagerFinished" << reply->errorString();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString answer = reply->readAll();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
QByteArray jsonBytes(answer.toStdString().c_str());
|
||||||
|
QJsonParseError error;
|
||||||
|
QJsonDocument doc = QJsonDocument::fromJson(jsonBytes, &error);
|
||||||
|
|
||||||
|
if (error.error == QJsonParseError::NoError)
|
||||||
|
{
|
||||||
|
analyzeChannelReport(doc.object());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QString errorMsg = QString("Reply JSON error: ") + error.errorString() + QString(" at offset ") + QString::number(error.offset);
|
||||||
|
qDebug().noquote() << "SDRdaemonSinkGui::networkManagerFinished" << errorMsg;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (const std::exception& ex)
|
||||||
|
{
|
||||||
|
QString errorMsg = QString("Error parsing request: ") + ex.what();
|
||||||
|
qDebug().noquote() << "SDRdaemonSinkGui::networkManagerFinished" << errorMsg;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SDRdaemonSinkGui::analyzeChannelReport(const QJsonObject& jsonObject)
|
||||||
|
{
|
||||||
|
if (jsonObject.contains("SDRDaemonChannelSourceReport"))
|
||||||
|
{
|
||||||
|
QJsonObject report = jsonObject["SDRDaemonChannelSourceReport"].toObject();
|
||||||
|
int queueSize = report["queueSize"].toInt();
|
||||||
|
queueSize = queueSize == 0 ? 10 : queueSize;
|
||||||
|
int queueLength = report["queueLength"].toInt();
|
||||||
|
QString queueLengthText = QString("%1/%2").arg(queueLength).arg(queueSize);
|
||||||
|
ui->queueLengthText->setText(queueLengthText);
|
||||||
|
ui->queueLengthGauge->setValue((queueLength*100)/queueSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -21,13 +21,16 @@
|
|||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QTime>
|
#include <QTime>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
#include <QNetworkRequest>
|
||||||
|
|
||||||
#include "util/messagequeue.h"
|
#include "util/messagequeue.h"
|
||||||
|
|
||||||
#include "sdrdaemonsinksettings.h"
|
#include "sdrdaemonsinksettings.h"
|
||||||
#include "sdrdaemonsinkoutput.h"
|
#include "sdrdaemonsinkoutput.h"
|
||||||
|
|
||||||
|
class QNetworkAccessManager;
|
||||||
|
class QNetworkReply;
|
||||||
|
class QJsonObject;
|
||||||
class DeviceSampleSink;
|
class DeviceSampleSink;
|
||||||
class DeviceUISet;
|
class DeviceUISet;
|
||||||
|
|
||||||
@ -84,6 +87,9 @@ private:
|
|||||||
|
|
||||||
MessageQueue m_inputMessageQueue;
|
MessageQueue m_inputMessageQueue;
|
||||||
|
|
||||||
|
QNetworkAccessManager *m_networkManager;
|
||||||
|
QNetworkRequest m_networkRequest;
|
||||||
|
|
||||||
void blockApplySettings(bool block);
|
void blockApplySettings(bool block);
|
||||||
void displaySettings();
|
void displaySettings();
|
||||||
void displayTime();
|
void displayTime();
|
||||||
@ -94,6 +100,7 @@ private:
|
|||||||
void updateTxDelayTooltip();
|
void updateTxDelayTooltip();
|
||||||
void displayEventCounts();
|
void displayEventCounts();
|
||||||
void displayEventTimer();
|
void displayEventTimer();
|
||||||
|
void analyzeChannelReport(const QJsonObject& jsonObject);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void handleInputMessages();
|
void handleInputMessages();
|
||||||
@ -112,6 +119,7 @@ private slots:
|
|||||||
void updateHardware();
|
void updateHardware();
|
||||||
void updateStatus();
|
void updateStatus();
|
||||||
void tick();
|
void tick();
|
||||||
|
void networkManagerFinished(QNetworkReply *reply);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // INCLUDE_FILESINKGUI_H
|
#endif // INCLUDE_FILESINKGUI_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user