1
0
Fork 0

Lots of Wires-X changes.

ycs232-kbc
Jonathan Naylor 7 years ago
parent f63c6069de
commit 0ad3f8712a

@ -42,11 +42,11 @@ const unsigned char DEFAULT_FICH[] = {0x20U, 0x00U, 0x01U, 0x00U};
const unsigned char NET_HEADER[] = "YSFD ALL "; const unsigned char NET_HEADER[] = "YSFD ALL ";
CWiresX::CWiresX(const std::string& callsign, const std::string& suffix, CYSFNetwork* network, const std::string& hostsFile, unsigned int reloadTime) : CWiresX::CWiresX(const std::string& callsign, const std::string& suffix, CYSFNetwork* network, CYSFReflectors& reflectors) :
m_callsign(callsign), m_callsign(callsign),
m_node(), m_node(),
m_network(network), m_network(network),
m_reflectors(hostsFile, reloadTime), m_reflectors(reflectors),
m_reflector(NULL), m_reflector(NULL),
m_id(), m_id(),
m_name(), m_name(),
@ -159,10 +159,6 @@ void CWiresX::setYSF2DMR(const std::string& address, unsigned int port)
bool CWiresX::start() bool CWiresX::start()
{ {
bool ret = m_reflectors.load();
if (!ret)
return false;
m_reflectors.reload(); m_reflectors.reload();
return true; return true;
@ -239,11 +235,9 @@ CYSFReflector* CWiresX::getReflector() const
return m_reflector; return m_reflector;
} }
CYSFReflector* CWiresX::getReflector(const std::string& id) void CWiresX::setReflector(CYSFReflector* reflector)
{ {
m_reflector = m_reflectors.find(id); m_reflector = reflector;
return m_reflector;
} }
void CWiresX::processDX(const unsigned char* source) void CWiresX::processDX(const unsigned char* source)
@ -287,7 +281,7 @@ WX_STATUS CWiresX::processConnect(const unsigned char* source, const unsigned ch
std::string id = std::string((char*)data, 5U); std::string id = std::string((char*)data, 5U);
m_reflector = m_reflectors.find(id); m_reflector = m_reflectors.findById(id);
if (m_reflector == NULL) if (m_reflector == NULL)
return WXS_NONE; return WXS_NONE;

@ -43,7 +43,7 @@ enum WXSI_STATUS {
class CWiresX { class CWiresX {
public: public:
CWiresX(const std::string& callsign, const std::string& suffix, CYSFNetwork* network, const std::string& hostsFile, unsigned int reloadTime); CWiresX(const std::string& callsign, const std::string& suffix, CYSFNetwork* network, CYSFReflectors& reflectors);
~CWiresX(); ~CWiresX();
void setInfo(const std::string& name, unsigned int txFrequency, unsigned int rxFrequency); void setInfo(const std::string& name, unsigned int txFrequency, unsigned int rxFrequency);
@ -55,7 +55,7 @@ public:
WX_STATUS process(const unsigned char* data, const unsigned char* source, unsigned char fi, unsigned char dt, unsigned char fn, unsigned char ft); WX_STATUS process(const unsigned char* data, const unsigned char* source, unsigned char fi, unsigned char dt, unsigned char fn, unsigned char ft);
CYSFReflector* getReflector() const; CYSFReflector* getReflector() const;
CYSFReflector* getReflector(const std::string& id); void setReflector(CYSFReflector* reflector);
void processConnect(CYSFReflector* reflector); void processConnect(CYSFReflector* reflector);
void processDisconnect(const unsigned char* source = NULL); void processDisconnect(const unsigned char* source = NULL);
@ -63,25 +63,25 @@ public:
void clock(unsigned int ms); void clock(unsigned int ms);
private: private:
std::string m_callsign; std::string m_callsign;
std::string m_node; std::string m_node;
CYSFNetwork* m_network; CYSFNetwork* m_network;
CYSFReflectors m_reflectors; CYSFReflectors& m_reflectors;
CYSFReflector* m_reflector; CYSFReflector* m_reflector;
std::string m_id; std::string m_id;
std::string m_name; std::string m_name;
unsigned char* m_command; unsigned char* m_command;
unsigned int m_txFrequency; unsigned int m_txFrequency;
unsigned int m_rxFrequency; unsigned int m_rxFrequency;
CTimer m_timer; CTimer m_timer;
unsigned char m_seqNo; unsigned char m_seqNo;
unsigned char* m_header; unsigned char* m_header;
unsigned char* m_csd1; unsigned char* m_csd1;
unsigned char* m_csd2; unsigned char* m_csd2;
unsigned char* m_csd3; unsigned char* m_csd3;
WXSI_STATUS m_status; WXSI_STATUS m_status;
unsigned int m_start; unsigned int m_start;
std::string m_search; std::string m_search;
WX_STATUS processConnect(const unsigned char* source, const unsigned char* data); WX_STATUS processConnect(const unsigned char* source, const unsigned char* data);
void processDX(const unsigned char* source); void processDX(const unsigned char* source);

@ -17,7 +17,6 @@
*/ */
#include "YSFGateway.h" #include "YSFGateway.h"
#include "YSFReflectors.h"
#include "UDPSocket.h" #include "UDPSocket.h"
#include "StopWatch.h" #include "StopWatch.h"
#include "Version.h" #include "Version.h"
@ -80,6 +79,7 @@ m_callsign(),
m_suffix(), m_suffix(),
m_conf(configFile), m_conf(configFile),
m_gps(NULL), m_gps(NULL),
m_reflectors(NULL),
m_wiresX(NULL), m_wiresX(NULL),
m_dtmf(), m_dtmf(),
m_ysfNetwork(NULL), m_ysfNetwork(NULL),
@ -182,7 +182,7 @@ int CYSFGateway::run()
unsigned int myPort = m_conf.getMyPort(); unsigned int myPort = m_conf.getMyPort();
CYSFNetwork rptNetwork(myAddress, myPort, m_callsign, debug); CYSFNetwork rptNetwork(myAddress, myPort, m_callsign, debug);
rptNetwork.setDestination(rptAddress, rptPort); rptNetwork.setDestination("MMDVM", rptAddress, rptPort);
ret = rptNetwork.open(); ret = rptNetwork.open();
if (!ret) { if (!ret) {
@ -224,6 +224,17 @@ int CYSFGateway::run()
m_inactivityTimer.setTimeout(m_conf.getNetworkInactivityTimeout() * 60U); m_inactivityTimer.setTimeout(m_conf.getNetworkInactivityTimeout() * 60U);
std::string fileName = m_conf.getYSFNetworkHosts();
unsigned int reloadTime = m_conf.getYSFNetworkReloadTime();
m_reflectors = new CYSFReflectors(fileName, reloadTime);
m_reflectors->load();
m_reflectors->reload();
createWiresX(&rptNetwork);
createGPS();
m_startup = m_conf.getNetworkStartup(); m_startup = m_conf.getNetworkStartup();
bool revert = m_conf.getNetworkRevert(); bool revert = m_conf.getNetworkRevert();
@ -234,10 +245,6 @@ int CYSFGateway::run()
LogMessage("Starting YSFGateway-%s", VERSION); LogMessage("Starting YSFGateway-%s", VERSION);
createWiresX(&rptNetwork);
createGPS();
for (;;) { for (;;) {
unsigned char buffer[200U]; unsigned char buffer[200U];
@ -441,10 +448,7 @@ void CYSFGateway::createWiresX(CYSFNetwork* rptNetwork)
{ {
assert(rptNetwork != NULL); assert(rptNetwork != NULL);
std::string fileName = m_conf.getYSFNetworkHosts(); m_wiresX = new CWiresX(m_callsign, m_suffix, rptNetwork, *m_reflectors);
unsigned int reloadTime = m_conf.getYSFNetworkReloadTime();
m_wiresX = new CWiresX(m_callsign, m_suffix, rptNetwork, fileName, reloadTime);
std::string name = m_conf.getName(); std::string name = m_conf.getName();
@ -485,7 +489,7 @@ void CYSFGateway::processWiresX(const unsigned char* buffer, unsigned char fi, u
CYSFReflector* reflector = m_wiresX->getReflector(); 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); 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->setDestination(reflector->m_name, reflector->m_address, reflector->m_port);
m_ysfNetwork->writePoll(3U); m_ysfNetwork->writePoll(3U);
m_current = reflector->m_id; m_current = reflector->m_id;
@ -539,7 +543,7 @@ void CYSFGateway::processDTMF(unsigned char* buffer, unsigned char dt)
switch (status) { switch (status) {
case WXS_CONNECT_YSF: { case WXS_CONNECT_YSF: {
std::string id = m_dtmf.getReflector(); std::string id = m_dtmf.getReflector();
CYSFReflector* reflector = m_wiresX->getReflector(id); CYSFReflector* reflector = m_reflectors->findById(id);
if (reflector != NULL) { if (reflector != NULL) {
m_wiresX->processConnect(reflector); m_wiresX->processConnect(reflector);
@ -553,7 +557,7 @@ void CYSFGateway::processDTMF(unsigned char* buffer, unsigned char dt)
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); 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->setDestination(reflector->m_name, reflector->m_address, reflector->m_port);
m_ysfNetwork->writePoll(3U); m_ysfNetwork->writePoll(3U);
m_current = id; m_current = id;
@ -576,6 +580,7 @@ void CYSFGateway::processDTMF(unsigned char* buffer, unsigned char dt)
} }
if (m_linkType == LINK_YSF) { if (m_linkType == LINK_YSF) {
m_wiresX->processDisconnect();
m_ysfNetwork->writeUnlink(3U); m_ysfNetwork->writeUnlink(3U);
m_ysfNetwork->clearDestination(); m_ysfNetwork->clearDestination();
} }
@ -707,11 +712,13 @@ void CYSFGateway::startupLinking()
m_lostTimer.stop(); m_lostTimer.stop();
m_linkType = LINK_NONE; m_linkType = LINK_NONE;
CYSFReflector* reflector = m_wiresX->getReflector(m_startup); CYSFReflector* reflector = m_reflectors->findByName(m_startup);
if (reflector != NULL) { if (reflector != NULL) {
LogMessage("Automatic (re-)connection to %5.5s - \"%s\"", reflector->m_id.c_str(), reflector->m_name.c_str()); LogMessage("Automatic (re-)connection to %5.5s - \"%s\"", reflector->m_id.c_str(), reflector->m_name.c_str());
m_ysfNetwork->setDestination(reflector->m_address, reflector->m_port); m_wiresX->setReflector(reflector);
m_ysfNetwork->setDestination(reflector->m_name, reflector->m_address, reflector->m_port);
m_ysfNetwork->writePoll(3U); m_ysfNetwork->writePoll(3U);
m_current = m_startup; m_current = m_startup;

@ -20,6 +20,7 @@
#define YSFGateway_H #define YSFGateway_H
#include "YSFNetwork.h" #include "YSFNetwork.h"
#include "YSFReflectors.h"
#include "FCSNetwork.h" #include "FCSNetwork.h"
#include "WiresX.h" #include "WiresX.h"
#include "Timer.h" #include "Timer.h"
@ -44,20 +45,21 @@ public:
int run(); int run();
private: private:
std::string m_callsign; std::string m_callsign;
std::string m_suffix; std::string m_suffix;
CConf m_conf; CConf m_conf;
CGPS* m_gps; CGPS* m_gps;
CWiresX* m_wiresX; CYSFReflectors* m_reflectors;
CDTMF m_dtmf; CWiresX* m_wiresX;
CYSFNetwork* m_ysfNetwork; CDTMF m_dtmf;
CFCSNetwork* m_fcsNetwork; CYSFNetwork* m_ysfNetwork;
LINK_TYPE m_linkType; CFCSNetwork* m_fcsNetwork;
std::string m_current; LINK_TYPE m_linkType;
std::string m_startup; std::string m_current;
bool m_exclude; std::string m_startup;
CTimer m_inactivityTimer; bool m_exclude;
CTimer m_lostTimer; CTimer m_inactivityTimer;
CTimer m_lostTimer;
void startupLinking(); void startupLinking();
std::string calculateLocator(); std::string calculateLocator();

@ -36,6 +36,7 @@ Description=APRS Description
[Network] [Network]
# Startup=FCS00120 # Startup=FCS00120
# Startup=Alabama-Link
InactivityTimeout=10 InactivityTimeout=10
Revert=0 Revert=0
Debug=0 Debug=0

@ -35,7 +35,9 @@ m_port(0U),
m_poll(NULL), m_poll(NULL),
m_unlink(NULL), m_unlink(NULL),
m_buffer(1000U, "YSF Network Buffer"), m_buffer(1000U, "YSF Network Buffer"),
m_pollTimer(1000U, 5U) m_pollTimer(1000U, 5U),
m_name(),
m_linked(false)
{ {
m_poll = new unsigned char[14U]; m_poll = new unsigned char[14U];
::memcpy(m_poll + 0U, "YSFP", 4U); ::memcpy(m_poll + 0U, "YSFP", 4U);
@ -89,16 +91,19 @@ bool CYSFNetwork::open()
return m_socket.open(); return m_socket.open();
} }
void CYSFNetwork::setDestination(const in_addr& address, unsigned int port) void CYSFNetwork::setDestination(const std::string& name, const in_addr& address, unsigned int port)
{ {
m_name = name;
m_address = address; m_address = address;
m_port = port; m_port = port;
m_linked = false;
} }
void CYSFNetwork::clearDestination() void CYSFNetwork::clearDestination()
{ {
m_address.s_addr = INADDR_NONE; m_address.s_addr = INADDR_NONE;
m_port = 0U; m_port = 0U;
m_linked = false;
m_pollTimer.stop(); m_pollTimer.stop();
} }
@ -136,6 +141,8 @@ void CYSFNetwork::writeUnlink(unsigned int count)
for (unsigned int i = 0U; i < count; i++) for (unsigned int i = 0U; i < count; i++)
m_socket.write(m_unlink, 14U, m_address, m_port); m_socket.write(m_unlink, 14U, m_address, m_port);
m_linked = false;
} }
void CYSFNetwork::clock(unsigned int ms) void CYSFNetwork::clock(unsigned int ms)
@ -158,6 +165,11 @@ void CYSFNetwork::clock(unsigned int ms)
if (address.s_addr != m_address.s_addr || port != m_port) if (address.s_addr != m_address.s_addr || port != m_port)
return; return;
if (::memcmp(buffer, "YSFP", 4U) == 0 && !m_linked) {
LogMessage("Linked to %s", m_name.c_str());
m_linked = true;
}
if (m_debug) if (m_debug)
CUtils::dump(1U, "YSF Network Data Received", buffer, length); CUtils::dump(1U, "YSF Network Data Received", buffer, length);

@ -35,7 +35,7 @@ public:
bool open(); bool open();
void setDestination(const in_addr& address, unsigned int port); void setDestination(const std::string& name, const in_addr& address, unsigned int port);
void clearDestination(); void clearDestination();
void write(const unsigned char* data); void write(const unsigned char* data);
@ -58,6 +58,8 @@ private:
unsigned char* m_unlink; unsigned char* m_unlink;
CRingBuffer<unsigned char> m_buffer; CRingBuffer<unsigned char> m_buffer;
CTimer m_pollTimer; CTimer m_pollTimer;
std::string m_name;
bool m_linked;
}; };
#endif #endif

@ -163,9 +163,9 @@ bool CYSFReflectors::load()
return true; return true;
} }
CYSFReflector* CYSFReflectors::find(const std::string& id) CYSFReflector* CYSFReflectors::findById(const std::string& id)
{ {
for (std::vector<CYSFReflector*>::iterator it = m_currReflectors.begin(); it != m_currReflectors.end(); ++it) { for (std::vector<CYSFReflector*>::const_iterator it = m_currReflectors.cbegin(); it != m_currReflectors.cend(); ++it) {
if (id == (*it)->m_id) if (id == (*it)->m_id)
return *it; return *it;
} }
@ -175,6 +175,21 @@ CYSFReflector* CYSFReflectors::find(const std::string& id)
return NULL; return NULL;
} }
CYSFReflector* CYSFReflectors::findByName(const std::string& name)
{
std::string fullName = name;
fullName.resize(16U, ' ');
for (std::vector<CYSFReflector*>::const_iterator it = m_currReflectors.cbegin(); it != m_currReflectors.cend(); ++it) {
if (fullName == (*it)->m_name)
return *it;
}
LogMessage("Trying to find non existent YSF reflector with a name of %s", name.c_str());
return NULL;
}
std::vector<CYSFReflector*>& CYSFReflectors::current() std::vector<CYSFReflector*>& CYSFReflectors::current()
{ {
return m_currReflectors; return m_currReflectors;

@ -55,7 +55,8 @@ public:
bool load(); bool load();
CYSFReflector* find(const std::string& id); CYSFReflector* findById(const std::string& id);
CYSFReflector* findByName(const std::string& name);
std::vector<CYSFReflector*>& current(); std::vector<CYSFReflector*>& current();

Loading…
Cancel
Save