1
0
Fork 0

Start splitting YSF and FCS functionality.

ycs232-kbc
Jonathan Naylor 7 years ago
parent 05c0cce1db
commit 9dc484ea64

@ -173,6 +173,8 @@ WX_STATUS CDTMF::validate() const
if (m_command.at(1U) < '0' || m_command.at(1U) > '9') if (m_command.at(1U) < '0' || m_command.at(1U) > '9')
return WXS_NONE; return WXS_NONE;
} }
return WXS_CONNECT_FCS;
} else { } else {
for (unsigned int i = 1U; i <= 6U; i++) { for (unsigned int i = 1U; i <= 6U; i++) {
if (m_command.at(1U) < '0' || m_command.at(1U) > '9') if (m_command.at(1U) < '0' || m_command.at(1U) > '9')
@ -181,9 +183,9 @@ WX_STATUS CDTMF::validate() const
if (m_command == "#99999") if (m_command == "#99999")
return WXS_DISCONNECT; return WXS_DISCONNECT;
}
return WXS_CONNECT; return WXS_CONNECT_YSF;
}
} }
std::string CDTMF::getReflector() std::string CDTMF::getReflector()

@ -294,7 +294,7 @@ WX_STATUS CWiresX::processConnect(const unsigned char* source, const unsigned ch
m_status = WXSI_CONNECT; m_status = WXSI_CONNECT;
m_timer.start(); m_timer.start();
return WXS_CONNECT; return WXS_CONNECT_YSF;
} }
void CWiresX::processConnect(CYSFReflector* reflector) void CWiresX::processConnect(CYSFReflector* reflector)

@ -27,7 +27,8 @@
enum WX_STATUS { enum WX_STATUS {
WXS_NONE, WXS_NONE,
WXS_CONNECT, WXS_CONNECT_YSF,
WXS_CONNECT_FCS,
WXS_DISCONNECT WXS_DISCONNECT
}; };

