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