Fix the NXCore to NXDN network transfer.

This commit is contained in:
Jonathan Naylor 2018-03-19 19:03:06 +00:00
parent 788cc74c5f
commit d0eb3802bc
3 changed files with 46 additions and 4 deletions

View File

@ -53,6 +53,42 @@ bool CNXDNNetwork::write(const unsigned char* data, unsigned int length, const i
return m_socket.write(data, length, address, port);
}
bool CNXDNNetwork::write(const unsigned char* data, unsigned int length, unsigned short srcId, unsigned short dstId, bool grp, const in_addr& address, unsigned int port)
{
assert(data != NULL);
assert(length > 0U);
assert(port > 0U);
unsigned char buffer[50U];
buffer[0U] = 'N';
buffer[1U] = 'X';
buffer[2U] = 'D';
buffer[3U] = 'N';
buffer[4U] = 'D';
buffer[5U] = (srcId >> 8) & 0xFFU;
buffer[6U] = (srcId >> 0) & 0xFFU;
buffer[7U] = (dstId >> 8) & 0xFFU;
buffer[8U] = (dstId >> 0) & 0xFFU;
buffer[9U] = 0x00U;
buffer[9U] |= grp ? 0x01U : 0x00U;
if (data[0U] == 0x81U || data[0U] == 0x83U) {
buffer[9U] |= data[5U] == 0x01U ? 0x04U : 0x00U;
buffer[9U] |= data[5U] == 0x08U ? 0x08U : 0x00U;
}
::memcpy(buffer + 10U, data, 33U);
if (m_debug)
CUtils::dump(1U, "NXDN Network Data Sent", buffer, 43U);
return m_socket.write(buffer, 43U, address, port);
}
unsigned int CNXDNNetwork::read(unsigned char* data, unsigned int length, in_addr& address, unsigned int& port)
{
assert(data != NULL);

View File

@ -32,6 +32,7 @@ public:
bool open();
bool write(const unsigned char* data, unsigned int length, const in_addr& address, unsigned int port);
bool write(const unsigned char* data, unsigned int length, unsigned short srcId, unsigned short dstId, bool grp, const in_addr& address, unsigned int port);
unsigned int read(unsigned char* data, unsigned int length, in_addr& address, unsigned int& port);

View File

@ -194,6 +194,10 @@ void CNXDNReflector::run()
CNXDNRepeater* current = NULL;
bool nxCore = false;
unsigned short srcId = 0U;
unsigned short dstId = 0U;
bool grp = false;
CTimer watchdogTimer(1000U, 0U, 1500U);
for (;;) {
@ -282,9 +286,10 @@ void CNXDNReflector::run()
if (current == NULL) {
if (!nxCore) {
if ((buffer[0U] == 0x81U || buffer[0U] == 0x83U) && buffer[5U] == 0x01U) {
bool grp = (buffer[7U] & 0x20U) == 0x20U;
unsigned short srcId = (buffer[8U] << 8) | buffer[9U];
unsigned short dstId = (buffer[10U] << 8) | buffer[11U];
// Save the grp, src and dest for use in the NXDN Protocol messages
grp = (buffer[7U] & 0x20U) == 0x20U;
srcId = (buffer[8U] << 8) | buffer[9U];
dstId = (buffer[10U] << 8) | buffer[11U];
std::string callsign = lookup->find(srcId);
LogMessage("Transmission from %s at NXCore to %s%u", callsign.c_str(), grp ? "TG " : "", dstId);
@ -299,7 +304,7 @@ void CNXDNReflector::run()
for (std::vector<CNXDNRepeater*>::const_iterator it = m_repeaters.begin(); it != m_repeaters.end(); ++it) {
in_addr addr = (*it)->m_address;
unsigned int prt = (*it)->m_port;
nxdnNetwork.write(buffer, len, addr, prt);
nxdnNetwork.write(buffer, len, srcId, dstId, grp, addr, prt);
}
if ((buffer[0U] == 0x81U || buffer[0U] == 0x83U) && buffer[5U] == 0x08U) {