From ee74cad81b7f54111136bf997a1eeb4cc1a6d8d4 Mon Sep 17 00:00:00 2001 From: Bryan Biedenkapp Date: Fri, 30 Jun 2023 20:37:57 -0400 Subject: [PATCH] report network peer ID in status API call; display network peer ID on dvmmon; --- src/host/Host.cpp | 7 ++++++- src/monitor/MonitorMainWnd.h | 3 ++- src/monitor/NodeStatusWnd.h | 12 ++++++++++++ src/monitor/SelectedNodeWnd.h | 2 +- src/network/BaseNetwork.cpp | 2 +- src/network/RESTAPI.cpp | 31 ++++++++++++++++++------------- 6 files changed, 40 insertions(+), 17 deletions(-) diff --git a/src/host/Host.cpp b/src/host/Host.cpp index 1269636e..4a203032 100644 --- a/src/host/Host.cpp +++ b/src/host/Host.cpp @@ -2293,7 +2293,7 @@ bool Host::createNetwork() uint16_t restApiPort = (uint16_t)networkConf["restPort"].as(REST_API_DEFAULT_PORT); std::string restApiPassword = networkConf["restPassword"].as(); bool restApiDebug = networkConf["restDebug"].as(false); - uint32_t id = networkConf["id"].as(1001U); + uint32_t id = networkConf["id"].as(1000U); uint32_t jitter = networkConf["talkgroupHang"].as(360U); std::string password = networkConf["password"].as(); bool slot1 = networkConf["slot1"].as(true); @@ -2303,6 +2303,11 @@ bool Host::createNetwork() bool updateLookup = networkConf["updateLookups"].as(false); bool debug = networkConf["debug"].as(false); + if (id > 999999999U) { + ::LogError(LOG_HOST, "Network Peer ID cannot be greater then 999999999."); + return false; + } + if (restApiPassword.length() > 64) { std::string password = restApiPassword; restApiPassword = password.substr(0, 64); diff --git a/src/monitor/MonitorMainWnd.h b/src/monitor/MonitorMainWnd.h index 1bdf031b..43936a9d 100644 --- a/src/monitor/MonitorMainWnd.h +++ b/src/monitor/MonitorMainWnd.h @@ -199,7 +199,8 @@ private: wnd->addCallback("update-selected", this, [&](NodeStatusWnd* wnd) { std::stringstream ss; ss << (uint32_t)(wnd->getChannelId()) << "-" << wnd->getChannelNo() << " / " - << wnd->getChData().address() << ":" << wnd->getChData().port(); + << wnd->getChData().address() << ":" << wnd->getChData().port() << " / " + << "Peer ID " << (uint32_t)(wnd->getPeerId()); m_selectWnd.setSelectedText(ss.str()); m_selectedCh = wnd->getChData(); diff --git a/src/monitor/NodeStatusWnd.h b/src/monitor/NodeStatusWnd.h index 9a1805e7..84393c49 100644 --- a/src/monitor/NodeStatusWnd.h +++ b/src/monitor/NodeStatusWnd.h @@ -86,6 +86,8 @@ public: lookups::VoiceChData getChData() { return m_chData; } /// Sets the channel data. void setChData(lookups::VoiceChData chData) { m_chData = chData; } + /// Gets the peer ID. + uint32_t getPeerId() const { return m_peerId; } private: int m_timerId; @@ -98,8 +100,10 @@ private: lookups::VoiceChData m_chData; uint8_t m_channelId; uint32_t m_channelNo; + uint32_t m_peerId; FLabel m_modeStr{this}; + FLabel m_peerIdStr{this}; FLabel m_channelNoLabel{"Ch. No.: ", this}; FLabel m_chanNo{this}; @@ -166,6 +170,9 @@ private: m_modeStr.setAlignment(Align::Right); m_modeStr.setEmphasis(); + m_peerIdStr.setGeometry(FPoint(17, 2), FSize(9, 1)); + m_peerIdStr.setAlignment(Align::Right); + // channel number { m_channelNoLabel.setGeometry(FPoint(2, 1), FSize(10, 1)); @@ -292,6 +299,11 @@ private: break; } + if (rsp["peerId"].is()) { + m_peerId = rsp["peerId"].get(); + m_peerIdStr.setText(__INT_STR(m_peerId)); + } + // get remote node state if (rsp["dmrTSCCEnable"].is() && rsp["p25CtrlEnable"].is() && rsp["nxdnCtrlEnable"].is()) { diff --git a/src/monitor/SelectedNodeWnd.h b/src/monitor/SelectedNodeWnd.h index 8353dd6a..ea0e6a87 100644 --- a/src/monitor/SelectedNodeWnd.h +++ b/src/monitor/SelectedNodeWnd.h @@ -100,7 +100,7 @@ private: FDialog::setShadow(false); m_selectedHostLabel.setGeometry(FPoint(2, 1), FSize(18, 1)); - m_selectedHost.setGeometry(FPoint(20, 1), FSize(30, 1)); + m_selectedHost.setGeometry(FPoint(20, 1), FSize(60, 1)); m_selectedHost.setText("None"); FDialog::initLayout(); diff --git a/src/network/BaseNetwork.cpp b/src/network/BaseNetwork.cpp index 33c0c21c..eb7c4581 100644 --- a/src/network/BaseNetwork.cpp +++ b/src/network/BaseNetwork.cpp @@ -79,7 +79,7 @@ BaseNetwork::BaseNetwork(uint32_t peerId, bool duplex, bool debug, bool slot1, b m_pktSeq(0U), m_audio() { - assert(peerId > 1000U); + assert(peerId < 999999999U); m_socket = new UDPSocket(localPort); m_frameQueue = new FrameQueue(m_socket, peerId, debug); diff --git a/src/network/RESTAPI.cpp b/src/network/RESTAPI.cpp index 4e0bf93b..268f046f 100644 --- a/src/network/RESTAPI.cpp +++ b/src/network/RESTAPI.cpp @@ -486,17 +486,8 @@ void RESTAPI::restAPI_GetStatus(const HTTPPayload& request, HTTPPayload& reply, setResponseDefaultStatus(response); yaml::Node systemConf = m_host->m_conf["system"]; + yaml::Node networkConf = m_host->m_conf["network"]; { - yaml::Node modemConfig = m_host->m_conf["system"]["modem"]; - std::string portType = modemConfig["protocol"]["type"].as(); - response["portType"].set(portType); - - yaml::Node uartConfig = modemConfig["protocol"]["uart"]; - std::string modemPort = uartConfig["port"].as(); - response["modemPort"].set(modemPort); - uint32_t portSpeed = uartConfig["speed"].as(115200U); - response["portSpeed"].set(portSpeed); - response["state"].set(m_host->m_state); bool dmrEnabled = m_dmr != nullptr; response["dmrEnabled"].set(dmrEnabled); @@ -505,9 +496,6 @@ void RESTAPI::restAPI_GetStatus(const HTTPPayload& request, HTTPPayload& reply, bool nxdnEnabled = m_nxdn != nullptr; response["nxdnEnabled"].set(nxdnEnabled); - uint8_t protoVer = m_host->m_modem->getVersion(); - response["protoVer"].set(protoVer); - response["fixedMode"].set(m_host->m_fixedMode); response["dmrTSCCEnable"].set(m_host->m_dmrTSCCData); @@ -532,10 +520,23 @@ void RESTAPI::restAPI_GetStatus(const HTTPPayload& request, HTTPPayload& reply, response["lastDstId"].set(m_host->m_lastDstId); response["lastSrcId"].set(m_host->m_lastSrcId); + + uint32_t peerId = networkConf["id"].as(); + response["peerId"].set(peerId); } + yaml::Node modemConfig = m_host->m_conf["system"]["modem"]; { json::object modemInfo = json::object(); + std::string portType = modemConfig["protocol"]["type"].as(); + modemInfo["portType"].set(portType); + + yaml::Node uartConfig = modemConfig["protocol"]["uart"]; + std::string modemPort = uartConfig["port"].as(); + modemInfo["modemPort"].set(modemPort); + uint32_t portSpeed = uartConfig["speed"].as(115200U); + modemInfo["portSpeed"].set(portSpeed); + if (!m_host->m_modem->isHotspot()) { modemInfo["pttInvert"].set(m_host->m_modem->m_pttInvert); modemInfo["rxInvert"].set(m_host->m_modem->m_rxInvert); @@ -611,6 +612,10 @@ void RESTAPI::restAPI_GetStatus(const HTTPPayload& request, HTTPPayload& reply, modemInfo["rxFrequencyEffective"].set(rxFreqEffective); uint32_t txFreqEffective = m_host->m_modem->m_txFrequency + m_host->m_modem->m_txTuning; modemInfo["txFrequencyEffective"].set(txFreqEffective); + + uint8_t protoVer = m_host->m_modem->getVersion(); + modemInfo["protoVer"].set(protoVer); + response["modem"].set(modemInfo); }