diff --git a/DMRDirectNetwork.cpp b/DMRDirectNetwork.cpp index 4ed871c5..a378f7a9 100644 --- a/DMRDirectNetwork.cpp +++ b/DMRDirectNetwork.cpp @@ -316,6 +316,11 @@ bool CDMRDirectNetwork::writeTalkerAlias(unsigned int id, unsigned char type, co return write(buffer, 15U); } +bool CDMRDirectNetwork::isConnected() const +{ + return (m_status == RUNNING); +} + void CDMRDirectNetwork::close() { LogMessage("Closing DMR Network"); diff --git a/DMRDirectNetwork.h b/DMRDirectNetwork.h index 30ba951d..f6e08342 100644 --- a/DMRDirectNetwork.h +++ b/DMRDirectNetwork.h @@ -55,6 +55,8 @@ class CDMRDirectNetwork : public IDMRNetwork virtual void clock(unsigned int ms); + virtual bool isConnected() const; + virtual void close(); private: diff --git a/DMRGatewayNetwork.cpp b/DMRGatewayNetwork.cpp index 5150d772..dd86e768 100644 --- a/DMRGatewayNetwork.cpp +++ b/DMRGatewayNetwork.cpp @@ -287,6 +287,11 @@ bool CDMRGatewayNetwork::writeTalkerAlias(unsigned int id, unsigned char type, c return write(buffer, 15U); } +bool CDMRGatewayNetwork::isConnected() const +{ + return (m_enabled && (m_addrLen != 0)); +} + void CDMRGatewayNetwork::close() { LogMessage("DMR, Closing DMR Network"); diff --git a/DMRGatewayNetwork.h b/DMRGatewayNetwork.h index 55afc726..bc00385c 100644 --- a/DMRGatewayNetwork.h +++ b/DMRGatewayNetwork.h @@ -56,6 +56,8 @@ class CDMRGatewayNetwork : public IDMRNetwork virtual void clock(unsigned int ms); + virtual bool isConnected() const; + virtual void close(); private: diff --git a/DMRNetwork.h b/DMRNetwork.h index 69d39268..4a3c4d76 100644 --- a/DMRNetwork.h +++ b/DMRNetwork.h @@ -48,6 +48,8 @@ class IDMRNetwork virtual void clock(unsigned int ms) = 0; + virtual bool isConnected() const = 0; + virtual void close() = 0; private: diff --git a/DStarNetwork.cpp b/DStarNetwork.cpp index 21bbc9d1..4a978e26 100644 --- a/DStarNetwork.cpp +++ b/DStarNetwork.cpp @@ -314,6 +314,11 @@ void CDStarNetwork::reset() m_inId = 0U; } +bool CDStarNetwork::isConnected() const +{ + return (m_enabled && (m_addrLen != 0)); +} + void CDStarNetwork::close() { m_socket.close(); diff --git a/DStarNetwork.h b/DStarNetwork.h index 1e0d5f08..cb41b789 100644 --- a/DStarNetwork.h +++ b/DStarNetwork.h @@ -46,6 +46,8 @@ class CDStarNetwork { void reset(); + bool isConnected() const; + void close(); void clock(unsigned int ms); diff --git a/MMDVMHost.cpp b/MMDVMHost.cpp index 2d76284a..8409aaca 100644 --- a/MMDVMHost.cpp +++ b/MMDVMHost.cpp @@ -635,7 +635,7 @@ int CMMDVMHost::run() LogInfo(" Address: %s", address.c_str()); LogInfo(" Port: %u", port); - m_remoteControl = new CRemoteControl(address, port); + m_remoteControl = new CRemoteControl(this, address, port); ret = m_remoteControl->open(); if (!ret) { @@ -2140,3 +2140,14 @@ void CMMDVMHost::processEnableCommand(bool& mode, bool enabled) if (!m_modem->writeConfig()) LogError("Cannot write Config to MMDVM"); } + +void CMMDVMHost::buildNetworkStatusString(std::string &str) +{ + str = ""; + str += std::string("dstar:") + (((m_dstarNetwork == NULL) || (m_dstarEnabled == false)) ? "n/a" : (m_dstarNetwork->isConnected() ? "conn" : "disc")); + str += std::string(" dmr:") + (((m_dmrNetwork == NULL) || (m_dmrEnabled == false)) ? "n/a" : (m_dmrNetwork->isConnected() ? "conn" : "disc")); + str += std::string(" ysf:") + (((m_ysfNetwork == NULL) || (m_ysfEnabled == false)) ? "n/a" : (m_ysfNetwork->isConnected() ? "conn" : "disc")); + str += std::string(" p25:") + (((m_p25Network == NULL) || (m_p25Enabled == false)) ? "n/a" : (m_p25Network->isConnected() ? "conn" : "disc")); + str += std::string(" nxdn:") + (((m_nxdnNetwork == NULL) || (m_nxdnEnabled == false)) ? "n/a" : (m_nxdnNetwork->isConnected() ? "conn" : "disc")); + str += std::string(" fm:") + (m_fmEnabled ? "conn" : "n/a"); +} diff --git a/MMDVMHost.h b/MMDVMHost.h index 735952ab..dd8ccf48 100644 --- a/MMDVMHost.h +++ b/MMDVMHost.h @@ -51,6 +51,8 @@ class CMMDVMHost int run(); + void buildNetworkStatusString(std::string &str); + private: CConf m_conf; CModem* m_modem; diff --git a/NXDNIcomNetwork.cpp b/NXDNIcomNetwork.cpp index b13ca2a8..5f20b37b 100644 --- a/NXDNIcomNetwork.cpp +++ b/NXDNIcomNetwork.cpp @@ -153,6 +153,11 @@ void CNXDNIcomNetwork::reset() { } +bool CNXDNIcomNetwork::isConnected() const +{ + return (m_enabled && (m_addrLen != 0)); +} + void CNXDNIcomNetwork::close() { m_socket.close(); diff --git a/NXDNIcomNetwork.h b/NXDNIcomNetwork.h index 3113a9fe..9f74710f 100644 --- a/NXDNIcomNetwork.h +++ b/NXDNIcomNetwork.h @@ -43,6 +43,8 @@ class CNXDNIcomNetwork : public INXDNNetwork { virtual void reset(); + virtual bool isConnected() const; + virtual void close(); virtual void clock(unsigned int ms); diff --git a/NXDNKenwoodNetwork.cpp b/NXDNKenwoodNetwork.cpp index 67de39bd..38661332 100644 --- a/NXDNKenwoodNetwork.cpp +++ b/NXDNKenwoodNetwork.cpp @@ -835,6 +835,11 @@ void CNXDNKenwoodNetwork::reset() m_seen4 = false; } +bool CNXDNKenwoodNetwork::isConnected() const +{ + return (m_enabled && (m_rtcpAddrLen != 0U) && (m_rtpAddrLen != 0U)); +} + void CNXDNKenwoodNetwork::close() { m_rtcpSocket.close(); diff --git a/NXDNKenwoodNetwork.h b/NXDNKenwoodNetwork.h index af286185..dc7bf1df 100644 --- a/NXDNKenwoodNetwork.h +++ b/NXDNKenwoodNetwork.h @@ -42,6 +42,8 @@ class CNXDNKenwoodNetwork : public INXDNNetwork { virtual void reset(); + virtual bool isConnected() const; + virtual void close(); virtual void clock(unsigned int ms); diff --git a/NXDNNetwork.h b/NXDNNetwork.h index 564196b6..107e02fc 100644 --- a/NXDNNetwork.h +++ b/NXDNNetwork.h @@ -46,6 +46,8 @@ class INXDNNetwork { virtual void reset() = 0; + virtual bool isConnected() const = 0; + virtual void close() = 0; virtual void clock(unsigned int ms) = 0; diff --git a/P25Network.cpp b/P25Network.cpp index 3bb39b94..27343735 100644 --- a/P25Network.cpp +++ b/P25Network.cpp @@ -424,6 +424,11 @@ unsigned int CP25Network::read(unsigned char* data, unsigned int length) return c; } +bool CP25Network::isConnected() const +{ + return (m_enabled && (m_addrLen != 0)); +} + void CP25Network::close() { m_socket.close(); diff --git a/P25Network.h b/P25Network.h index 4c52761e..6b8407c8 100644 --- a/P25Network.h +++ b/P25Network.h @@ -43,6 +43,8 @@ class CP25Network { unsigned int read(unsigned char* data, unsigned int length); + bool isConnected() const; + void close(); void clock(unsigned int ms); diff --git a/RemoteCommand.cpp b/RemoteCommand.cpp index 20db9479..c893d795 100644 --- a/RemoteCommand.cpp +++ b/RemoteCommand.cpp @@ -75,7 +75,7 @@ int CRemoteCommand::send(const std::string& command) int retStatus = 0; if (CUDPSocket::lookup("127.0.0.1", m_port, addr, addrLen) != 0) { - LogError("Unable to resolve the address of the host"); + ::fprintf(stderr, "Unable to resolve the address of the host\n"); return 1; } @@ -91,14 +91,14 @@ int CRemoteCommand::send(const std::string& command) return 1; } - LogMessage("Command sent: \"%s\" to port: %u", command.c_str(), m_port); + ::fprintf(stdout, "Command sent: \"%s\" to port: %u\n", command.c_str(), m_port); std::this_thread::sleep_for(std::chrono::milliseconds(50)); - int len = socket.read((unsigned char*)&buffer[0], BUFFER_LENGTH, addr, addrLen); + int len = socket.read((unsigned char*)buffer, BUFFER_LENGTH, addr, addrLen); if (len > 0) { buffer[len] = '\0'; - LogMessage("%s", buffer); + ::fprintf(stdout, "%s\n", buffer); } else { diff --git a/RemoteControl.cpp b/RemoteControl.cpp index 5274829c..a195d355 100644 --- a/RemoteControl.cpp +++ b/RemoteControl.cpp @@ -17,6 +17,7 @@ */ #include "RemoteControl.h" +#include "MMDVMHost.h" #include "Log.h" #include @@ -32,7 +33,8 @@ const unsigned int CW_ARGS = 2U; const unsigned int BUFFER_LENGTH = 100U; -CRemoteControl::CRemoteControl(const std::string address, unsigned int port) : +CRemoteControl::CRemoteControl(CMMDVMHost *host, const std::string address, unsigned int port) : +m_host(host), m_socket(address, port), m_command(RCD_NONE), m_args() @@ -131,7 +133,16 @@ REMOTE_COMMAND CRemoteControl::getCommand() } else if (m_args.at(0U) == "reload") { // Reload command is in the form of "reload" m_command = RCD_RELOAD; - } + } else if (m_args.at(0U) == "status") { + if (m_host != NULL) { + m_host->buildNetworkStatusString(replyStr); + } + else { + replyStr = "KO"; + } + + m_command = RCD_CONNECTION_STATUS; + } else replyStr = "KO"; diff --git a/RemoteControl.h b/RemoteControl.h index 3f07f031..addbb3e6 100644 --- a/RemoteControl.h +++ b/RemoteControl.h @@ -24,6 +24,8 @@ #include #include +class CMMDVMHost; + enum REMOTE_COMMAND { RCD_NONE, RCD_MODE_IDLE, @@ -48,12 +50,13 @@ enum REMOTE_COMMAND { RCD_DISABLE_FM, RCD_PAGE, RCD_CW, - RCD_RELOAD + RCD_RELOAD, + RCD_CONNECTION_STATUS }; class CRemoteControl { public: - CRemoteControl(const std::string address, unsigned int port); + CRemoteControl(class CMMDVMHost *host, const std::string address, unsigned int port); ~CRemoteControl(); bool open(); @@ -69,6 +72,7 @@ class CRemoteControl { void close(); private: + CMMDVMHost* m_host; CUDPSocket m_socket; REMOTE_COMMAND m_command; std::vector m_args; diff --git a/YSFNetwork.cpp b/YSFNetwork.cpp index 089a932d..451d3af0 100644 --- a/YSFNetwork.cpp +++ b/YSFNetwork.cpp @@ -183,6 +183,11 @@ void CYSFNetwork::reset() ::memset(m_tag, ' ', YSF_CALLSIGN_LENGTH); } +bool CYSFNetwork::isConnected() const +{ + return (m_enabled && (m_addrLen != 0)); +} + void CYSFNetwork::close() { m_socket.close(); diff --git a/YSFNetwork.h b/YSFNetwork.h index aef43d36..3fd7c569 100644 --- a/YSFNetwork.h +++ b/YSFNetwork.h @@ -42,6 +42,8 @@ class CYSFNetwork { void reset(); + bool isConnected() const; + void close(); void clock(unsigned int ms);