1
0
Fork 0

Mostly work on the ALL command.

ycs232-kbc
Jonathan Naylor 9 years ago
parent 489d6077fd
commit 1f2b25de46

@ -20,9 +20,11 @@
#include "Hosts.h" #include "Hosts.h"
#include "Log.h" #include "Log.h"
#include <algorithm>
#include <cstdio> #include <cstdio>
#include <cassert> #include <cassert>
#include <cstring> #include <cstring>
#include <cctype>
CReflectors::CReflectors(const std::string& hostsFile, unsigned int statusPort) : CReflectors::CReflectors(const std::string& hostsFile, unsigned int statusPort) :
m_hostsFile(hostsFile), m_hostsFile(hostsFile),
@ -30,13 +32,15 @@ m_socket(statusPort),
m_reflectors(), m_reflectors(),
m_it(), m_it(),
m_current(), m_current(),
m_timer(1000U, 60U) m_timer(1000U, 15U)
{ {
assert(statusPort > 0U); assert(statusPort > 0U);
} }
CReflectors::~CReflectors() CReflectors::~CReflectors()
{ {
for (std::vector<CYSFReflector*>::iterator it = m_reflectors.begin(); it != m_reflectors.end(); ++it)
delete *it;
} }
bool CReflectors::load() bool CReflectors::load()
@ -82,15 +86,34 @@ CYSFReflector* CReflectors::find(const std::string& id)
return NULL; return NULL;
} }
static int refComparison(const CYSFReflector* r1, const CYSFReflector* r2)
{
assert(r1 != NULL);
assert(r2 != NULL);
std::string name1 = r1->m_name;
std::string name2 = r2->m_name;
for (unsigned int i = 0U; i < name1.size() && i < name2.size(); i++) {
int c = ::toupper(name1.at(i)) - ::toupper(name2.at(i));
if (c != 0)
return c;
}
return int(name1.size()) - int(name2.size());
}
std::vector<CYSFReflector*>& CReflectors::current() std::vector<CYSFReflector*>& CReflectors::current()
{ {
m_current.clear(); m_current.clear();
for (std::vector<CYSFReflector*>::iterator it = m_reflectors.begin(); it != m_reflectors.end(); ++it) { for (std::vector<CYSFReflector*>::iterator it = m_reflectors.begin(); it != m_reflectors.end(); ++it) {
if ((*it)->m_timer.isRunning()) if ((*it)->m_seen)
m_current.push_back(*it); m_current.push_back(*it);
} }
std::sort(m_current.begin(), m_current.end(), ::refComparison);
return m_current; return m_current;
} }
@ -121,7 +144,7 @@ void CReflectors::clock(unsigned int ms)
std::string desc = std::string((char*)(buffer + 25U), 14U); std::string desc = std::string((char*)(buffer + 25U), 14U);
std::string cnt = std::string((char*)(buffer + 39U), 3U); std::string cnt = std::string((char*)(buffer + 39U), 3U);
LogDebug("Have YSFS reply from %s/%s/%s/%s", id.c_str(), name.c_str(), desc.c_str(), cnt.c_str()); LogDebug("Have reflector status reply from %s/%s/%s/%s", id.c_str(), name.c_str(), desc.c_str(), cnt.c_str());
for (std::vector<CYSFReflector*>::iterator it = m_reflectors.begin(); it != m_reflectors.end(); ++it) { for (std::vector<CYSFReflector*>::iterator it = m_reflectors.begin(); it != m_reflectors.end(); ++it) {
in_addr itAddr = (*it)->m_address; in_addr itAddr = (*it)->m_address;
@ -132,14 +155,10 @@ void CReflectors::clock(unsigned int ms)
(*it)->m_name = name; (*it)->m_name = name;
(*it)->m_desc = desc; (*it)->m_desc = desc;
(*it)->m_count = cnt; (*it)->m_count = cnt;
(*it)->m_timer.start(); (*it)->m_seen = true;
LogDebug("Updating %s", id.c_str());
break; break;
} }
} }
} }
} }
for (std::vector<CYSFReflector*>::iterator it = m_reflectors.begin(); it != m_reflectors.end(); ++it)
(*it)->m_timer.clock(ms);
} }

@ -34,7 +34,7 @@ public:
m_count("000"), m_count("000"),
m_address(), m_address(),
m_port(0U), m_port(0U),
m_timer(1000U, 700U) m_seen(false)
{ {
} }
@ -44,7 +44,7 @@ public:
std::string m_count; std::string m_count;
in_addr m_address; in_addr m_address;
unsigned int m_port; unsigned int m_port;
CTimer m_timer; bool m_seen;
}; };
class CReflectors { class CReflectors {

@ -50,7 +50,7 @@ m_id(),
m_name(), m_name(),
m_txFrequency(0U), m_txFrequency(0U),
m_rxFrequency(0U), m_rxFrequency(0U),
m_timer(1000U, 1U), m_timer(1000U, 2U),
m_seqNo(0U), m_seqNo(0U),
m_header(NULL), m_header(NULL),
m_source(NULL), m_source(NULL),
@ -303,8 +303,17 @@ void CWiresX::createReply(const unsigned char* data, unsigned int length)
break; break;
case 1U: case 1U:
payload.writeDataFRModeData1(m_csd3, buffer + 35U); payload.writeDataFRModeData1(m_csd3, buffer + 35U);
if (bn == 0U) {
payload.writeDataFRModeData2(data + offset, buffer + 35U); payload.writeDataFRModeData2(data + offset, buffer + 35U);
offset += 20U; offset += 20U;
} else {
// All subsequent entries start with 0x00U
unsigned char buffer[20U];
::memcpy(buffer + 1U, data + offset, 19U);
buffer[0U] = 0x00U;
payload.writeDataFRModeData2(buffer, buffer + 35U);
offset += 19U;
}
break ; break ;
default: default:
payload.writeDataFRModeData1(data + offset, buffer + 35U); payload.writeDataFRModeData1(data + offset, buffer + 35U);

Loading…
Cancel
Save