Allow simultaneous connection to an Icom NXCore and a Kenwood NXCore.

This commit is contained in:
Jonathan Naylor 2020-08-22 14:26:44 +01:00
parent 3d04c4f993
commit ee52b702d1
13 changed files with 327 additions and 222 deletions

View File

@ -31,8 +31,9 @@ enum SECTION {
SECTION_GENERAL, SECTION_GENERAL,
SECTION_ID_LOOKUP, SECTION_ID_LOOKUP,
SECTION_LOG, SECTION_LOG,
SECTION_NETWORK, SECTION_YSF_NETWORK,
SECTION_NXCORE SECTION_ICOM_NETWORK,
SECTION_KENWOOD_NETWORK
}; };
CConf::CConf(const std::string& file) : CConf::CConf(const std::string& file) :
@ -45,14 +46,18 @@ m_logDisplayLevel(0U),
m_logFileLevel(0U), m_logFileLevel(0U),
m_logFilePath(), m_logFilePath(),
m_logFileRoot(), m_logFileRoot(),
m_networkPort(0U), m_ysfPort(0U),
m_networkDebug(false), m_ysfDebug(false),
m_nxCoreEnabled(false), m_icomEnabled(false),
m_nxCoreProtocol("Icom"), m_icomAddress(),
m_nxCoreAddress(), m_icomTGEnable(0U),
m_nxCoreTGEnable(0U), m_icomTGDisable(0U),
m_nxCoreTGDisable(0U), m_icomDebug(false),
m_nxCoreDebug(false) m_kenwoodEnabled(false),
m_kenwoodAddress(),
m_kenwoodTGEnable(0U),
m_kenwoodTGDisable(0U),
m_kenwoodDebug(false)
{ {
} }
@ -82,10 +87,12 @@ bool CConf::read()
section = SECTION_ID_LOOKUP; section = SECTION_ID_LOOKUP;
else if (::strncmp(buffer, "[Log]", 5U) == 0) else if (::strncmp(buffer, "[Log]", 5U) == 0)
section = SECTION_LOG; section = SECTION_LOG;
else if (::strncmp(buffer, "[Network]", 9U) == 0) else if (::strncmp(buffer, "[YSF Network]", 13U) == 0)
section = SECTION_NETWORK; section = SECTION_YSF_NETWORK;
else if (::strncmp(buffer, "[NXCore]", 8U) == 0) else if (::strncmp(buffer, "[Icom Network]", 14U) == 0)
section = SECTION_NXCORE; section = SECTION_ICOM_NETWORK;
else if (::strncmp(buffer, "[Kenwood Network]", 17U) == 0)
section = SECTION_KENWOOD_NETWORK;
else else
section = SECTION_NONE; section = SECTION_NONE;
@ -116,24 +123,33 @@ bool CConf::read()
m_logFileLevel = (unsigned int)::atoi(value); m_logFileLevel = (unsigned int)::atoi(value);
else if (::strcmp(key, "DisplayLevel") == 0) else if (::strcmp(key, "DisplayLevel") == 0)
m_logDisplayLevel = (unsigned int)::atoi(value); m_logDisplayLevel = (unsigned int)::atoi(value);
} else if (section == SECTION_NETWORK) { } else if (section == SECTION_YSF_NETWORK) {
if (::strcmp(key, "Port") == 0) if (::strcmp(key, "Port") == 0)
m_networkPort = (unsigned int)::atoi(value); m_ysfPort = (unsigned int)::atoi(value);
else if (::strcmp(key, "Debug") == 0) else if (::strcmp(key, "Debug") == 0)
m_networkDebug = ::atoi(value) == 1; m_ysfDebug = ::atoi(value) == 1;
} else if (section == SECTION_NXCORE) { } else if (section == SECTION_ICOM_NETWORK) {
if (::strcmp(key, "Enabled") == 0) if (::strcmp(key, "Enabled") == 0)
m_nxCoreEnabled = ::atoi(value) == 1; m_icomEnabled = ::atoi(value) == 1;
else if (::strcmp(key, "Protocol") == 0)
m_nxCoreProtocol = value;
else if (::strcmp(key, "Address") == 0) else if (::strcmp(key, "Address") == 0)
m_nxCoreAddress = value; m_icomAddress = value;
else if (::strcmp(key, "TGEnable") == 0) else if (::strcmp(key, "TGEnable") == 0)
m_nxCoreTGEnable = (unsigned short)::atoi(value); m_icomTGEnable = (unsigned short)::atoi(value);
else if (::strcmp(key, "TGDisable") == 0) else if (::strcmp(key, "TGDisable") == 0)
m_nxCoreTGDisable = (unsigned short)::atoi(value); m_icomTGDisable = (unsigned short)::atoi(value);
else if (::strcmp(key, "Debug") == 0) else if (::strcmp(key, "Debug") == 0)
m_nxCoreDebug = ::atoi(value) == 1; m_icomDebug = ::atoi(value) == 1;
} else if (section == SECTION_KENWOOD_NETWORK) {
if (::strcmp(key, "Enabled") == 0)
m_kenwoodEnabled = ::atoi(value) == 1;
else if (::strcmp(key, "Address") == 0)
m_kenwoodAddress = value;
else if (::strcmp(key, "TGEnable") == 0)
m_kenwoodTGEnable = (unsigned short)::atoi(value);
else if (::strcmp(key, "TGDisable") == 0)
m_kenwoodTGDisable = (unsigned short)::atoi(value);
else if (::strcmp(key, "Debug") == 0)
m_kenwoodDebug = ::atoi(value) == 1;
} }
} }
@ -182,42 +198,62 @@ std::string CConf::getLogFileRoot() const
return m_logFileRoot; return m_logFileRoot;
} }
unsigned int CConf::getNetworkPort() const unsigned int CConf::getYSFPort() const
{ {
return m_networkPort; return m_ysfPort;
} }
bool CConf::getNetworkDebug() const bool CConf::getYSFDebug() const
{ {
return m_networkDebug; return m_ysfDebug;
} }
bool CConf::getNXCoreEnabled() const bool CConf::getIcomEnabled() const
{ {
return m_nxCoreEnabled; return m_icomEnabled;
} }
std::string CConf::getNXCoreProtocol() const std::string CConf::getIcomAddress() const
{ {
return m_nxCoreProtocol; return m_icomAddress;
} }
std::string CConf::getNXCoreAddress() const unsigned short CConf::getIcomTGEnable() const
{ {
return m_nxCoreAddress; return m_icomTGEnable;
} }
unsigned short CConf::getNXCoreTGEnable() const unsigned short CConf::getIcomTGDisable() const
{ {
return m_nxCoreTGEnable; return m_icomTGDisable;
} }
unsigned short CConf::getNXCoreTGDisable() const bool CConf::getIcomDebug() const
{ {
return m_nxCoreTGDisable; return m_icomDebug;
} }
bool CConf::getNXCoreDebug() const bool CConf::getKenwoodEnabled() const
{ {
return m_nxCoreDebug; return m_kenwoodEnabled;
}
std::string CConf::getKenwoodAddress() const
{
return m_kenwoodAddress;
}
unsigned short CConf::getKenwoodTGEnable() const
{
return m_kenwoodTGEnable;
}
unsigned short CConf::getKenwoodTGDisable() const
{
return m_kenwoodTGDisable;
}
bool CConf::getKenwoodDebug() const
{
return m_kenwoodDebug;
} }

