diff --git a/YSFGateway/FCSNetwork.cpp b/YSFGateway/FCSNetwork.cpp index ec90975..e0ee7d6 100644 --- a/YSFGateway/FCSNetwork.cpp +++ b/YSFGateway/FCSNetwork.cpp @@ -54,17 +54,16 @@ CFCSNetwork::~CFCSNetwork() bool CFCSNetwork::open() { + m_addresses["FCS001"] = CUDPSocket::lookup("fcs001.xreflector.net"); + m_addresses["FCS002"] = CUDPSocket::lookup("fcs002.xreflector.net"); + m_addresses["FCS003"] = CUDPSocket::lookup("fcs003.xreflector.net"); + m_addresses["FCS004"] = CUDPSocket::lookup("fcs004.xreflector.net"); + LogMessage("Opening FCS network connection"); return m_socket.open(); } -void CFCSNetwork::setDestination(const in_addr& address, unsigned int port) -{ - m_address = address; - m_port = port; -} - void CFCSNetwork::clearDestination() { m_address.s_addr = INADDR_NONE; @@ -91,8 +90,17 @@ bool CFCSNetwork::write(const unsigned char* data) bool CFCSNetwork::writeLink(const std::string& reflector) { - if (m_port == 0U) - return true; + m_port = 0U; + + if (m_addresses.count(reflector) == 0U) + return false; + + m_address = m_addresses[reflector]; + + if (m_address.s_addr == INADDR_NONE) + return false; + + m_port = FCS_PORT; m_reflector = reflector; m_reflector.resize(8U, ' '); diff --git a/YSFGateway/FCSNetwork.h b/YSFGateway/FCSNetwork.h index 3d89d20..836c462 100644 --- a/YSFGateway/FCSNetwork.h +++ b/YSFGateway/FCSNetwork.h @@ -25,6 +25,7 @@ #include #include +#include class CFCSNetwork { public: @@ -33,7 +34,6 @@ public: bool open(); - void setDestination(const in_addr& address, unsigned int port); void clearDestination(); bool write(const unsigned char* data); @@ -49,14 +49,15 @@ public: void close(); private: - CUDPSocket m_socket; - bool m_debug; - in_addr m_address; - unsigned int m_port; - unsigned char* m_info; - std::string m_callsign; - std::string m_reflector; - CRingBuffer m_buffer; + CUDPSocket m_socket; + bool m_debug; + in_addr m_address; + unsigned int m_port; + unsigned char* m_info; + std::string m_callsign; + std::string m_reflector; + CRingBuffer m_buffer; + std::map m_addresses; void writeInfo(); }; diff --git a/YSFGateway/YSFDefines.h b/YSFGateway/YSFDefines.h index 2e75625..b2aefc6 100644 --- a/YSFGateway/YSFDefines.h +++ b/YSFGateway/YSFDefines.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015,2016,2017 by Jonathan Naylor G4KLX + * Copyright (C) 2015,2016,2017,2018 by Jonathan Naylor G4KLX * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -47,4 +47,6 @@ const unsigned char YSF_CM_INDIVIDUAL = 0x03U; const unsigned char YSF_MR_NOT_BUSY = 0x01U; const unsigned char YSF_MR_BUSY = 0x02U; +const unsigned int FCS_PORT = 62500U; + #endif diff --git a/YSFGateway/YSFGateway.cpp b/YSFGateway/YSFGateway.cpp index 01c942d..6db2dc2 100644 --- a/YSFGateway/YSFGateway.cpp +++ b/YSFGateway/YSFGateway.cpp @@ -397,6 +397,9 @@ int CYSFGateway::run() if (m_wiresX != NULL) m_wiresX->processDisconnect(); + if (m_fcsNetwork != NULL) + m_fcsNetwork->clearDestination(); + if (m_ysfNetwork != NULL) m_ysfNetwork->clearDestination(); @@ -556,6 +559,12 @@ void CYSFGateway::processDTMF(const unsigned char* buffer, unsigned char dt) m_ysfNetwork->writeUnlink(); m_ysfNetwork->writeUnlink(); } + if (m_linkType == LINK_FCS) { + m_fcsNetwork->writeUnlink(); + m_fcsNetwork->writeUnlink(); + m_fcsNetwork->writeUnlink(); + m_fcsNetwork->clearDestination(); + } LogMessage("Connect via DTMF to %5.5s - \"%s\" has been requested by %10.10s", reflector->m_id.c_str(), reflector->m_name.c_str(), buffer + 14U); @@ -572,6 +581,38 @@ void CYSFGateway::processDTMF(const unsigned char* buffer, unsigned char dt) } } break; + case WXS_CONNECT_FCS: { + std::string id = m_dtmf.getReflector(); + if (id.length() == 2U) + id = "FCS00" + id.at(0U) + std::string("0") + id.at(1U); + else + id = "FCS00" + id.at(0U) + id.at(1U) + id.at(2U); + + if (m_linkType == LINK_YSF) { + m_ysfNetwork->writeUnlink(); + m_ysfNetwork->writeUnlink(); + m_ysfNetwork->writeUnlink(); + m_ysfNetwork->clearDestination(); + m_ysfPollTimer.stop(); + } + if (m_linkType == LINK_FCS) { + m_fcsNetwork->writeUnlink(); + m_fcsNetwork->writeUnlink(); + m_fcsNetwork->writeUnlink(); + } + + LogMessage("Connect via DTMF to %s has been requested by %10.10s", id.c_str(), buffer + 14U); + + m_fcsNetwork->writeLink(id); + m_fcsNetwork->writeLink(id); + m_fcsNetwork->writeLink(id); + + m_inactivityTimer.start(); + m_lostTimer.start(); + + m_linkType = LINK_FCS; + } + break; case WXS_DISCONNECT: if (m_linkType == LINK_YSF) { if (m_wiresX != NULL)