From 98a31e8d205df61d6ef8830edb11ec778d22aab1 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Mon, 12 Mar 2018 20:55:53 +0000 Subject: [PATCH] Allow more control over NXDN networking. --- Conf.cpp | 34 +++++++++++++++++++++++++++++----- Conf.h | 10 ++++++++-- MMDVM.ini | 5 ++++- MMDVMHost.cpp | 16 +++++++++++----- NXDNDefines.h | 2 -- NXDNNetwork.cpp | 16 ++++++++++------ NXDNNetwork.h | 3 ++- 7 files changed, 64 insertions(+), 22 deletions(-) diff --git a/Conf.cpp b/Conf.cpp index 18bd2da66..4c308e9bb 100644 --- a/Conf.cpp +++ b/Conf.cpp @@ -183,7 +183,10 @@ m_p25LocalPort(0U), m_p25NetworkModeHang(3U), m_p25NetworkDebug(false), m_nxdnNetworkEnabled(false), -m_nxdnNetworkAddress(), +m_nxdnGatewayAddress(), +m_nxdnGatewayPort(0U), +m_nxdnLocalAddress(), +m_nxdnLocalPort(0U), m_nxdnNetworkModeHang(3U), m_nxdnNetworkDebug(false), m_tftSerialPort("/dev/ttyAMA0"), @@ -631,8 +634,14 @@ bool CConf::read() } else if (section == SECTION_NXDN_NETWORK) { if (::strcmp(key, "Enable") == 0) m_nxdnNetworkEnabled = ::atoi(value) == 1; - else if (::strcmp(key, "Address") == 0) - m_nxdnNetworkAddress = value; + else if (::strcmp(key, "LocalAddress") == 0) + m_nxdnLocalAddress = value; + else if (::strcmp(key, "LocalPort") == 0) + m_nxdnLocalPort = (unsigned int)::atoi(value); + else if (::strcmp(key, "GatewayAddress") == 0) + m_nxdnGatewayAddress = value; + else if (::strcmp(key, "GatewayPort") == 0) + m_nxdnGatewayPort = (unsigned int)::atoi(value); else if (::strcmp(key, "ModeHang") == 0) m_nxdnNetworkModeHang = (unsigned int)::atoi(value); else if (::strcmp(key, "Debug") == 0) @@ -1342,9 +1351,24 @@ bool CConf::getNXDNNetworkEnabled() const return m_nxdnNetworkEnabled; } -std::string CConf::getNXDNNetworkAddress() const +std::string CConf::getNXDNGatewayAddress() const +{ + return m_nxdnGatewayAddress; +} + +unsigned int CConf::getNXDNGatewayPort() const +{ + return m_nxdnGatewayPort; +} + +std::string CConf::getNXDNLocalAddress() const +{ + return m_nxdnLocalAddress; +} + +unsigned int CConf::getNXDNLocalPort() const { - return m_nxdnNetworkAddress; + return m_nxdnLocalPort; } unsigned int CConf::getNXDNNetworkModeHang() const diff --git a/Conf.h b/Conf.h index d13d024f7..4add05f6d 100644 --- a/Conf.h +++ b/Conf.h @@ -191,7 +191,10 @@ class CConf // The NXDN Network section bool getNXDNNetworkEnabled() const; - std::string getNXDNNetworkAddress() const; + std::string getNXDNGatewayAddress() const; + unsigned int getNXDNGatewayPort() const; + std::string getNXDNLocalAddress() const; + unsigned int getNXDNLocalPort() const; unsigned int getNXDNNetworkModeHang() const; bool getNXDNNetworkDebug() const; @@ -378,7 +381,10 @@ class CConf bool m_p25NetworkDebug; bool m_nxdnNetworkEnabled; - std::string m_nxdnNetworkAddress; + std::string m_nxdnGatewayAddress; + unsigned int m_nxdnGatewayPort; + std::string m_nxdnLocalAddress; + unsigned int m_nxdnLocalPort; unsigned int m_nxdnNetworkModeHang; bool m_nxdnNetworkDebug; diff --git a/MMDVM.ini b/MMDVM.ini index ecc5ba02f..2f2b385b9 100644 --- a/MMDVM.ini +++ b/MMDVM.ini @@ -160,7 +160,10 @@ Debug=0 [NXDN Network] Enable=1 -Address=127.0.0.1 +LocalAddress=127.0.0.1 +LocalPort=14021 +RemoteAddress=127.0.0.1 +RemotePort=14020 # ModeHang=3 Debug=0 diff --git a/MMDVMHost.cpp b/MMDVMHost.cpp index e646c1234..b71336dbc 100644 --- a/MMDVMHost.cpp +++ b/MMDVMHost.cpp @@ -1159,15 +1159,21 @@ bool CMMDVMHost::createP25Network() bool CMMDVMHost::createNXDNNetwork() { - std::string address = m_conf.getNXDNNetworkAddress(); - m_nxdnNetModeHang = m_conf.getNXDNNetworkModeHang(); - bool debug = m_conf.getNXDNNetworkDebug(); + std::string gatewayAddress = m_conf.getNXDNGatewayAddress(); + unsigned int gatewayPort = m_conf.getNXDNGatewayPort(); + std::string localAddress = m_conf.getNXDNLocalAddress(); + unsigned int localPort = m_conf.getNXDNLocalPort(); + m_nxdnNetModeHang = m_conf.getNXDNNetworkModeHang(); + bool debug = m_conf.getNXDNNetworkDebug(); LogInfo("NXDN Network Parameters"); - LogInfo(" Address: %s", address.c_str()); + LogInfo(" Gateway Address: %s", gatewayAddress.c_str()); + LogInfo(" Gateway Port: %u", gatewayPort); + LogInfo(" Local Address: %s", localAddress.c_str()); + LogInfo(" Local Port: %u", localPort); LogInfo(" Mode Hang: %us", m_nxdnNetModeHang); - m_nxdnNetwork = new CNXDNNetwork(address, debug); + m_nxdnNetwork = new CNXDNNetwork(localAddress, localPort, gatewayAddress, gatewayPort, debug); bool ret = m_nxdnNetwork->open(); if (!ret) { diff --git a/NXDNDefines.h b/NXDNDefines.h index 9aaeb8fda..31291c492 100644 --- a/NXDNDefines.h +++ b/NXDNDefines.h @@ -99,6 +99,4 @@ const unsigned char NXDN_DATA_CALL_OPTION_9600 = 0x02U; const unsigned char SACCH_IDLE[] = { NXDN_MESSAGE_TYPE_IDLE, 0x00U, 0x00U }; -const unsigned int NXCORE_ICOM_PORT = 41300U; - #endif diff --git a/NXDNNetwork.cpp b/NXDNNetwork.cpp index 25464cbc1..04703b0b2 100644 --- a/NXDNNetwork.cpp +++ b/NXDNNetwork.cpp @@ -28,14 +28,18 @@ const unsigned int BUFFER_LENGTH = 200U; -CNXDNNetwork::CNXDNNetwork(const std::string& address, bool debug) : -m_socket("", NXCORE_ICOM_PORT), +CNXDNNetwork::CNXDNNetwork(const std::string& localAddress, unsigned int localPort, const std::string& gatewayAddress, unsigned int gatewayPort, bool debug) : +m_socket(localAddress, localPort), m_address(), +m_port(gatewayPort), m_debug(debug), m_enabled(false), m_buffer(1000U, "NXDN Network") { - m_address = CUDPSocket::lookup(address); + assert(gatewayPort > 0U); + assert(!gatewayAddress.empty()); + + m_address = CUDPSocket::lookup(gatewayAddress); } CNXDNNetwork::~CNXDNNetwork() @@ -77,7 +81,7 @@ bool CNXDNNetwork::write(const unsigned char* data, bool single) if (m_debug) CUtils::dump(1U, "NXDN Network Data Sent", buffer, 102U); - return m_socket.write(buffer, 102U, m_address, NXCORE_ICOM_PORT); + return m_socket.write(buffer, 102U, m_address, m_port); } void CNXDNNetwork::clock(unsigned int ms) @@ -91,8 +95,8 @@ void CNXDNNetwork::clock(unsigned int ms) return; // Check if the data is for us - if (m_address.s_addr != address.s_addr || port != NXCORE_ICOM_PORT) { - LogMessage("NXDN packet received from an invalid source, %08X != %08X and/or %u != %u", m_address.s_addr, address.s_addr, NXCORE_ICOM_PORT, port); + if (m_address.s_addr != address.s_addr || port != m_port) { + LogMessage("NXDN packet received from an invalid source, %08X != %08X and/or %u != %u", m_address.s_addr, address.s_addr, m_port, port); return; } diff --git a/NXDNNetwork.h b/NXDNNetwork.h index f640e5e02..4a6c05383 100644 --- a/NXDNNetwork.h +++ b/NXDNNetwork.h @@ -29,7 +29,7 @@ class CNXDNNetwork { public: - CNXDNNetwork(const std::string& address, bool debug); + CNXDNNetwork(const std::string& localAddress, unsigned int localPort, const std::string& gatewayAddress, unsigned int gatewayPort, bool debug); ~CNXDNNetwork(); bool open(); @@ -49,6 +49,7 @@ class CNXDNNetwork { private: CUDPSocket m_socket; in_addr m_address; + unsigned int m_port; bool m_debug; bool m_enabled; CRingBuffer m_buffer;