From e0e6546cc64e2817a3cc8674c90e44edaed53cbc Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Tue, 7 Jun 2016 23:17:34 +0100 Subject: [PATCH] Have initial reply to ALL working. --- YSFGateway/Makefile | 3 +- YSFGateway/Reflectors.cpp | 13 ++++++++ YSFGateway/Reflectors.h | 3 ++ YSFGateway/WiresX.cpp | 65 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 83 insertions(+), 1 deletion(-) diff --git a/YSFGateway/Makefile b/YSFGateway/Makefile index 0508eb8..747ae2c 100644 --- a/YSFGateway/Makefile +++ b/YSFGateway/Makefile @@ -4,7 +4,8 @@ CFLAGS = -g -O3 -Wall -std=c++0x -pthread LIBS = -lpthread LDFLAGS = -g -OBJECTS = Network.o StopWatch.o Timer.o UDPSocket.o Utils.o YSFReflector.o +OBJECTS = APRSWriterThread.o Conf.o CRC.o Golay24128.o GPS.o Hosts.o Log.o Network.o Reflectors.o StopWatch.o Sync.o TCPSocket.o Thread.o Timer.o UDPSocket.o Utils.o \ + WiresX.o YSFConvolution.o YSFFICH.o YSFGateway.o YSFPayload.o all: YSFGateway diff --git a/YSFGateway/Reflectors.cpp b/YSFGateway/Reflectors.cpp index 88d1c7a..c579597 100644 --- a/YSFGateway/Reflectors.cpp +++ b/YSFGateway/Reflectors.cpp @@ -29,6 +29,7 @@ m_hostsFile(hostsFile), m_socket(statusPort), m_reflectors(), m_it(), +m_current(), m_timer(1000U, 60U) { assert(statusPort > 0U); @@ -81,6 +82,18 @@ CYSFReflector* CReflectors::find(const std::string& id) return NULL; } +std::vector& CReflectors::current() +{ + m_current.clear(); + + for (std::vector::iterator it = m_reflectors.begin(); it != m_reflectors.end(); ++it) { + if ((*it)->m_timer.isRunning() && !(*it)->m_timer.hasExpired()) + m_current.push_back(*it); + } + + return m_current; +} + void CReflectors::clock(unsigned int ms) { m_timer.clock(ms); diff --git a/YSFGateway/Reflectors.h b/YSFGateway/Reflectors.h index 1d535bd..c4b25b6 100644 --- a/YSFGateway/Reflectors.h +++ b/YSFGateway/Reflectors.h @@ -56,6 +56,8 @@ public: CYSFReflector* find(const std::string& id); + std::vector& current(); + void clock(unsigned int ms); private: @@ -63,6 +65,7 @@ private: CUDPSocket m_socket; std::vector m_reflectors; std::vector ::iterator m_it; + std::vector m_current; CTimer m_timer; }; diff --git a/YSFGateway/WiresX.cpp b/YSFGateway/WiresX.cpp index c5eaa37..836202a 100644 --- a/YSFGateway/WiresX.cpp +++ b/YSFGateway/WiresX.cpp @@ -200,6 +200,8 @@ void CWiresX::processDX() void CWiresX::processAll() { + ::LogDebug("Received ALL from %10.10s", m_source + 10U); + m_status = WXSI_ALL; m_timer.start(); } @@ -504,5 +506,68 @@ void CWiresX::sendDisconnectReply() void CWiresX::sendAllReply() { + std::vector& curr = m_reflectors.current(); + + unsigned char data[1100U]; + ::memset(data, 0x00U, 1100U); + + data[0U] = m_seqNo; + + for (unsigned int i = 0U; i < 4U; i++) + data[i + 1U] = ALL_RESP[i]; + + data[5U] = '2'; + data[6U] = '1'; + + for (unsigned int i = 0U; i < 5U; i++) + data[i + 7U] = m_id.at(i); + + for (unsigned int i = 0U; i < 10U; i++) + data[i + 12U] = m_callsign.at(i); + + unsigned int total = curr.size(); + if (total > 999U) total = 999U; + + unsigned int n = curr.size(); + if (n > 20U) n = 20U; + + ::sprintf((char*)(data + 22U), "%03u%03u", n, total); + + data[28U] = 0x0DU; + unsigned int offset = 29U; + for (unsigned int j = 0U; j < n; j++, offset += 50U) { + CYSFReflector* refl = curr.at(j); + + data[offset + 0U] = '5'; + + for (unsigned int i = 0U; i < 5U; i++) + data[i + offset + 1U] = refl->m_id.at(i); + + for (unsigned int i = 0U; i < 16U; i++) + data[i + offset + 6U] = refl->m_name.at(i); + + for (unsigned int i = 0U; i < 3U; i++) + data[i + offset + 22U] = refl->m_count.at(i); + + for (unsigned int i = 0U; i < 10U; i++) + data[i + offset + 25U] = ' '; + + for (unsigned int i = 0U; i < 14U; i++) + data[i + offset + 35U] = refl->m_desc.at(i); + + data[offset + 49U] = 0x0DU; + } + + data[offset + 0U] = 0x03U; // End of data marker + data[offset + 1U] = CCRC::addCRC(data, offset + 1U); + + unsigned int blocks = (offset + 1U) / 20U; + if ((blocks % 20U) > 0U) blocks++; + + CUtils::dump(1U, "ALL Reply", data, blocks * 20U); + + createReply(data, blocks * 20U); + + m_seqNo++; }