Skip to content

Commit

Permalink
Allow more control over NXDN networking.
Browse files Browse the repository at this point in the history
  • Loading branch information
g4klx committed Mar 12, 2018
1 parent 6fe8110 commit 98a31e8
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 22 deletions.
34 changes: 29 additions & 5 deletions Conf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions Conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down
5 changes: 4 additions & 1 deletion MMDVM.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 11 additions & 5 deletions MMDVMHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 0 additions & 2 deletions NXDNDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 10 additions & 6 deletions NXDNNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand All @@ -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;
}

Expand Down
3 changes: 2 additions & 1 deletion NXDNNetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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<unsigned char> m_buffer;
Expand Down

0 comments on commit 98a31e8

Please sign in to comment.