From b71c77a9b8c86ae1de1ba45fa15eef5d414c8c9f Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Tue, 7 Jun 2016 21:54:57 +0100 Subject: [PATCH] Now have a valid response to the DX command :-) --- YSFGateway/Network.cpp | 7 ++----- YSFGateway/Reflectors.cpp | 12 ++++++++---- YSFGateway/WiresX.cpp | 13 +++++++++++-- YSFGateway/WiresX.h | 1 + YSFGateway/YSFFICH.cpp | 4 ++-- 5 files changed, 24 insertions(+), 13 deletions(-) diff --git a/YSFGateway/Network.cpp b/YSFGateway/Network.cpp index 0e90d02..0d09915 100644 --- a/YSFGateway/Network.cpp +++ b/YSFGateway/Network.cpp @@ -134,15 +134,12 @@ void CNetwork::clock(unsigned int ms) if (length <= 0) return; - if (address.s_addr != m_address.s_addr || port != m_port) { - LogDebug("Addr: %u != %u || Port: %u != %u", address.s_addr, m_address.s_addr, port, m_port); - CUtils::dump("Data from unknown address/port", buffer, length); + if (address.s_addr != m_address.s_addr || port != m_port) return; - } // Handle incoming polls if (::memcmp(buffer, "YSFP", 4U) == 0) { - // XXX How to handle lost polls? + writePoll(); return; } diff --git a/YSFGateway/Reflectors.cpp b/YSFGateway/Reflectors.cpp index dc60ab1..88d1c7a 100644 --- a/YSFGateway/Reflectors.cpp +++ b/YSFGateway/Reflectors.cpp @@ -52,10 +52,14 @@ bool CReflectors::load() std::vector& hostList = hosts.list(); for (std::vector::const_iterator it = hostList.begin(); it != hostList.end(); ++it) { - CYSFReflector* reflector = new CYSFReflector; - reflector->m_address = CUDPSocket::lookup((*it)->m_address); - reflector->m_port = (*it)->m_port; - m_reflectors.push_back(reflector); + in_addr address = CUDPSocket::lookup((*it)->m_address); + + if (address.s_addr != INADDR_NONE) { + CYSFReflector* reflector = new CYSFReflector; + reflector->m_address = address; + reflector->m_port = (*it)->m_port; + m_reflectors.push_back(reflector); + } } m_it = m_reflectors.begin(); diff --git a/YSFGateway/WiresX.cpp b/YSFGateway/WiresX.cpp index fcfbf1a..c5eaa37 100644 --- a/YSFGateway/WiresX.cpp +++ b/YSFGateway/WiresX.cpp @@ -39,7 +39,7 @@ const unsigned char ALL_RESP[] = {0x5DU, 0x46U, 0x5FU, 0x26U}; const unsigned char DEFAULT_FICH[] = {0x20U, 0x00U, 0x01U, 0x00U}; -const unsigned char NET_HEADER[] = "YSFDGATEWAY ALL "; +const unsigned char NET_HEADER[] = "YSFDGATEWAY ALL "; CWiresX::CWiresX(const std::string& callsign, CNetwork* network, const std::string& hostsFile, unsigned int statusPort) : m_callsign(callsign), @@ -52,6 +52,7 @@ m_txFrequency(0U), m_rxFrequency(0U), m_timer(1000U, 0U, 100U + 750U), m_seqNo(0U), +m_header(NULL), m_source(NULL), m_csd1(NULL), m_csd2(NULL), @@ -63,6 +64,7 @@ m_status(WXSI_NONE) m_callsign.resize(YSF_CALLSIGN_LENGTH, ' '); + m_header = new unsigned char[34U]; m_source = new unsigned char[20U]; m_csd1 = new unsigned char[20U]; m_csd2 = new unsigned char[20U]; @@ -75,6 +77,7 @@ CWiresX::~CWiresX() delete[] m_csd2; delete[] m_csd1; delete[] m_source; + delete[] m_header; } void CWiresX::setInfo(const std::string& name, unsigned int txFrequency, unsigned int rxFrequency) @@ -121,6 +124,12 @@ void CWiresX::setInfo(const std::string& name, unsigned int txFrequency, unsigne m_csd3[i + 0U] = m_id.at(i); m_csd3[i + 10U] = m_id.at(i); } + + for (unsigned int i = 0U; i < 34U; i++) + m_header[i] = NET_HEADER[i]; + + for (unsigned int i = 0U; i < 10U; i++) + m_header[i + 14U] = m_callsign.at(i); } bool CWiresX::start() @@ -257,7 +266,7 @@ void CWiresX::createReply(const unsigned char* data, unsigned int length) // Write the header unsigned char buffer[200U]; - ::memcpy(buffer, NET_HEADER, 34U); + ::memcpy(buffer, m_header, 34U); buffer[34U] = 0x00U; CSync::add(buffer + 35U); diff --git a/YSFGateway/WiresX.h b/YSFGateway/WiresX.h index 86c1306..9b40ee1 100644 --- a/YSFGateway/WiresX.h +++ b/YSFGateway/WiresX.h @@ -65,6 +65,7 @@ private: unsigned int m_rxFrequency; CTimer m_timer; unsigned char m_seqNo; + unsigned char* m_header; unsigned char* m_source; unsigned char* m_csd1; unsigned char* m_csd2; diff --git a/YSFGateway/YSFFICH.cpp b/YSFGateway/YSFFICH.cpp index 2b3ffaf..1198ed3 100644 --- a/YSFGateway/YSFFICH.cpp +++ b/YSFGateway/YSFFICH.cpp @@ -211,8 +211,8 @@ void CYSFFICH::setBT(unsigned char bt) void CYSFFICH::setFN(unsigned char fn) { - m_fich[0U] &= 0xC7U; - m_fich[0U] |= (fn << 3) & 0x38U; + m_fich[1U] &= 0xC7U; + m_fich[1U] |= (fn << 3) & 0x38U; } void CYSFFICH::setFT(unsigned char ft)