View File

@ -44,17 +44,23 @@ public:
std::string getLogFilePath() const; std::string getLogFilePath() const;
std::string getLogFileRoot() const; std::string getLogFileRoot() const;
// The Network section // The YSF Network section
unsigned int getNetworkPort() const; unsigned int getYSFPort() const;
bool getNetworkDebug() const; bool getYSFDebug() const;
// The NXCore section // The Icom Network section
bool getNXCoreEnabled() const; bool getIcomEnabled() const;
std::string getNXCoreProtocol() const; std::string getIcomAddress() const;
std::string getNXCoreAddress() const; unsigned short getIcomTGEnable() const;
unsigned short getNXCoreTGEnable() const; unsigned short getIcomTGDisable() const;
unsigned short getNXCoreTGDisable() const; bool getIcomDebug() const;
bool getNXCoreDebug() const;
// The Kenwood Network section
bool getKenwoodEnabled() const;
std::string getKenwoodAddress() const;
unsigned short getKenwoodTGEnable() const;
unsigned short getKenwoodTGDisable() const;
bool getKenwoodDebug() const;
private: private:
std::string m_file; std::string m_file;
@ -69,15 +75,20 @@ private:
std::string m_logFilePath; std::string m_logFilePath;
std::string m_logFileRoot; std::string m_logFileRoot;
unsigned int m_networkPort; unsigned int m_ysfPort;
bool m_networkDebug; bool m_ysfDebug;
bool m_nxCoreEnabled; bool m_icomEnabled;
std::string m_nxCoreProtocol; std::string m_icomAddress;
std::string m_nxCoreAddress; unsigned short m_icomTGEnable;
unsigned short m_nxCoreTGEnable; unsigned short m_icomTGDisable;
unsigned short m_nxCoreTGDisable; bool m_icomDebug;
bool m_nxCoreDebug;
bool m_kenwoodEnabled;
std::string m_kenwoodAddress;
unsigned short m_kenwoodTGEnable;
unsigned short m_kenwoodTGDisable;
bool m_kenwoodDebug;
}; };
#endif #endif

