1
0
Fork 0

More changes, including FCS linking at startup.

ycs232-kbc
Jonathan Naylor 7 years ago
parent 9719b1d269
commit 22e5bb523f

@ -32,6 +32,7 @@ enum SECTION {
SECTION_INFO,
SECTION_LOG,
SECTION_APRS_FI,
SECTION_NETWORK,
SECTION_YSF_NETWORK,
SECTION_FCS_NETWORK
};
@ -63,6 +64,10 @@ m_aprsServer(),
m_aprsPort(0U),
m_aprsPassword(),
m_aprsDescription(),
m_networkStartup(),
m_networkInactivityTimeout(0U),
m_networkRevert(false),
m_networkDebug(false),
m_ysfNetworkEnabled(false),
m_ysfNetworkPort(0U),
m_ysfNetworkHosts(),
@ -71,13 +76,8 @@ m_ysfNetworkParrotAddress("127.0.0.1"),
m_ysfNetworkParrotPort(0U),
m_ysfNetworkYSF2DMRAddress("127.0.0.1"),
m_ysfNetworkYSF2DMRPort(0U),
m_ysfNetworkStartup(),
m_ysfNetworkInactivityTimeout(0U),
m_ysfNetworkRevert(false),
m_ysfNetworkDebug(false),
m_fcsNetworkEnabled(false),
m_fcsNetworkPort(0U),
m_fcsNetworkDebug(false)
m_fcsNetworkPort(0U)
{
}
@ -109,6 +109,8 @@ bool CConf::read()
section = SECTION_LOG;
else if (::strncmp(buffer, "[aprs.fi]", 9U) == 0)
section = SECTION_APRS_FI;
else if (::strncmp(buffer, "[Network]", 9U) == 0)
section = SECTION_NETWORK;
else if (::strncmp(buffer, "[YSF Network]", 13U) == 0)
section = SECTION_YSF_NETWORK;
else if (::strncmp(buffer, "[FCS Network]", 13U) == 0)
@ -184,6 +186,15 @@ bool CConf::read()
m_aprsPassword = value;
else if (::strcmp(key, "Description") == 0)
m_aprsDescription = value;
} else if (section == SECTION_NETWORK) {
if (::strcmp(key, "Startup") == 0)
m_networkStartup = value;
else if (::strcmp(key, "InactivityTimeout") == 0)
m_networkInactivityTimeout = (unsigned int)::atoi(value);
else if (::strcmp(key, "Revert") == 0)
m_networkRevert = ::atoi(value) == 1;
else if (::strcmp(key, "Debug") == 0)
m_networkDebug = ::atoi(value) == 1;
} else if (section == SECTION_YSF_NETWORK) {
if (::strcmp(key, "Enable") == 0)
m_ysfNetworkEnabled = ::atoi(value) == 1;
@ -201,21 +212,11 @@ bool CConf::read()
m_ysfNetworkYSF2DMRAddress = value;
else if (::strcmp(key, "YSF2DMRPort") == 0)
m_ysfNetworkYSF2DMRPort = (unsigned int)::atoi(value);
else if (::strcmp(key, "Startup") == 0)
m_ysfNetworkStartup = value;
else if (::strcmp(key, "InactivityTimeout") == 0)
m_ysfNetworkInactivityTimeout = (unsigned int)::atoi(value);
else if (::strcmp(key, "Revert") == 0)
m_ysfNetworkRevert = ::atoi(value) == 1;
else if (::strcmp(key, "Debug") == 0)
m_ysfNetworkDebug = ::atoi(value) == 1;
} else if (section == SECTION_FCS_NETWORK) {
if (::strcmp(key, "Enable") == 0)
m_fcsNetworkEnabled = ::atoi(value) == 1;
else if (::strcmp(key, "Port") == 0)
m_fcsNetworkPort = (unsigned int)::atoi(value);
else if (::strcmp(key, "Debug") == 0)
m_fcsNetworkDebug = ::atoi(value) == 1;
}
}
@ -349,6 +350,26 @@ std::string CConf::getAPRSDescription() const
return m_aprsDescription;
}
std::string CConf::getNetworkStartup() const
{
return m_networkStartup;
}
unsigned int CConf::getNetworkInactivityTimeout() const
{
return m_networkInactivityTimeout;
}
bool CConf::getNetworkRevert() const
{
return m_networkRevert;
}
bool CConf::getNetworkDebug() const
{
return m_networkDebug;
}
bool CConf::getYSFNetworkEnabled() const
{
return m_ysfNetworkEnabled;
@ -389,26 +410,6 @@ unsigned int CConf::getYSFNetworkYSF2DMRPort() const
return m_ysfNetworkYSF2DMRPort;
}
std::string CConf::getYSFNetworkStartup() const
{
return m_ysfNetworkStartup;
}
unsigned int CConf::getYSFNetworkInactivityTimeout() const
{
return m_ysfNetworkInactivityTimeout;
}
bool CConf::getYSFNetworkRevert() const
{
return m_ysfNetworkRevert;
}
bool CConf::getYSFNetworkDebug() const
{
return m_ysfNetworkDebug;
}
bool CConf::getFCSNetworkEnabled() const
{
return m_fcsNetworkEnabled;
@ -418,8 +419,3 @@ unsigned int CConf::getFCSNetworkPort() const
{
return m_fcsNetworkPort;
}
bool CConf::getFCSNetworkDebug() const
{
return m_fcsNetworkDebug;
}

@ -63,6 +63,12 @@ public:
std::string getAPRSPassword() const;
std::string getAPRSDescription() const;
// The Network section
std::string getNetworkStartup() const;
unsigned int getNetworkInactivityTimeout() const;
bool getNetworkRevert() const;
bool getNetworkDebug() const;
// The YSF Network section
bool getYSFNetworkEnabled() const;
unsigned int getYSFNetworkPort() const;
@ -72,15 +78,10 @@ public:
unsigned int getYSFNetworkParrotPort() const;
std::string getYSFNetworkYSF2DMRAddress() const;
unsigned int getYSFNetworkYSF2DMRPort() const;
std::string getYSFNetworkStartup() const;
unsigned int getYSFNetworkInactivityTimeout() const;
bool getYSFNetworkRevert() const;
bool getYSFNetworkDebug() const;
// The FCS Network section
bool getFCSNetworkEnabled() const;
unsigned int getFCSNetworkPort() const;
bool getFCSNetworkDebug() const;
private:
std::string m_file;
@ -113,6 +114,11 @@ private:
std::string m_aprsPassword;
std::string m_aprsDescription;
std::string m_networkStartup;
unsigned int m_networkInactivityTimeout;
bool m_networkRevert;
bool m_networkDebug;
bool m_ysfNetworkEnabled;
unsigned int m_ysfNetworkPort;
std::string m_ysfNetworkHosts;
@ -121,14 +127,9 @@ private:
unsigned int m_ysfNetworkParrotPort;
std::string m_ysfNetworkYSF2DMRAddress;
unsigned int m_ysfNetworkYSF2DMRPort;
std::string m_ysfNetworkStartup;
unsigned int m_ysfNetworkInactivityTimeout;
bool m_ysfNetworkRevert;
bool m_ysfNetworkDebug;
bool m_fcsNetworkEnabled;
unsigned int m_fcsNetworkPort;
bool m_fcsNetworkDebug;
};
#endif

@ -119,7 +119,8 @@ int CYSFGateway::run()
if (pid == -1) {
::LogWarning("Couldn't fork() , exiting");
return -1;
} else if (pid != 0)
}
else if (pid != 0)
exit(EXIT_SUCCESS);
// Create new session and process group
@ -170,13 +171,13 @@ int CYSFGateway::run()
#endif
m_callsign = m_conf.getCallsign();
m_suffix = m_conf.getSuffix();
m_suffix = m_conf.getSuffix();
bool debug = m_conf.getYSFNetworkDebug();
in_addr rptAddress = CUDPSocket::lookup(m_conf.getRptAddress());
unsigned int rptPort = m_conf.getRptPort();
bool debug = m_conf.getNetworkDebug();
in_addr rptAddress = CUDPSocket::lookup(m_conf.getRptAddress());
unsigned int rptPort = m_conf.getRptPort();
std::string myAddress = m_conf.getMyAddress();
unsigned int myPort = m_conf.getMyPort();
unsigned int myPort = m_conf.getMyPort();
CYSFNetwork rptNetwork(myAddress, myPort, m_callsign, debug);
rptNetwork.setDestination(rptAddress, rptPort);
@ -188,63 +189,55 @@ int CYSFGateway::run()
return 1;
}
unsigned int ysfPort = m_conf.getYSFNetworkPort();
m_ysfNetwork = new CYSFNetwork(ysfPort, m_callsign, debug);
ret = m_ysfNetwork->open();
if (!ret) {
::LogError("Cannot open the YSF reflector network port");
::LogFinalise();
return 1;
}
unsigned int txFrequency = m_conf.getTxFrequency();
unsigned int rxFrequency = m_conf.getRxFrequency();
std::string locator = calculateLocator();
unsigned int id = m_conf.getId();
unsigned int fcsPort = m_conf.getFCSNetworkPort();
m_fcsNetwork = new CFCSNetwork(fcsPort, m_callsign, rxFrequency, txFrequency, locator, id, debug);
ret = m_fcsNetwork->open();
if (!ret) {
::LogError("Cannot open the FCS reflector network port");
::LogFinalise();
return 1;
}
m_inactivityTimer.setTimeout(m_conf.getYSFNetworkInactivityTimeout() * 60U);
bool revert = m_conf.getYSFNetworkRevert();
std::string startup = m_conf.getYSFNetworkStartup();
bool fcsNetworkEnabled = m_conf.getFCSNetworkEnabled();
bool ysfNetworkEnabled = m_conf.getYSFNetworkEnabled();
if (ysfNetworkEnabled) {
std::string fileName = m_conf.getYSFNetworkHosts();
unsigned int reloadTime = m_conf.getYSFNetworkReloadTime();
m_wiresX = new CWiresX(m_callsign, m_suffix, &rptNetwork, fileName, reloadTime);
unsigned int ysfPort = m_conf.getYSFNetworkPort();
m_ysfNetwork = new CYSFNetwork(ysfPort, m_callsign, debug);
ret = m_ysfNetwork->open();
if (!ret) {
::LogError("Cannot open the YSF reflector network port");
::LogFinalise();
return 1;
}
}
std::string name = m_conf.getName();
bool fcsNetworkEnabled = m_conf.getFCSNetworkEnabled();
if (fcsNetworkEnabled) {
unsigned int txFrequency = m_conf.getTxFrequency();
unsigned int rxFrequency = m_conf.getRxFrequency();
std::string locator = calculateLocator();
unsigned int id = m_conf.getId();
unsigned int fcsPort = m_conf.getFCSNetworkPort();
m_fcsNetwork = new CFCSNetwork(fcsPort, m_callsign, rxFrequency, txFrequency, locator, id, debug);
ret = m_fcsNetwork->open();
if (!ret) {
::LogError("Cannot open the FCS reflector network port");
::LogFinalise();
return 1;
}
}
m_wiresX->setInfo(name, txFrequency, rxFrequency);
m_inactivityTimer.setTimeout(m_conf.getNetworkInactivityTimeout() * 60U);
std::string address = m_conf.getYSFNetworkParrotAddress();
unsigned int port = m_conf.getYSFNetworkParrotPort();
bool revert = m_conf.getNetworkRevert();
std::string startup = m_conf.getNetworkStartup();
if (port > 0U)
m_wiresX->setParrot(address, port);
if (!startup.empty()) {
if (startup.substr(0U, 3U) == "FCS" && m_fcsNetwork != NULL) {
LogMessage("Automatic connection to %s", startup.c_str());
address = m_conf.getYSFNetworkYSF2DMRAddress();
port = m_conf.getYSFNetworkYSF2DMRPort();
m_fcsNetwork->writeLink(startup);
if (port > 0U)
m_wiresX->setYSF2DMR(address, port);
if (!revert)
m_inactivityTimer.start();
m_wiresX->start();
m_lostTimer.start();
if (!startup.empty()) {
m_linkType = LINK_FCS;
} else if (m_ysfNetwork != NULL) {
CYSFReflector* reflector = m_wiresX->getReflector(startup);
if (reflector != NULL) {
LogMessage("Automatic connection to %5.5s - \"%s\"", reflector->m_id.c_str(), reflector->m_name.c_str());
@ -267,6 +260,8 @@ int CYSFGateway::run()
LogMessage("Starting YSFGateway-%s", VERSION);
createWiresX(&rptNetwork);
createGPS();
for (;;) {
@ -284,8 +279,7 @@ int CYSFGateway::run()
// Don't send out control data
m_exclude = (dt == YSF_DT_DATA_FR_MODE);
if (m_wiresX != NULL)
processWiresX(buffer, fi, dt, fn, ft);
processWiresX(buffer, fi, dt, fn, ft);
processDTMF(buffer, dt);
@ -293,13 +287,13 @@ int CYSFGateway::run()
m_gps->data(buffer + 14U, buffer + 35U, fi, dt, fn, ft);
}
if (ysfNetworkEnabled && m_linkType == LINK_YSF && !m_exclude) {
if (m_ysfNetwork != NULL && m_linkType == LINK_YSF && !m_exclude) {
m_ysfNetwork->write(buffer);
if (::memcmp(buffer + 0U, "YSFD", 4U) == 0)
m_inactivityTimer.start();
}
if (fcsNetworkEnabled && m_linkType == LINK_FCS && !m_exclude) {
if (m_fcsNetwork != NULL && m_linkType == LINK_FCS && !m_exclude) {
if (::memcmp(buffer + 0U, "YSFD", 4U) == 0) {
m_fcsNetwork->write(buffer);
m_inactivityTimer.start();
@ -314,20 +308,27 @@ int CYSFGateway::run()
}
}
while (m_ysfNetwork->read(buffer) > 0U) {
if (ysfNetworkEnabled && m_linkType == LINK_YSF) {
// Only pass through YSF data packets
if (::memcmp(buffer + 0U, "YSFD", 4U) == 0)
rptNetwork.write(buffer);
if (m_ysfNetwork != NULL) {
while (m_ysfNetwork->read(buffer) > 0U) {
if (m_linkType == LINK_YSF) {
// Only pass through YSF data packets
if (::memcmp(buffer + 0U, "YSFD", 4U) == 0)
rptNetwork.write(buffer);
m_lostTimer.start();
m_lostTimer.start();
}
}
}
while (m_fcsNetwork->read(buffer) > 0U) {
if (fcsNetworkEnabled && m_linkType == LINK_FCS) {
rptNetwork.write(buffer);
m_lostTimer.start();
if (m_fcsNetwork != NULL) {
while (m_fcsNetwork->read(buffer) > 0U) {
if (m_linkType == LINK_FCS) {
// Only pass through YSF data packets
if (::memcmp(buffer + 0U, "YSFD", 4U) == 0)
rptNetwork.write(buffer);
m_lostTimer.start();
}
}
}
@ -335,25 +336,25 @@ int CYSFGateway::run()
stopWatch.start();
rptNetwork.clock(ms);
m_ysfNetwork->clock(ms);
m_fcsNetwork->clock(ms);
if (m_ysfNetwork != NULL)
m_ysfNetwork->clock(ms);
if (m_fcsNetwork != NULL)
m_fcsNetwork->clock(ms);
if (m_gps != NULL)
m_gps->clock(ms);
if (m_wiresX != NULL)
m_wiresX->clock(ms);
m_wiresX->clock(ms);
m_inactivityTimer.clock(ms);
if (m_inactivityTimer.isRunning() && m_inactivityTimer.hasExpired()) {
if (m_linkType == LINK_YSF) {
CYSFReflector* reflector = NULL;
if (revert && !startup.empty() && m_wiresX != NULL)
if (revert && !startup.empty())
reflector = m_wiresX->getReflector(startup);
if (reflector != NULL) {
LogMessage("Reverting connection to %5.5s - \"%s\"", reflector->m_id.c_str(), reflector->m_name.c_str());
if (m_wiresX != NULL)
m_wiresX->processConnect(reflector);
m_wiresX->processConnect(reflector);
m_ysfNetwork->writeUnlink(3U);
@ -364,8 +365,7 @@ int CYSFGateway::run()
} else {
LogMessage("Disconnecting due to inactivity");
if (m_wiresX != NULL)
m_wiresX->processDisconnect();
m_wiresX->processDisconnect();
m_ysfNetwork->writeUnlink(3U);
m_ysfNetwork->clearDestination();
@ -383,7 +383,7 @@ int CYSFGateway::run()
if (m_lostTimer.isRunning() && m_lostTimer.hasExpired()) {
LogWarning("Link has failed, polls lost");
if (m_wiresX != NULL)
if (m_linkType == LINK_YSF)
m_wiresX->processDisconnect();
if (m_fcsNetwork != NULL)
@ -403,16 +403,22 @@ int CYSFGateway::run()
}
rptNetwork.close();
m_ysfNetwork->close();
m_fcsNetwork->close();
if (m_gps != NULL) {
m_gps->close();
delete m_gps;
}
delete m_ysfNetwork;
delete m_fcsNetwork;
if (m_ysfNetwork != NULL) {
m_ysfNetwork->close();
delete m_ysfNetwork;
}
if (m_fcsNetwork != NULL) {
m_fcsNetwork->close();
delete m_fcsNetwork;
}
delete m_wiresX;
::LogFinalise();
@ -447,6 +453,36 @@ void CYSFGateway::createGPS()
}
}
void CYSFGateway::createWiresX(CYSFNetwork* rptNetwork)
{
assert(rptNetwork != NULL);
std::string fileName = m_conf.getYSFNetworkHosts();
unsigned int reloadTime = m_conf.getYSFNetworkReloadTime();
m_wiresX = new CWiresX(m_callsign, m_suffix, rptNetwork, fileName, reloadTime);
std::string name = m_conf.getName();
unsigned int txFrequency = m_conf.getTxFrequency();
unsigned int rxFrequency = m_conf.getRxFrequency();
m_wiresX->setInfo(name, txFrequency, rxFrequency);
std::string address = m_conf.getYSFNetworkParrotAddress();
unsigned int port = m_conf.getYSFNetworkParrotPort();
if (port > 0U)
m_wiresX->setParrot(address, port);
address = m_conf.getYSFNetworkYSF2DMRAddress();
port = m_conf.getYSFNetworkYSF2DMRPort();
if (port > 0U)
m_wiresX->setYSF2DMR(address, port);
m_wiresX->start();
}
void CYSFGateway::processWiresX(const unsigned char* buffer, unsigned char fi, unsigned char dt, unsigned char fn, unsigned char ft)
{
assert(buffer != NULL);
@ -521,8 +557,7 @@ void CYSFGateway::processDTMF(const unsigned char* buffer, unsigned char dt)
std::string id = m_dtmf.getReflector();
CYSFReflector* reflector = m_wiresX->getReflector(id);
if (reflector != NULL) {
if (m_wiresX != NULL)
m_wiresX->processConnect(reflector);
m_wiresX->processConnect(reflector);
if (m_linkType == LINK_YSF)
m_ysfNetwork->writeUnlink(3U);
@ -570,8 +605,7 @@ void CYSFGateway::processDTMF(const unsigned char* buffer, unsigned char dt)
break;
case WXS_DISCONNECT:
if (m_linkType == LINK_YSF) {
if (m_wiresX != NULL)
m_wiresX->processDisconnect();
m_wiresX->processDisconnect();
LogMessage("Disconnect via DTMF has been requested by %10.10s", buffer + 14U);

@ -60,6 +60,7 @@ private:
std::string calculateLocator();
void processWiresX(const unsigned char* buffer, unsigned char fi, unsigned char dt, unsigned char fn, unsigned char ft);
void processDTMF(const unsigned char* buffer, unsigned char dt);
void createWiresX(CYSFNetwork* rptNetwork);
void createGPS();
};

@ -34,6 +34,12 @@ Port=14580
Password=9999
Description=APRS Description
[Network]
# Startup=
InactivityTimeout=10
# Revert=0
Debug=0
[YSF Network]
Enable=1
Port=42000
@ -43,12 +49,7 @@ ParrotAddress=127.0.0.1
ParrotPort=42012
YSF2DMRAddress=127.0.0.1
YSF2DMRPort=42013
# Startup=
InactivityTimeout=10
# Revert=0
Debug=0
[FCS Network]
Enable=1
Port=42000
Debug=0
Port=42001

Loading…
Cancel
Save