Reinstate the remote command handler.

This commit is contained in:
Jonathan Naylor 2020-10-27 11:34:50 +00:00
parent 26427333c6
commit 60cc911ac3
4 changed files with 128 additions and 2 deletions

View File

@ -35,7 +35,8 @@ enum SECTION {
SECTION_LOG, SECTION_LOG,
SECTION_APRS, SECTION_APRS,
SECTION_NETWORK, SECTION_NETWORK,
SECTION_GPSD SECTION_GPSD,
SECTION_REMOTE_COMMANDS
}; };
CConf::CConf(const std::string& file) : CConf::CConf(const std::string& file) :
@ -84,7 +85,9 @@ m_networkNetHangTime(60U),
m_networkDebug(false), m_networkDebug(false),
m_gpsdEnabled(false), m_gpsdEnabled(false),
m_gpsdAddress(), m_gpsdAddress(),
m_gpsdPort() m_gpsdPort(),
m_remoteCommandsEnabled(false),
m_remoteCommandsPort(6075U)
{ {
} }
@ -124,6 +127,8 @@ bool CConf::read()
section = SECTION_NETWORK; section = SECTION_NETWORK;
else if (::strncmp(buffer, "[GPSD]", 6U) == 0) else if (::strncmp(buffer, "[GPSD]", 6U) == 0)
section = SECTION_GPSD; section = SECTION_GPSD;
else if (::strncmp(buffer, "[Remote Commands]", 17U) == 0)
section = SECTION_REMOTE_COMMANDS;
else else
section = SECTION_NONE; section = SECTION_NONE;
@ -264,6 +269,11 @@ bool CConf::read()
m_gpsdAddress = value; m_gpsdAddress = value;
else if (::strcmp(key, "Port") == 0) else if (::strcmp(key, "Port") == 0)
m_gpsdPort = value; m_gpsdPort = value;
} else if (section == SECTION_REMOTE_COMMANDS) {
if (::strcmp(key, "Enable") == 0)
m_remoteCommandsEnabled = ::atoi(value) == 1;
else if (::strcmp(key, "Port") == 0)
m_remoteCommandsPort = (unsigned int)::atoi(value);
} }
} }
@ -496,3 +506,13 @@ std::string CConf::getGPSDPort() const
{ {
return m_gpsdPort; return m_gpsdPort;
} }
bool CConf::getRemoteCommandsEnabled() const
{
return m_remoteCommandsEnabled;
}
unsigned int CConf::getRemoteCommandsPort() const
{
return m_remoteCommandsPort;
}

View File

@ -91,6 +91,10 @@ public:
std::string getGPSDAddress() const; std::string getGPSDAddress() const;
std::string getGPSDPort() const; std::string getGPSDPort() const;
// The Remote Commands section
bool getRemoteCommandsEnabled() const;
unsigned int getRemoteCommandsPort() const;
private: private:
std::string m_file; std::string m_file;
std::string m_callsign; std::string m_callsign;
@ -145,6 +149,9 @@ private:
bool m_gpsdEnabled; bool m_gpsdEnabled;
std::string m_gpsdAddress; std::string m_gpsdAddress;
std::string m_gpsdPort; std::string m_gpsdPort;
bool m_remoteCommandsEnabled;
unsigned int m_remoteCommandsPort;
}; };
#endif #endif

View File