View File

@ -1,23 +0,0 @@
/*
* Copyright (C) 2009-2014,2016,2018,2020 by Jonathan Naylor G4KLX
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "CoreNetwork.h"
ICoreNetwork::~ICoreNetwork()
{
}

View File

@ -1,55 +0,0 @@
/*
* Copyright (C) 2009-2014,2016,2018,2020 by Jonathan Naylor G4KLX
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef CoreNetwork_H
#define CoreNetwork_H
#if !defined(_WIN32) && !defined(_WIN64)
#include <netdb.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <errno.h>
#else
#include <winsock.h>
#endif
#include <cstdint>
#include <string>
class ICoreNetwork {
public:
virtual ~ICoreNetwork() = 0;
virtual bool open() = 0;
virtual bool write(const unsigned char* data, unsigned int length) = 0;
virtual unsigned int read(unsigned char* data) = 0;
virtual void close() = 0;
virtual void clock(unsigned int ms) = 0;
private:
};
#endif

View File

@ -19,27 +19,26 @@
#ifndef IcomNetwork_H #ifndef IcomNetwork_H
#define IcomNetwork_H #define IcomNetwork_H
#include "CoreNetwork.h"
#include "UDPSocket.h" #include "UDPSocket.h"
#include "Timer.h" #include "Timer.h"
#include <cstdint> #include <cstdint>
#include <string> #include <string>
class CIcomNetwork : public ICoreNetwork { class CIcomNetwork {
public: public:
CIcomNetwork(const std::string& address, bool debug); CIcomNetwork(const std::string& address, bool debug);
virtual ~CIcomNetwork(); ~CIcomNetwork();
virtual bool open(); bool open();
virtual bool write(const unsigned char* data, unsigned int len); bool write(const unsigned char* data, unsigned int len);
virtual unsigned int read(unsigned char* data); unsigned int read(unsigned char* data);
virtual void close(); void close();
virtual void clock(unsigned int ms); void clock(unsigned int ms);
private: private:
CUDPSocket m_socket; CUDPSocket m_socket;

View File

@ -19,7 +19,6 @@
#ifndef KenwoodNetwork_H #ifndef KenwoodNetwork_H
#define KenwoodNetwork_H #define KenwoodNetwork_H
#include "CoreNetwork.h"
#include "UDPSocket.h" #include "UDPSocket.h"
#include "Timer.h" #include "Timer.h"
@ -27,20 +26,20 @@
#include <string> #include <string>
#include <random> #include <random>
class CKenwoodNetwork : public ICoreNetwork { class CKenwoodNetwork {
public: public:
CKenwoodNetwork(const std::string& address, bool debug); CKenwoodNetwork(const std::string& address, bool debug);
virtual ~CKenwoodNetwork(); ~CKenwoodNetwork();
virtual bool open(); bool open();
virtual bool write(const unsigned char* data, unsigned int length); bool write(const unsigned char* data, unsigned int length);
virtual unsigned int read(unsigned char* data); unsigned int read(unsigned char* data);
virtual void close(); void close();
virtual void clock(unsigned int ms); void clock(unsigned int ms);
private: private:
CUDPSocket m_rtpSocket; CUDPSocket m_rtpSocket;

View File

@ -4,7 +4,7 @@ CFLAGS = -g -O3 -Wall -std=c++0x -pthread
LIBS = -lpthread LIBS = -lpthread
LDFLAGS = -g LDFLAGS = -g
OBJECTS = Conf.o CoreNetwork.o IcomNetwork.o KenwoodNetwork.o Log.o Mutex.o NXDNCRC.o NXDNLookup.o NXDNNetwork.o NXDNReflector.o StopWatch.o Thread.o Timer.o UDPSocket.o Utils.o OBJECTS = Conf.o IcomNetwork.o KenwoodNetwork.o Log.o Mutex.o NXDNCRC.o NXDNLookup.o NXDNNetwork.o NXDNReflector.o StopWatch.o Thread.o Timer.o UDPSocket.o Utils.o
all: NXDNReflector all: NXDNReflector

View File

@ -16,10 +16,8 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
#include "KenwoodNetwork.h"
#include "NXDNReflector.h" #include "NXDNReflector.h"
#include "NXDNNetwork.h" #include "NXDNNetwork.h"
#include "IcomNetwork.h"
#include "NXDNLookup.h" #include "NXDNLookup.h"
#include "StopWatch.h" #include "StopWatch.h"
#include "Version.h" #include "Version.h"
@ -81,7 +79,8 @@ int main(int argc, char** argv)
CNXDNReflector::CNXDNReflector(const std::string& file) : CNXDNReflector::CNXDNReflector(const std::string& file) :
m_conf(file), m_conf(file),
m_nxCoreNetwork(NULL), m_icomNetwork(NULL),
m_kenwoodNetwork(NULL),
m_repeaters() m_repeaters()
{ {
} }
@ -169,26 +168,41 @@ void CNXDNReflector::run()
unsigned short tg = m_conf.getTG(); unsigned short tg = m_conf.getTG();
CNXDNNetwork nxdnNetwork(m_conf.getNetworkPort(), m_conf.getNetworkDebug()); CNXDNNetwork nxdnNetwork(m_conf.getYSFPort(), m_conf.getYSFDebug());
ret = nxdnNetwork.open(); ret = nxdnNetwork.open();
if (!ret) { if (!ret) {
::LogFinalise(); ::LogFinalise();
return; return;
} }
unsigned short nxCoreTGEnable = 0U; unsigned short icomTGEnable = 0U;
unsigned short nxCoreTGDisable = 0U; unsigned short icomTGDisable = 0U;
if (m_conf.getNXCoreEnabled()) { if (m_conf.getIcomEnabled()) {
ret = openNXCore(); ret = openIcomNetwork();
if (!ret) { if (!ret) {
nxdnNetwork.close(); nxdnNetwork.close();
::LogFinalise(); ::LogFinalise();
return; return;
} }
nxCoreTGEnable = m_conf.getNXCoreTGEnable(); icomTGEnable = m_conf.getIcomTGEnable();
nxCoreTGDisable = m_conf.getNXCoreTGDisable(); icomTGDisable = m_conf.getIcomTGDisable();
}
unsigned short kenwoodTGEnable = 0U;
unsigned short kenwoodTGDisable = 0U;
if (m_conf.getKenwoodEnabled()) {
ret = openKenwoodNetwork();
if (!ret) {
nxdnNetwork.close();
::LogFinalise();
return;
}
kenwoodTGEnable = m_conf.getKenwoodTGEnable();
kenwoodTGDisable = m_conf.getKenwoodTGDisable();
} }
CNXDNLookup* lookup = new CNXDNLookup(m_conf.getLookupName(), m_conf.getLookupTime()); CNXDNLookup* lookup = new CNXDNLookup(m_conf.getLookupName(), m_conf.getLookupTime());
@ -203,7 +217,8 @@ void CNXDNReflector::run()
LogMessage("Starting NXDNReflector-%s", VERSION); LogMessage("Starting NXDNReflector-%s", VERSION);
CNXDNRepeater* current = NULL; CNXDNRepeater* current = NULL;
bool nxCoreActive = false; bool icomActive = false;
bool kenwoodActive = false;
unsigned short srcId = 0U; unsigned short srcId = 0U;
unsigned short dstId = 0U; unsigned short dstId = 0U;
@ -262,24 +277,46 @@ void CNXDNReflector::run()
unsigned short dstId = (buffer[7U] << 8) | buffer[8U]; unsigned short dstId = (buffer[7U] << 8) | buffer[8U];
bool grp = (buffer[9U] & 0x01U) == 0x01U; bool grp = (buffer[9U] & 0x01U) == 0x01U;
if (nxCoreTGEnable != 0U && grp && dstId == nxCoreTGEnable) { if (icomTGEnable != 0U && grp && dstId == icomTGEnable) {
if (m_nxCoreNetwork == NULL) { if (m_icomNetwork == NULL) {
std::string callsign = lookup->find(srcId); std::string callsign = lookup->find(srcId);
LogMessage("NXCore link enabled by %s at %s", callsign.c_str(), current->m_callsign.c_str()); LogMessage("Icom Network link enabled by %s at %s", callsign.c_str(), current->m_callsign.c_str());
bool ok = openNXCore(); bool ok = openIcomNetwork();
if (!ok) if (!ok)
LogWarning("Unable to open the NXCore link"); LogWarning("Unable to open the Icom Network link");
} }
} else if (nxCoreTGDisable != 0U && grp && dstId == nxCoreTGDisable) { }
if (m_nxCoreNetwork != NULL) {
if (kenwoodTGEnable != 0U && grp && dstId == kenwoodTGEnable) {
if (m_kenwoodNetwork == NULL) {
std::string callsign = lookup->find(srcId); std::string callsign = lookup->find(srcId);
LogMessage("NXCore link disabled by %s at %s", callsign.c_str(), current->m_callsign.c_str()); LogMessage("Kenwood Network link enabled by %s at %s", callsign.c_str(), current->m_callsign.c_str());
closeNXCore(); bool ok = openKenwoodNetwork();
if (!ok)
LogWarning("Unable to open the Kenwood Network link");
} }
} else if (grp && dstId == tg) { }
if (icomTGDisable != 0U && grp && dstId == icomTGDisable) {
if (m_icomNetwork != NULL) {
std::string callsign = lookup->find(srcId);
LogMessage("Icom Network link disabled by %s at %s", callsign.c_str(), current->m_callsign.c_str());
closeIcomNetwork();
}
}
if (kenwoodTGDisable != 0U && grp && dstId == kenwoodTGDisable) {
if (m_kenwoodNetwork != NULL) {
std::string callsign = lookup->find(srcId);
LogMessage("Kenwood Network link disabled by %s at %s", callsign.c_str(), current->m_callsign.c_str());
closeKenwoodNetwork();
}
}
if (grp && dstId == tg) {
rpt->m_timer.start(); rpt->m_timer.start();
if (current == NULL && !nxCoreActive) { if (current == NULL && !(icomActive || kenwoodActive)) {
current = rpt; current = rpt;
std::string callsign = lookup->find(srcId); std::string callsign = lookup->find(srcId);
@ -296,8 +333,11 @@ void CNXDNReflector::run()
nxdnNetwork.write(buffer, len, addr, prt); nxdnNetwork.write(buffer, len, addr, prt);
} }
if (m_nxCoreNetwork != NULL) if (m_icomNetwork != NULL)
m_nxCoreNetwork->write(buffer, len); m_icomNetwork->write(buffer, len);
if (m_kenwoodNetwork != NULL)
m_kenwoodNetwork->write(buffer, len);
if ((buffer[9U] & 0x08U) == 0x08U) { if ((buffer[9U] & 0x08U) == 0x08U) {
LogMessage("Received end of transmission"); LogMessage("Received end of transmission");
@ -313,11 +353,11 @@ void CNXDNReflector::run()
} }
} }
if (m_nxCoreNetwork != NULL) { if (m_icomNetwork != NULL) {
len = m_nxCoreNetwork->read(buffer); len = m_icomNetwork->read(buffer);
if (len > 0U) { if (len > 0U) {
if (current == NULL) { if (current == NULL) {
if (!nxCoreActive) { if (!icomActive) {
if ((buffer[0U] == 0x81U || buffer[0U] == 0x83U) && buffer[5U] == 0x01U) { if ((buffer[0U] == 0x81U || buffer[0U] == 0x83U) && buffer[5U] == 0x01U) {
bool tempGrp = (buffer[7U] & 0x20U) == 0x20U; bool tempGrp = (buffer[7U] & 0x20U) == 0x20U;
unsigned short tempSrcId = (buffer[8U] << 8) | buffer[9U]; unsigned short tempSrcId = (buffer[8U] << 8) | buffer[9U];
@ -330,9 +370,9 @@ void CNXDNReflector::run()
dstId = tempDstId; dstId = tempDstId;
std::string callsign = lookup->find(srcId); std::string callsign = lookup->find(srcId);
LogMessage("Transmission from %s at NXCore to %s%u", callsign.c_str(), grp ? "TG " : "", dstId); LogMessage("Transmission from %s on Icom Network to %s%u", callsign.c_str(), grp ? "TG " : "", dstId);
nxCoreActive = true; icomActive = true;
} }
} }
if ((buffer[0U] & 0xF0U) == 0x90U && buffer[2U] == 0x09U) { if ((buffer[0U] & 0xF0U) == 0x90U && buffer[2U] == 0x09U) {
@ -347,14 +387,14 @@ void CNXDNReflector::run()
dstId = tempDstId; dstId = tempDstId;
std::string callsign = lookup->find(srcId); std::string callsign = lookup->find(srcId);
LogMessage("Transmission from %s at NXCore to %s%u", callsign.c_str(), grp ? "TG " : "", dstId); LogMessage("Transmission from %s on Icom Network to %s%u", callsign.c_str(), grp ? "TG " : "", dstId);
nxCoreActive = true; icomActive = true;
} }
} }
} }
if (nxCoreActive) { if (icomActive) {
watchdogTimer.start(); watchdogTimer.start();
for (std::vector<CNXDNRepeater*>::const_iterator it = m_repeaters.begin(); it != m_repeaters.end(); ++it) { for (std::vector<CNXDNRepeater*>::const_iterator it = m_repeaters.begin(); it != m_repeaters.end(); ++it) {
@ -363,14 +403,85 @@ void CNXDNReflector::run()
nxdnNetwork.write(buffer, len, srcId, dstId, grp, addr, prt); nxdnNetwork.write(buffer, len, srcId, dstId, grp, addr, prt);
} }
if (m_kenwoodNetwork != NULL)
m_kenwoodNetwork->write(buffer, len);
if ((buffer[0U] == 0x81U || buffer[0U] == 0x83U) && buffer[5U] == 0x08U) { if ((buffer[0U] == 0x81U || buffer[0U] == 0x83U) && buffer[5U] == 0x08U) {
LogMessage("Received end of transmission"); LogMessage("Received end of transmission");
nxCoreActive = false; icomActive = false;
watchdogTimer.stop(); watchdogTimer.stop();
} }
if ((buffer[0U] & 0xF0U) == 0x90U && buffer[2U] == 0x08U) { if ((buffer[0U] & 0xF0U) == 0x90U && buffer[2U] == 0x08U) {
LogMessage("Received end of transmission"); LogMessage("Received end of transmission");
nxCoreActive = false; icomActive = false;
watchdogTimer.stop();
}
}
}
}
}
if (m_kenwoodNetwork != NULL) {
len = m_kenwoodNetwork->read(buffer);
if (len > 0U) {
if (current == NULL) {
if (!kenwoodActive) {
if ((buffer[0U] == 0x81U || buffer[0U] == 0x83U) && buffer[5U] == 0x01U) {
bool tempGrp = (buffer[7U] & 0x20U) == 0x20U;
unsigned short tempSrcId = (buffer[8U] << 8) | buffer[9U];
unsigned short tempDstId = (buffer[10U] << 8) | buffer[11U];
if (tempGrp && tempDstId == tg) {
// Save the grp, src and dest for use in the NXDN Protocol messages
grp = tempGrp;
srcId = tempSrcId;
dstId = tempDstId;
std::string callsign = lookup->find(srcId);
LogMessage("Transmission from %s on Kenwood Network to %s%u", callsign.c_str(), grp ? "TG " : "", dstId);
kenwoodActive = true;
}
}
if ((buffer[0U] & 0xF0U) == 0x90U && buffer[2U] == 0x09U) {
bool tempGrp = (buffer[4U] & 0x20U) == 0x20U;
unsigned short tempSrcId = (buffer[5U] << 8) | buffer[6U];
unsigned short tempDstId = (buffer[7U] << 8) | buffer[8U];
if (tempGrp && tempDstId == tg) {
// Save the grp, src and dest for use in the NXDN Protocol messages
grp = tempGrp;
srcId = tempSrcId;
dstId = tempDstId;
std::string callsign = lookup->find(srcId);
LogMessage("Transmission from %s on Kenwood Network to %s%u", callsign.c_str(), grp ? "TG " : "", dstId);
kenwoodActive = true;
}
}
}
if (kenwoodActive) {
watchdogTimer.start();
for (std::vector<CNXDNRepeater*>::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, srcId, dstId, grp, addr, prt);
}
if (m_icomNetwork != NULL)
m_icomNetwork->write(buffer, len);
if ((buffer[0U] == 0x81U || buffer[0U] == 0x83U) && buffer[5U] == 0x08U) {
LogMessage("Received end of transmission");
kenwoodActive = false;
watchdogTimer.stop();
}
if ((buffer[0U] & 0xF0U) == 0x90U && buffer[2U] == 0x08U) {
LogMessage("Received end of transmission");
kenwoodActive = false;
watchdogTimer.stop(); watchdogTimer.stop();
} }
} }
@ -403,7 +514,8 @@ void CNXDNReflector::run()
LogMessage("Network watchdog has expired"); LogMessage("Network watchdog has expired");
watchdogTimer.stop(); watchdogTimer.stop();
current = NULL; current = NULL;
nxCoreActive = false; icomActive = false;
kenwoodActive = false;
} }
dumpTimer.clock(ms); dumpTimer.clock(ms);
@ -412,8 +524,11 @@ void CNXDNReflector::run()
dumpTimer.start(); dumpTimer.start();
} }
if (m_nxCoreNetwork != NULL) if (m_icomNetwork != NULL)
m_nxCoreNetwork->clock(ms); m_icomNetwork->clock(ms);
if (m_kenwoodNetwork != NULL)
m_kenwoodNetwork->clock(ms);
if (ms < 5U) if (ms < 5U)
CThread::sleep(5U); CThread::sleep(5U);
@ -421,7 +536,9 @@ void CNXDNReflector::run()
nxdnNetwork.close(); nxdnNetwork.close();
closeNXCore(); closeIcomNetwork();
closeKenwoodNetwork();
lookup->stop(); lookup->stop();
@ -457,28 +574,46 @@ void CNXDNReflector::dumpRepeaters() const
} }
} }
bool CNXDNReflector::openNXCore() bool CNXDNReflector::openIcomNetwork()
{ {
std::string protocol = m_conf.getNXCoreProtocol(); m_icomNetwork = new CIcomNetwork(m_conf.getIcomAddress(), m_conf.getIcomDebug());
if (protocol == "Kenwood") bool ret = m_icomNetwork->open();
m_nxCoreNetwork = new CKenwoodNetwork(m_conf.getNXCoreAddress(), m_conf.getNXCoreDebug());
else
m_nxCoreNetwork = new CIcomNetwork(m_conf.getNXCoreAddress(), m_conf.getNXCoreDebug());
bool ret = m_nxCoreNetwork->open();
if (!ret) { if (!ret) {
delete m_nxCoreNetwork; delete m_icomNetwork;
m_nxCoreNetwork = NULL; m_icomNetwork = NULL;
return false; return false;
} }
return true; return true;
} }
void CNXDNReflector::closeNXCore() bool CNXDNReflector::openKenwoodNetwork()
{ {
if (m_nxCoreNetwork != NULL) { m_kenwoodNetwork = new CKenwoodNetwork(m_conf.getKenwoodAddress(), m_conf.getKenwoodDebug());
m_nxCoreNetwork->close(); bool ret = m_kenwoodNetwork->open();
delete m_nxCoreNetwork; if (!ret) {
m_nxCoreNetwork = NULL; delete m_kenwoodNetwork;
m_kenwoodNetwork = NULL;
return false;
}
return true;
}
void CNXDNReflector::closeIcomNetwork()
{
if (m_icomNetwork != NULL) {
m_icomNetwork->close();
delete m_icomNetwork;
m_icomNetwork = NULL;
}
}
void CNXDNReflector::closeKenwoodNetwork()
{
if (m_kenwoodNetwork != NULL) {
m_kenwoodNetwork->close();
delete m_kenwoodNetwork;
m_kenwoodNetwork = NULL;
} }
} }

View File

@ -19,7 +19,8 @@
#if !defined(NXDNReflector_H) #if !defined(NXDNReflector_H)
#define NXDNReflector_H #define NXDNReflector_H
#include "CoreNetwork.h" #include "KenwoodNetwork.h"
#include "IcomNetwork.h"
#include "Timer.h" #include "Timer.h"
#include "Conf.h" #include "Conf.h"
@ -65,14 +66,17 @@ public:
private: private:
CConf m_conf; CConf m_conf;
ICoreNetwork* m_nxCoreNetwork; CIcomNetwork* m_icomNetwork;
CKenwoodNetwork* m_kenwoodNetwork;
std::vector<CNXDNRepeater*> m_repeaters; std::vector<CNXDNRepeater*> m_repeaters;
CNXDNRepeater* findRepeater(const in_addr& address, unsigned int port) const; CNXDNRepeater* findRepeater(const in_addr& address, unsigned int port) const;
void dumpRepeaters() const; void dumpRepeaters() const;
bool openNXCore(); bool openIcomNetwork();
void closeNXCore(); bool openKenwoodNetwork();
void closeIcomNetwork();
void closeKenwoodNetwork();
}; };
#endif #endif

View File

@ -13,13 +13,20 @@ FileLevel=1
FilePath=. FilePath=.
FileRoot=NXDNReflector FileRoot=NXDNReflector
[Network] [YSF Network]
Port=41400 Port=41400
Debug=0 Debug=0
[NXCore] [Icom Network]
Enabled=0
# Address=208.111.3.45
Address=44.131.4.1
# TGEnable=1234
# TGDisable=3456
Debug=0
[Kenwood Network]
Enabled=0 Enabled=0
Protocol=Icom
# Address=208.111.3.45 # Address=208.111.3.45
Address=44.131.4.1 Address=44.131.4.1
# TGEnable=1234 # TGEnable=1234

View File

@ -20,7 +20,6 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="Conf.h" /> <ClInclude Include="Conf.h" />
<ClInclude Include="CoreNetwork.h" />
<ClInclude Include="IcomNetwork.h" /> <ClInclude Include="IcomNetwork.h" />
<ClInclude Include="KenwoodNetwork.h" /> <ClInclude Include="KenwoodNetwork.h" />
<ClInclude Include="NXDNCRC.h" /> <ClInclude Include="NXDNCRC.h" />
@ -38,7 +37,6 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="Conf.cpp" /> <ClCompile Include="Conf.cpp" />
<ClCompile Include="CoreNetwork.cpp" />
<ClCompile Include="IcomNetwork.cpp" /> <ClCompile Include="IcomNetwork.cpp" />
<ClCompile Include="KenwoodNetwork.cpp" /> <ClCompile Include="KenwoodNetwork.cpp" />
<ClCompile Include="NXDNCRC.cpp" /> <ClCompile Include="NXDNCRC.cpp" />

View File

@ -53,9 +53,6 @@
<ClInclude Include="KenwoodNetwork.h"> <ClInclude Include="KenwoodNetwork.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="CoreNetwork.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="NXDNCRC.h"> <ClInclude Include="NXDNCRC.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
@ -100,9 +97,6 @@
<ClCompile Include="KenwoodNetwork.cpp"> <ClCompile Include="KenwoodNetwork.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="CoreNetwork.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="NXDNCRC.cpp"> <ClCompile Include="NXDNCRC.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>

View File

@ -19,6 +19,6 @@
#if !defined(VERSION_H) #if !defined(VERSION_H)
#define VERSION_H #define VERSION_H
const char* VERSION = "20200701"; const char* VERSION = "20200822";
#endif #endif