@ -80,11 +80,14 @@ m_suffix(),
m_conf(configFile), m_conf(configFile),
m_gps(NULL), m_gps(NULL),
m_wiresX(NULL), m_wiresX(NULL),
m_dtmf(NULL), m_dtmf(),
m_ysfNetwork(NULL), m_ysfNetwork(NULL),
m_fcsNetwork(NULL), m_fcsNetwork(NULL),
m_linked(false), m_linkType(LINK_NONE),
m_exclude(false) m_exclude(false),
m_inactivityTimer(1000U),
m_lostTimer(1000U, 120U),
m_ysfPollTimer(1000U, 5U)
{ {
} }
@ -205,20 +208,18 @@ int CYSFGateway::run()
return 1; return 1;
} }
CTimer inactivityTimer(1000U, m_conf.getYSFNetworkInactivityTimeout() * 60U); m_inactivityTimer.setTimeout(m_conf.getYSFNetworkInactivityTimeout() * 60U);
CTimer lostTimer(1000U, 120U);
CTimer pollTimer(1000U, 5U);
bool revert = m_conf.getYSFNetworkRevert(); bool revert = m_conf.getYSFNetworkRevert();
std::string startup = m_conf.getYSFNetworkStartup(); std::string startup = m_conf.getYSFNetworkStartup();
bool fcsNetworkEnabled = m_conf.getFCSNetworkEnabled();
bool ysfNetworkEnabled = m_conf.getYSFNetworkEnabled(); bool ysfNetworkEnabled = m_conf.getYSFNetworkEnabled();
if (ysfNetworkEnabled) { if (ysfNetworkEnabled) {
std::string fileName = m_conf.getYSFNetworkHosts(); std::string fileName = m_conf.getYSFNetworkHosts();
unsigned int reloadTime = m_conf.getYSFNetworkReloadTime(); unsigned int reloadTime = m_conf.getYSFNetworkReloadTime();
m_wiresX = new CWiresX(m_callsign, m_suffix, &rptNetwork, fileName, reloadTime); m_wiresX = new CWiresX(m_callsign, m_suffix, &rptNetwork, fileName, reloadTime);
m_dtmf = new CDTMF;
std::string name = m_conf.getName(); std::string name = m_conf.getName();
unsigned int txFrequency = m_conf.getTxFrequency(); unsigned int txFrequency = m_conf.getTxFrequency();
@ -251,12 +252,12 @@ int CYSFGateway::run()
m_ysfNetwork->writePoll(); m_ysfNetwork->writePoll();
if (!revert) if (!revert)
inactivityTimer.start(); m_inactivityTimer.start();
lostTimer.start(); m_lostTimer.start();
pollTimer.start(); m_ysfPollTimer.start();
m_linked = true; m_linkType = LINK_YSF;
} }
} }
} }
@ -283,133 +284,52 @@ int CYSFGateway::run()
// Don't send out control data // Don't send out control data
m_exclude = (dt == YSF_DT_DATA_FR_MODE); m_exclude = (dt == YSF_DT_DATA_FR_MODE);
if (m_wiresX != NULL) { if (m_wiresX != NULL)
WX_STATUS status = m_wiresX->process(buffer + 35U, buffer + 14U, fi, dt, fn, ft); processWiresX(buffer, fi, dt, fn, ft);
switch (status) {
case WXS_CONNECT: {
m_ysfNetwork->writeUnlink();
m_ysfNetwork->writeUnlink();
m_ysfNetwork->writeUnlink();
CYSFReflector* reflector = m_wiresX->getReflector();
LogMessage("Connect to %5.5s - \"%s\" has been requested by %10.10s", reflector->m_id.c_str(), reflector->m_name.c_str(), buffer + 14U);
m_ysfNetwork->setDestination(reflector->m_address, reflector->m_port);
m_ysfNetwork->writePoll();
m_ysfNetwork->writePoll();
m_ysfNetwork->writePoll();
inactivityTimer.start();
lostTimer.start();
pollTimer.start();
m_linked = true;
}
break;
case WXS_DISCONNECT:
LogMessage("Disconnect has been requested by %10.10s", buffer + 14U);
m_ysfNetwork->writeUnlink();
m_ysfNetwork->writeUnlink();
m_ysfNetwork->writeUnlink();
m_ysfNetwork->clearDestination();
inactivityTimer.stop();
lostTimer.stop();
pollTimer.stop();
m_linked = false;
break;
default:
break;
}
status = WXS_NONE;
switch (dt) {
case YSF_DT_VD_MODE2:
status = m_dtmf->decodeVDMode2(buffer + 35U, (buffer[34U] & 0x01U) == 0x01U);
break;
default:
break;
}
switch (status) {
case WXS_CONNECT: {
std::string id = m_dtmf->getReflector();
CYSFReflector* reflector = m_wiresX->getReflector(id);
if (reflector != NULL) {
m_wiresX->processConnect(reflector);
if (m_linked) {
m_ysfNetwork->writeUnlink();
m_ysfNetwork->writeUnlink();
m_ysfNetwork->writeUnlink();
}
LogMessage("Connect via DTMF to %5.5s - \"%s\" has been requested by %10.10s", reflector->m_id.c_str(), reflector->m_name.c_str(), buffer + 14U);
m_ysfNetwork->setDestination(reflector->m_address, reflector->m_port);
m_ysfNetwork->writePoll();
m_ysfNetwork->writePoll();
m_ysfNetwork->writePoll();
inactivityTimer.start();
lostTimer.start();
pollTimer.start();
m_linked = true;
}
}
break;
case WXS_DISCONNECT:
if (m_linked) {
m_wiresX->processDisconnect();
LogMessage("Disconnect via DTMF has been requested by %10.10s", buffer + 14U);
m_ysfNetwork->writeUnlink();
m_ysfNetwork->writeUnlink();
m_ysfNetwork->writeUnlink();
m_ysfNetwork->clearDestination();
inactivityTimer.stop();
lostTimer.stop();
pollTimer.stop();
m_linked = false; processDTMF(buffer, dt);
}
break;
default:
break;
}
}
if (m_gps != NULL) if (m_gps != NULL)
m_gps->data(buffer + 14U, buffer + 35U, fi, dt, fn, ft); m_gps->data(buffer + 14U, buffer + 35U, fi, dt, fn, ft);
} }
if (ysfNetworkEnabled && m_linked && !m_exclude) { if (ysfNetworkEnabled && m_linkType == LINK_YSF && !m_exclude) {
m_ysfNetwork->write(buffer); m_ysfNetwork->write(buffer);
if (::memcmp(buffer + 0U, "YSFD", 4U) == 0) if (::memcmp(buffer + 0U, "YSFD", 4U) == 0)
inactivityTimer.start(); m_inactivityTimer.start();
}
if (fcsNetworkEnabled && m_linkType == LINK_FCS && !m_exclude) {
m_fcsNetwork->write(buffer);
if (::memcmp(buffer + 0U, "YSFD", 4U) == 0)
m_inactivityTimer.start();
} }
if ((buffer[34U] & 0x01U) == 0x01U) { if ((buffer[34U] & 0x01U) == 0x01U) {
if (m_gps != NULL) if (m_gps != NULL)
m_gps->reset(); m_gps->reset();
if (m_dtmf != NULL) m_dtmf.reset();
m_dtmf->reset();
m_exclude = false; m_exclude = false;
} }
} }
while (m_ysfNetwork->read(buffer) > 0U) { while (m_ysfNetwork->read(buffer) > 0U) {
if (ysfNetworkEnabled && m_linked) { if (ysfNetworkEnabled && m_linkType == LINK_YSF) {
// Only pass through YSF data packets
if (::memcmp(buffer + 0U, "YSFD", 4U) == 0)
rptNetwork.write(buffer);
m_lostTimer.start();
}
}
while (m_fcsNetwork->read(buffer) > 0U) {
if (fcsNetworkEnabled && m_linkType == LINK_FCS) {
// Only pass through YSF data packets // Only pass through YSF data packets
if (::memcmp(buffer + 0U, "YSFD", 4U) == 0) if (::memcmp(buffer + 0U, "YSFD", 4U) == 0)
rptNetwork.write(buffer); rptNetwork.write(buffer);
lostTimer.start(); m_lostTimer.start();
} }
} }
@ -424,9 +344,9 @@ int CYSFGateway::run()
if (m_wiresX != NULL) if (m_wiresX != NULL)
m_wiresX->clock(ms); m_wiresX->clock(ms);
inactivityTimer.clock(ms); m_inactivityTimer.clock(ms);
if (inactivityTimer.isRunning() && inactivityTimer.hasExpired()) { if (m_inactivityTimer.isRunning() && m_inactivityTimer.hasExpired()) {
if (m_linked) { if (m_linkType == LINK_YSF) {
CYSFReflector* reflector = NULL; CYSFReflector* reflector = NULL;
if (revert && !startup.empty() && m_wiresX != NULL) if (revert && !startup.empty() && m_wiresX != NULL)
reflector = m_wiresX->getReflector(startup); reflector = m_wiresX->getReflector(startup);
@ -434,6 +354,7 @@ int CYSFGateway::run()
if (reflector != NULL) { if (reflector != NULL) {
LogMessage("Reverting connection to %5.5s - \"%s\"", reflector->m_id.c_str(), reflector->m_name.c_str()); 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(); m_ysfNetwork->writeUnlink();
@ -445,8 +366,8 @@ int CYSFGateway::run()
m_ysfNetwork->writePoll(); m_ysfNetwork->writePoll();
m_ysfNetwork->writePoll(); m_ysfNetwork->writePoll();
lostTimer.start(); m_lostTimer.start();
pollTimer.start(); m_ysfPollTimer.start();
} else { } else {
LogMessage("Disconnecting due to inactivity"); LogMessage("Disconnecting due to inactivity");
@ -458,36 +379,37 @@ int CYSFGateway::run()
m_ysfNetwork->writeUnlink(); m_ysfNetwork->writeUnlink();
m_ysfNetwork->clearDestination(); m_ysfNetwork->clearDestination();
lostTimer.stop(); m_lostTimer.stop();
pollTimer.stop(); m_ysfPollTimer.stop();
m_linked = false; m_linkType = LINK_NONE;
} }
} }
inactivityTimer.stop(); m_inactivityTimer.stop();
} }
lostTimer.clock(ms); m_lostTimer.clock(ms);
if (lostTimer.isRunning() && lostTimer.hasExpired()) { if (m_lostTimer.isRunning() && m_lostTimer.hasExpired()) {
LogWarning("Link has failed, polls lost"); LogWarning("Link has failed, polls lost");
if (m_wiresX != NULL) if (m_wiresX != NULL)
m_wiresX->processDisconnect(); m_wiresX->processDisconnect();
if (m_ysfNetwork != NULL)
m_ysfNetwork->clearDestination(); m_ysfNetwork->clearDestination();
inactivityTimer.stop(); m_inactivityTimer.stop();
lostTimer.stop(); m_lostTimer.stop();
pollTimer.stop(); m_ysfPollTimer.stop();
m_linked = false; m_linkType = LINK_NONE;
} }
pollTimer.clock(ms); m_ysfPollTimer.clock(ms);
if (pollTimer.isRunning() && pollTimer.hasExpired()) { if (m_ysfPollTimer.isRunning() && m_ysfPollTimer.hasExpired()) {
m_ysfNetwork->writePoll(); m_ysfNetwork->writePoll();
pollTimer.start(); m_ysfPollTimer.start();
} }
if (ms < 5U) if (ms < 5U)
@ -506,7 +428,6 @@ int CYSFGateway::run()
delete m_ysfNetwork; delete m_ysfNetwork;
delete m_fcsNetwork; delete m_fcsNetwork;
delete m_wiresX; delete m_wiresX;
delete m_dtmf;
::LogFinalise(); ::LogFinalise();
@ -539,3 +460,114 @@ void CYSFGateway::createGPS()
m_gps = NULL; m_gps = NULL;
} }
} }
void CYSFGateway::processWiresX(const unsigned char* buffer, unsigned char fi, unsigned char dt, unsigned char fn, unsigned char ft)
{
assert(buffer != NULL);
WX_STATUS status = m_wiresX->process(buffer + 35U, buffer + 14U, fi, dt, fn, ft);
switch (status) {
case WXS_CONNECT_YSF: {
m_ysfNetwork->writeUnlink();
m_ysfNetwork->writeUnlink();
m_ysfNetwork->writeUnlink();
CYSFReflector* reflector = m_wiresX->getReflector();
LogMessage("Connect to %5.5s - \"%s\" has been requested by %10.10s", reflector->m_id.c_str(), reflector->m_name.c_str(), buffer + 14U);
m_ysfNetwork->setDestination(reflector->m_address, reflector->m_port);
m_ysfNetwork->writePoll();
m_ysfNetwork->writePoll();
m_ysfNetwork->writePoll();
m_inactivityTimer.start();
m_lostTimer.start();
m_ysfPollTimer.start();
m_linkType = LINK_YSF;
}
break;
case WXS_DISCONNECT:
LogMessage("Disconnect has been requested by %10.10s", buffer + 14U);
m_ysfNetwork->writeUnlink();
m_ysfNetwork->writeUnlink();
m_ysfNetwork->writeUnlink();
m_ysfNetwork->clearDestination();
m_inactivityTimer.stop();
m_lostTimer.stop();
m_ysfPollTimer.stop();
m_linkType = LINK_NONE;
break;
default:
break;
}
}
void CYSFGateway::processDTMF(const unsigned char* buffer, unsigned char dt)
{
assert(buffer != NULL);
WX_STATUS status = WXS_NONE;
switch (dt) {
case YSF_DT_VD_MODE2:
status = m_dtmf.decodeVDMode2(buffer + 35U, (buffer[34U] & 0x01U) == 0x01U);
break;
default:
break;
}
switch (status) {
case WXS_CONNECT_YSF: {
std::string id = m_dtmf.getReflector();
CYSFReflector* reflector = m_wiresX->getReflector(id);
if (reflector != NULL) {
if (m_wiresX != NULL)
m_wiresX->processConnect(reflector);
if (m_linkType == LINK_YSF) {
m_ysfNetwork->writeUnlink();
m_ysfNetwork->writeUnlink();
m_ysfNetwork->writeUnlink();
}
LogMessage("Connect via DTMF to %5.5s - \"%s\" has been requested by %10.10s", reflector->m_id.c_str(), reflector->m_name.c_str(), buffer + 14U);
m_ysfNetwork->setDestination(reflector->m_address, reflector->m_port);
m_ysfNetwork->writePoll();
m_ysfNetwork->writePoll();
m_ysfNetwork->writePoll();
m_inactivityTimer.start();
m_lostTimer.start();
m_ysfPollTimer.start();
m_linkType = LINK_YSF;
}
}
break;
case WXS_DISCONNECT:
if (m_linkType == LINK_YSF) {
if (m_wiresX != NULL)
m_wiresX->processDisconnect();
LogMessage("Disconnect via DTMF has been requested by %10.10s", buffer + 14U);
m_ysfNetwork->writeUnlink();
m_ysfNetwork->writeUnlink();
m_ysfNetwork->writeUnlink();
m_ysfNetwork->clearDestination();
m_inactivityTimer.stop();
m_lostTimer.stop();
m_ysfPollTimer.stop();
m_linkType = LINK_NONE;
}
break;
default:
break;
}
}

