From d0eb3802bccc036358a4a27367ec1ea64dbf786e Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Mon, 19 Mar 2018 19:03:06 +0000 Subject: [PATCH] Fix the NXCore to NXDN network transfer. --- NXDNReflector/NXDNNetwork.cpp | 36 +++++++++++++++++++++++++++++++++ NXDNReflector/NXDNNetwork.h | 1 + NXDNReflector/NXDNReflector.cpp | 13 ++++++++---- 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/NXDNReflector/NXDNNetwork.cpp b/NXDNReflector/NXDNNetwork.cpp index 75f25a6..091b82a 100644 --- a/NXDNReflector/NXDNNetwork.cpp +++ b/NXDNReflector/NXDNNetwork.cpp @@ -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); diff --git a/NXDNReflector/NXDNNetwork.h b/NXDNReflector/NXDNNetwork.h index a037b34..174a7be 100644 --- a/NXDNReflector/NXDNNetwork.h +++ b/NXDNReflector/NXDNNetwork.h @@ -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); diff --git a/NXDNReflector/NXDNReflector.cpp b/NXDNReflector/NXDNReflector.cpp index ce15dce..6f15a7a 100644 --- a/NXDNReflector/NXDNReflector.cpp +++ b/NXDNReflector/NXDNReflector.cpp @@ -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::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) {