PR for #323 - cont.

- Add "Reconnect=0" configuration option to the [Network] section to avoid ambiguity
  - Keep the original behaviors when Revert=1 and Reconnect=1
  - Bugfix on Wires-DX reconnect (find reflector both by id and name)
This commit is contained in:
Shawn 2025-04-29 15:43:05 +08:00
parent 811caaa823
commit 30596b3cc4
5 changed files with 85 additions and 64 deletions

View file

@ -74,6 +74,7 @@ m_aprsSymbol("/r"),
m_networkStartup(),
m_networkOptions(),
m_networkInactivityTimeout(0U),
m_networkReconnect(false),
m_networkRevert(false),
m_networkDebug(false),
m_ysfNetworkEnabled(false),
@ -245,6 +246,8 @@ bool CConf::read()
m_networkOptions = value;
else if (::strcmp(key, "InactivityTimeout") == 0)
m_networkInactivityTimeout = (unsigned int)::atoi(value);
else if (::strcmp(key, "Reconnect") == 0)
m_networkReconnect = ::atoi(value) == 1;
else if (::strcmp(key, "Revert") == 0)
m_networkRevert = ::atoi(value) == 1;
else if (::strcmp(key, "Debug") == 0)
@ -466,6 +469,11 @@ unsigned int CConf::getNetworkInactivityTimeout() const
return m_networkInactivityTimeout;
}
bool CConf::getNetworkReconnect() const
{
return m_networkReconnect;
}
bool CConf::getNetworkRevert() const
{
return m_networkRevert;

View file

@ -71,6 +71,7 @@ public:
std::string getNetworkStartup() const;
std::string getNetworkOptions() const;
unsigned int getNetworkInactivityTimeout() const;
bool getNetworkReconnect() const;
bool getNetworkRevert() const;
bool getNetworkDebug() const;
@ -141,6 +142,7 @@ private:
std::string m_networkStartup;
std::string m_networkOptions;
unsigned int m_networkInactivityTimeout;
bool m_networkReconnect;
bool m_networkRevert;
bool m_networkDebug;

View file

@ -300,6 +300,7 @@ int CYSFGateway::run()
m_startup = m_conf.getNetworkStartup();
m_options = m_conf.getNetworkOptions();
bool revert = m_conf.getNetworkRevert();
bool reconnect = m_conf.getNetworkReconnect();
bool wiresXCommandPassthrough = m_conf.getWiresXCommandPassthrough();
startupLinking();
@ -401,40 +402,23 @@ int CYSFGateway::run()
m_inactivityTimer.clock(ms);
if (m_inactivityTimer.isRunning() && m_inactivityTimer.hasExpired()) {
if (revert) {
if (m_current != m_startup) {
if (m_linkType == LINK_TYPE::YSF) {
m_wiresX->processDisconnect();
m_ysfNetwork->writeUnlink(3U);
m_ysfNetwork->clearDestination();
}
if (m_linkType == LINK_TYPE::FCS) {
m_fcsNetwork->writeUnlink(3U);
m_fcsNetwork->clearDestination();
}
m_current.clear();
m_lostTimer.stop();
m_linkType = LINK_TYPE::NONE;
if (m_linkType != LINK_TYPE::NONE && m_current != m_startup) {
LogMessage("Reverting to startup ref due to inactivity");
disconnectCurrentReflector();
startupLinking();
} else if (m_linkType == LINK_TYPE::NONE && reconnect) {
// reconnect if current one is timeout and reconnect = 1
LogMessage("Reconnecting startup reflector ...");
startupLinking();
}
} else {
if (m_linkType == LINK_TYPE::YSF) {
if (m_linkType != LINK_TYPE::NONE && !reconnect) {
LogMessage("Disconnecting due to inactivity");
m_wiresX->processDisconnect();
m_ysfNetwork->writeUnlink(3U);
m_ysfNetwork->clearDestination();
disconnectCurrentReflector();
} else if (m_linkType == LINK_TYPE::NONE && reconnect) {
LogMessage("Reconnecting reflector ...");
reconnectReflector(m_current);
}
if (m_linkType == LINK_TYPE::FCS) {
LogMessage("Disconnecting due to inactivity");
m_fcsNetwork->writeUnlink(3U);
m_fcsNetwork->clearDestination();
}
m_lostTimer.stop();
m_linkType = LINK_TYPE::NONE;
}
m_inactivityTimer.start();
@ -668,42 +652,9 @@ void CYSFGateway::processWiresX(const unsigned char* buffer, const CYSFFICH& fic
}
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();
if (m_linkType == LINK_TYPE::NONE && !m_current.empty())
reconnectReflector(m_current);
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:
@ -924,6 +875,63 @@ void CYSFGateway::startupLinking()
LogMessage("No connection startup");
}
void CYSFGateway::reconnectReflector(const std::string& refNameOrId) {
if (refNameOrId.substr(0U, 3U) == "FCS" && m_fcsNetwork != nullptr) {
m_inactivityTimer.stop();
m_lostTimer.stop();
bool ok = m_fcsNetwork->writeLink(refNameOrId);
m_fcsNetwork->setOptions(m_options);
if (ok) {
LogMessage("(re-)connection to %s", refNameOrId.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->findById(refNameOrId);
if (reflector == nullptr)
reflector = m_reflectors->findByName(refNameOrId);
if (reflector != nullptr) {
LogMessage("(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;
}
}
}
void CYSFGateway::disconnectCurrentReflector() {
if (m_linkType == LINK_TYPE::YSF) {
m_wiresX->processDisconnect();
m_ysfNetwork->writeUnlink(3U);
m_ysfNetwork->clearDestination();
}
if (m_linkType == LINK_TYPE::FCS) {
m_fcsNetwork->writeUnlink(3U);
m_fcsNetwork->clearDestination();
}
// m_current.clear();
m_lostTimer.stop();
m_linkType = LINK_TYPE::NONE;
}
void CYSFGateway::readFCSRoomsFile(const std::string& filename)
{
FILE* fp = ::fopen(filename.c_str(), "rt");

View file

@ -68,6 +68,8 @@ private:
CUDPSocket* m_remoteSocket;
void startupLinking();
void reconnectReflector(const std::string& nameOrId);
void disconnectCurrentReflector();
std::string calculateLocator();
void processWiresX(const unsigned char* buffer, const CYSFFICH& fich, bool dontProcessWiresXLocal, bool wiresXCommandPassthrough);
void processDTMF(unsigned char* buffer, unsigned char dt);

View file

@ -44,6 +44,7 @@ Suffix=Y
# book DG-ID for Reflector
# Options=20;21;
InactivityTimeout=10
Reconnect=0
Revert=0
Debug=0