Merge branch 'master' into Kenwood

This commit is contained in:
Jonathan Naylor 2020-05-03 18:12:27 +01:00
commit 6afbe5939a
4 changed files with 124 additions and 6 deletions

View File

@ -35,7 +35,8 @@ enum SECTION {
SECTION_LOG,
SECTION_APRS_FI,
SECTION_NETWORK,
SECTION_MOBILE_GPS
SECTION_MOBILE_GPS,
SECTION_REMOTE_COMMANDS
};
CConf::CConf(const std::string& file) :
@ -82,7 +83,9 @@ m_networkInactivityTimeout(0U),
m_networkDebug(false),
m_mobileGPSEnabled(false),
m_mobileGPSAddress(),
m_mobileGPSPort(0U)
m_mobileGPSPort(0U),
m_remoteCommandsEnabled(false),
m_remoteCommandsPort(6075U)
{
}
@ -122,6 +125,8 @@ bool CConf::read()
section = SECTION_NETWORK;
else if (::strncmp(buffer, "[Mobile GPS]", 12U) == 0)
section = SECTION_MOBILE_GPS;
else if (::strncmp(buffer, "[Remote Commands]", 17U) == 0)
section = SECTION_REMOTE_COMMANDS;
else
section = SECTION_NONE;
@ -233,6 +238,11 @@ bool CConf::read()
m_mobileGPSAddress = value;
else if (::strcmp(key, "Port") == 0)
m_mobileGPSPort = (unsigned int)::atoi(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);
}
}
@ -456,3 +466,12 @@ unsigned int CConf::getMobileGPSPort() const
return m_mobileGPSPort;
}
bool CConf::getRemoteCommandsEnabled() const
{
return m_remoteCommandsEnabled;
}
unsigned int CConf::getRemoteCommandsPort() const
{
return m_remoteCommandsPort;
}

View File

@ -85,9 +85,13 @@ public:
bool getNetworkDebug() const;
// The Mobile GPS section
bool getMobileGPSEnabled() const;
std::string getMobileGPSAddress() const;
unsigned int getMobileGPSPort() const;
bool getMobileGPSEnabled() const;
std::string getMobileGPSAddress() const;
unsigned int getMobileGPSPort() const;
// The Remote Commands section
bool getRemoteCommandsEnabled() const;
unsigned int getRemoteCommandsPort() const;
private:
std::string m_file;
@ -141,6 +145,9 @@ private:
bool m_mobileGPSEnabled;
std::string m_mobileGPSAddress;
unsigned int m_mobileGPSPort;
bool m_remoteCommandsEnabled;
unsigned int m_remoteCommandsPort;
};
#endif

View File

@ -29,6 +29,7 @@
#include "Thread.h"
#include "Voice.h"
#include "Timer.h"
#include "Utils.h"
#include "Log.h"
#if defined(_WIN32) || defined(_WIN64)
@ -202,6 +203,16 @@ void CNXDNGateway::run()
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());
if (m_conf.getNetworkParrotPort() > 0U)
reflectors.setParrot(m_conf.getNetworkParrotAddress(), m_conf.getNetworkParrotPort());
@ -257,7 +268,7 @@ void CNXDNGateway::run()
LogMessage("Linked at startup to reflector %u", currentId);
} else {
startupId = 9999U;
startupId = 9999U;
}
}
@ -392,6 +403,79 @@ startupId = 9999U;
localNetwork->write(buffer, length);
}
if (remoteSocket != NULL) {
int res = remoteSocket->read(buffer, 200U, address, port);
if (res > 0) {
buffer[res] = '\0';
if (::memcmp(buffer + 0U, "TalkGroup", 9U) == 0) {
unsigned int tg = (unsigned int)::atoi((char*)(buffer + 9U));
CNXDNReflector* reflector = NULL;
if (tg != 9999U)
reflector = reflectors.find(tg);
if (reflector == NULL && currentId != 9999U) {
LogMessage("Unlinked from reflector %u by remote command", currentId);
if (voice != NULL)
voice->unlinked();
remoteNetwork.writeUnlink(currentAddr, currentPort, currentId);
remoteNetwork.writeUnlink(currentAddr, currentPort, currentId);
remoteNetwork.writeUnlink(currentAddr, currentPort, currentId);
inactivityTimer.stop();
pollTimer.stop();
lostTimer.stop();
currentId = 9999U;
} else if (reflector != NULL && currentId == 9999U) {
currentId = tg;
currentAddr = reflector->m_address;
currentPort = reflector->m_port;
LogMessage("Linked to reflector %u by remote command", currentId);
if (voice != NULL)
voice->linkedTo(currentId);
remoteNetwork.writePoll(currentAddr, currentPort, currentId);
remoteNetwork.writePoll(currentAddr, currentPort, currentId);
remoteNetwork.writePoll(currentAddr, currentPort, currentId);
inactivityTimer.start();
pollTimer.start();
lostTimer.start();
} else if (reflector != NULL && currentId != 9999U) {
LogMessage("Unlinked from reflector %u by remote command", currentId);
remoteNetwork.writeUnlink(currentAddr, currentPort, currentId);
remoteNetwork.writeUnlink(currentAddr, currentPort, currentId);
remoteNetwork.writeUnlink(currentAddr, currentPort, currentId);
currentId = tg;
currentAddr = reflector->m_address;
currentPort = reflector->m_port;
LogMessage("Linked to reflector %u by remote command", currentId);
if (voice != NULL)
voice->linkedTo(currentId);
remoteNetwork.writePoll(currentAddr, currentPort, currentId);
remoteNetwork.writePoll(currentAddr, currentPort, currentId);
remoteNetwork.writePoll(currentAddr, currentPort, currentId);
inactivityTimer.start();
pollTimer.start();
lostTimer.start();
}
} else {
CUtils::dump("Invalid remote command received", buffer, res);
}
}
}
unsigned int ms = stopWatch.elapsed();
stopWatch.start();
@ -482,6 +566,11 @@ startupId = 9999U;
localNetwork->close();
delete localNetwork;
if (remoteSocket != NULL) {
remoteSocket->close();
delete remoteSocket;
}
remoteNetwork.close();
lookup->stop();

View File

@ -58,3 +58,6 @@ Enable=0
Address=127.0.0.1
Port=7834
[Remote Commands]
Enable=0
Port=6075