From b7260b4bf8143711bcb063a1d137048f40b97f52 Mon Sep 17 00:00:00 2001 From: Shawn Date: Sun, 27 Apr 2025 18:20:48 +0800 Subject: [PATCH] Change the YSFGateway a little bit to auto-reconnect current timed-out reflector if WiresX DX command is received. That means if your hotspot lost the connection to the network reflector, just re-press the X button on your Yaesu device and everything will be back online again. --- YSFGateway/WiresX.cpp | 2 +- YSFGateway/WiresX.h | 3 ++- YSFGateway/YSFGateway.cpp | 41 +++++++++++++++++++++++++++++++++++++-- 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/YSFGateway/WiresX.cpp b/YSFGateway/WiresX.cpp index 1c8765c..9f06420 100644 --- a/YSFGateway/WiresX.cpp +++ b/YSFGateway/WiresX.cpp @@ -260,7 +260,7 @@ WX_STATUS CWiresX::process(const unsigned char* data, const unsigned char* sourc else { if (::memcmp(m_command + 1U, DX_REQ, 3U) == 0) { processDX(source); - return WX_STATUS::NONE; + return WX_STATUS::RECONNECT_CURRENT; } else if (::memcmp(m_command + 1U, ALL_REQ, 3U) == 0) { processAll(source, m_command + 5U); return WX_STATUS::NONE; diff --git a/YSFGateway/WiresX.h b/YSFGateway/WiresX.h index 2f4de45..bcaad5a 100644 --- a/YSFGateway/WiresX.h +++ b/YSFGateway/WiresX.h @@ -32,7 +32,8 @@ enum class WX_STATUS { NONE, CONNECT_YSF, CONNECT_FCS, - DISCONNECT + DISCONNECT, + RECONNECT_CURRENT }; enum class WXSI_STATUS { diff --git a/YSFGateway/YSFGateway.cpp b/YSFGateway/YSFGateway.cpp index 7cddea9..476c2f4 100644 --- a/YSFGateway/YSFGateway.cpp +++ b/YSFGateway/YSFGateway.cpp @@ -433,7 +433,6 @@ int CYSFGateway::run() m_fcsNetwork->clearDestination(); } - m_current.clear(); m_lostTimer.stop(); m_linkType = LINK_TYPE::NONE; } @@ -454,7 +453,6 @@ int CYSFGateway::run() m_fcsNetwork->clearDestination(); } - m_current.clear(); m_inactivityTimer.start(); m_lostTimer.stop(); m_linkType = LINK_TYPE::NONE; @@ -669,6 +667,45 @@ void CYSFGateway::processWiresX(const unsigned char* buffer, const CYSFFICH& fic m_linkType = LINK_TYPE::NONE; } break; + case WX_STATUS::RECONNECT_CURRENT: { + if (m_wiresX->getReflector() == nullptr && !m_current.empty()) { + // trying to reconnect + if (m_current.substr(0U, 3U) == "FCS" && m_fcsNetwork != nullptr) { + m_inactivityTimer.stop(); + m_lostTimer.stop(); + + bool ok = m_fcsNetwork->writeLink(m_current); + m_fcsNetwork->setOptions(m_options); + + if (ok) { + LogMessage("Automatic (re-)connection to %s", m_current.c_str()); + + m_inactivityTimer.start(); + m_lostTimer.start(); + m_linkType = LINK_TYPE::FCS;; + } + } else if (m_ysfNetwork != nullptr) { + m_inactivityTimer.stop(); + m_lostTimer.stop(); + + CYSFReflector* reflector = m_reflectors->findByName(m_current); + if (reflector != nullptr) { + LogMessage("Automatic (re-)connection to %5.5s - \"%s\"", reflector->m_id.c_str(), reflector->m_name.c_str()); + + m_wiresX->setReflector(reflector); + + m_ysfNetwork->setDestination(reflector->m_name, reflector->m_addr, reflector->m_addrLen); + m_ysfNetwork->setOptions(m_options); + m_ysfNetwork->writePoll(3U); + + m_inactivityTimer.start(); + m_lostTimer.start(); + m_linkType = LINK_TYPE::YSF; + } + } + } + } + break; default: break; }