Add new remote command:

- hosts: display connected hosts, or NONE if disconnected (surrounded with double quotes).
Increase buffer size, for reply string, from 100 to 1024.
This commit is contained in:
Daniel Caujolle-Bert 2022-01-21 10:51:41 +00:00
parent e0adf4328b
commit a30ae3af4d
6 changed files with 48 additions and 2 deletions

View File

@ -51,6 +51,7 @@ m_random()
m_addrLen = 0U;
m_linkReflector = new unsigned char[DSTAR_LONG_CALLSIGN_LENGTH];
::memset(m_linkReflector, 0, DSTAR_LONG_CALLSIGN_LENGTH);
std::random_device rd;
std::mt19937 mt(rd());

View File

@ -28,6 +28,7 @@
#include "I2CController.h"
#endif
#include "UDPController.h"
#include "DStarDefines.h"
#include "Version.h"
#include "StopWatch.h"
#include "Defines.h"
@ -2701,3 +2702,37 @@ void CMMDVMHost::buildNetworkStatusString(std::string &str)
str += std::string(" m17:") + (((m_m17Network == NULL) || (m_m17Enabled == false)) ? "n/a" : (m_m17Network->isConnected() ? "conn" : "disc"));
str += std::string(" fm:") + (m_fmEnabled ? "conn" : "n/a");
}
void CMMDVMHost::buildNetworkHostsString(std::string &str)
{
str = "";
std::string dstarReflector;
if (m_dstarEnabled && (m_dstarNetwork != NULL)) {
unsigned char ref[DSTAR_LONG_CALLSIGN_LENGTH + 1];
LINK_STATUS status;
::memset(ref, 0, sizeof(ref));
m_dstarNetwork->getStatus(status, &ref[0]);
switch (status) {
case LINK_STATUS::LS_LINKED_LOOPBACK:
case LINK_STATUS::LS_LINKED_DEXTRA:
case LINK_STATUS::LS_LINKED_DPLUS:
case LINK_STATUS::LS_LINKED_DCS:
case LINK_STATUS::LS_LINKED_CCS:
dstarReflector = std::string((char *)ref);
break;
default:
break;
}
}
str += std::string("dstar:\"") + ((dstarReflector.length() == 0) ? "NONE" : dstarReflector) + "\"";
str += std::string(" dmr:\"") + ((m_dmrEnabled && (m_dmrNetwork != NULL)) ? m_conf.getDMRNetworkRemoteAddress() : "NONE") + "\"";
str += std::string(" ysf:\"") + ((m_ysfEnabled && (m_ysfNetwork != NULL)) ? m_conf.getFusionNetworkGatewayAddress() : "NONE") + "\"";
str += std::string(" p25:\"") + ((m_p25Enabled && (m_p25Network != NULL)) ? m_conf.getP25GatewayAddress() : "NONE") + "\"";
str += std::string(" nxdn:\"") + ((m_nxdnEnabled && (m_nxdnNetwork != NULL)) ? m_conf.getNXDNGatewayAddress() : "NONE") + "\"";
str += std::string(" m17:\"") + ((m_m17Enabled && (m_m17Network != NULL)) ? m_conf.getM17GatewayAddress() : "NONE") + "\"";
str += std::string(" fm:\"") + ((m_fmEnabled && (m_fmNetwork != NULL)) ? m_conf.getFMGatewayAddress() : "NONE") + "\"";
}

View File

@ -57,6 +57,7 @@ public:
int run();
void buildNetworkStatusString(std::string &str);
void buildNetworkHostsString(std::string &str);
private:
CConf m_conf;

View File

@ -25,7 +25,7 @@
#include <chrono>
#include <thread>
const unsigned int BUFFER_LENGTH = 100U;
const unsigned int BUFFER_LENGTH = 1024U;
int main(int argc, char** argv)
{

View File

@ -151,6 +151,14 @@ REMOTE_COMMAND CRemoteControl::getCommand()
}
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 {
replyStr = "KO";
}

View File

@ -56,7 +56,8 @@ enum REMOTE_COMMAND {
RCD_PAGE,
RCD_CW,
RCD_RELOAD,
RCD_CONNECTION_STATUS
RCD_CONNECTION_STATUS,
RCD_CONFIG_HOSTS
};
class CRemoteControl {