Add new remote command:

- hosts: display connected hosts, or NONE if disconnected (surrounded with double quotes).
This commit is contained in:
Daniel Caujolle-Bert
2022-01-21 08:13:24 +00:00
parent 5aa6e54130
commit 6c36e29f88
6 changed files with 44 additions and 0 deletions

View File

@@ -2658,3 +2658,29 @@ void CDMRGateway::buildNetworkStatusNetworkString(std::string &str, const std::s
str += name + ":"+ (((network == NULL) || (enabled == false)) ? "n/a" : (network->isConnected() ? "conn" : "disc")); str += name + ":"+ (((network == NULL) || (enabled == false)) ? "n/a" : (network->isConnected() ? "conn" : "disc"));
} }
void CDMRGateway::buildNetworkHostsString(std::string &str)
{
str = "";
buildNetworkHostNetworkString(str, "xlx", m_xlxNetwork);
str += " ";
buildNetworkHostNetworkString(str, "net1", m_dmrNetwork1);
str += " ";
buildNetworkHostNetworkString(str, "net2", m_dmrNetwork2);
str += " ";
buildNetworkHostNetworkString(str, "net3", m_dmrNetwork3);
str += " ";
buildNetworkHostNetworkString(str, "net4", m_dmrNetwork4);
str += " ";
buildNetworkHostNetworkString(str, "net5", m_dmrNetwork5);
}
void CDMRGateway::buildNetworkHostNetworkString(std::string &str, const std::string& name, CDMRNetwork* network)
{
if (network && (network == m_xlxNetwork)) {
std::string module = ((m_xlxReflector >= 4001U && m_xlxReflector <= 4026U) ? ("_" + std::string(1, (('A' + (m_xlxReflector % 100U)) - 1U))) : "");
str += name + ":\"XLX" + std::to_string(m_xlxNumber) + module + "\"";
} else {
std::string host = ((network == NULL) ? "NONE" : network->getName());
str += name + ":\""+ ((network == NULL) ? "NONE" : ((host.length() > 0) ? host : "NONE")) + "\"";
}
}

View File

@@ -56,6 +56,7 @@ public:
int run(); int run();
void buildNetworkStatusString(std::string &str); void buildNetworkStatusString(std::string &str);
void buildNetworkHostsString(std::string &str);
private: private:
CConf m_conf; CConf m_conf;
@@ -156,6 +157,7 @@ private:
void remoteControl(); void remoteControl();
void processEnableCommand(CDMRNetwork* network, const std::string& name, bool& mode, bool enabled); void processEnableCommand(CDMRNetwork* network, const std::string& name, bool& mode, bool enabled);
void buildNetworkStatusNetworkString(std::string &str, const std::string& name, CDMRNetwork* network, bool enabled); void buildNetworkStatusNetworkString(std::string &str, const std::string& name, CDMRNetwork* network, bool enabled);
void buildNetworkHostNetworkString(std::string &str, const std::string& name, CDMRNetwork* network);
}; };
#endif #endif

View File

@@ -298,6 +298,11 @@ bool CDMRNetwork::isConnected() const
return m_status == RUNNING; return m_status == RUNNING;
} }
std::string const CDMRNetwork::getName() const
{
return m_name;
}
void CDMRNetwork::close(bool sayGoodbye) void CDMRNetwork::close(bool sayGoodbye)
{ {
LogMessage("%s, Closing DMR Network", m_name.c_str()); LogMessage("%s, Closing DMR Network", m_name.c_str());

View File

@@ -56,6 +56,7 @@ public:
void clock(unsigned int ms); void clock(unsigned int ms);
bool isConnected() const; bool isConnected() const;
std::string const getName() const;
void close(bool sayGoodbye); void close(bool sayGoodbye);

View File

@@ -111,6 +111,15 @@ REMOTE_COMMAND CRemoteControl::getCommand()
} }
m_command = RCD_CONNECTION_STATUS; m_command = RCD_CONNECTION_STATUS;
} else if (m_args.at(0U) == "hosts") {
if (m_host != NULL) {
m_host->buildNetworkHostsString(replyStr);
}
else {
replyStr = "KO";
}
m_command = RCD_CONFIG_HOSTS;
} else { } else {
replyStr = "KO"; replyStr = "KO";
} }

View File

@@ -38,6 +38,7 @@ enum REMOTE_COMMAND {
RCD_DISABLE_NETWORK5, RCD_DISABLE_NETWORK5,
RCD_DISABLE_XLX, RCD_DISABLE_XLX,
RCD_CONNECTION_STATUS, RCD_CONNECTION_STATUS,
RCD_CONFIG_HOSTS,
RCD_NONE RCD_NONE
}; };