1
0
Fork 0

Update the reflector to accomodate the new YSF protocol.

ycs232-kbc
Jonathan Naylor 8 years ago
parent 61ee63da69
commit 1c45e41db8

@ -115,19 +115,13 @@ void CNetwork::clock(unsigned int ms)
return; return;
} }
// Invalid packet type?
if (::memcmp(buffer, "YSFD", 4U) != 0)
return;
// Simulate a poll with the data
m_callsign = std::string((char*)(buffer + 4U), YSF_CALLSIGN_LENGTH);
m_address = address;
m_port = port;
if (m_debug) if (m_debug)
CUtils::dump(1U, "YSF Network Data Received", buffer, length); CUtils::dump(1U, "YSF Network Data Received", buffer, length);
m_buffer.addData(buffer, 155U); unsigned char len = length;
m_buffer.addData(&len, 1U);
m_buffer.addData(buffer, length);
} }
unsigned int CNetwork::readData(unsigned char* data) unsigned int CNetwork::readData(unsigned char* data)
@ -137,9 +131,12 @@ unsigned int CNetwork::readData(unsigned char* data)
if (m_buffer.isEmpty()) if (m_buffer.isEmpty())
return 0U; return 0U;
m_buffer.getData(data, 155U); unsigned char len = 0U;
m_buffer.getData(&len, 1U);
m_buffer.getData(data, len);
return 155U; return len;
} }
bool CNetwork::readPoll(std::string& callsign, in_addr& address, unsigned int& port) bool CNetwork::readPoll(std::string& callsign, in_addr& address, unsigned int& port)

@ -42,6 +42,7 @@ const char* DEFAULT_INI_FILE = "YSFReflector.ini";
const char* DEFAULT_INI_FILE = "/etc/YSFReflector.ini"; const char* DEFAULT_INI_FILE = "/etc/YSFReflector.ini";
#endif #endif
#include <algorithm>
#include <cstdio> #include <cstdio>
#include <cstdlib> #include <cstdlib>
#include <cstdarg> #include <cstdarg>
@ -186,7 +187,7 @@ void CYSFReflector::run()
for (;;) { for (;;) {
unsigned char buffer[200U]; unsigned char buffer[200U];
// Refresh/add repeaters based on their polls/simulated polls // Refresh/add repeaters based on their polls
in_addr address; in_addr address;
unsigned int port; unsigned int port;
std::string callsign; std::string callsign;
@ -212,6 +213,17 @@ void CYSFReflector::run()
unsigned int len = network.readData(buffer); unsigned int len = network.readData(buffer);
if (len > 0U) { if (len > 0U) {
if (::memcmp(buffer + 0U, "YSFU", 4U) == 0) {
std::string callsign = std::string((char*)(buffer + 4U), 10U);
CYSFRepeater* rpt = findRepeater(callsign);
if (rpt != NULL) {
LogMessage("Removing %s (unlinked)", callsign.c_str());
std::vector<CYSFRepeater*>::iterator it = std::find(m_repeaters.begin(), m_repeaters.end(), rpt);
if (it != m_repeaters.end())
m_repeaters.erase(it);
network.setCount(m_repeaters.size());
}
} else if (::memcmp(buffer + 0U, "YSFD", 4U) == 0) {
if (!watchdogTimer.isRunning()) { if (!watchdogTimer.isRunning()) {
::memcpy(tag, buffer + 4U, YSF_CALLSIGN_LENGTH); ::memcpy(tag, buffer + 4U, YSF_CALLSIGN_LENGTH);
@ -260,6 +272,7 @@ void CYSFReflector::run()
} }
} }
} }
}
unsigned int ms = stopWatch.elapsed(); unsigned int ms = stopWatch.elapsed();
stopWatch.start(); stopWatch.start();
@ -279,7 +292,7 @@ void CYSFReflector::run()
for (std::vector<CYSFRepeater*>::iterator it = m_repeaters.begin(); it != m_repeaters.end(); ++it) { for (std::vector<CYSFRepeater*>::iterator it = m_repeaters.begin(); it != m_repeaters.end(); ++it) {
if ((*it)->m_timer.hasExpired()) { if ((*it)->m_timer.hasExpired()) {
LogMessage("Removing %s", (*it)->m_callsign.c_str()); LogMessage("Removing %s (polls lost)", (*it)->m_callsign.c_str());
m_repeaters.erase(it); m_repeaters.erase(it);
network.setCount(m_repeaters.size()); network.setCount(m_repeaters.size());
break; break;
@ -322,6 +335,16 @@ CYSFRepeater* CYSFReflector::findRepeater(const std::string& callsign, const in_
return NULL; return NULL;
} }
CYSFRepeater* CYSFReflector::findRepeater(const std::string& callsign) const
{
for (std::vector<CYSFRepeater*>::const_iterator it = m_repeaters.begin(); it != m_repeaters.end(); ++it) {
if ((*it)->m_callsign == callsign)
return *it;
}
return NULL;
}
void CYSFReflector::dumpRepeaters() const void CYSFReflector::dumpRepeaters() const
{ {
if (m_repeaters.size() == 0U) { if (m_repeaters.size() == 0U) {

@ -67,6 +67,7 @@ private:
std::vector<CYSFRepeater*> m_repeaters; std::vector<CYSFRepeater*> m_repeaters;
CYSFRepeater* findRepeater(const std::string& callsign, const in_addr& address, unsigned int port) const; CYSFRepeater* findRepeater(const std::string& callsign, const in_addr& address, unsigned int port) const;
CYSFRepeater* findRepeater(const std::string& callsign) const;
void dumpRepeaters() const; void dumpRepeaters() const;
}; };

Loading…
Cancel
Save