Skip to content

Commit 98a31e8

Browse files
committed
Allow more control over NXDN networking.
1 parent 6fe8110 commit 98a31e8

File tree

7 files changed

+64
-22
lines changed

7 files changed

+64
-22
lines changed

Conf.cpp

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,10 @@ m_p25LocalPort(0U),
183183
m_p25NetworkModeHang(3U),
184184
m_p25NetworkDebug(false),
185185
m_nxdnNetworkEnabled(false),
186-
m_nxdnNetworkAddress(),
186+
m_nxdnGatewayAddress(),
187+
m_nxdnGatewayPort(0U),
188+
m_nxdnLocalAddress(),
189+
m_nxdnLocalPort(0U),
187190
m_nxdnNetworkModeHang(3U),
188191
m_nxdnNetworkDebug(false),
189192
m_tftSerialPort("/dev/ttyAMA0"),
@@ -631,8 +634,14 @@ bool CConf::read()
631634
} else if (section == SECTION_NXDN_NETWORK) {
632635
if (::strcmp(key, "Enable") == 0)
633636
m_nxdnNetworkEnabled = ::atoi(value) == 1;
634-
else if (::strcmp(key, "Address") == 0)
635-
m_nxdnNetworkAddress = value;
637+
else if (::strcmp(key, "LocalAddress") == 0)
638+
m_nxdnLocalAddress = value;
639+
else if (::strcmp(key, "LocalPort") == 0)
640+
m_nxdnLocalPort = (unsigned int)::atoi(value);
641+
else if (::strcmp(key, "GatewayAddress") == 0)
642+
m_nxdnGatewayAddress = value;
643+
else if (::strcmp(key, "GatewayPort") == 0)
644+
m_nxdnGatewayPort = (unsigned int)::atoi(value);
636645
else if (::strcmp(key, "ModeHang") == 0)
637646
m_nxdnNetworkModeHang = (unsigned int)::atoi(value);
638647
else if (::strcmp(key, "Debug") == 0)
@@ -1342,9 +1351,24 @@ bool CConf::getNXDNNetworkEnabled() const
13421351
return m_nxdnNetworkEnabled;
13431352
}
13441353

1345-
std::string CConf::getNXDNNetworkAddress() const
1354+
std::string CConf::getNXDNGatewayAddress() const
1355+
{
1356+
return m_nxdnGatewayAddress;
1357+
}
1358+
1359+
unsigned int CConf::getNXDNGatewayPort() const
1360+
{
1361+
return m_nxdnGatewayPort;
1362+
}
1363+
1364+
std::string CConf::getNXDNLocalAddress() const
1365+
{
1366+
return m_nxdnLocalAddress;
1367+
}
1368+
1369+
unsigned int CConf::getNXDNLocalPort() const
13461370
{
1347-
return m_nxdnNetworkAddress;
1371+
return m_nxdnLocalPort;
13481372
}
13491373

13501374
unsigned int CConf::getNXDNNetworkModeHang() const

Conf.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,10 @@ class CConf
191191

192192
// The NXDN Network section
193193
bool getNXDNNetworkEnabled() const;
194-
std::string getNXDNNetworkAddress() const;
194+
std::string getNXDNGatewayAddress() const;
195+
unsigned int getNXDNGatewayPort() const;
196+
std::string getNXDNLocalAddress() const;
197+
unsigned int getNXDNLocalPort() const;
195198
unsigned int getNXDNNetworkModeHang() const;
196199
bool getNXDNNetworkDebug() const;
197200

@@ -378,7 +381,10 @@ class CConf
378381
bool m_p25NetworkDebug;
379382

380383
bool m_nxdnNetworkEnabled;
381-
std::string m_nxdnNetworkAddress;
384+
std::string m_nxdnGatewayAddress;
385+
unsigned int m_nxdnGatewayPort;
386+
std::string m_nxdnLocalAddress;
387+
unsigned int m_nxdnLocalPort;
382388
unsigned int m_nxdnNetworkModeHang;
383389
bool m_nxdnNetworkDebug;
384390

MMDVM.ini

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,10 @@ Debug=0
160160

161161
[NXDN Network]
162162
Enable=1
163-
Address=127.0.0.1
163+
LocalAddress=127.0.0.1
164+
LocalPort=14021
165+
RemoteAddress=127.0.0.1
166+
RemotePort=14020
164167
# ModeHang=3
165168
Debug=0
166169

MMDVMHost.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,15 +1159,21 @@ bool CMMDVMHost::createP25Network()
11591159

