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 ";
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_node(),
m_network(network),
m_reflectors(hostsFile, reloadTime),
m_reflectors(reflectors),
m_reflector(NULL),
m_id(),
m_name(),
@ -159,10 +159,6 @@ void CWiresX::setYSF2DMR(const std::string& address, unsigned int port)
bool CWiresX::start()
{
bool ret = m_reflectors.load();
if (!ret)
return false;
m_reflectors.reload();
return true;
@ -239,11 +235,9 @@ CYSFReflector* CWiresX::getReflector() const
return m_reflector;
}
CYSFReflector* CWiresX::getReflector(const std::string& id)
void CWiresX::setReflector(CYSFReflector* reflector)
{
m_reflector = m_reflectors.find(id);
return m_reflector;
m_reflector = reflector;
}
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);
m_reflector = m_reflectors.find(id);
m_reflector = m_reflectors.findById(id);
if (m_reflector == NULL)
return WXS_NONE;

@ -43,7 +43,7 @@ enum WXSI_STATUS {
class CWiresX {
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();
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);
CYSFReflector* getReflector() const;
CYSFReflector* getReflector(const std::string& id);
void setReflector(CYSFReflector* reflector);
void processConnect(CYSFReflector* reflector);
void processDisconnect(const unsigned char* source = NULL);
@ -63,25 +63,25 @@ public:
void clock(unsigned int ms);
private:
std::string m_callsign;
std::string m_node;
CYSFNetwork* m_network;
CYSFReflectors m_reflectors;
CYSFReflector* m_reflector;
std::string m_id;
std::string m_name;
unsigned char* m_command;
unsigned int m_txFrequency;
unsigned int m_rxFrequency;
CTimer m_timer;
unsigned char m_seqNo;
unsigned char* m_header;
unsigned char* m_csd1;
unsigned char* m_csd2;
unsigned char* m_csd3;
WXSI_STATUS m_status;
unsigned int m_start;
std::string m_search;
std::string m_callsign;
std::string m_node;
CYSFNetwork* m_network;
CYSFReflectors& m_reflectors;
CYSFReflector* m_reflector;
std::string m_id;
std::string m_name;
unsigned char* m_command;
unsigned int m_txFrequency;
unsigned int m_rxFrequency;
CTimer m_timer;
unsigned char m_seqNo;
unsigned char* m_header;
unsigned char* m_csd1;
unsigned char* m_csd2;
unsigned char* m_csd3;
WXSI_STATUS m_status;
unsigned int m_start;
std::string m_search;
WX_STATUS processConnect(const unsigned char* source, const unsigned char* data);
void processDX(const unsigned char* source);

@ -17,7 +17,6 @@
*/
#include "YSFGateway.h"
#include "YSFReflectors.h"
#include "UDPSocket.h"
#include "StopWatch.h"
#include "Version.h"
@ -80,6 +79,7 @@ m_callsign(),
m_suffix(),
m_conf(configFile),
m_gps(NULL),
m_reflectors(NULL),
m_wiresX(NULL),
m_dtmf(),
m_ysfNetwork(NULL),
@ -182,7 +182,7 @@ int CYSFGateway::run()
unsigned int myPort = m_conf.getMyPort();
CYSFNetwork rptNetwork(myAddress, myPort, m_callsign, debug);
rptNetwork.setDestination(rptAddress, rptPort);
rptNetwork.setDestination("MMDVM", rptAddress, rptPort);
ret = rptNetwork.open();
if (!ret) {
@ -224,6 +224,17 @@ int CYSFGateway::run()
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();
bool revert = m_conf.getNetworkRevert();
@ -234,10 +245,6 @@ int CYSFGateway::run()
LogMessage("Starting YSFGateway-%s", VERSION);
createWiresX(&rptNetwork);
createGPS();
for (;;) {
unsigned char buffer[200U];
@ -441,10 +448,7 @@ 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);
m_wiresX = new CWiresX(m_callsign, m_suffix, rptNetwork, *m_reflectors);
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();
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_current = reflector->m_id;
@ -539,7 +543,7 @@ void CYSFGateway::processDTMF(unsigned char* buffer, unsigned char dt)
switch (status) {
case WXS_CONNECT_YSF: {
std::string id = m_dtmf.getReflector();
CYSFReflector* reflector = m_wiresX->getReflector(id);
CYSFReflector* reflector = m_reflectors->findById(id);
if (reflector != NULL) {
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);
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_current = id;
@ -576,6 +580,7 @@ void CYSFGateway::processDTMF(unsigned char* buffer, unsigned char dt)
}
if (m_linkType == LINK_YSF) {
m_wiresX->processDisconnect();
m_ysfNetwork->writeUnlink(3U);
m_ysfNetwork->clearDestination();
}
@ -707,11 +712,13 @@ void CYSFGateway::startupLinking()
m_lostTimer.stop();
m_linkType = LINK_NONE;
CYSFReflector* reflector = m_wiresX->getReflector(m_startup);
CYSFReflector* reflector = m_reflectors->findByName(m_startup);
if (reflector != NULL) {
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_current = m_startup;

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

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

@ -35,7 +35,9 @@ m_port(0U),
m_poll(NULL),
m_unlink(NULL),
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];
::memcpy(m_poll + 0U, "YSFP", 4U);
@ -89,16 +91,19 @@ bool CYSFNetwork::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_port = port;
m_linked = false;
}
void CYSFNetwork::clearDestination()
{
m_address.s_addr = INADDR_NONE;
m_port = 0U;
m_linked = false;
m_pollTimer.stop();
}
@ -136,6 +141,8 @@ void CYSFNetwork::writeUnlink(unsigned int count)
for (unsigned int i = 0U; i < count; i++)
m_socket.write(m_unlink, 14U, m_address, m_port);
m_linked = false;
}
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)
return;
if (::memcmp(buffer, "YSFP", 4U) == 0 && !m_linked) {
LogMessage("Linked to %s", m_name.c_str());
m_linked = true;
}
if (m_debug)
CUtils::dump(1U, "YSF Network Data Received", buffer, length);

@ -35,7 +35,7 @@ public:
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 write(const unsigned char* data);
@ -58,6 +58,8 @@ private:
unsigned char* m_unlink;
CRingBuffer<unsigned char> m_buffer;
CTimer m_pollTimer;
std::string m_name;
bool m_linked;
};
#endif

@ -163,9 +163,9 @@ bool CYSFReflectors::load()
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)
return *it;
}
@ -175,6 +175,21 @@ CYSFReflector* CYSFReflectors::find(const std::string& id)
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()
{
return m_currReflectors;

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

Loading…
Cancel
Save