@ -22,12 +22,19 @@
#include "YSFNetwork.h" #include "YSFNetwork.h"
#include "FCSNetwork.h" #include "FCSNetwork.h"
#include "WiresX.h" #include "WiresX.h"
#include "Timer.h"
#include "Conf.h" #include "Conf.h"
#include "DTMF.h" #include "DTMF.h"
#include "GPS.h" #include "GPS.h"
#include <string> #include <string>
enum LINK_TYPE {
LINK_NONE,
LINK_YSF,
LINK_FCS
};
class CYSFGateway class CYSFGateway
{ {
public: public:
@ -42,12 +49,17 @@ private:
CConf m_conf; CConf m_conf;
CGPS* m_gps; CGPS* m_gps;
CWiresX* m_wiresX; CWiresX* m_wiresX;
CDTMF* m_dtmf; CDTMF m_dtmf;
CYSFNetwork* m_ysfNetwork; CYSFNetwork* m_ysfNetwork;
CFCSNetwork* m_fcsNetwork; CFCSNetwork* m_fcsNetwork;
bool m_linked; LINK_TYPE m_linkType;
bool m_exclude; bool m_exclude;
CTimer m_inactivityTimer;
CTimer m_lostTimer;
CTimer m_ysfPollTimer;
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 createGPS(); void createGPS();
}; };

Loading…
Cancel
Save