mirror of
				https://github.com/f4exb/sdrangel.git
				synced 2025-10-30 20:40:20 -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 <QString> | ||||
| #include <QMessageBox> | ||||
| #include <QNetworkAccessManager> | ||||
| #include <QNetworkReply> | ||||
| #include <QJsonParseError> | ||||
| 
 | ||||
| #include <boost/algorithm/string.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); | ||||
| 
 | ||||
| 	m_networkManager = new QNetworkAccessManager(); | ||||
| 	connect(m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkManagerFinished(QNetworkReply*))); | ||||
| 
 | ||||
|     m_time.start(); | ||||
|     displayEventCounts(); | ||||
|     displayEventTimer(); | ||||
| @ -84,6 +90,7 @@ SDRdaemonSinkGui::SDRdaemonSinkGui(DeviceUISet *deviceUISet, QWidget* parent) : | ||||
| 
 | ||||
| SDRdaemonSinkGui::~SDRdaemonSinkGui() | ||||
| { | ||||
|     delete m_networkManager; | ||||
| 	delete ui; | ||||
| } | ||||
| 
 | ||||
| @ -451,9 +458,60 @@ void SDRdaemonSinkGui::tick() | ||||
| { | ||||
| 	if ((++m_tickCount & 0xf) == 0) // 16*50ms ~800ms
 | ||||
| 	{ | ||||
| 		SDRdaemonSinkOutput::MsgConfigureSDRdaemonSinkStreamTiming* message = SDRdaemonSinkOutput::MsgConfigureSDRdaemonSinkStreamTiming::create(); | ||||
| 		m_deviceSampleSink->getInputMessageQueue()->push(message); | ||||
| 	    QString reportURL = QString("http://%1:%2/sdrdaemon/channel/report").arg(m_settings.m_apiAddress).arg(m_settings.m_apiPort); | ||||
| 	    m_networkRequest.setUrl(QUrl(reportURL)); | ||||
| 	    m_networkManager->get(m_networkRequest); | ||||
| 
 | ||||
| //		SDRdaemonSinkOutput::MsgConfigureSDRdaemonSinkStreamTiming* message = SDRdaemonSinkOutput::MsgConfigureSDRdaemonSinkStreamTiming::create();
 | ||||
| //		m_deviceSampleSink->getInputMessageQueue()->push(message);
 | ||||
| 
 | ||||
|         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 <QTime> | ||||
| #include <QWidget> | ||||
| #include <QNetworkRequest> | ||||
| 
 | ||||
| #include "util/messagequeue.h" | ||||
| 
 | ||||
| #include "sdrdaemonsinksettings.h" | ||||
| #include "sdrdaemonsinkoutput.h" | ||||
| 
 | ||||
| 
 | ||||
| class QNetworkAccessManager; | ||||
| class QNetworkReply; | ||||
| class QJsonObject; | ||||
| class DeviceSampleSink; | ||||
| class DeviceUISet; | ||||
| 
 | ||||
| @ -84,6 +87,9 @@ private: | ||||
| 
 | ||||
|     MessageQueue m_inputMessageQueue; | ||||
| 
 | ||||
|     QNetworkAccessManager *m_networkManager; | ||||
|     QNetworkRequest m_networkRequest; | ||||
| 
 | ||||
|     void blockApplySettings(bool block); | ||||
| 	void displaySettings(); | ||||
| 	void displayTime(); | ||||
| @ -94,6 +100,7 @@ private: | ||||
| 	void updateTxDelayTooltip(); | ||||
| 	void displayEventCounts(); | ||||
|     void displayEventTimer(); | ||||
|     void analyzeChannelReport(const QJsonObject& jsonObject); | ||||
| 
 | ||||
| private slots: | ||||
|     void handleInputMessages(); | ||||
| @ -112,6 +119,7 @@ private slots: | ||||
|     void updateHardware(); | ||||
|     void updateStatus(); | ||||
| 	void tick(); | ||||
| 	void networkManagerFinished(QNetworkReply *reply); | ||||
| }; | ||||
| 
 | ||||
| #endif // INCLUDE_FILESINKGUI_H
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user