From c5491958e48098f1a0782e1a86d0da52e976ae3a Mon Sep 17 00:00:00 2001 From: Dominic Reich Date: Sun, 1 Jan 2023 21:10:20 +0100 Subject: [PATCH] applies changes made by OE1KBC allows the use of "Options=10,20" in YSFGateway.ini --- YSFGateway/FCSNetwork.cpp | 38 +++++++++++++++----- YSFGateway/FCSNetwork.h | 8 +++-- YSFGateway/YSFGateway.cpp | 11 ++++-- YSFGateway/YSFGateway.h | 1 + YSFGateway/YSFGateway.ini | 76 ++------------------------------------- YSFGateway/YSFNetwork.cpp | 25 +++++++++++-- YSFGateway/YSFNetwork.h | 3 +- 7 files changed, 71 insertions(+), 91 deletions(-) diff --git a/YSFGateway/FCSNetwork.cpp b/YSFGateway/FCSNetwork.cpp index 7b22b62..19abd4f 100644 --- a/YSFGateway/FCSNetwork.cpp +++ b/YSFGateway/FCSNetwork.cpp @@ -29,7 +29,7 @@ const char* FCS_VERSION = "MMDVM"; const unsigned int BUFFER_LENGTH = 200U; -CFCSNetwork::CFCSNetwork(unsigned int port, const std::string& callsign, unsigned int rxFrequency, unsigned int txFrequency, const std::string& locator, unsigned int id, bool debug) : +CFCSNetwork::CFCSNetwork(unsigned int port, const std::string& callsign, unsigned int rxFrequency, unsigned int txFrequency, const std::string& locator, const std::string& name, unsigned int id, bool debug) : m_socket(port), m_debug(debug), m_addr(), @@ -38,6 +38,7 @@ m_ping(NULL), m_options(NULL), m_opt(), m_info(NULL), +m_info_long(NULL), m_reflector(), m_print(), m_buffer(1000U, "FCS Network Buffer"), @@ -46,9 +47,13 @@ m_pingTimer(1000U, 0U, 800U), m_resetTimer(1000U, 1U), m_state(FCS_UNLINKED) { - m_info = new unsigned char[100U]; - ::sprintf((char*)m_info, "%9u%9u%-6.6s%-12.12s%7u", rxFrequency, txFrequency, locator.c_str(), FCS_VERSION, id); - ::memset(m_info + 43U, ' ', 57U); + m_info_long = new unsigned char[100U]; + ::sprintf((char*)m_info_long, "%9u%9u%-6.6s%-12.12s%7u", rxFrequency, txFrequency, locator.c_str(), FCS_VERSION, id); + ::memset(m_info_long + 43U, ' ', 57U); + + m_info = new unsigned char[80U]; + ::sprintf((char*)m_info, "FCSIFCS99999%9u%9u%-6.6s%-20.20s%-12.12s%7u", rxFrequency, txFrequency, locator.c_str(), name.c_str(), FCS_VERSION, id); // KBC 2020-09-07 + ::memset(m_info + 75U, ' ', 5U); m_ping = new unsigned char[25U]; ::memcpy(m_ping + 0U, "PING", 4U); @@ -65,6 +70,7 @@ m_state(FCS_UNLINKED) CFCSNetwork::~CFCSNetwork() { delete[] m_info; + delete[] m_info_long; delete[] m_ping; delete[] m_options; } @@ -198,14 +204,15 @@ void CFCSNetwork::clock(unsigned int ms) if (m_state == FCS_LINKING) LogMessage("Linked to %s", m_print.c_str()); m_state = FCS_LINKED; - writeInfo(); + writeInfo(m_print); writeOptions(m_print); } if (length == 10 && m_state == FCS_LINKING) { LogMessage("Linked to %s", m_print.c_str()); m_state = FCS_LINKED; - writeInfo(); + writeInfoLong(m_print); + writeInfo(m_print); writeOptions(m_print); } @@ -262,15 +269,28 @@ void CFCSNetwork::close() LogMessage("Closing FCS network connection"); } -void CFCSNetwork::writeInfo() +void CFCSNetwork::writeInfo(const std::string& reflector) { if (m_state != FCS_LINKED) return; + ::memcpy(m_info + 4U, (reflector.substr(0,6)+reflector.substr(7,2)).c_str(), 8U); + if (m_debug) CUtils::dump(1U, "FCS Network Data Sent", m_info, 100U); - m_socket.write(m_info, 100U, m_addr, m_addrLen); + m_socket.write(m_info, 80U, m_addr, m_addrLen); +} + +void CFCSNetwork::writeInfoLong(const std::string& reflector) +{ + if (m_state != FCS_LINKED) + return; + + if (m_debug) + CUtils::dump(1U, "FCS Network Data Sent long", m_info_long, 100U); + + m_socket.write(m_info_long, 100U, m_addr, m_addrLen); } void CFCSNetwork::writePing() @@ -292,7 +312,7 @@ void CFCSNetwork::writeOptions(const std::string& reflector) if (m_opt.size() < 1) return; - ::memset(m_options + 14U, 0x20U, 36U); + ::memset(m_options + 4U, 0x20U, 46U); ::memcpy(m_options + 4U, (reflector.substr(0,6)+reflector.substr(7,2)).c_str(), 8U); ::memcpy(m_options + 12U, m_opt.c_str(), m_opt.size()); diff --git a/YSFGateway/FCSNetwork.h b/YSFGateway/FCSNetwork.h index 103323c..afe1083 100644 --- a/YSFGateway/FCSNetwork.h +++ b/YSFGateway/FCSNetwork.h @@ -36,7 +36,7 @@ enum FCS_STATE { class CFCSNetwork { public: - CFCSNetwork(unsigned int port, const std::string& callsign, unsigned int rxFrequency, unsigned int txFrequency, const std::string& locator, unsigned int id, bool debug); + CFCSNetwork(unsigned int port, const std::string& callsign, unsigned int rxFrequency, unsigned int txFrequency, const std::string& locator, const std::string& name, unsigned int id, bool debug); ~CFCSNetwork(); bool open(); @@ -65,7 +65,8 @@ private: unsigned char* m_ping; unsigned char* m_options; std::string m_opt; - unsigned char* m_info; + unsigned char* m_info; + unsigned char* m_info_long; std::string m_reflector; std::string m_print; CRingBuffer m_buffer; @@ -76,7 +77,8 @@ private: FCS_STATE m_state; void writeOptions(const std::string& reflector); - void writeInfo(); + void writeInfo(const std::string& reflector); + void writeInfoLong(const std::string& reflector); void writePing(); }; diff --git a/YSFGateway/YSFGateway.cpp b/YSFGateway/YSFGateway.cpp index 1318ca5..5e749b7 100644 --- a/YSFGateway/YSFGateway.cpp +++ b/YSFGateway/YSFGateway.cpp @@ -211,8 +211,14 @@ int CYSFGateway::run() bool ysfNetworkEnabled = m_conf.getYSFNetworkEnabled(); if (ysfNetworkEnabled) { + unsigned int txFrequency = m_conf.getTxFrequency(); + unsigned int rxFrequency = m_conf.getRxFrequency(); + std::string locator = calculateLocator(); + std::string name = m_conf.getName(); + unsigned int id = m_conf.getId(); + unsigned int ysfPort = m_conf.getYSFNetworkPort(); - m_ysfNetwork = new CYSFNetwork(ysfPort, m_callsign, debug); + m_ysfNetwork = new CYSFNetwork(ysfPort, m_callsign, rxFrequency, txFrequency, locator, name, id, debug); } m_fcsNetworkEnabled = m_conf.getFCSNetworkEnabled(); @@ -220,11 +226,12 @@ int CYSFGateway::run() unsigned int txFrequency = m_conf.getTxFrequency(); unsigned int rxFrequency = m_conf.getRxFrequency(); std::string locator = calculateLocator(); + std::string name = m_conf.getName(); // KBC 2020-09-07 unsigned int id = m_conf.getId(); unsigned int fcsPort = m_conf.getFCSNetworkPort(); - m_fcsNetwork = new CFCSNetwork(fcsPort, m_callsign, rxFrequency, txFrequency, locator, id, debug); + m_fcsNetwork = new CFCSNetwork(fcsPort, m_callsign, rxFrequency, txFrequency, locator, name, id, debug); ret = m_fcsNetwork->open(); if (!ret) { ::LogError("Cannot open the FCS reflector network port"); diff --git a/YSFGateway/YSFGateway.h b/YSFGateway/YSFGateway.h index 069a95c..6896e13 100644 --- a/YSFGateway/YSFGateway.h +++ b/YSFGateway/YSFGateway.h @@ -61,6 +61,7 @@ private: std::string m_current; std::string m_startup; std::string m_options; + std::string m_info; bool m_exclude; CTimer m_inactivityTimer; CTimer m_lostTimer; diff --git a/YSFGateway/YSFGateway.ini b/YSFGateway/YSFGateway.ini index cc9f53e..7b215d4 100644 --- a/YSFGateway/YSFGateway.ini +++ b/YSFGateway/YSFGateway.ini @@ -1,75 +1,5 @@ -[General] -Callsign=G9BF -Suffix=RPT -# Suffix=ND -Id=1234567 -RptAddress=127.0.0.1 -RptPort=3200 -LocalAddress=127.0.0.1 -LocalPort=4200 -WiresXMakeUpper=1 -WiresXCommandPassthrough=0 -Debug=0 -Daemon=0 - -[Info] -RXFrequency=430475000 -TXFrequency=439475000 -Power=1 -Latitude=0.0 -Longitude=0.0 -Height=0 -Name=Nowhere -Description=Multi-Mode Repeater - -[Log] -# Logging levels, 0=No logging -DisplayLevel=1 -FileLevel=1 -FilePath=. -FileRoot=YSFGateway -FileRotate=1 - -[APRS] -Enable=0 -Address=127.0.0.1 -Port=8673 -Description=APRS Description -Suffix=Y [Network] -# Startup=FCS00120 -# Startup=Alabama-Link -# book DG-ID for Reflector -# Options=20;21; -InactivityTimeout=10 -Revert=0 -Debug=0 - -[YSF Network] -Enable=1 -Port=42000 -Hosts=./YSFHosts.txt -ReloadTime=60 -ParrotAddress=127.0.0.1 -ParrotPort=42012 -YSF2DMRAddress=127.0.0.1 -YSF2DMRPort=42013 -YSF2NXDNAddress=127.0.0.1 -YSF2NXDNPort=42014 -YSF2P25Address=127.0.0.1 -YSF2P25Port=42015 - -[FCS Network] -Enable=1 -Rooms=./FCSRooms.txt -Port=42001 - -[GPSD] -Enable=0 -Address=127.0.0.1 -Port=2947 - -[Remote Commands] -Enable=0 -Port=6073 +Startup=DE-C4FM-Germany +# DG-ID OPTIONS e.g. 10,20 booked to MATRIX +Options=10;20; diff --git a/YSFGateway/YSFNetwork.cpp b/YSFGateway/YSFNetwork.cpp index f139c53..ae20c8f 100644 --- a/YSFGateway/YSFNetwork.cpp +++ b/YSFGateway/YSFNetwork.cpp @@ -25,6 +25,8 @@ #include #include +const char* YSF_VERSION = "YSFG-MMDVM"; + const unsigned int BUFFER_LENGTH = 200U; CYSFNetwork::CYSFNetwork(const std::string& address, unsigned int port, const std::string& callsign, bool debug) : @@ -35,9 +37,10 @@ m_addrLen(0U), m_poll(NULL), m_options(NULL), m_opt(), +m_info(NULL), m_unlink(NULL), m_buffer(1000U, "YSF Network Buffer"), -m_pollTimer(1000U, 5U), +m_pollTimer(3000U, 5U), m_name(), m_linked(false) { @@ -60,7 +63,7 @@ m_linked(false) } } -CYSFNetwork::CYSFNetwork(unsigned int port, const std::string& callsign, bool debug) : +CYSFNetwork::CYSFNetwork(unsigned int port, const std::string& callsign, unsigned int rxFrequency, unsigned int txFrequency, const std::string& locator, const std::string& name, unsigned int id, bool debug) : m_socket(port), m_debug(debug), m_addr(), @@ -68,9 +71,10 @@ m_addrLen(0U), m_poll(NULL), m_options(NULL), m_opt(), +m_info(NULL), m_unlink(NULL), m_buffer(1000U, "YSF Network Buffer"), -m_pollTimer(1000U, 5U), +m_pollTimer(3000U, 5U), m_name(), m_linked(false) { @@ -83,6 +87,9 @@ m_linked(false) m_options = new unsigned char[50U]; ::memcpy(m_options + 0U, "YSFO", 4U); + m_info = new unsigned char[80U]; + ::sprintf((char*)m_info, "YSFI%-10.10s%9u%9u%-6.6s%-20.20s%-12.12s%7u ", callsign.c_str(), rxFrequency, txFrequency, locator.c_str(), name.c_str(), YSF_VERSION, id); + std::string node = callsign; node.resize(YSF_CALLSIGN_LENGTH, ' '); @@ -98,6 +105,7 @@ CYSFNetwork::~CYSFNetwork() delete[] m_poll; delete[] m_unlink; delete[] m_options; + delete[] m_info; } bool CYSFNetwork::open() @@ -221,6 +229,14 @@ void CYSFNetwork::clock(unsigned int ms) if (m_debug) CUtils::dump(1U, "YSF Network Data Received", buffer, length); + if (::memcmp(buffer, "YSFPONLINE", 10U) == 0 && m_linked) { + if (m_info != NULL) + m_socket.write(m_info, 80U, m_addr, m_addrLen); + + if (m_options != NULL) + m_socket.write(m_options, 50U, m_addr, m_addrLen); + } + // Throw away any options messages if (::memcmp(buffer, "YSFO", 4U) == 0) return; @@ -237,6 +253,9 @@ void CYSFNetwork::clock(unsigned int ms) m_linked = true; + if (m_info != NULL) + m_socket.write(m_info, 80U, m_addr, m_addrLen); + if (!m_opt.empty()) m_socket.write(m_options, 50U, m_addr, m_addrLen); } diff --git a/YSFGateway/YSFNetwork.h b/YSFGateway/YSFNetwork.h index e20054d..984f727 100644 --- a/YSFGateway/YSFNetwork.h +++ b/YSFGateway/YSFNetwork.h @@ -30,7 +30,7 @@ class CYSFNetwork { public: CYSFNetwork(const std::string& address, unsigned int port, const std::string& callsign, bool debug); - CYSFNetwork(unsigned int port, const std::string& callsign, bool debug); + CYSFNetwork(unsigned int port, const std::string& callsign, unsigned int rxFrequency, unsigned int txFrequency, const std::string& locator, const std::string& name, unsigned int id, bool debug); ~CYSFNetwork(); bool setDestination(const std::string& name, const sockaddr_storage& addr, unsigned int addrLen); @@ -54,6 +54,7 @@ private: unsigned char* m_poll; unsigned char* m_options; std::string m_opt; + unsigned char* m_info; unsigned char* m_unlink; CRingBuffer m_buffer; CTimer m_pollTimer;