11601160
bool CMMDVMHost::createNXDNNetwork()
11611161
{
1162-
std::string address = m_conf.getNXDNNetworkAddress();
1163-
m_nxdnNetModeHang = m_conf.getNXDNNetworkModeHang();
1164-
bool debug = m_conf.getNXDNNetworkDebug();
1162+
std::string gatewayAddress = m_conf.getNXDNGatewayAddress();
1163+
unsigned int gatewayPort = m_conf.getNXDNGatewayPort();
1164+
std::string localAddress = m_conf.getNXDNLocalAddress();
1165+
unsigned int localPort = m_conf.getNXDNLocalPort();
1166+
m_nxdnNetModeHang = m_conf.getNXDNNetworkModeHang();
1167+
bool debug = m_conf.getNXDNNetworkDebug();
11651168

11661169
LogInfo("NXDN Network Parameters");
1167-
LogInfo(" Address: %s", address.c_str());
1170+
LogInfo(" Gateway Address: %s", gatewayAddress.c_str());
1171+
LogInfo(" Gateway Port: %u", gatewayPort);
1172+
LogInfo(" Local Address: %s", localAddress.c_str());
1173+
LogInfo(" Local Port: %u", localPort);
11681174
LogInfo(" Mode Hang: %us", m_nxdnNetModeHang);
11691175

1170-
m_nxdnNetwork = new CNXDNNetwork(address, debug);
1176+
m_nxdnNetwork = new CNXDNNetwork(localAddress, localPort, gatewayAddress, gatewayPort, debug);
11711177

11721178
bool ret = m_nxdnNetwork->open();
11731179
if (!ret) {

NXDNDefines.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,4 @@ const unsigned char NXDN_DATA_CALL_OPTION_9600 = 0x02U;
9999

100100
const unsigned char SACCH_IDLE[] = { NXDN_MESSAGE_TYPE_IDLE, 0x00U, 0x00U };
101101

102-
const unsigned int NXCORE_ICOM_PORT = 41300U;
103-
104102
#endif

NXDNNetwork.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,18 @@
2828

2929
const unsigned int BUFFER_LENGTH = 200U;
3030

31-
CNXDNNetwork::CNXDNNetwork(const std::string& address, bool debug) :
32-
m_socket("", NXCORE_ICOM_PORT),
31+
CNXDNNetwork::CNXDNNetwork(const std::string& localAddress, unsigned int localPort, const std::string& gatewayAddress, unsigned int gatewayPort, bool debug) :
32+
m_socket(localAddress, localPort),
3333
m_address(),
34+
m_port(gatewayPort),
3435
m_debug(debug),
3536
m_enabled(false),
3637
m_buffer(1000U, "NXDN Network")
3738
{
38-
m_address = CUDPSocket::lookup(address);
39+
assert(gatewayPort > 0U);
40+
assert(!gatewayAddress.empty());
41+
42+
m_address = CUDPSocket::lookup(gatewayAddress);
3943
}
4044

4145
CNXDNNetwork::~CNXDNNetwork()
@@ -77,7 +81,7 @@ bool CNXDNNetwork::write(const unsigned char* data, bool single)
7781
if (m_debug)
7882
CUtils::dump(1U, "NXDN Network Data Sent", buffer, 102U);
7983

80-
return m_socket.write(buffer, 102U, m_address, NXCORE_ICOM_PORT);
84+
return m_socket.write(buffer, 102U, m_address, m_port);
8185
}
8286

8387
void CNXDNNetwork::clock(unsigned int ms)
@@ -91,8 +95,8 @@ void CNXDNNetwork::clock(unsigned int ms)
9195
return;
9296

9397
// Check if the data is for us
94-
if (m_address.s_addr != address.s_addr || port != NXCORE_ICOM_PORT) {
95-
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);
98+
if (m_address.s_addr != address.s_addr || port != m_port) {
99+
LogMessage("NXDN packet received from an invalid source, %08X != %08X and/or %u != %u", m_address.s_addr, address.s_addr, m_port, port);
96100
return;
97101
}
98102

NXDNNetwork.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
class CNXDNNetwork {
3131
public:
32-
CNXDNNetwork(const std::string& address, bool debug);
32+
CNXDNNetwork(const std::string& localAddress, unsigned int localPort, const std::string& gatewayAddress, unsigned int gatewayPort, bool debug);
3333
~CNXDNNetwork();
3434

3535
bool open();
@@ -49,6 +49,7 @@ class CNXDNNetwork {
4949
private:
5050
CUDPSocket m_socket;
5151
in_addr m_address;
52+
unsigned int m_port;
5253
bool m_debug;
5354
bool m_enabled;
5455
CRingBuffer<unsigned char> m_buffer;

0 commit comments

Comments
 (0)