From c11065855e0d2eb4cd73b802691d5649985f4d7c Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Fri, 15 Apr 2022 07:35:04 +0200 Subject: [PATCH 01/11] Clean Up --- BaseCommon/UDPReaderWriter.cpp | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/BaseCommon/UDPReaderWriter.cpp b/BaseCommon/UDPReaderWriter.cpp index d0b826f..7047eeb 100644 --- a/BaseCommon/UDPReaderWriter.cpp +++ b/BaseCommon/UDPReaderWriter.cpp @@ -157,23 +157,6 @@ bool CUDPReaderWriter::write(const unsigned char* buffer, unsigned int length, c TOIPV4(addr)->sin_port = htons(port); return write(buffer, length, addr); - // sockaddr_in addr; - // ::memset(&addr, 0x00, sizeof(sockaddr_in)); - - // addr.sin_family = AF_INET; - // addr.sin_addr = address; - // addr.sin_port = htons(port); - - // ssize_t ret = ::sendto(m_fd, (char *)buffer, length, 0, (sockaddr *)&addr, sizeof(sockaddr_in)); - // if (ret < 0) { - // CLog::logError("Error returned from sendto (port: %u), err: %s\n", m_port, strerror(errno)); - // return false; - // } - - // if (ret != ssize_t(length)) - // return false; - - // return true; } bool CUDPReaderWriter::write(const unsigned char* buffer, unsigned int length, const struct sockaddr_storage& addr) From 0ddbe62b18b7ef1c7ca73358c8e785c8f529a65f Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Fri, 15 Apr 2022 08:55:07 +0200 Subject: [PATCH 02/11] #24 Port DRats --- BaseCommon/TCPReaderWriterServer.cpp | 267 +++++++++++++++++++ BaseCommon/TCPReaderWriterServer.h | 61 +++++ Common/DRATSServer.cpp | 384 +++++++++++++++++++++++++++ Common/DRATSServer.h | 66 +++++ Common/RepeaterHandler.cpp | 2 +- DStarGateway/DStarGatewayApp.cpp | 3 + Makefile | 1 + 7 files changed, 783 insertions(+), 1 deletion(-) create mode 100644 BaseCommon/TCPReaderWriterServer.cpp create mode 100644 BaseCommon/TCPReaderWriterServer.h create mode 100644 Common/DRATSServer.cpp create mode 100644 Common/DRATSServer.h diff --git a/BaseCommon/TCPReaderWriterServer.cpp b/BaseCommon/TCPReaderWriterServer.cpp new file mode 100644 index 0000000..181a3bb --- /dev/null +++ b/BaseCommon/TCPReaderWriterServer.cpp @@ -0,0 +1,267 @@ +/* + * Copyright (C) 2011 by Jonathan Naylor G4KLX + * Copyright (c) 2021-2022 by Geoffrey Merck F4FXL / KC3FRA + * + * 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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include "TCPReaderWriterServer.h" +#include "Log.h" +#include "NetUtils.h" + +#include +#include + + +CTCPReaderWriterServer::CTCPReaderWriterServer(const std::string& address, unsigned int port) : +CThread("TCP server"), +m_address(address), +m_port(port), +m_fd(-1), +m_client(NULL), +m_stopped(false) +{ + assert(port > 0U); +} + +CTCPReaderWriterServer::~CTCPReaderWriterServer() +{ +} + +bool CTCPReaderWriterServer::start() +{ + bool ret = open(); + if (!ret) { + close(); + return false; + } + + Create(); + Run(); + + return true; +} + +int CTCPReaderWriterServer::read(unsigned char* buffer, unsigned int length, unsigned int secs) +{ + assert(buffer != NULL); + assert(length > 0U); + + if (m_client != NULL) { + int ret = m_client->read(buffer, length, secs); + if (ret < 0) { + CLog::logInfo("Lost TCP connection to port %u", m_port); + + m_client->close(); + delete m_client; + m_client = NULL; + + open(); + + return 0; + } + + return ret; + } + + return 0; +} + +bool CTCPReaderWriterServer::write(const unsigned char* buffer, unsigned int length) +{ + assert(buffer != NULL); + assert(length > 0U); + + if (m_client != NULL) { + bool ret = m_client->write(buffer, length); + if (!ret) { + CLog::logInfo("Lost TCP connection to port %u", m_port); + + m_client->close(); + delete m_client; + m_client = NULL; + + open(); + + return false; + } + + return true; + } + + return true; +} + +void* CTCPReaderWriterServer::Entry() +{ +#ifndef DEBUG_DSTARGW + try { +#endif + while (!m_stopped) { + int ret = accept(); + switch (ret) { + case -2: + break; + case -1: + break; + default: + CLog::logInfo("Incoming TCP connection to port %u", m_port); + m_client = new CTCPReaderWriterClient(ret); + close(); + break; + } + + Sleep(1000UL); + } + + if (m_client != NULL) { + m_client->close(); + delete m_client; + } + + close(); + +#ifndef DEBUG_DSTARGW + } + catch (std::exception& e) { + std::string message(e.what()); + CLog::logError("Exception raised in the TCP Reader-Writer Server thread - \"%s\"", message.c_str()); + } + catch (...) { + CLog::logError("Unknown exception raised in the TCP Reader-Writer Server thread"); + } +#endif + + return NULL; +} + +void CTCPReaderWriterServer::stop() +{ + m_stopped = true; + + Wait(); +} + +bool CTCPReaderWriterServer::open() +{ + m_fd = ::socket(PF_INET, SOCK_STREAM, 0); + if (m_fd < 0) { + CLog::logError("Cannot create the TCP server socket, err=%d", errno); + return false; + } + + struct sockaddr_in addr; + ::memset(&addr, 0x00, sizeof(struct sockaddr_in)); + addr.sin_family = AF_INET; + addr.sin_port = htons(m_port); + if (m_address.empty()) + addr.sin_addr.s_addr = htonl(INADDR_ANY); + else + addr.sin_addr = lookup(m_address); + + if (addr.sin_addr.s_addr == INADDR_NONE) { + CLog::logError("The address is invalid - %s", m_address.c_str()); + close(); + return false; + } + + int reuse = 1; + if (::setsockopt(m_fd, SOL_SOCKET, SO_REUSEADDR, (char *)&reuse, sizeof(reuse)) == -1) { + CLog::logError("Cannot set the TCP server socket option, err=%d", errno); + close(); + return false; + } + + if (::bind(m_fd, (sockaddr*)&addr, sizeof(struct sockaddr_in)) == -1) { + CLog::logError("Cannot bind the TCP server address, err=%d", errno); + close(); + return false; + } + + ::listen(m_fd, 5); + + return true; +} + +int CTCPReaderWriterServer::accept() +{ + if (m_fd == -1) + return -1; + + // Check that the accept() won't block + fd_set readFds; + FD_ZERO(&readFds); +#if defined(__WINDOWS__) + FD_SET((unsigned int)m_fd, &readFds); +#else + FD_SET(m_fd, &readFds); +#endif + + // Return after timeout + timeval tv; + tv.tv_sec = 0L; + tv.tv_usec = 0L; + + int ret = ::select(m_fd + 1, &readFds, NULL, NULL, &tv); + if (ret < 0) { + CLog::logError("Error returned from TCP server select, err=%d", errno); + return -2; + } + +#if defined(__WINDOWS__) + if (!FD_ISSET((unsigned int)m_fd, &readFds)) + return -1; +#else + if (!FD_ISSET(m_fd, &readFds)) + return -1; +#endif + + struct sockaddr_in addr; +#if defined(__WINDOWS__) + int len = sizeof(struct sockaddr_in); +#else + socklen_t len = sizeof(struct sockaddr_in); +#endif + + ret = ::accept(m_fd, (sockaddr*)&addr, &len); + if (ret < 0) { + CLog::logError("Error returned from TCP server accept, err=%d", errno); + } + + return ret; +} + +void CTCPReaderWriterServer::close() +{ + if (m_fd != -1) { + ::close(m_fd); + m_fd = -1; + } +} + +in_addr CTCPReaderWriterServer::lookup(const std::string& hostname) const +{ + in_addr addrv4; + addrv4.s_addr = INADDR_NONE; + + sockaddr_storage addr; + auto res = CNetUtils::lookupV4(hostname, addr); + + if(res) { + addrv4 = TOIPV4(addr)->sin_addr; + } + + return addrv4; +} diff --git a/BaseCommon/TCPReaderWriterServer.h b/BaseCommon/TCPReaderWriterServer.h new file mode 100644 index 0000000..25a6deb --- /dev/null +++ b/BaseCommon/TCPReaderWriterServer.h @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2011 by Jonathan Naylor G4KLX + * Copyright (c) 2021-2022 by Geoffrey Merck F4FXL / KC3FRA + * + * 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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#pragma once + +#include "TCPReaderWriterClient.h" +#include "Thread.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +class CTCPReaderWriterServer : public CThread { +public: + CTCPReaderWriterServer(const std::string& address, unsigned int port); + virtual ~CTCPReaderWriterServer(); + + virtual bool start(); + + virtual bool write(const unsigned char* buffer, unsigned int length); + virtual int read(unsigned char* buffer, unsigned int length, unsigned int secs); + + virtual void stop(); + + virtual void* Entry(); + +private: + std::string m_address; + unsigned short m_port; + int m_fd; + CTCPReaderWriterClient* m_client; + bool m_stopped; + + bool open(); + int accept(); + void close(); + in_addr lookup(const std::string& hostname) const; +}; diff --git a/Common/DRATSServer.cpp b/Common/DRATSServer.cpp new file mode 100644 index 0000000..d83bbc4 --- /dev/null +++ b/Common/DRATSServer.cpp @@ -0,0 +1,384 @@ +/* + * Copyright (C) 2011-2015 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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include "DStarDefines.h" +#include "DRATSServer.h" +#include "Utils.h" +#include "Log.h" + +#include +#include +#include + +// #define LOOPBACK + +const unsigned int BUFFER_LENGTH = 30000U; + +CDRATSServer::CDRATSServer(const std::string& address, unsigned int port, const std::string& callsign, IRepeaterCallback* handler) : +CThread("DRats"), +m_address(address), +m_port(port), +m_callsign(callsign), +m_handler(handler), +m_socket(NULL), +m_stopped(false), +m_readState(SS_FIRST), +m_readBuffer(NULL), +m_readLength(0U), +m_readPos(0U), +m_readEnd(false), +m_writeText(NULL), +m_writeState(SS_FIRST), +m_writeBuffer(NULL), +m_writeLength(0U) +{ + assert(handler != NULL); + assert(port > 0U); + + m_readBuffer = new unsigned char[BUFFER_LENGTH]; + m_writeBuffer = new unsigned char[BUFFER_LENGTH]; + m_writeText = new unsigned char[6U]; +} + +CDRATSServer::~CDRATSServer() +{ + delete[] m_readBuffer; + delete[] m_writeBuffer; + delete[] m_writeText; +} + +bool CDRATSServer::open() +{ + m_socket = new CTCPReaderWriterServer(m_address, m_port); + bool ret = m_socket->start(); + if (!ret) { + delete m_socket; + m_socket = NULL; + return false; + } + + Create(); + Run(); + + return true; +} + +void CDRATSServer::writeHeader(const CHeaderData&) +{ + m_writeState = SS_FIRST; + + if (m_writeLength > 0U && m_socket != NULL) { + CUtils::dump("From RF", m_writeBuffer, m_writeLength); + m_socket->write(m_writeBuffer, m_writeLength); + } + + m_writeLength = 0U; +} + +void CDRATSServer::writeData(const CAMBEData& data) +{ + // Sync data isn't sent on + if (data.isSync()) { + m_writeState = SS_FIRST; + return; + } + + if (data.isEnd()) { + if (m_writeLength > 0U && m_socket != NULL) { + CUtils::dump("From RF", m_writeBuffer, m_writeLength); + m_socket->write(m_writeBuffer, m_writeLength); + } + + m_writeLength = 0U; + return; + } + + unsigned char buffer[DV_FRAME_MAX_LENGTH_BYTES]; + unsigned int length = data.getData(buffer, DV_FRAME_MAX_LENGTH_BYTES); + + if (length != DV_FRAME_LENGTH_BYTES) + return; + + unsigned char byte1 = buffer[VOICE_FRAME_LENGTH_BYTES + 0U] ^ SCRAMBLER_BYTE1; + unsigned char byte2 = buffer[VOICE_FRAME_LENGTH_BYTES + 1U] ^ SCRAMBLER_BYTE2; + unsigned char byte3 = buffer[VOICE_FRAME_LENGTH_BYTES + 2U] ^ SCRAMBLER_BYTE3; + + switch (m_writeState) { + case SS_FIRST: + m_writeText[0U] = byte1; + m_writeText[1U] = byte2; + m_writeText[2U] = byte3; + m_writeState = SS_SECOND; + return; + + case SS_SECOND: + m_writeText[3U] = byte1; + m_writeText[4U] = byte2; + m_writeText[5U] = byte3; + m_writeState = SS_FIRST; + break; + } + + if ((m_writeText[0U] & SLOW_DATA_TYPE_MASK) != SLOW_DATA_TYPE_GPS) + return; + + length = m_writeText[0U] & 0x07; // Maximum value of 5 + if (length > 5U) + length = 5U; + + for (unsigned int i = 0U; i < length; i++) { + m_writeBuffer[m_writeLength++] = m_writeText[i + 1U]; + + // Check for [EOB] in the buffer to signal the end of the D-RATS data. + // To allow strstr() to run correctly + m_writeBuffer[m_writeLength] = 0x00U; + + if (::strstr((char*)m_writeBuffer, "[EOB]") != NULL) { + if (m_socket != NULL) { + CUtils::dump("From RF", m_writeBuffer, m_writeLength); + m_socket->write(m_writeBuffer, m_writeLength); + } + + m_writeLength = 0U; + } + } +} + +void CDRATSServer::writeEnd() +{ + if (m_writeLength > 0U && m_socket != NULL) { + CUtils::dump("From RF", m_writeBuffer, m_writeLength); + m_socket->write(m_writeBuffer, m_writeLength); + } + + m_writeLength = 0U; +} + +void* CDRATSServer::Entry() +{ + CLog::logInfo("Starting the D-RATS Server thread for %s", m_callsign.c_str()); + + bool sending = false; + unsigned int id = 0U; + + unsigned char seqNo = 0U; + unsigned int sent = 0U; + + std::chrono::high_resolution_clock::time_point time; + +#ifndef DEBUG_DSTARGW + try { +#endif + while (!m_stopped) { + serviceSocket(); + + if (m_readEnd && !sending) { + id = CHeaderData::createId(); + + // Write header + CHeaderData header; + header.setMyCall1(m_callsign); + header.setMyCall2("DATA"); + header.setYourCall("CQCQCQ "); + header.setId(id); + +#if defined(LOOPBACK) + writeHeader(header); +#else + m_handler->process(header, DIR_INCOMING, AS_DRATS); +#endif + + m_readState = SS_FIRST; + m_readPos = 0U; + sending = true; + seqNo = 0U; + sent = 0U; + + time = std::chrono::high_resolution_clock::now(); + } + + if (m_readEnd && sending) { + unsigned int needed = std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - time).count() / DSTAR_FRAME_TIME_MS; + + while (sent < needed && sending) { + // Write AMBE data + CAMBEData data; + data.setId(id); + + unsigned char buffer[DV_FRAME_LENGTH_BYTES]; + ::memcpy(buffer + 0U, NULL_AMBE_DATA_BYTES, VOICE_FRAME_LENGTH_BYTES); + + // Insert sync bytes when the sequence number is zero, slow data otherwise + if (seqNo == 0U) { + ::memcpy(buffer + VOICE_FRAME_LENGTH_BYTES, DATA_SYNC_BYTES, DATA_FRAME_LENGTH_BYTES); + m_readState = SS_FIRST; + } else { + if (m_readState == SS_FIRST) { + unsigned char readText[3U]; + ::memset(readText, 'f', 3U); + + unsigned int length = m_readLength - m_readPos; + unsigned char bytes = 5U; + if (length < 5U) + bytes = length; + + readText[0U] = SLOW_DATA_TYPE_GPS | bytes; + + for (unsigned int i = 0U; i < 2U && m_readPos < m_readLength; i++) + readText[i + 1U] = m_readBuffer[m_readPos++]; + + readText[0U] ^= SCRAMBLER_BYTE1; + readText[1U] ^= SCRAMBLER_BYTE2; + readText[2U] ^= SCRAMBLER_BYTE3; + + ::memcpy(buffer + VOICE_FRAME_LENGTH_BYTES, readText, DATA_FRAME_LENGTH_BYTES); + + m_readState = SS_SECOND; + } else { + unsigned char readText[3U]; + ::memset(readText, 'f', 3U); + + for (unsigned int i = 0U; i < 3U && m_readPos < m_readLength; i++) + readText[i] = m_readBuffer[m_readPos++]; + + readText[0U] ^= SCRAMBLER_BYTE1; + readText[1U] ^= SCRAMBLER_BYTE2; + readText[2U] ^= SCRAMBLER_BYTE3; + + ::memcpy(buffer + VOICE_FRAME_LENGTH_BYTES, readText, DATA_FRAME_LENGTH_BYTES); + + m_readState = SS_FIRST; + } + } + + data.setSeq(seqNo); + data.setData(buffer, DV_FRAME_LENGTH_BYTES); + sent++; + +#if defined(LOOPBACK) + writeData(data); +#else + m_handler->process(data, DIR_INCOMING, AS_DRATS); +#endif + if (m_readPos == m_readLength) { + if (m_readState == SS_SECOND) { + seqNo++; + if (seqNo == 21U) + seqNo = 0U; + + unsigned char readText[3U]; + readText[0U] = 'f' ^ SCRAMBLER_BYTE1; + readText[1U] = 'f' ^ SCRAMBLER_BYTE2; + readText[2U] = 'f' ^ SCRAMBLER_BYTE3; + + ::memcpy(buffer + VOICE_FRAME_LENGTH_BYTES, readText, DATA_FRAME_LENGTH_BYTES); + + data.setSeq(seqNo); + data.setData(buffer, DV_FRAME_LENGTH_BYTES); + sent++; +#if defined(LOOPBACK) + writeData(data); +#else + m_handler->process(data, DIR_INCOMING, AS_DRATS); +#endif + } + + seqNo++; + if (seqNo == 21U) + seqNo = 0U; + + if (seqNo == 0U) + ::memcpy(buffer + VOICE_FRAME_LENGTH_BYTES, DATA_SYNC_BYTES, DATA_FRAME_LENGTH_BYTES); + else + ::memcpy(buffer + VOICE_FRAME_LENGTH_BYTES, NULL_SLOW_DATA_BYTES, DATA_FRAME_LENGTH_BYTES); + + data.setData(buffer, DV_FRAME_LENGTH_BYTES); + data.setSeq(seqNo); + data.setEnd(true); + sent++; +#if defined(LOOPBACK) + writeData(data); +#else + m_handler->process(data, DIR_INCOMING, AS_DRATS); +#endif + m_readLength = 0U; + m_readPos = 0U; + m_readEnd = false; + sending = false; + sent = 0U; + } + + seqNo++; + if (seqNo == 21U) + seqNo = 0U; + } + } + + // 50ms + Sleep(50UL); + } + + if (m_socket != NULL) + m_socket->stop(); +#ifndef DEBUG_DSTARGW + } + catch (std::exception& e) { + std::string message(e.what()); + CLog::logError("Exception raised in the D-RATS Server thread - \"%s\""), message.c_str(); + } + catch (...) { + CLog::logError("Unknown exception raised in the D-RATS Server thread"); + } +#endif + + CLog::logInfo("Stopping the D-RATS Server thread for %s", m_callsign.c_str()); + + return NULL; +} + +void CDRATSServer::close() +{ + m_stopped = true; + + Wait(); +} + +void CDRATSServer::serviceSocket() +{ + if (m_socket == NULL) { + m_readLength = 0U; + m_readPos = 0U; + m_readEnd = false; + return; + } + + int len = m_socket->read(m_readBuffer + m_readLength, BUFFER_LENGTH - m_readLength, 0U); + if (len > 0) { + m_readLength += len; + + if (!m_readEnd) { + // To allow strstr() to run correctly + m_readBuffer[m_readLength] = 0x00U; + + if (::strstr((char*)m_readBuffer, "[EOB]") != NULL) { + CUtils::dump("To RF", m_readBuffer, m_readLength); + m_readEnd = true; + } + } + } +} diff --git a/Common/DRATSServer.h b/Common/DRATSServer.h new file mode 100644 index 0000000..0436bcf --- /dev/null +++ b/Common/DRATSServer.h @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2011,2012 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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#ifndef DRATSServer_H +#define DRATSServer_H + +#include "TCPReaderWriterServer.h" +#include "RepeaterCallback.h" +#include "HeaderData.h" +#include "AMBEData.h" +#include "Defs.h" +#include "Thread.h" + +#include + +class CDRATSServer : public CThread { +public: + CDRATSServer(const std::string& address, unsigned int port, const std::string& callsign, IRepeaterCallback* handler); + virtual ~CDRATSServer(); + + virtual bool open(); + + virtual void writeHeader(const CHeaderData& header); + virtual void writeData(const CAMBEData& data); + virtual void writeEnd(); + + virtual void close(); + + virtual void* Entry(); + +private: + std::string m_address; + unsigned int m_port; + std::string m_callsign; + IRepeaterCallback* m_handler; + CTCPReaderWriterServer* m_socket; + bool m_stopped; + SLOWDATA_STATE m_readState; + unsigned char* m_readBuffer; + unsigned int m_readLength; + unsigned int m_readPos; + bool m_readEnd; + unsigned char* m_writeText; + SLOWDATA_STATE m_writeState; + unsigned char* m_writeBuffer; + unsigned int m_writeLength; + + void serviceSocket(); +}; + +#endif diff --git a/Common/RepeaterHandler.cpp b/Common/RepeaterHandler.cpp index 35685a6..9f817ca 100644 --- a/Common/RepeaterHandler.cpp +++ b/Common/RepeaterHandler.cpp @@ -64,7 +64,7 @@ CAPRSHandler* CRepeaterHandler::m_aprsWriter = NULL; CCallsignList* CRepeaterHandler::m_restrictList = NULL; #ifdef USE_DRATS - CRepeaterHandler::CRepeaterHandler(const std::string& callsign, const std::string& band, const std::string& address, unsigned int port, HW_TYPE hwType, const std::string& reflector, bool atStartup, RECONNECT reconnect, bool dratsEnabled, double frequency, double offset, double range, double latitude, double longitude, double agl, const std::string& description1, const std::string& description2, const std::string& url, IRepeaterProtocolHandler* handler, unsigned char band1, unsigned char band2, unigned char band3) : + CRepeaterHandler::CRepeaterHandler(const std::string& callsign, const std::string& band, const std::string& address, unsigned int port, HW_TYPE hwType, const std::string& reflector, bool atStartup, RECONNECT reconnect, bool dratsEnabled, double frequency, double offset, double range, double latitude, double longitude, double agl, const std::string& description1, const std::string& description2, const std::string& url, IRepeaterProtocolHandler* handler, unsigned char band1, unsigned char band2, unsigned char band3) : #else CRepeaterHandler::CRepeaterHandler(const std::string& callsign, const std::string& band, const std::string& address, unsigned int port, HW_TYPE hwType, const std::string& reflector, bool atStartup, RECONNECT reconnect, double frequency, double offset, double range, double latitude, double longitude, double agl, const std::string& description1, const std::string& description2, const std::string& url, IRepeaterProtocolHandler* handler, unsigned char band1, unsigned char band2, unsigned char band3) : #endif diff --git a/DStarGateway/DStarGatewayApp.cpp b/DStarGateway/DStarGatewayApp.cpp index 328e8fc..b29c2c0 100644 --- a/DStarGateway/DStarGatewayApp.cpp +++ b/DStarGateway/DStarGatewayApp.cpp @@ -260,6 +260,9 @@ bool CDStarGatewayApp::createThread() rptrConfig.reflectorAtStartup, rptrConfig.reflectorReconnect, rptrConfig.frequency, + #ifdef USE_DRATS + true, + #endif rptrConfig.offset, rptrConfig.range, rptrConfig.latitude, diff --git a/Makefile b/Makefile index ce115f6..d9f7720 100644 --- a/Makefile +++ b/Makefile @@ -38,6 +38,7 @@ export CPPFLAGS+= -DUSE_GPSD export LDFLAGS+= -lgps endif +export CPPFLAGS+= -DUSE_DRATS .PHONY: all all: DStarGateway/dstargateway DGWRemoteControl/dgwremotecontrol DGWTextTransmit/dgwtexttransmit DGWTimeServer/dgwtimeserver DGWVoiceTransmit/dgwvoicetransmit #tests From b5cef98c0082a06a8052a705fbbf1104aa1ceec8 Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Sat, 16 Apr 2022 07:49:07 +0200 Subject: [PATCH 03/11] #24 add DRats Config --- DStarGateway/DStarGatewayApp.cpp | 6 +++++- DStarGateway/DStarGatewayConfig.cpp | 21 ++++++++++++++++++++- DStarGateway/DStarGatewayConfig.h | 15 +++++++++++++++ DStarGateway/example.cfg | 3 +++ 4 files changed, 43 insertions(+), 2 deletions(-) diff --git a/DStarGateway/DStarGatewayApp.cpp b/DStarGateway/DStarGatewayApp.cpp index b29c2c0..940fc8f 100644 --- a/DStarGateway/DStarGatewayApp.cpp +++ b/DStarGateway/DStarGatewayApp.cpp @@ -240,6 +240,10 @@ bool CDStarGatewayApp::createThread() delete restrictList; } + // Drats + TDRats drats; + m_config->getDRats(drats); + // Setup the repeaters bool ddEnabled = false; bool atLeastOneRepeater = false; @@ -261,7 +265,7 @@ bool CDStarGatewayApp::createThread() rptrConfig.reflectorReconnect, rptrConfig.frequency, #ifdef USE_DRATS - true, + drats.enabled, #endif rptrConfig.offset, rptrConfig.range, diff --git a/DStarGateway/DStarGatewayConfig.cpp b/DStarGateway/DStarGatewayConfig.cpp index 9fd97c0..635a647 100644 --- a/DStarGateway/DStarGatewayConfig.cpp +++ b/DStarGateway/DStarGatewayConfig.cpp @@ -57,6 +57,9 @@ bool CDStarGatewayConfig::load() #endif ret = loadDaemon(cfg) && ret; ret = loadAccessControl(cfg) && ret; +#ifdef USE_DRATS + ret = loadDRats(cfg) && ret; +#endif } if(ret) { @@ -360,6 +363,15 @@ bool CDStarGatewayConfig::loadAccessControl(const CConfig & cfg) return ret; } +#ifdef USE_DRATS +bool CDStarGatewayConfig::loadDRats(const CConfig & cfg) +{ + bool ret = cfg.getValue("DRats", "enabled", m_drats.enabled, false); + + return ret; +} +#endif + bool CDStarGatewayConfig::open(CConfig & cfg) { try { @@ -465,4 +477,11 @@ void CDStarGatewayConfig::getDaemon(TDaemon & gen) const void CDStarGatewayConfig::getAccessControl(TAccessControl & accessControl) const { accessControl = m_accessControl; -} \ No newline at end of file +} + +#if USE_DRATS +void CDStarGatewayConfig::getDRats(TDRats & drats) const +{ + drats = m_drats; +} +#endif \ No newline at end of file diff --git a/DStarGateway/DStarGatewayConfig.h b/DStarGateway/DStarGatewayConfig.h index b39dd84..fdb5339 100644 --- a/DStarGateway/DStarGatewayConfig.h +++ b/DStarGateway/DStarGatewayConfig.h @@ -115,6 +115,12 @@ typedef struct { bool enabled; } TDCS; +#ifdef USE_DRATS +typedef struct { + bool enabled; +} TDRats; +#endif + typedef struct { bool enabled; std::string url; @@ -164,6 +170,9 @@ public: #endif void getDaemon(TDaemon & gen) const; void getAccessControl(TAccessControl & accessControl) const; +#ifdef USE_DRATS + void getDRats(TDRats & drats) const; +#endif private: bool open(CConfig & cfg); @@ -183,6 +192,9 @@ private: #endif bool loadDaemon(const CConfig & cfg); bool loadAccessControl(const CConfig & cfg); +#ifdef USE_DRATS + bool loadDRats(const CConfig & cfg); +#endif std::string m_fileName; TGateway m_gateway; @@ -199,6 +211,9 @@ private: #endif TDaemon m_daemon; TAccessControl m_accessControl; +#ifdef USE_DRATS + TDRats m_drats; +#endif std::vector m_repeaters; std::vector m_ircDDB; diff --git a/DStarGateway/example.cfg b/DStarGateway/example.cfg index 5d117bb..731da4e 100644 --- a/DStarGateway/example.cfg +++ b/DStarGateway/example.cfg @@ -172,6 +172,9 @@ enabled=true # There is no reason to disable this enabled=true hostfileUrl=http://xlxapi.rlx.lu/api.php?do=GetXLXDMRMaster +[DRats] +enabled=false # Defaults to false. The program need to be compiled with DRats support for DRats to be actually enabled + [Remote] enabled=false port=4242 From e442acadc70b2154f934d49fc27e7dc2598263ff Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Wed, 15 Jun 2022 17:20:16 +0200 Subject: [PATCH 04/11] #24 Clean up --- Common/RepeaterHandler.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Common/RepeaterHandler.h b/Common/RepeaterHandler.h index 0b29b85..6b7e10d 100644 --- a/Common/RepeaterHandler.h +++ b/Common/RepeaterHandler.h @@ -20,10 +20,6 @@ #ifndef RepeaterHandler_H #define RepeaterHandler_H -//#define USE_CCS -//#define USE_STARNET -//#define USE_DRATS - #include "RepeaterProtocolHandler.h" #include "DExtraProtocolHandler.h" #include "DPlusProtocolHandler.h" From 948e0889ed457ba01982b4ff4fd3ec24f98595cd Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Wed, 15 Jun 2022 17:56:02 +0200 Subject: [PATCH 05/11] #24 Make Drats a build option --- .vscode/tasks.json | 1 + DStarGateway/DStarGatewayApp.cpp | 2 ++ Makefile | 2 ++ 3 files changed, 5 insertions(+) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 587d251..e1ed666 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -11,6 +11,7 @@ "-j3", "ENABLE_DEBUG=1", "USE_GPSD=1", + "USE_DRATS=1", "all" ], "group": "build", diff --git a/DStarGateway/DStarGatewayApp.cpp b/DStarGateway/DStarGatewayApp.cpp index 940fc8f..16c7f52 100644 --- a/DStarGateway/DStarGatewayApp.cpp +++ b/DStarGateway/DStarGatewayApp.cpp @@ -240,9 +240,11 @@ bool CDStarGatewayApp::createThread() delete restrictList; } +#ifdef USE_DRATS // Drats TDRats drats; m_config->getDRats(drats); +#endif // Setup the repeaters bool ddEnabled = false; diff --git a/Makefile b/Makefile index d9f7720..28e98c0 100644 --- a/Makefile +++ b/Makefile @@ -38,7 +38,9 @@ export CPPFLAGS+= -DUSE_GPSD export LDFLAGS+= -lgps endif +ifeq ($(USE_DRATS), 1) export CPPFLAGS+= -DUSE_DRATS +endif .PHONY: all all: DStarGateway/dstargateway DGWRemoteControl/dgwremotecontrol DGWTextTransmit/dgwtexttransmit DGWTimeServer/dgwtimeserver DGWVoiceTransmit/dgwvoicetransmit #tests From 7a79e5c5c0b7ea291437188aebcd3697110630ee Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Wed, 15 Jun 2022 17:58:24 +0200 Subject: [PATCH 06/11] #24 Update readme --- README.md | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f300bcf..d444ef7 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,8 @@ - [3.4. Prerequisites and dependencies](#34-prerequisites-and-dependencies) - [3.5. Building](#35-building) - [3.5.0.1. Build With GPSD Support](#3501-build-with-gpsd-support) - - [3.5.0.2. Debug Build](#3502-debug-build) + - [3.5.0.2. Build With DRats Support](#3502-build-with-drats-support) + - [3.5.0.3. Debug Build](#3503-debug-build) - [3.6. Installing](#36-installing) - [3.7. Configuring](#37-configuring) - [4. Contributing](#4-contributing) @@ -100,7 +101,12 @@ make ``` make USE_GPS=1 ``` -#### 3.5.0.2. Debug Build +#### 3.5.0.2. Build With DRats Support +IMHO Drats is a dying thing, therefore it is included as a build option. +``` +make USE_DRATS=1 +``` +#### 3.5.0.3. Debug Build ``` make ENABLE_DEBUG=1 ``` @@ -135,6 +141,7 @@ the testing framwework used is Google Test. # 5. Version History ## 5.1. Version 0.6 +- [**Improvement**] Add DRats Support (conditional build) ([#22](https://github.com/F4FXL/DStarGateway/issues/22)) - [**Improvement**] Add call sign lists ([#22](https://github.com/F4FXL/DStarGateway/issues/22)) - [**Improvement**] Add a way to override Slow Data in VoiceTransmit ([#23](https://github.com/F4FXL/DStarGateway/issues/23)) - [**Improvement**] Add time server From 856d481b3fc5beaa1fc77026e64cfb1d185b8182 Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Wed, 15 Jun 2022 18:00:32 +0200 Subject: [PATCH 07/11] #24 include DRats build option in CI --- .circleci/config.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index f858990..6960b90 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -21,10 +21,10 @@ jobs: sudo apt-get -y install libgtest-dev libcurl4-openssl-dev libboost-dev libgps-dev - run: name: "Build" - command: "make -j 3 ENABLE_DEBUG=1 USE_GPSD=1" + command: "make -j 3 ENABLE_DEBUG=1 USE_GPSD=1 USE_DRATS=1" - run: name: "Run Tests" - command: "make run-tests ENABLE_DEBUG=1 USE_GPSD=1" + command: "make run-tests ENABLE_DEBUG=1 USE_GPSD=1 USE_DRATS=1" # Invoke jobs via workflows # See: https://circleci.com/docs/2.0/configuration-reference/#workflows workflows: From c951ddae6f220505b7404f152ee482becc43c458 Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Sat, 3 Sep 2022 06:53:06 +0200 Subject: [PATCH 08/11] #24 update readme --- README.md | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index d444ef7..bc530e6 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ - [3.5.0.3. Debug Build](#3503-debug-build) - [3.6. Installing](#36-installing) - [3.7. Configuring](#37-configuring) + - [3.8. Updating host files](#38-updating-host-files) - [4. Contributing](#4-contributing) - [4.1. Work Flow](#41-work-flow) - [4.2. Continuous Integration](#42-continuous-integration) @@ -102,7 +103,7 @@ make make USE_GPS=1 ``` #### 3.5.0.2. Build With DRats Support -IMHO Drats is a dying thing, therefore it is included as a build option. +IMHO Drats is a decaying thing, therefore it is included as a build option. ``` make USE_DRATS=1 ``` @@ -110,7 +111,7 @@ make USE_DRATS=1 ``` make ENABLE_DEBUG=1 ``` -Note that this will link with libl +Note that this will will add libl dependency. Building this way will output the stack trace in case of a crash. ## 3.6. Installing The program is meant to run as a systemd service. All bits an pieces are provided. ``` @@ -122,13 +123,21 @@ After installing you have to edit the configuration file. If you went with defau The configuration format is quite straight forward. It is organised in sections and key/value pairs. The order of the sections or key/values pairs inside the sections does not matter nor does casing. Boolean values can be set using true, false, 1 or 0 -Floating point values must use . (point) as decimal separatorsensitive. +Floating point values must use . (point) as decimal separator. -When done with configuration, the daemon will be started automatically on boot. To manual start and stop it use the usual systemd commands +When done with configuration, the daemon will be started automatically on next boot. To manual start and stop it, use the usual systemd commands ``` sudo systemctl start dstargateway.service sudo systemctl stop dstargateway.service ``` + +## 3.8. Updating host files +To update host files, from within the source code directory, run +``` +sudo make newhostfiles +sudo systemctl restart dstargateway.service +``` + # 4. Contributing ## 4.1. Work Flow I Use [Git flow](https://danielkummer.github.io/git-flow-cheatsheet/) as my workflow. PR are welcome but pleasee observe following rules : @@ -137,7 +146,7 @@ I Use [Git flow](https://danielkummer.github.io/git-flow-cheatsheet/) as my work - Code formating rules are observed (these are very lousy though) ## 4.2. Continuous Integration I have added some basic CI using CircleCI [![F4FXL](https://circleci.com/gh/F4FXL/DStarGateway.svg?style=svg)](https://app.circleci.com/pipelines/github/F4FXL/DStarGateway?filter=all) I am trying to rewrite the code so that it can be put into some Behavior Driven Development scheme. This is a long haul task and I'll try do do it on the go while changing/adding stuff. -the testing framwework used is Google Test. +The testing framwework used is Google Test. # 5. Version History ## 5.1. Version 0.6 From cae6aea472ebadadc98e165b8707f9869a0707d2 Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Tue, 20 Sep 2022 20:48:15 +0200 Subject: [PATCH 09/11] Do not make DRats a compile option --- .circleci/config.yml | 4 ++-- .vscode/tasks.json | 1 - Common/RepeaterHandler.cpp | 32 +++++++---------------------- Common/RepeaterHandler.h | 13 +----------- DStarGateway/DStarGatewayApp.cpp | 4 ---- DStarGateway/DStarGatewayConfig.cpp | 8 +------- DStarGateway/DStarGatewayConfig.h | 10 --------- DStarGateway/DStarGatewayThread.cpp | 7 +------ DStarGateway/DStarGatewayThread.h | 7 ++----- Makefile | 4 ---- README.md | 10 ++------- 11 files changed, 16 insertions(+), 84 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 6960b90..f858990 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -21,10 +21,10 @@ jobs: sudo apt-get -y install libgtest-dev libcurl4-openssl-dev libboost-dev libgps-dev - run: name: "Build" - command: "make -j 3 ENABLE_DEBUG=1 USE_GPSD=1 USE_DRATS=1" + command: "make -j 3 ENABLE_DEBUG=1 USE_GPSD=1" - run: name: "Run Tests" - command: "make run-tests ENABLE_DEBUG=1 USE_GPSD=1 USE_DRATS=1" + command: "make run-tests ENABLE_DEBUG=1 USE_GPSD=1" # Invoke jobs via workflows # See: https://circleci.com/docs/2.0/configuration-reference/#workflows workflows: diff --git a/.vscode/tasks.json b/.vscode/tasks.json index e1ed666..587d251 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -11,7 +11,6 @@ "-j3", "ENABLE_DEBUG=1", "USE_GPSD=1", - "USE_DRATS=1", "all" ], "group": "build", diff --git a/Common/RepeaterHandler.cpp b/Common/RepeaterHandler.cpp index 9f817ca..c66e95f 100644 --- a/Common/RepeaterHandler.cpp +++ b/Common/RepeaterHandler.cpp @@ -63,11 +63,8 @@ CAPRSHandler* CRepeaterHandler::m_aprsWriter = NULL; CCallsignList* CRepeaterHandler::m_restrictList = NULL; -#ifdef USE_DRATS - CRepeaterHandler::CRepeaterHandler(const std::string& callsign, const std::string& band, const std::string& address, unsigned int port, HW_TYPE hwType, const std::string& reflector, bool atStartup, RECONNECT reconnect, bool dratsEnabled, double frequency, double offset, double range, double latitude, double longitude, double agl, const std::string& description1, const std::string& description2, const std::string& url, IRepeaterProtocolHandler* handler, unsigned char band1, unsigned char band2, unsigned char band3) : -#else - CRepeaterHandler::CRepeaterHandler(const std::string& callsign, const std::string& band, const std::string& address, unsigned int port, HW_TYPE hwType, const std::string& reflector, bool atStartup, RECONNECT reconnect, double frequency, double offset, double range, double latitude, double longitude, double agl, const std::string& description1, const std::string& description2, const std::string& url, IRepeaterProtocolHandler* handler, unsigned char band1, unsigned char band2, unsigned char band3) : -#endif +CRepeaterHandler::CRepeaterHandler(const std::string& callsign, const std::string& band, const std::string& address, unsigned int port, HW_TYPE hwType, const std::string& reflector, bool atStartup, RECONNECT reconnect, bool dratsEnabled, double frequency, double offset, double range, double latitude, double longitude, double agl, const std::string& description1, const std::string& description2, const std::string& url, IRepeaterProtocolHandler* handler, unsigned char band1, unsigned char band2, unsigned char band3) : + m_index(0x00U), m_rptCallsign(), m_gwyCallsign(), @@ -137,9 +134,7 @@ m_wxAudio(NULL), m_wxNeeded(false), #endif m_version(NULL), -#ifdef USE_DRATS m_drats(NULL), -#endif m_dtmf(), m_pollTimer(1000U, 900U), // 15 minutes #ifdef USE_CSS @@ -228,7 +223,7 @@ m_heardTimer(1000U, 0U, 100U) // 100ms m_version = new CVersionUnit(this, callsign); m_aprsUnit = new CAPRSUnit(this); -#ifdef USE_DRATS + if (dratsEnabled) { m_drats = new CDRATSServer(m_localAddress, port, callsign, this); bool ret = m_drats->open(); @@ -237,7 +232,6 @@ m_heardTimer(1000U, 0U, 100U) // 100ms m_drats = NULL; } } -#endif } CRepeaterHandler::~CRepeaterHandler() @@ -250,10 +244,8 @@ CRepeaterHandler::~CRepeaterHandler() #endif delete m_version; -#ifdef USE_DRATS if (m_drats != NULL) m_drats->close(); -#endif } void CRepeaterHandler::initialise(unsigned int maxRepeaters) @@ -272,21 +264,14 @@ void CRepeaterHandler::setIndex(unsigned int index) m_index = index; } -#ifdef USE_DRATS void CRepeaterHandler::add(const std::string& callsign, const std::string& band, const std::string& address, unsigned int port, HW_TYPE hwType, const std::string& reflector, bool atStartup, RECONNECT reconnect, bool dratsEnabled, double frequency, double offset, double range, double latitude, double longitude, double agl, const std::string& description1, const std::string& description2, const std::string& url, IRepeaterProtocolHandler* handler, unsigned char band1, unsigned char band2, unsigned char band3) -#else -void CRepeaterHandler::add(const std::string& callsign, const std::string& band, const std::string& address, unsigned int port, HW_TYPE hwType, const std::string& reflector, bool atStartup, RECONNECT reconnect, double frequency, double offset, double range, double latitude, double longitude, double agl, const std::string& description1, const std::string& description2, const std::string& url, IRepeaterProtocolHandler* handler, unsigned char band1, unsigned char band2, unsigned char band3) -#endif { assert(!callsign.empty()); assert(port > 0U); assert(handler != NULL); -#ifdef USE_DRATS + CRepeaterHandler* repeater = new CRepeaterHandler(callsign, band, address, port, hwType, reflector, atStartup, reconnect, dratsEnabled, frequency, offset, range, latitude, longitude, agl, description1, description2, url, handler, band1, band2, band3); -#else - CRepeaterHandler* repeater = new CRepeaterHandler(callsign, band, address, port, hwType, reflector, atStartup, reconnect, frequency, offset, range, latitude, longitude, agl, description1, description2, url, handler, band1, band2, band3); -#endif for (unsigned int i = 0U; i < m_maxRepeaters; i++) { if (m_repeaters[i] == NULL) { @@ -606,10 +591,8 @@ void CRepeaterHandler::processRepeater(CHeaderData& header) // The Icom heard timer m_heardTimer.stop(); -#ifdef USE_DRATS if (m_drats != NULL) m_drats->writeHeader(header); -#endif // Reset the statistics m_frames = 0U; @@ -836,10 +819,9 @@ void CRepeaterHandler::processRepeater(CAMBEData& data) // CCS gets everything m_ccsHandler->writeAMBE(data); #endif -#ifdef USE_DRATS + if (m_drats != NULL) m_drats->writeData(data); -#endif if (m_aprsWriter != NULL) m_aprsWriter->writeData(m_rptCallsign, data); @@ -1572,10 +1554,10 @@ void CRepeaterHandler::clockInt(unsigned int ms) if (m_repeaterId != 0x00U) { if (m_text.empty()) sendHeard(); -#ifdef USE_DRATS + if (m_drats != NULL) m_drats->writeEnd(); -#endif + sendStats(); diff --git a/Common/RepeaterHandler.h b/Common/RepeaterHandler.h index 6b7e10d..e0422c4 100644 --- a/Common/RepeaterHandler.h +++ b/Common/RepeaterHandler.h @@ -35,9 +35,7 @@ #include "CacheManager.h" #include "HeaderLogger.h" #include "CallsignList.h" -#ifdef USE_DRATS #include "DRATSServer.h" -#endif #include "CCSCallback.h" #include "VersionUnit.h" #ifdef USE_CCS @@ -64,11 +62,7 @@ class CRepeaterHandler : public IRepeaterCallback, public IReflectorCallback, pu public: static void initialise(unsigned int maxRepeaters); -#ifdef USE_DRATS static void add(const std::string& callsign, const std::string& band, const std::string& address, unsigned int port, HW_TYPE hwType, const std::string& reflector, bool atStartup, RECONNECT reconnect, bool dratsEnabled, double frequency, double offset, double range, double latitude, double longitude, double agl, const std::string& description1, const std::string& description2, const std::string& url, IRepeaterProtocolHandler* handler, unsigned char band1, unsigned char band2, unsigned char band3); -#else - static void add(const std::string& callsign, const std::string& band, const std::string& address, unsigned int port, HW_TYPE hwType, const std::string& reflector, bool atStartup, RECONNECT reconnect, double frequency, double offset, double range, double latitude, double longitude, double agl, const std::string& description1, const std::string& description2, const std::string& url, IRepeaterProtocolHandler* handler, unsigned char band1, unsigned char band2, unsigned char band3); -#endif static void setLocalAddress(const std::string& address); static void setG2HandlerPool(CG2ProtocolHandlerPool* handler); @@ -143,11 +137,8 @@ public: virtual void readAPRSFrame(CAPRSFrame& frame); protected: -#ifdef USE_DRATS CRepeaterHandler(const std::string& callsign, const std::string& band, const std::string& address, unsigned int port, HW_TYPE hwType, const std::string& reflector, bool atStartup, RECONNECT reconnect, bool dratsEnabled, double frequency, double offset, double range, double latitude, double longitude, double agl, const std::string& description1, const std::string& description2, const std::string& url, IRepeaterProtocolHandler* handler, unsigned char band1, unsigned char band2, unsigned char band3); -#else - CRepeaterHandler(const std::string& callsign, const std::string& band, const std::string& address, unsigned int port, HW_TYPE hwType, const std::string& reflector, bool atStartup, RECONNECT reconnect, double frequency, double offset, double range, double latitude, double longitude, double agl, const std::string& description1, const std::string& description2, const std::string& url, IRepeaterProtocolHandler* handler, unsigned char band1, unsigned char band2, unsigned char band3); -#endif + virtual ~CRepeaterHandler(); void resolveUserInt(const std::string& user, const std::string& repeater, const std::string& gateway, const std::string& address); @@ -278,10 +269,8 @@ private: // APRS to DPRS CAPRSUnit* m_aprsUnit; -#ifdef USE_DRATS // D-RATS handler CDRATSServer* m_drats; -#endif // DTMF commands CDTMF m_dtmf; diff --git a/DStarGateway/DStarGatewayApp.cpp b/DStarGateway/DStarGatewayApp.cpp index 16c7f52..792a6bf 100644 --- a/DStarGateway/DStarGatewayApp.cpp +++ b/DStarGateway/DStarGatewayApp.cpp @@ -240,11 +240,9 @@ bool CDStarGatewayApp::createThread() delete restrictList; } -#ifdef USE_DRATS // Drats TDRats drats; m_config->getDRats(drats); -#endif // Setup the repeaters bool ddEnabled = false; @@ -266,9 +264,7 @@ bool CDStarGatewayApp::createThread() rptrConfig.reflectorAtStartup, rptrConfig.reflectorReconnect, rptrConfig.frequency, - #ifdef USE_DRATS drats.enabled, - #endif rptrConfig.offset, rptrConfig.range, rptrConfig.latitude, diff --git a/DStarGateway/DStarGatewayConfig.cpp b/DStarGateway/DStarGatewayConfig.cpp index 635a647..2cfd90a 100644 --- a/DStarGateway/DStarGatewayConfig.cpp +++ b/DStarGateway/DStarGatewayConfig.cpp @@ -57,9 +57,7 @@ bool CDStarGatewayConfig::load() #endif ret = loadDaemon(cfg) && ret; ret = loadAccessControl(cfg) && ret; -#ifdef USE_DRATS ret = loadDRats(cfg) && ret; -#endif } if(ret) { @@ -363,14 +361,12 @@ bool CDStarGatewayConfig::loadAccessControl(const CConfig & cfg) return ret; } -#ifdef USE_DRATS bool CDStarGatewayConfig::loadDRats(const CConfig & cfg) { bool ret = cfg.getValue("DRats", "enabled", m_drats.enabled, false); return ret; } -#endif bool CDStarGatewayConfig::open(CConfig & cfg) { @@ -479,9 +475,7 @@ void CDStarGatewayConfig::getAccessControl(TAccessControl & accessControl) const accessControl = m_accessControl; } -#if USE_DRATS void CDStarGatewayConfig::getDRats(TDRats & drats) const { drats = m_drats; -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/DStarGateway/DStarGatewayConfig.h b/DStarGateway/DStarGatewayConfig.h index fdb5339..d148987 100644 --- a/DStarGateway/DStarGatewayConfig.h +++ b/DStarGateway/DStarGatewayConfig.h @@ -56,9 +56,7 @@ typedef struct { HW_TYPE hwType; bool reflectorAtStartup; RECONNECT reflectorReconnect; -#ifdef USE_DRATS bool dRatsEnabled; -#endif double frequency; double offset; double range; @@ -115,11 +113,9 @@ typedef struct { bool enabled; } TDCS; -#ifdef USE_DRATS typedef struct { bool enabled; } TDRats; -#endif typedef struct { bool enabled; @@ -170,9 +166,7 @@ public: #endif void getDaemon(TDaemon & gen) const; void getAccessControl(TAccessControl & accessControl) const; -#ifdef USE_DRATS void getDRats(TDRats & drats) const; -#endif private: bool open(CConfig & cfg); @@ -192,9 +186,7 @@ private: #endif bool loadDaemon(const CConfig & cfg); bool loadAccessControl(const CConfig & cfg); -#ifdef USE_DRATS bool loadDRats(const CConfig & cfg); -#endif std::string m_fileName; TGateway m_gateway; @@ -211,9 +203,7 @@ private: #endif TDaemon m_daemon; TAccessControl m_accessControl; -#ifdef USE_DRATS TDRats m_drats; -#endif std::vector m_repeaters; std::vector m_ircDDB; diff --git a/DStarGateway/DStarGatewayThread.cpp b/DStarGateway/DStarGatewayThread.cpp index 73ea87c..1d7d074 100644 --- a/DStarGateway/DStarGatewayThread.cpp +++ b/DStarGateway/DStarGatewayThread.cpp @@ -511,15 +511,10 @@ void CDStarGatewayThread::setGateway(GATEWAY_TYPE gatewayType, const std::string m_gatewayAddress = gatewayAddress; } -#ifdef USE_DRATS + void CDStarGatewayThread::addRepeater(const std::string& callsign, const std::string& band, const std::string& address, unsigned int port, HW_TYPE hwType, const std::string& reflector, bool atStartup, RECONNECT reconnect, bool dratsEnabled, double frequency, double offset, double range, double latitude, double longitude, double agl, const std::string& description1, const std::string& description2, const std::string& url, IRepeaterProtocolHandler* handler, unsigned char band1, unsigned char band2, unsigned char band3) { CRepeaterHandler::add(callsign, band, address, port, hwType, reflector, atStartup, reconnect, dratsEnabled, frequency, offset, range, latitude, longitude, agl, description1, description2, url, handler, band1, band2, band3); -#else -void CDStarGatewayThread::addRepeater(const std::string& callsign, const std::string& band, const std::string& address, unsigned int port, HW_TYPE hwType, const std::string& reflector, bool atStartup, RECONNECT reconnect, double frequency, double offset, double range, double latitude, double longitude, double agl, const std::string& description1, const std::string& description2, const std::string& url, IRepeaterProtocolHandler* handler, unsigned char band1, unsigned char band2, unsigned char band3) -{ - CRepeaterHandler::add(callsign, band, address, port, hwType, reflector, atStartup, reconnect, frequency, offset, range, latitude, longitude, agl, description1, description2, url, handler, band1, band2, band3); -#endif std::string repeater = callsign; repeater.resize(LONG_CALLSIGN_LENGTH - 1U); diff --git a/DStarGateway/DStarGatewayThread.h b/DStarGateway/DStarGatewayThread.h index 5b4fe3c..767a81d 100644 --- a/DStarGateway/DStarGatewayThread.h +++ b/DStarGateway/DStarGatewayThread.h @@ -44,11 +44,8 @@ public: virtual ~CDStarGatewayThread(); virtual void setGateway(GATEWAY_TYPE type, const std::string& callsign, const std::string& address); -#ifdef USE_DRATS -virtual void addRepeater(const std::string& callsign, const std::string& band, const std::string& address, unsigned int port, HW_TYPE hwType, const std::string& reflector, bool atStartup, RECONNECT reconnect, bool dratsEnabled, double frequency, double offset, double range, double latitude, double longitude, double agl, const std::string& description1, const std::string& description2, const std::string& url, IRepeaterProtocolHandler* handler, unsigned char band1 = 0x00U, unsigned char band2 = 0x00U, unsigned char band3 = 0x00U); -#else - virtual void addRepeater(const std::string& callsign, const std::string& band, const std::string& address, unsigned int port, HW_TYPE hwType, const std::string& reflector, bool atStartup, RECONNECT reconnect, double frequency, double offset, double range, double latitude, double longitude, double agl, const std::string& description1, const std::string& description2, const std::string& url, IRepeaterProtocolHandler* handler, unsigned char band1 = 0x00U, unsigned char band2 = 0x00U, unsigned char band3 = 0x00U); -#endif + virtual void addRepeater(const std::string& callsign, const std::string& band, const std::string& address, unsigned int port, HW_TYPE hwType, const std::string& reflector, bool atStartup, RECONNECT reconnect, bool dratsEnabled, double frequency, double offset, double range, double latitude, double longitude, double agl, const std::string& description1, const std::string& description2, const std::string& url, IRepeaterProtocolHandler* handler, unsigned char band1 = 0x00U, unsigned char band2 = 0x00U, unsigned char band3 = 0x00U); + #ifdef USE_STARNET #if defined(DEXTRA_LINK) || defined(DCS_LINK) virtual void addStarNet(const std::string& callsign, const std::string& logoff, const std::string& repeater, const std::string& infoText, const std::string& permanent, unsigned int userTimeout, unsigned int groupTimeout, STARNET_CALLSIGN_SWITCH callsignSwitch, bool txMsgSwitch, const std::string& reflector); diff --git a/Makefile b/Makefile index 28e98c0..d7daf6d 100644 --- a/Makefile +++ b/Makefile @@ -38,10 +38,6 @@ export CPPFLAGS+= -DUSE_GPSD export LDFLAGS+= -lgps endif -ifeq ($(USE_DRATS), 1) -export CPPFLAGS+= -DUSE_DRATS -endif - .PHONY: all all: DStarGateway/dstargateway DGWRemoteControl/dgwremotecontrol DGWTextTransmit/dgwtexttransmit DGWTimeServer/dgwtimeserver DGWVoiceTransmit/dgwvoicetransmit #tests diff --git a/README.md b/README.md index bc530e6..afda621 100644 --- a/README.md +++ b/README.md @@ -13,8 +13,7 @@ - [3.4. Prerequisites and dependencies](#34-prerequisites-and-dependencies) - [3.5. Building](#35-building) - [3.5.0.1. Build With GPSD Support](#3501-build-with-gpsd-support) - - [3.5.0.2. Build With DRats Support](#3502-build-with-drats-support) - - [3.5.0.3. Debug Build](#3503-debug-build) + - [3.5.0.2. Debug Build](#3502-debug-build) - [3.6. Installing](#36-installing) - [3.7. Configuring](#37-configuring) - [3.8. Updating host files](#38-updating-host-files) @@ -102,12 +101,7 @@ make ``` make USE_GPS=1 ``` -#### 3.5.0.2. Build With DRats Support -IMHO Drats is a decaying thing, therefore it is included as a build option. -``` -make USE_DRATS=1 -``` -#### 3.5.0.3. Debug Build +#### 3.5.0.2. Debug Build ``` make ENABLE_DEBUG=1 ``` From 464b6e32db74451fece304255d4110080c0e5847 Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Tue, 20 Sep 2022 21:23:22 +0200 Subject: [PATCH 10/11] #22 Update Readme --- README.md | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index afda621..c0cf48c 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ - [2.3. Thanks](#23-thanks) - [2.4. Features](#24-features) - [2.4.1. Features that where left out :](#241-features-that-where-left-out-) - - [2.4.2. Additional Features :](#242-additional-features-) + - [2.4.2. Additional Features compared to ircddbGateway:](#242-additional-features-compared-to-ircddbgateway) - [3. Building and installing](#3-building-and-installing) - [3.1. Initial setup](#31-initial-setup) - [3.2. Get latest stable version (recommended)](#32-get-latest-stable-version-recommended) @@ -55,12 +55,11 @@ All the features found in ircddbGateway are supposed to be working. Except the o - Starnet: You might consider running [Smart Group Server XL](https://github.com/F4FXL/smart-group-server-xl) from a dedicated computer instead. - Announcement: same can be achieved using VoiceTransmit. - APRSGateway capability: I would prefer to have some sort of TCP "APRS-IS proxy" program sitting between the program and the APRS server, thus keeping the ability to directly connect to APRS-IS or not, depending on the system owner wish. I run mostly DStar Only repeaters, having an additional program to maintain is unnecessary burden. -- DRats : Is on the to-do list see [#6](#6) - CallSign Server : this is a legacy from the dead project xreflector.net, I will most probably drop it for good. -### 2.4.2. Additional Features : -- DPlus, DExtra and G2 NAT Traversal using ircddb network as rendez-vous server -- Forward RSMS1A app messages from/to APRS-IS Network, yes you can send/receive messages to and from aprs. +### 2.4.2. Additional Features compared to ircddbGateway: +- DPlus, DExtra and G2 NAT Traversal using ircddb network as rendez-vous server. I.e. it is not required to open firewall ports for Callsign Routing or Gateway calls. however it is still recommended to do so. But NAT Traversal will bring more flexibility when operating on CGNAT (Mobile) Networks. +- Forward RSMS1A app messages from/to APRS-IS Network, yes you can send/receive messages to and from aprs. Yes, you can send messages to APRS stations and Vice Versa. Additionnally part of the message is sent as Text Dat in the slow data. This allows you to read the message dirdclty on your radio screen. - Repeater Link status is sent to APRS-IS as a status frame # 3. Building and installing @@ -144,7 +143,7 @@ The testing framwework used is Google Test. # 5. Version History ## 5.1. Version 0.6 -- [**Improvement**] Add DRats Support (conditional build) ([#22](https://github.com/F4FXL/DStarGateway/issues/22)) +- [**Improvement**] Add DRats Support ([#22](https://github.com/F4FXL/DStarGateway/issues/22)) - [**Improvement**] Add call sign lists ([#22](https://github.com/F4FXL/DStarGateway/issues/22)) - [**Improvement**] Add a way to override Slow Data in VoiceTransmit ([#23](https://github.com/F4FXL/DStarGateway/issues/23)) - [**Improvement**] Add time server @@ -177,9 +176,9 @@ I started this during my 2021 seasons holiday. It took me almost 8 days to get t - No banging on every gateway: use ircDDB (or something else) as mitigation server to notify peer - Support for all protocols (G2, DExtra, DPlus) DCS does nto make sense as it was historically never used as protocol for linking repeaters - ☑ Send the connection status to APRS-IS as a status frame -- ☒ Reinstantiate DRATS +- ☑ Reinstantiate DRATS - ☑ Migrate all the "accessories" (VoiceTransmit, RemoteControl ...) - ☒ Automatic refresh of host files - ☒ Reduce ircDDB dependency, build something more P2P, maybe based on [Distributed Hashtable](https://github.com/DavidKeller/kademlia) ? -- ☒ Forward messages from RS-MS1A to APRS and vice versa +- ☑ Forward messages from RS-MS1A to APRS and vice versa - Everything that might come handy to make dstar the most powerful system ever :) From ae81a8855e89ebd509e62a988df639a9ee177616 Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Wed, 21 Sep 2022 11:41:07 +0200 Subject: [PATCH 11/11] Correct some Typos in Readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c0cf48c..5003389 100644 --- a/README.md +++ b/README.md @@ -51,10 +51,10 @@ Quite a few classes are more or less copy/paste from each other some sanitizatio All the features found in ircddbGateway are supposed to be working. Except the ones listed below ### 2.4.1. Features that where left out : -- CCS: is still being used? I always considered this as trojan horse to push some DMR Agenda into DStar an more or les a burdain to use. Call sign routing is by far more flexible and superior. +- CCS: is still being used? I always considered this as trojan horse to push some DMR Agenda into DStar and a burdain to use. Call sign routing is by far more flexible and superior. - Starnet: You might consider running [Smart Group Server XL](https://github.com/F4FXL/smart-group-server-xl) from a dedicated computer instead. - Announcement: same can be achieved using VoiceTransmit. -- APRSGateway capability: I would prefer to have some sort of TCP "APRS-IS proxy" program sitting between the program and the APRS server, thus keeping the ability to directly connect to APRS-IS or not, depending on the system owner wish. I run mostly DStar Only repeaters, having an additional program to maintain is unnecessary burden. +- APRSGateway capability: I would prefer to have some sort of TCP "APRS-IS proxy" program sitting between the program and the APRS server, thus keeping the ability to directly connect to APRS-IS or not, depending on the system owner wish. I run mostly DStar Only repeaters, having an additional program to maintain is unnecessary overkill. - CallSign Server : this is a legacy from the dead project xreflector.net, I will most probably drop it for good. ### 2.4.2. Additional Features compared to ircddbGateway: