mirror of
https://github.com/ShaYmez/P25Clients.git
synced 2024-11-21 19:55:22 -05:00
Clean up the gateway configuration.
This commit is contained in:
parent
de483c5f51
commit
728c87a8e7
@ -45,8 +45,7 @@ m_lookupName(),
|
||||
m_lookupTime(0U),
|
||||
m_logFilePath(),
|
||||
m_logFileRoot(),
|
||||
m_networkEnabled(false),
|
||||
m_networkDataPort(0U),
|
||||
m_networkPort(0U),
|
||||
m_networkHosts(),
|
||||
m_networkReloadTime(0U),
|
||||
m_networkParrotAddress("127.0.0.1"),
|
||||
@ -120,10 +119,8 @@ bool CConf::read()
|
||||
else if (::strcmp(key, "FileRoot") == 0)
|
||||
m_logFileRoot = value;
|
||||
} else if (section == SECTION_NETWORK) {
|
||||
if (::strcmp(key, "Enable") == 0)
|
||||
m_networkEnabled = ::atoi(value) == 1;
|
||||
else if (::strcmp(key, "DataPort") == 0)
|
||||
m_networkDataPort = (unsigned int)::atoi(value);
|
||||
if (::strcmp(key, "Port") == 0)
|
||||
m_networkPort = (unsigned int)::atoi(value);
|
||||
else if (::strcmp(key, "Hosts") == 0)
|
||||
m_networkHosts = value;
|
||||
else if (::strcmp(key, "ReloadTime") == 0)
|
||||
@ -189,14 +186,9 @@ std::string CConf::getLogFileRoot() const
|
||||
return m_logFileRoot;
|
||||
}
|
||||
|
||||
bool CConf::getNetworkEnabled() const
|
||||
unsigned int CConf::getNetworkPort() const
|
||||
{
|
||||
return m_networkEnabled;
|
||||
}
|
||||
|
||||
unsigned int CConf::getNetworkDataPort() const
|
||||
{
|
||||
return m_networkDataPort;
|
||||
return m_networkPort;
|
||||
}
|
||||
|
||||
std::string CConf::getNetworkHosts() const
|
||||
|
@ -46,8 +46,7 @@ public:
|
||||
std::string getLogFileRoot() const;
|
||||
|
||||
// The Network section
|
||||
bool getNetworkEnabled() const;
|
||||
unsigned int getNetworkDataPort() const;
|
||||
unsigned int getNetworkPort() const;
|
||||
std::string getNetworkHosts() const;
|
||||
unsigned int getNetworkReloadTime() const;
|
||||
std::string getNetworkParrotAddress() const;
|
||||
@ -69,8 +68,7 @@ private:
|
||||
std::string m_logFilePath;
|
||||
std::string m_logFileRoot;
|
||||
|
||||
bool m_networkEnabled;
|
||||
unsigned int m_networkDataPort;
|
||||
unsigned int m_networkPort;
|
||||
std::string m_networkHosts;
|
||||
unsigned int m_networkReloadTime;
|
||||
std::string m_networkParrotAddress;
|
||||
|
@ -161,23 +161,19 @@ void CP25Gateway::run()
|
||||
unsigned int rptPort = m_conf.getRptPort();
|
||||
|
||||
CNetwork localNetwork(m_conf.getMyPort(), m_conf.getCallsign(), false);
|
||||
|
||||
ret = localNetwork.open();
|
||||
if (!ret) {
|
||||
::LogFinalise();
|
||||
return;
|
||||
}
|
||||
|
||||
CNetwork* remoteNetwork = NULL;
|
||||
if (m_conf.getNetworkEnabled()) {
|
||||
remoteNetwork = new CNetwork(m_conf.getNetworkDataPort(), m_conf.getCallsign(), m_conf.getNetworkDebug());
|
||||
ret = remoteNetwork->open();
|
||||
CNetwork remoteNetwork(m_conf.getNetworkPort(), m_conf.getCallsign(), m_conf.getNetworkDebug());
|
||||
ret = remoteNetwork.open();
|
||||
if (!ret) {
|
||||
localNetwork.close();
|
||||
::LogFinalise();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
CReflectors reflectors(m_conf.getNetworkHosts(), m_conf.getNetworkReloadTime());
|
||||
if (m_conf.getNetworkParrotPort() > 0U)
|
||||
@ -202,7 +198,6 @@ void CP25Gateway::run()
|
||||
in_addr currentAddr;
|
||||
unsigned int currentPort = 0U;
|
||||
|
||||
if (remoteNetwork != NULL) {
|
||||
unsigned int id = m_conf.getNetworkStartup();
|
||||
if (id != 9999U) {
|
||||
CP25Reflector* reflector = reflectors.find(id);
|
||||
@ -214,14 +209,13 @@ void CP25Gateway::run()
|
||||
pollTimer.start();
|
||||
lostTimer.start();
|
||||
|
||||
remoteNetwork->writePoll(currentAddr, currentPort);
|
||||
remoteNetwork->writePoll(currentAddr, currentPort);
|
||||
remoteNetwork->writePoll(currentAddr, currentPort);
|
||||
remoteNetwork.writePoll(currentAddr, currentPort);
|
||||
remoteNetwork.writePoll(currentAddr, currentPort);
|
||||
remoteNetwork.writePoll(currentAddr, currentPort);
|
||||
|
||||
LogMessage("Linked at startup to reflector %u", currentId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
unsigned char buffer[200U];
|
||||
@ -229,8 +223,7 @@ void CP25Gateway::run()
|
||||
unsigned int port;
|
||||
|
||||
// From the reflector to the MMDVM
|
||||
if (remoteNetwork != NULL) {
|
||||
unsigned int len = remoteNetwork->readData(buffer, 200U, address, port);
|
||||
unsigned int len = remoteNetwork.readData(buffer, 200U, address, port);
|
||||
if (len > 0U) {
|
||||
// If we're linked and it's from the right place, send it on
|
||||
if (currentId != 9999U && currentAddr.s_addr == address.s_addr && currentPort == port) {
|
||||
@ -252,10 +245,9 @@ void CP25Gateway::run()
|
||||
lostTimer.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// From the MMDVM to the reflector or control data
|
||||
unsigned int len = localNetwork.readData(buffer, 200U, address, port);
|
||||
len = localNetwork.readData(buffer, 200U, address, port);
|
||||
if (len > 0U) {
|
||||
if (buffer[0U] == 0x65U) {
|
||||
dstId = (buffer[1U] << 16) & 0xFF0000U;
|
||||
@ -276,10 +268,11 @@ void CP25Gateway::run()
|
||||
std::string callsign = lookup->find(srcId);
|
||||
LogMessage("Unlinked from reflector %u by %s", currentId, callsign.c_str());
|
||||
|
||||
if (remoteNetwork != NULL && currentId != 9999U) {
|
||||
remoteNetwork->writeUnlink(currentAddr, currentPort);
|
||||
remoteNetwork->writeUnlink(currentAddr, currentPort);
|
||||
remoteNetwork->writeUnlink(currentAddr, currentPort);
|
||||
if (currentId != 9999U) {
|
||||
remoteNetwork.writeUnlink(currentAddr, currentPort);
|
||||
remoteNetwork.writeUnlink(currentAddr, currentPort);
|
||||
remoteNetwork.writeUnlink(currentAddr, currentPort);
|
||||
|
||||
pollTimer.stop();
|
||||
lostTimer.stop();
|
||||
}
|
||||
@ -296,19 +289,18 @@ void CP25Gateway::run()
|
||||
std::string callsign = lookup->find(srcId);
|
||||
LogMessage("Linked to reflector %u by %s", currentId, callsign.c_str());
|
||||
|
||||
if (remoteNetwork != NULL) {
|
||||
remoteNetwork->writePoll(currentAddr, currentPort);
|
||||
remoteNetwork->writePoll(currentAddr, currentPort);
|
||||
remoteNetwork->writePoll(currentAddr, currentPort);
|
||||
remoteNetwork.writePoll(currentAddr, currentPort);
|
||||
remoteNetwork.writePoll(currentAddr, currentPort);
|
||||
remoteNetwork.writePoll(currentAddr, currentPort);
|
||||
|
||||
pollTimer.start();
|
||||
lostTimer.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If we're linked and we have a network, send it on
|
||||
if (currentId != 9999U && remoteNetwork != NULL) {
|
||||
if (currentId != 9999U) {
|
||||
// Rewrite the LCF and the destination TG
|
||||
if (buffer[0U] == 0x64U) {
|
||||
buffer[1U] = 0x00U; // LCF is for TGs
|
||||
@ -318,7 +310,7 @@ void CP25Gateway::run()
|
||||
buffer[3U] = (currentId >> 0) & 0xFFU;
|
||||
}
|
||||
|
||||
remoteNetwork->writeData(buffer, len, currentAddr, currentPort);
|
||||
remoteNetwork.writeData(buffer, len, currentAddr, currentPort);
|
||||
}
|
||||
}
|
||||
|
||||
@ -329,8 +321,8 @@ void CP25Gateway::run()
|
||||
|
||||
pollTimer.clock(ms);
|
||||
if (pollTimer.isRunning() && pollTimer.hasExpired()) {
|
||||
if (currentId != 9999U && remoteNetwork != NULL)
|
||||
remoteNetwork->writePoll(currentAddr, currentPort);
|
||||
if (currentId != 9999U)
|
||||
remoteNetwork.writePoll(currentAddr, currentPort);
|
||||
pollTimer.start();
|
||||
}
|
||||
|
||||
@ -340,6 +332,7 @@ void CP25Gateway::run()
|
||||
LogWarning("No response from %u, unlinking", currentId);
|
||||
currentId = 9999U;
|
||||
}
|
||||
|
||||
lostTimer.stop();
|
||||
}
|
||||
|
||||
@ -354,10 +347,7 @@ void CP25Gateway::run()
|
||||
|
||||
localNetwork.close();
|
||||
|
||||
if (remoteNetwork != NULL) {
|
||||
remoteNetwork->close();
|
||||
delete remoteNetwork;
|
||||
}
|
||||
remoteNetwork.close();
|
||||
|
||||
lookup->stop();
|
||||
|
||||
|
@ -14,8 +14,7 @@ FilePath=.
|
||||
FileRoot=P25Gateway
|
||||
|
||||
[Network]
|
||||
Enable=1
|
||||
DataPort=42010
|
||||
Port=42010
|
||||
Hosts=P25Hosts.txt
|
||||
ReloadTime=60
|
||||
ParrotAddress=127.0.0.1
|
||||
|
Loading…
Reference in New Issue
Block a user