@ -216,6 +216,16 @@ void CNXDNGateway::run()
return; return;
} }
CUDPSocket* remoteSocket = NULL;
if (m_conf.getRemoteCommandsEnabled()) {
remoteSocket = new CUDPSocket(m_conf.getRemoteCommandsPort());
ret = remoteSocket->open();
if (!ret) {
delete remoteSocket;
remoteSocket = NULL;
}
}
CReflectors reflectors(m_conf.getNetworkHosts1(), m_conf.getNetworkHosts2(), m_conf.getNetworkReloadTime()); CReflectors reflectors(m_conf.getNetworkHosts1(), m_conf.getNetworkHosts2(), m_conf.getNetworkReloadTime());
if (m_conf.getNetworkParrotPort() > 0U) if (m_conf.getNetworkParrotPort() > 0U)
reflectors.setParrot(m_conf.getNetworkParrotAddress(), m_conf.getNetworkParrotPort()); reflectors.setParrot(m_conf.getNetworkParrotAddress(), m_conf.getNetworkParrotPort());
@ -402,6 +412,8 @@ void CNXDNGateway::run()
hangTimer.setTimeout(rfHangTime); hangTimer.setTimeout(rfHangTime);
hangTimer.start(); hangTimer.start();
} else {
hangTimer.stop();
} }
if (voice != NULL) { if (voice != NULL) {
@ -455,6 +467,84 @@ void CNXDNGateway::run()
localNetwork->write(buffer, length); localNetwork->write(buffer, length);
} }
if (remoteSocket != NULL) {
sockaddr_storage addr;
unsigned int addrLen;
int res = remoteSocket->read(buffer, 200U, addr, addrLen);
if (res > 0) {
buffer[res] = '\0';
if (::memcmp(buffer + 0U, "TalkGroup", 9U) == 0) {
unsigned int tg = (unsigned int)::atoi((char*)(buffer + 9U));
if (tg != currentTG) {
if (currentAddrLen > 0U) {
LogMessage("Unlinked from reflector %u by remote command", currentTG);
if (!currentIsStatic) {
remoteNetwork.writeUnlink(currentAddr, currentAddrLen, currentTG);
remoteNetwork.writeUnlink(currentAddr, currentAddrLen, currentTG);
remoteNetwork.writeUnlink(currentAddr, currentAddrLen, currentTG);
}
hangTimer.stop();
}
const CStaticTG* found = NULL;
for (std::vector<CStaticTG>::const_iterator it = staticTGs.cbegin(); it != staticTGs.cend(); ++it) {
if (tg == (*it).m_tg) {
found = &(*it);
break;
}
}
if (found == NULL) {
CNXDNReflector* refl = reflectors.find(tg);
if (refl != NULL) {
currentTG = tg;
currentAddr = refl->m_addr;
currentAddrLen = refl->m_addrLen;
currentIsStatic = false;
} else {
currentTG = tg;
currentAddrLen = 0U;
currentIsStatic = false;
}
} else {
currentTG = found->m_tg;
currentAddr = found->m_addr;
currentAddrLen = found->m_addrLen;
currentIsStatic = true;
}
// Link to the new reflector
if (currentAddrLen > 0U) {
LogMessage("Switched to reflector %u by remote command", currentTG);
if (!currentIsStatic) {
remoteNetwork.writePoll(currentAddr, currentAddrLen, currentTG);
remoteNetwork.writePoll(currentAddr, currentAddrLen, currentTG);
remoteNetwork.writePoll(currentAddr, currentAddrLen, currentTG);
}
hangTimer.setTimeout(rfHangTime);
hangTimer.start();
} else {
hangTimer.stop();
}
if (voice != NULL) {
if (currentAddrLen == 0U)
voice->unlinked();
else
voice->linkedTo(currentTG);
}
}
} else {
CUtils::dump("Invalid remote command received", buffer, res);
}
}
}
unsigned int ms = stopWatch.elapsed(); unsigned int ms = stopWatch.elapsed();
stopWatch.start(); stopWatch.start();
@ -512,6 +602,11 @@ void CNXDNGateway::run()
localNetwork->close(); localNetwork->close();
delete localNetwork; delete localNetwork;
if (remoteSocket != NULL) {
remoteSocket->close();
delete remoteSocket;
}
remoteNetwork.close(); remoteNetwork.close();
lookup->stop(); lookup->stop();

View File

@ -70,3 +70,7 @@ Debug=0
Enable=0 Enable=0
Address=127.0.0.1 Address=127.0.0.1
Port=2947 Port=2947
[Remote Commands]
Enable=0
Port=6075