Allow more control over NXDN networking.

This commit is contained in:
Jonathan Naylor 2018-03-12 20:55:53 +00:00
parent 6fe81109fd
commit 98a31e8d20
7 changed files with 64 additions and 22 deletions

View File

@ -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_nxdnNetworkAddress;
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_nxdnLocalPort;
}
unsigned int CConf::getNXDNNetworkModeHang() const

10
Conf.h
View File

@ -191,7 +191,10 @@ public:
// 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 @@ private:
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;

View File

@ -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

View File

@ -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) {

View File

@ -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

View File

@ -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;
}

View File

@ -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 @@ public:
private:
CUDPSocket m_socket;
in_addr m_address;
unsigned int m_port;
bool m_debug;
bool m_enabled;
CRingBuffer<unsigned char> m_buffer;