mirror of
https://github.com/ShaYmez/NXDNClients.git
synced 2024-12-01 11:30:37 -05:00
Add NXCore control via private TGs.
This commit is contained in:
parent
58109e2faa
commit
e14ecebb62
@ -48,6 +48,8 @@ m_networkPort(0U),
|
|||||||
m_networkDebug(false),
|
m_networkDebug(false),
|
||||||
m_nxCoreEnabled(false),
|
m_nxCoreEnabled(false),
|
||||||
m_nxCoreAddress(),
|
m_nxCoreAddress(),
|
||||||
|
m_nxCoreTGEnable(0U),
|
||||||
|
m_nxCoreTGDisable(0U),
|
||||||
m_nxCoreDebug(false)
|
m_nxCoreDebug(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -120,6 +122,10 @@ bool CConf::read()
|
|||||||
m_nxCoreEnabled = ::atoi(value) == 1;
|
m_nxCoreEnabled = ::atoi(value) == 1;
|
||||||
else if (::strcmp(key, "Address") == 0)
|
else if (::strcmp(key, "Address") == 0)
|
||||||
m_nxCoreAddress = value;
|
m_nxCoreAddress = value;
|
||||||
|
else if (::strcmp(key, "TGEnable") == 0)
|
||||||
|
m_nxCoreTGEnable = (unsigned short)::atoi(value);
|
||||||
|
else if (::strcmp(key, "TGDisable") == 0)
|
||||||
|
m_nxCoreTGDisable = (unsigned short)::atoi(value);
|
||||||
else if (::strcmp(key, "Debug") == 0)
|
else if (::strcmp(key, "Debug") == 0)
|
||||||
m_nxCoreDebug = ::atoi(value) == 1;
|
m_nxCoreDebug = ::atoi(value) == 1;
|
||||||
}
|
}
|
||||||
@ -185,6 +191,16 @@ std::string CConf::getNXCoreAddress() const
|
|||||||
return m_nxCoreAddress;
|
return m_nxCoreAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned short CConf::getNXCoreTGEnable() const
|
||||||
|
{
|
||||||
|
return m_nxCoreTGEnable;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned short CConf::getNXCoreTGDisable() const
|
||||||
|
{
|
||||||
|
return m_nxCoreTGDisable;
|
||||||
|
}
|
||||||
|
|
||||||
bool CConf::getNXCoreDebug() const
|
bool CConf::getNXCoreDebug() const
|
||||||
{
|
{
|
||||||
return m_nxCoreDebug;
|
return m_nxCoreDebug;
|
||||||
|
@ -50,6 +50,8 @@ public:
|
|||||||
// The NXCore section
|
// The NXCore section
|
||||||
bool getNXCoreEnabled() const;
|
bool getNXCoreEnabled() const;
|
||||||
std::string getNXCoreAddress() const;
|
std::string getNXCoreAddress() const;
|
||||||
|
unsigned short getNXCoreTGEnable() const;
|
||||||
|
unsigned short getNXCoreTGDisable() const;
|
||||||
bool getNXCoreDebug() const;
|
bool getNXCoreDebug() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -69,6 +71,8 @@ private:
|
|||||||
|
|
||||||
bool m_nxCoreEnabled;
|
bool m_nxCoreEnabled;
|
||||||
std::string m_nxCoreAddress;
|
std::string m_nxCoreAddress;
|
||||||
|
unsigned short m_nxCoreTGEnable;
|
||||||
|
unsigned short m_nxCoreTGDisable;
|
||||||
bool m_nxCoreDebug;
|
bool m_nxCoreDebug;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "NXCoreNetwork.h"
|
|
||||||
#include "NXDNReflector.h"
|
#include "NXDNReflector.h"
|
||||||
#include "NXDNNetwork.h"
|
#include "NXDNNetwork.h"
|
||||||
#include "NXDNLookup.h"
|
#include "NXDNLookup.h"
|
||||||
@ -80,6 +79,7 @@ int main(int argc, char** argv)
|
|||||||
|
|
||||||
CNXDNReflector::CNXDNReflector(const std::string& file) :
|
CNXDNReflector::CNXDNReflector(const std::string& file) :
|
||||||
m_conf(file),
|
m_conf(file),
|
||||||
|
m_nxCoreNetwork(NULL),
|
||||||
m_repeaters()
|
m_repeaters()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -168,16 +168,19 @@ void CNXDNReflector::run()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CNXCoreNetwork* nxCoreNetwork = NULL;
|
unsigned short nxCoreTGEnable = 0U;
|
||||||
|
unsigned short nxCoreTGDisable = 0U;
|
||||||
|
|
||||||
if (m_conf.getNXCoreEnabled()) {
|
if (m_conf.getNXCoreEnabled()) {
|
||||||
nxCoreNetwork = new CNXCoreNetwork(m_conf.getNXCoreAddress(), m_conf.getNXCoreDebug());
|
ret = openNXCore();
|
||||||
ret = nxCoreNetwork->open();
|
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
nxdnNetwork.close();
|
nxdnNetwork.close();
|
||||||
delete nxCoreNetwork;
|
|
||||||
::LogFinalise();
|
::LogFinalise();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nxCoreTGEnable = m_conf.getNXCoreTGEnable();
|
||||||
|
nxCoreTGDisable = m_conf.getNXCoreTGDisable();
|
||||||
}
|
}
|
||||||
|
|
||||||
CNXDNLookup* lookup = new CNXDNLookup(m_conf.getLookupName(), m_conf.getLookupTime());
|
CNXDNLookup* lookup = new CNXDNLookup(m_conf.getLookupName(), m_conf.getLookupTime());
|
||||||
@ -192,7 +195,7 @@ void CNXDNReflector::run()
|
|||||||
LogMessage("Starting NXDNReflector-%s", VERSION);
|
LogMessage("Starting NXDNReflector-%s", VERSION);
|
||||||
|
|
||||||
CNXDNRepeater* current = NULL;
|
CNXDNRepeater* current = NULL;
|
||||||
bool nxCore = false;
|
bool nxCoreActive = false;
|
||||||
|
|
||||||
unsigned short srcId = 0U;
|
unsigned short srcId = 0U;
|
||||||
unsigned short dstId = 0U;
|
unsigned short dstId = 0U;
|
||||||
@ -241,15 +244,28 @@ void CNXDNReflector::run()
|
|||||||
}
|
}
|
||||||
} else if (::memcmp(buffer, "NXDND", 5U) == 0 && len == 43U) {
|
} else if (::memcmp(buffer, "NXDND", 5U) == 0 && len == 43U) {
|
||||||
if (rpt != NULL) {
|
if (rpt != NULL) {
|
||||||
rpt->m_timer.start();
|
|
||||||
|
|
||||||
if (current == NULL && !nxCore) {
|
|
||||||
current = rpt;
|
|
||||||
|
|
||||||
unsigned short srcId = (buffer[5U] << 8) | buffer[6U];
|
unsigned short srcId = (buffer[5U] << 8) | buffer[6U];
|
||||||
unsigned short dstId = (buffer[7U] << 8) | buffer[8U];
|
unsigned short dstId = (buffer[7U] << 8) | buffer[8U];
|
||||||
bool grp = (buffer[9U] & 0x01U) == 0x01U;
|
bool grp = (buffer[9U] & 0x01U) == 0x01U;
|
||||||
|
|
||||||
|
if (nxCoreTGEnable != 0U && grp && dstId == nxCoreTGEnable) {
|
||||||
|
if (m_nxCoreNetwork == NULL) {
|
||||||
|
std::string callsign = lookup->find(srcId);
|
||||||
|
LogMessage("NXCore link enabled by %s at %s", callsign.c_str(), current->m_callsign.c_str());
|
||||||
|
openNXCore();
|
||||||
|
}
|
||||||
|
} else if (nxCoreTGDisable != 0U && grp && dstId == nxCoreTGDisable) {
|
||||||
|
if (m_nxCoreNetwork != NULL) {
|
||||||
|
std::string callsign = lookup->find(srcId);
|
||||||
|
LogMessage("NXCore link disabled by %s at %s", callsign.c_str(), current->m_callsign.c_str());
|
||||||
|
closeNXCore();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
rpt->m_timer.start();
|
||||||
|
|
||||||
|
if (current == NULL && !nxCoreActive) {
|
||||||
|
current = rpt;
|
||||||
|
|
||||||
std::string callsign = lookup->find(srcId);
|
std::string callsign = lookup->find(srcId);
|
||||||
LogMessage("Transmission from %s at %s to %s%u", callsign.c_str(), current->m_callsign.c_str(), grp ? "TG " : "", dstId);
|
LogMessage("Transmission from %s at %s to %s%u", callsign.c_str(), current->m_callsign.c_str(), grp ? "TG " : "", dstId);
|
||||||
}
|
}
|
||||||
@ -263,8 +279,8 @@ void CNXDNReflector::run()
|
|||||||
if (addr.s_addr != address.s_addr || prt != port)
|
if (addr.s_addr != address.s_addr || prt != port)
|
||||||
nxdnNetwork.write(buffer, len, addr, prt);
|
nxdnNetwork.write(buffer, len, addr, prt);
|
||||||
|
|
||||||
if (nxCoreNetwork != NULL)
|
if (m_nxCoreNetwork != NULL)
|
||||||
nxCoreNetwork->write(buffer, len);
|
m_nxCoreNetwork->write(buffer, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((buffer[9U] & 0x08U) == 0x08U) {
|
if ((buffer[9U] & 0x08U) == 0x08U) {
|
||||||
@ -273,6 +289,7 @@ void CNXDNReflector::run()
|
|||||||
current = NULL;
|
current = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
LogMessage("Data received from an unknown source - %s:%u", ::inet_ntoa(address), port);
|
LogMessage("Data received from an unknown source - %s:%u", ::inet_ntoa(address), port);
|
||||||
CUtils::dump(2U, "Data", buffer, len);
|
CUtils::dump(2U, "Data", buffer, len);
|
||||||
@ -280,11 +297,11 @@ void CNXDNReflector::run()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nxCoreNetwork != NULL) {
|
if (m_nxCoreNetwork != NULL) {
|
||||||
len = nxCoreNetwork->read(buffer, 200U);
|
len = m_nxCoreNetwork->read(buffer, 200U);
|
||||||
if (len > 0U) {
|
if (len > 0U) {
|
||||||
if (current == NULL) {
|
if (current == NULL) {
|
||||||
if (!nxCore) {
|
if (!nxCoreActive) {
|
||||||
if ((buffer[0U] == 0x81U || buffer[0U] == 0x83U) && buffer[5U] == 0x01U) {
|
if ((buffer[0U] == 0x81U || buffer[0U] == 0x83U) && buffer[5U] == 0x01U) {
|
||||||
// Save the grp, src and dest for use in the NXDN Protocol messages
|
// Save the grp, src and dest for use in the NXDN Protocol messages
|
||||||
grp = (buffer[7U] & 0x20U) == 0x20U;
|
grp = (buffer[7U] & 0x20U) == 0x20U;
|
||||||
@ -294,11 +311,11 @@ void CNXDNReflector::run()
|
|||||||
std::string callsign = lookup->find(srcId);
|
std::string callsign = lookup->find(srcId);
|
||||||
LogMessage("Transmission from %s at NXCore to %s%u", callsign.c_str(), grp ? "TG " : "", dstId);
|
LogMessage("Transmission from %s at NXCore to %s%u", callsign.c_str(), grp ? "TG " : "", dstId);
|
||||||
|
|
||||||
nxCore = true;
|
nxCoreActive = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nxCore) {
|
if (nxCoreActive) {
|
||||||
watchdogTimer.start();
|
watchdogTimer.start();
|
||||||
|
|
||||||
for (std::vector<CNXDNRepeater*>::const_iterator it = m_repeaters.begin(); it != m_repeaters.end(); ++it) {
|
for (std::vector<CNXDNRepeater*>::const_iterator it = m_repeaters.begin(); it != m_repeaters.end(); ++it) {
|
||||||
@ -309,7 +326,7 @@ void CNXDNReflector::run()
|
|||||||
|
|
||||||
if ((buffer[0U] == 0x81U || buffer[0U] == 0x83U) && buffer[5U] == 0x08U) {
|
if ((buffer[0U] == 0x81U || buffer[0U] == 0x83U) && buffer[5U] == 0x08U) {
|
||||||
LogMessage("Received end of transmission");
|
LogMessage("Received end of transmission");
|
||||||
nxCore = false;
|
nxCoreActive = false;
|
||||||
watchdogTimer.stop();
|
watchdogTimer.stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -342,7 +359,7 @@ void CNXDNReflector::run()
|
|||||||
LogMessage("Network watchdog has expired");
|
LogMessage("Network watchdog has expired");
|
||||||
watchdogTimer.stop();
|
watchdogTimer.stop();
|
||||||
current = NULL;
|
current = NULL;
|
||||||
nxCore = false;
|
nxCoreActive = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
dumpTimer.clock(ms);
|
dumpTimer.clock(ms);
|
||||||
@ -351,8 +368,8 @@ void CNXDNReflector::run()
|
|||||||
dumpTimer.start();
|
dumpTimer.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nxCoreNetwork != NULL)
|
if (m_nxCoreNetwork != NULL)
|
||||||
nxCoreNetwork->clock(ms);
|
m_nxCoreNetwork->clock(ms);
|
||||||
|
|
||||||
if (ms < 5U)
|
if (ms < 5U)
|
||||||
CThread::sleep(5U);
|
CThread::sleep(5U);
|
||||||
@ -360,10 +377,7 @@ void CNXDNReflector::run()
|
|||||||
|
|
||||||
nxdnNetwork.close();
|
nxdnNetwork.close();
|
||||||
|
|
||||||
if (nxCoreNetwork != NULL) {
|
closeNXCore();
|
||||||
nxCoreNetwork->close();
|
|
||||||
delete nxCoreNetwork;
|
|
||||||
}
|
|
||||||
|
|
||||||
lookup->stop();
|
lookup->stop();
|
||||||
|
|
||||||
@ -398,3 +412,25 @@ void CNXDNReflector::dumpRepeaters() const
|
|||||||
LogMessage(" %s (%s:%u) %u/%u", callsign.c_str(), ::inet_ntoa(address), port, timer, timeout);
|
LogMessage(" %s (%s:%u) %u/%u", callsign.c_str(), ::inet_ntoa(address), port, timer, timeout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CNXDNReflector::openNXCore()
|
||||||
|
{
|
||||||
|
m_nxCoreNetwork = new CNXCoreNetwork(m_conf.getNXCoreAddress(), m_conf.getNXCoreDebug());
|
||||||
|
bool ret = m_nxCoreNetwork->open();
|
||||||
|
if (!ret) {
|
||||||
|
delete m_nxCoreNetwork;
|
||||||
|
m_nxCoreNetwork = NULL;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CNXDNReflector::closeNXCore()
|
||||||
|
{
|
||||||
|
if (m_nxCoreNetwork != NULL) {
|
||||||
|
m_nxCoreNetwork->close();
|
||||||
|
delete m_nxCoreNetwork;
|
||||||
|
m_nxCoreNetwork = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#if !defined(NXDNReflector_H)
|
#if !defined(NXDNReflector_H)
|
||||||
#define NXDNReflector_H
|
#define NXDNReflector_H
|
||||||
|
|
||||||
|
#include "NXCoreNetwork.h"
|
||||||
#include "Timer.h"
|
#include "Timer.h"
|
||||||
#include "Conf.h"
|
#include "Conf.h"
|
||||||
|
|
||||||
@ -64,10 +65,14 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
CConf m_conf;
|
CConf m_conf;
|
||||||
|
CNXCoreNetwork* m_nxCoreNetwork;
|
||||||
std::vector<CNXDNRepeater*> m_repeaters;
|
std::vector<CNXDNRepeater*> m_repeaters;
|
||||||
|
|
||||||
CNXDNRepeater* findRepeater(const in_addr& address, unsigned int port) const;
|
CNXDNRepeater* findRepeater(const in_addr& address, unsigned int port) const;
|
||||||
void dumpRepeaters() const;
|
void dumpRepeaters() const;
|
||||||
|
|
||||||
|
bool openNXCore();
|
||||||
|
void closeNXCore();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -20,4 +20,6 @@ Debug=0
|
|||||||
Enabled=0
|
Enabled=0
|
||||||
# Address=208.111.3.45
|
# Address=208.111.3.45
|
||||||
Address=44.131.4.1
|
Address=44.131.4.1
|
||||||
|
# TGEnable=1234
|
||||||
|
# TGDisable=3456
|
||||||
Debug=0
|
Debug=0
|
||||||
|
Loading…
Reference in New Issue
Block a user