diff --git a/kstars/CMakeLists.txt b/kstars/CMakeLists.txt --- a/kstars/CMakeLists.txt +++ b/kstars/CMakeLists.txt @@ -140,6 +140,7 @@ ekos/ekoslive/ekoslivedialog.ui # INDI Hub ekos/indihub.ui + ekos/indihubagent.ui ) set(ekos_SRCS @@ -149,6 +150,7 @@ ekos/profilewizard.cpp ekos/qMDNS.cpp ekos/opsekos.cpp + ekos/indihub.cpp # Auxiliary ekos/auxiliary/dome.cpp diff --git a/kstars/ekos/indihub.h b/kstars/ekos/indihub.h --- a/kstars/ekos/indihub.h +++ b/kstars/ekos/indihub.h @@ -22,15 +22,16 @@ Robotic }; -QString toString(uint8_t mode) +struct AgentStatus { - if (mode == Solo) - return "solo"; - else if (mode == Share) - return "share"; - else if (mode == Robotic) - return "robotic"; - else - return "none"; -} + QString version; + QString mode; + QString indiProfile; + QString indiServer; + QString phd2Server; + QString indiServerEndpoint; + QString phd2ServerEndpoint; +}; + +QString toString(uint8_t mode); } diff --git a/kstars/ekos/indihub.ui b/kstars/ekos/indihub.ui --- a/kstars/ekos/indihub.ui +++ b/kstars/ekos/indihub.ui @@ -67,6 +67,9 @@ true + + true + diff --git a/kstars/ekos/manager.h b/kstars/ekos/manager.h --- a/kstars/ekos/manager.h +++ b/kstars/ekos/manager.h @@ -18,6 +18,7 @@ #include "ui_manager.h" #include "ekos.h" +#include "indihub.h" #include "align/align.h" #include "auxiliary/dome.h" #include "auxiliary/weather.h" @@ -395,6 +396,11 @@ void updateGuideStarPixmap(QPixmap &starPix); void updateGuideProfilePixmap(QPixmap &profilePix); void updateSigmas(double ra, double de); + + // INDI Hub Agent + void getINDIHubAgentStatus(); + void receiveINDIHubAgentStatus(QNetworkReply* reply); + void showINDIHubAgentStatus(); private: explicit Manager(QWidget *parent); @@ -528,6 +534,10 @@ friend class EkosLive::Client; friend class EkosLive::Message; friend class EkosLive::Media; + + // INDI Hub Agent + QNetworkAccessManager m_Manager; + INDIHub::AgentStatus indihubAgentStatus; static Manager *_Manager; }; diff --git a/kstars/ekos/manager.cpp b/kstars/ekos/manager.cpp --- a/kstars/ekos/manager.cpp +++ b/kstars/ekos/manager.cpp @@ -38,6 +38,8 @@ #include "ekoslive/message.h" #include "ekoslive/media.h" +#include "ui_indihubagent.h" + #include #include @@ -140,6 +142,10 @@ emit ekosLiveStatusChanged(false); }); + // INDI HUB Agent status + connect(indihubB, &QPushButton::clicked, this, &Ekos::Manager::showINDIHubAgentStatus); + + // INDI Control Panel //connect(controlPanelB, &QPushButton::clicked, GUIManager::Instance(), SLOT(show())); connect(ekosLiveB, &QPushButton::clicked, [&]() @@ -540,7 +546,10 @@ serialPortAssistantB->setEnabled(false); if (indiHubAgent) + { indiHubAgent->terminate(); + indihubB->setEnabled(false); + } profileGroup->setEnabled(true); @@ -1081,7 +1090,10 @@ { cleanDevices(false); if (indiHubAgent) + { indiHubAgent->terminate(); + indihubB->setEnabled(false); + } } } @@ -1101,6 +1113,9 @@ indiHubAgent->start(Options::iNDIHubAgent(), args); qCDebug(KSTARS_EKOS) << "Started INDIHub agent."; + + // wait 5 sec, then get indihub-agent status + QTimer::singleShot(5000, this, &Ekos::Manager::getINDIHubAgentStatus); } } } @@ -2145,6 +2160,78 @@ observatoryProcess->clearLog(); } +void Manager::getINDIHubAgentStatus() +{ + connect(&m_Manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(receiveINDIHubAgentStatus(QNetworkReply*))); + QUrl url(QString("http://localhost:2020/status")); + m_Manager.get(QNetworkRequest(url)); +} + +void Manager::receiveINDIHubAgentStatus(QNetworkReply* reply) +{ + if (reply->error() != QNetworkReply::NoError) + return; + + QJsonParseError parseError; + QString json = (QString)reply->readAll(); + QJsonDocument json_doc = QJsonDocument::fromJson(json.toUtf8(), &parseError); + if (parseError.error != QJsonParseError::NoError) + return; + + QVariant json_result = json_doc.toVariant(); + QVariantMap result = json_result.toMap(); + indihubAgentStatus.version = result["version"].toString(); + indihubAgentStatus.indiProfile = result["indiProfile"].toString(); + indihubAgentStatus.indiServer = result["indiServer"].toString(); + indihubAgentStatus.phd2Server = result["phd2Server"].toString(); + indihubAgentStatus.mode = result["mode"].toString(); + indihubAgentStatus.indiServerEndpoint = ""; + indihubAgentStatus.phd2ServerEndpoint = ""; + if (indihubAgentStatus.mode != "solo") + { + QList endpointList = result["publicEndpoints"].toList(); + foreach (QVariant endpointVar, endpointList) + { + QVariantMap endpointMap = endpointVar.toMap(); + QString name = endpointMap["name"].toString(); + QString addr = endpointMap["addr"].toString(); + if (name == "INDI-Server") + indihubAgentStatus.indiServerEndpoint = addr; + else if (name == "PHD2-Server") + indihubAgentStatus.phd2ServerEndpoint = addr; + } + } + + + indihubB->setEnabled(true); +} + +void Manager::showINDIHubAgentStatus() +{ + QDialog agentDialog; + Ui::INDIHubAgent indihubAgentUI; + indihubAgentUI.setupUi(&agentDialog); + + indihubAgentUI.logoLabel->setPixmap(QIcon(":/icons/indihub_logo.svg").pixmap(QSize(128, 128))); + indihubAgentUI.agentVersion->setText(QString("Version: ") + indihubAgentStatus.version); + indihubAgentUI.agentMode->setText(QString("Mode: ") + indihubAgentStatus.mode); + + if (indihubAgentStatus.indiServerEndpoint != "") + indihubAgentUI.agentIndiServerEndpoint->setText(QString("INDI-Server: ") + indihubAgentStatus.indiServerEndpoint); + else + indihubAgentUI.agentIndiServerEndpoint->setText(""); + + if (indihubAgentStatus.phd2ServerEndpoint != "") + indihubAgentUI.agentPhd2ServerEndpoint->setText(QString("PHD2-Server: ") + indihubAgentStatus.phd2ServerEndpoint); + else + indihubAgentUI.agentPhd2ServerEndpoint->setText(""); + + + connect(indihubAgentUI.closeB, &QPushButton::clicked, &agentDialog, &QDialog::close); + + agentDialog.exec(); +} + void Manager::initCapture() { if (captureProcess.get() != nullptr) diff --git a/kstars/ekos/manager.ui b/kstars/ekos/manager.ui --- a/kstars/ekos/manager.ui +++ b/kstars/ekos/manager.ui @@ -415,6 +415,35 @@ + + + + false + + + + 32 + 32 + + + + INDI Hub Agent status + + + + + + + :/icons/indihub.svg:/icons/indihub.svg + + + + 22 + 22 + + + +