From 35beaf8febedb95812b1a218c6f8ca131e63cdf3 Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Sun, 26 Dec 2021 21:27:44 +0100 Subject: [PATCH] Contineu implementation of config and main thread --- DStarGatewayApp.cpp | 75 +++++++---- DStarGatewayConfig.cpp | 197 +++++++++++++++++++++++++---- DStarGatewayConfig.h | 15 ++- DStarGatewayThread.cpp | 17 ++- DStarGatewayThread.h | 14 +- Defs.h | 35 ++++- Makefile | 3 +- RepeaterProtocolHandlerFactory.cpp | 79 ++++++++++++ RepeaterProtocolHandlerFactory.h | 40 ++++++ example.cfg | 35 ++++- 10 files changed, 437 insertions(+), 73 deletions(-) create mode 100644 RepeaterProtocolHandlerFactory.cpp create mode 100644 RepeaterProtocolHandlerFactory.h diff --git a/DStarGatewayApp.cpp b/DStarGatewayApp.cpp index f3c306e..d9e6b8f 100644 --- a/DStarGatewayApp.cpp +++ b/DStarGatewayApp.cpp @@ -1,6 +1,6 @@ /* * Copyright (C) 2010,2011 by Jonathan Naylor G4KLX - * Copyright (c) 2017,2018 by Thomas A. Early N7TAE + * Copyright (c) 2021 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 @@ -22,6 +22,7 @@ #include #include #include +#include #include "DStarGatewayDefs.h" #include "DStarGatewayConfig.h" @@ -31,6 +32,7 @@ #include "IRCDDBClient.h" #include "Utils.h" #include "GitVersion.h" +#include "RepeaterProtocolHandlerFactory.h" int main(int argc, char *argv[]) { @@ -92,34 +94,63 @@ bool CDStarGatewayApp::createThread() printf("FATAL: Invalid configuration"); return false; } - // m_thread = new CDStarGatewayThread(config.getLinkCount("XRF"), config.getLinkCount("DCS")); - // std::string CallSign, address; - // config.getGateway(CallSign, address); + Tpaths paths; + config.getPaths(paths); + m_thread = new CDStarGatewayThread(paths.logDir, paths.dataDir, ""); - // CallSign.resize(7, ' '); - // CallSign.push_back('G'); + TGateway gatewayConfig; + config.getGateway(gatewayConfig); // printf("Gateway callsign set to %s, local address set to %s\n", CallSign.c_str(), address.c_str()); - // CIRCDDB_Array clients; - // for(unsigned int i=0; i < config.getIrcDDBCount(); i++) { - // std::string hostname, username, password; - // bool isQuadNet; - // config.getIrcDDB(i, hostname, username, password, isQuadNet); - // std::cout << "ircDDB " << i + 1 << " set to " << hostname << " username set to " << username << " QuadNet " << isQuadNet << std::endl; - // CIRCDDB *ircDDB = new CIRCDDBClient(hostname, 9007U, username, password, std::string("linux_SmartGroupServer") + std::string("-") + VERSION, address, isQuadNet); - // clients.push_back(ircDDB); - // } + std::vector clients; + for(unsigned int i=0; i < config.getIrcDDBCount(); i++) { + TircDDB ircDDBConfig; + config.getIrcDDB(i, ircDDBConfig); + std::cout << "ircDDB " << i + 1 << " set to " << ircDDBConfig.hostname << " username set to " << ircDDBConfig.username << " QuadNet " << ircDDBConfig.isQuadNet << std::endl; + + CIRCDDB * ircDDB = new CIRCDDBClient(ircDDBConfig.hostname, 9007U, ircDDBConfig.username, ircDDBConfig.password, std::string("DStarGateway") + std::string("-") + VERSION, gatewayConfig.address, ircDDBConfig.isQuadNet); + clients.push_back(ircDDB); + } - // CIRCDDBMultiClient* multiClient = new CIRCDDBMultiClient(clients); - // bool res = multiClient->open(); - // if (!res) { - // printf("Cannot initialise the ircDDB protocol handler\n"); - // return false; - // } + CIRCDDBMultiClient* multiClient = new CIRCDDBMultiClient(clients); + bool res = multiClient->open(); + if (!res) { + printf("Cannot initialise the ircDDB protocol handler\n"); + return false; + } - // m_thread->setIRC(multiClient); + m_thread->setIRC(multiClient); + + CRepeaterHandlerFactory repeaterProtocolFactory; + + for(unsigned int i = 0U; i < config.getRepeaterCount(); i++) { + TRepeater rptrConfig; + config.getRepeater(i, rptrConfig); + + m_thread->addRepeater(rptrConfig.callsign, + rptrConfig.band, + rptrConfig.address, + rptrConfig.port, + rptrConfig.hwType, + rptrConfig.reflector, + rptrConfig.reflectorAtStartup, + rptrConfig.reflectorReconnect, + rptrConfig.frequency, + rptrConfig.offset, + rptrConfig.range, + rptrConfig.latitude, + rptrConfig.longitude, + rptrConfig.agl, + rptrConfig.description1, + rptrConfig.description2, + rptrConfig.url, + repeaterProtocolFactory.getRepeaterProtocolHandler(rptrConfig.hwType, gatewayConfig, rptrConfig.address, rptrConfig.port), + rptrConfig.band1, + rptrConfig.band2, + rptrConfig.band3); + } // for (unsigned int i=0; icallsign, 0, 7, m_gateway.callsign, true)) { @@ -71,6 +89,84 @@ bool CDStarGatewayConfig::loadRepeaters(Config & cfg) // ??? } + std::string hwType; + if(get_value(cfg, key.str() + ".type", hwType, 1, 5, "", false, {"hb", "icom"} )) { + if(hwType == "hb") repeater->hwType = HW_HOMEBREW; + else if(hwType == "icom") repeater->hwType = HW_ICOM; + } + + if (get_value(cfg, key.str() + ".reflector", repeater->reflector, 0, LONG_CALLSIGN_LENGTH, "", true)) { + // ??? + } + + if (get_value(cfg, key.str() + ".reflectorAtStartup", repeater->reflectorAtStartup, true)) { + // ??? + } + + std::string reconnect; + if (get_value(cfg, key.str() + ".reflectorReconnect", reconnect, 1, 5, "never", true, + {"never", "fixed", "5", "10", "15", "20", "25", "30", "60", "90", "120", "180"})) { + if(reconnect == "never") repeater->reflectorReconnect = RECONNECT_NEVER; + else if(reconnect == "5") repeater->reflectorReconnect = RECONNECT_5MINS; + else if(reconnect == "10") repeater->reflectorReconnect = RECONNECT_10MINS; + else if(reconnect == "15") repeater->reflectorReconnect = RECONNECT_15MINS; + else if(reconnect == "20") repeater->reflectorReconnect = RECONNECT_20MINS; + else if(reconnect == "25") repeater->reflectorReconnect = RECONNECT_25MINS; + else if(reconnect == "30") repeater->reflectorReconnect = RECONNECT_30MINS; + else if(reconnect == "60") repeater->reflectorReconnect = RECONNECT_60MINS; + else if(reconnect == "90") repeater->reflectorReconnect = RECONNECT_90MINS; + else if(reconnect == "120") repeater->reflectorReconnect = RECONNECT_120MINS; + else if(reconnect == "180") repeater->reflectorReconnect = RECONNECT_180MINS; + else if(reconnect == "fixed") repeater->reflectorReconnect = RECONNECT_FIXED; + } + + if(get_value(cfg, key.str() + ".frequency", repeater->frequency, 0.0, 1500.0, 434.0)) { + // ??? + } + + if(get_value(cfg, key.str() + ".offset", repeater->offset, 0.0, 50.0, 0.0)) { + // ??? + } + + if(get_value(cfg, key.str() + ".rangeKm", repeater->range, 0.0, 3000.0, 0.0)) { + // ??? + } + + if(get_value(cfg, key.str() + ".latitude", repeater->latitude, -90, 90.0, m_gateway.latitude)) { + // ??? + } + + if(get_value(cfg, key.str() + ".longitude", repeater->longitude, -180, 180.0, m_gateway.longitude)) { + // ??? + } + + if(get_value(cfg, key.str() + ".agl", repeater->agl, 0, 1000.0, 0.0)) { + // ??? + } + + if(get_value(cfg, key.str() + ".description1", m_gateway.description1, 0, 1024, "")) { + // ??? + } + + if(get_value(cfg, key.str() + ".description2", m_gateway.description2, 0, 1024, "")) { + // ??? + } + + if(get_value(cfg, key.str() + ".url", m_gateway.url, 0, 1024, "")) { + // ??? + } + + int band; + if(get_value(cfg, key.str() + ".band1", band, 0, 255, 0)) { + repeater->band1 = (unsigned char)band; + } + if(get_value(cfg, key.str() + ".band2", band, 0, 255, 0)) { + repeater->band2 = (unsigned char)band; + } + if(get_value(cfg, key.str() + ".band3", band, 0, 255, 0)) { + repeater->band3 = (unsigned char)band; + } + // We have read a complete repeater record, validate it if(repeater->callsign.length() > 0) { isOk = true; @@ -99,7 +195,7 @@ bool CDStarGatewayConfig::loadRepeaters(Config & cfg) return m_repeaters.size() > 0; } -bool CDStarGatewayConfig::loadIrcDDB(Config & cfg) +bool CDStarGatewayConfig::loadIrcDDB(const Config & cfg) { //ircDDB Networks for(int i = 0; i < cfg.lookup("ircddb").getLength(); i++) { @@ -144,7 +240,7 @@ bool CDStarGatewayConfig::loadIrcDDB(Config & cfg) return true; } -bool CDStarGatewayConfig::loadGateway(Config & cfg) +bool CDStarGatewayConfig::loadGateway(const Config & cfg) { if (! get_value(cfg, "gateway.callsign", m_gateway.callsign, 3, 8, "") || 0 == m_gateway.callsign.size()) @@ -154,8 +250,21 @@ bool CDStarGatewayConfig::loadGateway(Config & cfg) } CUtils::ToUpper(m_gateway.callsign); get_value(cfg, "gateway.address", m_gateway.address, 0, 20, "0.0.0.0", true); - get_value(cfg, "gateway.port", m_gateway.port, 1U, 65535U, 20010U); - std::cout << "GATEWAY: callsign='" << m_gateway.callsign << "' listen address='" << m_gateway.address << ":" << m_gateway.port << std::endl; + get_value(cfg, "gateway.hbaddress", m_gateway.hbAddress, 0, 20, "127.0.0.1", true); + get_value(cfg, "gateway.hbport", m_gateway.hbPort, 1U, 65535U, 20010U); + get_value(cfg, "gateway.icomAddress", m_gateway.icomAddress, 0, 20, "127.0.0.1", true); + get_value(cfg, "gateway.icomPort", m_gateway.icomPort, 1U, 65535U, 20000U); + get_value(cfg, "gateway.latitude", m_gateway.latitude, -90.0, 90.0, 0.0); + get_value(cfg, "gateway.longitude", m_gateway.longitude, -180.0, 180.0, 0.0); + get_value(cfg, "gateway.description1", m_gateway.description1, 0, 1024, ""); + get_value(cfg, "gateway.description2", m_gateway.description2, 0, 1024, ""); + get_value(cfg, "gateway.url", m_gateway.url, 0, 1024, ""); + + std::cout << "GATEWAY: callsign='" << m_gateway.callsign << "' listen address='" << m_gateway.address << std::endl; + + CUtils::clean(m_gateway.description1, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 .,&*()-+=@/?:;"); + CUtils::clean(m_gateway.description2, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 .,&*()-+=@/?:;"); + CUtils::clean(m_gateway.url, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 .,&*()-+=@/?:;"); //properly size values m_gateway.callsign.resize(LONG_CALLSIGN_LENGTH - 1U, ' '); @@ -199,16 +308,6 @@ CDStarGatewayConfig::~CDStarGatewayConfig() } } -unsigned int CDStarGatewayConfig::getRepeaterCount() -{ - return m_repeaters.size(); -} - -unsigned int CDStarGatewayConfig::getIrcDDBCount() -{ - return m_ircDDB.size(); -} - bool CDStarGatewayConfig::get_value(const Config &cfg, const std::string &path, unsigned int &value, unsigned int min, unsigned int max, unsigned int default_value) { value = default_value; @@ -231,6 +330,16 @@ bool CDStarGatewayConfig::get_value(const Config &cfg, const std::string &path, return true; } +bool CDStarGatewayConfig::get_value(const Config &cfg, const std::string &path, double &value, double min, double max, double default_value) +{ + if (cfg.lookupValue(path, value)) { + if (value < min || value > max) + value = default_value; + } else + value = default_value; + return true; +} + bool CDStarGatewayConfig::get_value(const Config &cfg, const std::string &path, bool &value, bool default_value) { if (! cfg.lookupValue(path, value)) @@ -261,26 +370,58 @@ bool CDStarGatewayConfig::get_value(const Config &cfg, const std::string &path, return true; } +bool CDStarGatewayConfig::get_value(const Config &cfg, const std::string &path, std::string &value, int min, int max, const std::string &default_value, bool emptyToDefault, const std::vector& allowedValues) +{ + bool ret = get_value(cfg, path, value, min, max, default_value, emptyToDefault); + + if(ret) { + for(std::string s : allowedValues) { + if(s == value) { + ret = true; + break; + } + } + } + + if(!ret) { + std::stringstream message; + message << path << "=" << value << " has an invalid value. Valid values are : "; + for(std::string s : allowedValues) { + message << s << ", "; + } + message << std::endl; + std::cout << message.str(); + } + + return ret; +} + void CDStarGatewayConfig::getGateway(TGateway & gateway) const { - gateway.callsign = m_gateway.callsign; - gateway.address = m_gateway.address; - gateway.port = m_gateway.port; + gateway = m_gateway; } void CDStarGatewayConfig::getIrcDDB(unsigned int ircddb, TircDDB & ircDDB) const { - ircDDB.hostname = m_ircDDB[ircddb]->hostname; - ircDDB.username = m_ircDDB[ircddb]->username; - ircDDB.password = m_ircDDB[ircddb]->password; - ircDDB.isQuadNet = m_ircDDB[ircddb]->isQuadNet; + ircDDB = *(m_ircDDB[ircddb]); +} + +unsigned int CDStarGatewayConfig::getRepeaterCount() const +{ + return m_repeaters.size(); +} + +unsigned int CDStarGatewayConfig::getIrcDDBCount() const +{ + return m_ircDDB.size(); } void CDStarGatewayConfig::getRepeater(unsigned int index, TRepeater & repeater) const { - repeater.address = m_repeaters[index]->address; - repeater.band = m_repeaters[index]->band; - repeater.callsign = m_repeaters[index]->callsign; - repeater.port = m_repeaters[index]->port; - repeater.reflector = m_repeaters[index]->reflector; + repeater = *(m_repeaters[index]); +} + +void CDStarGatewayConfig::getPaths(Tpaths & paths) const +{ + paths = m_paths; } diff --git a/DStarGatewayConfig.h b/DStarGatewayConfig.h index 2a3de4f..4b83cb2 100644 --- a/DStarGatewayConfig.h +++ b/DStarGatewayConfig.h @@ -33,22 +33,27 @@ public: void getGateway(TGateway & gateway) const; void getIrcDDB(unsigned int ircddbIndex, TircDDB & ircddb) const; void getRepeater(unsigned int repeaterIndex, TRepeater & repeater) const; - unsigned int getRepeaterCount(); - unsigned int getIrcDDBCount(); + void getPaths(Tpaths & paths) const; + unsigned int getRepeaterCount() const; + unsigned int getIrcDDBCount() const; private: bool open(Config & cfg); - bool loadGateway(Config & cfg); - bool loadIrcDDB(Config & cfg); - bool loadRepeaters(Config & cfg); + bool loadGateway(const Config & cfg); + bool loadIrcDDB(const Config & cfg); + bool loadRepeaters(const Config & cfg); + bool loadPaths(const Config & cfg); bool get_value(const Config &cfg, const std::string &path, unsigned int &value, unsigned int min, unsigned int max, unsigned int default_value); bool get_value(const Config &cfg, const std::string &path, int &value, int min, int max, int default_value); + bool get_value(const Config &cfg, const std::string &path, double &value, double min, double max, double default_value); bool get_value(const Config &cfg, const std::string &path, bool &value, bool default_value); bool get_value(const Config &cfg, const std::string &path, std::string &value, int min, int max, const std::string &default_value); bool get_value(const Config &cfg, const std::string &path, std::string &value, int min, int max, const std::string &default_value, bool emptyToDefault); + bool get_value(const Config &cfg, const std::string &path, std::string &value, int min, int max, const std::string &default_value, bool emptyToDefault, const std::vector& allowedValues); std::string m_fileName; TGateway m_gateway; + Tpaths m_paths; std::vector m_repeaters; std::vector m_ircDDB; }; diff --git a/DStarGatewayThread.cpp b/DStarGatewayThread.cpp index d650b1d..8f74680 100644 --- a/DStarGatewayThread.cpp +++ b/DStarGatewayThread.cpp @@ -59,9 +59,10 @@ const std::string LOOPBACK_ADDRESS("127.0.0.1"); const unsigned int REMOTE_DUMMY_PORT = 65016U; -CDStarGatewayThread::CDStarGatewayThread(const std::string& logDir, const std::string& name) : +CDStarGatewayThread::CDStarGatewayThread(const std::string& logDir, const std::string& dataDir, const std::string& name) : CThread(), m_logDir(logDir), +m_dataDir(dataDir), m_name(name), m_killed(false), m_stopped(true), @@ -508,11 +509,13 @@ 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) { -#ifdef USE_DRATS 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 @@ -616,7 +619,7 @@ void CDStarGatewayThread::setCCS(bool enabled, const std::string& host) #if defined(__WINDOWS__) fileName.Assign(::wxGetCwd(), CCS_HOSTS_FILE_NAME); #else - fileName.Assign(wxT(DATA_DIR), CCS_HOSTS_FILE_NAME); + fileName.Assign(wxT(m_dataDir), CCS_HOSTS_FILE_NAME); #endif if (!fileName.IsFileReadable()) { wxLogMessage(wxT("File %s not readable"), fileName.GetFullPath().c_str()); @@ -1101,7 +1104,7 @@ void CDStarGatewayThread::processDD() void CDStarGatewayThread::loadGateways() { - std::string fileName = std::string(DATA_DIR) + "/" + GATEWAY_HOSTS_FILE_NAME; + std::string fileName = m_dataDir + "/" + GATEWAY_HOSTS_FILE_NAME; loadReflectors(fileName, DP_DEXTRA); } @@ -1112,17 +1115,17 @@ void CDStarGatewayThread::loadAllReflectors() } if (m_dplusEnabled) { - std::string fileName = std::string(DATA_DIR) + "/" + DPLUS_HOSTS_FILE_NAME; + std::string fileName = m_dataDir + "/" + DPLUS_HOSTS_FILE_NAME; loadReflectors(fileName, DP_DPLUS); } if (m_dextraEnabled) { - std::string fileName = std::string(DATA_DIR) + "/" + DCS_HOSTS_FILE_NAME; + std::string fileName = m_dataDir + "/" + DCS_HOSTS_FILE_NAME; loadReflectors(fileName, DP_DEXTRA); } if (m_dcsEnabled) { - std::string fileName = std::string(DATA_DIR) + "/" + DCS_HOSTS_FILE_NAME; + std::string fileName = m_dataDir + "/" + DCS_HOSTS_FILE_NAME; loadReflectors(fileName, DP_DCS); } } diff --git a/DStarGatewayThread.h b/DStarGatewayThread.h index 254f8b9..6b5d912 100644 --- a/DStarGatewayThread.h +++ b/DStarGatewayThread.h @@ -43,11 +43,15 @@ class CDStarGatewayThread : public CThread{ public: - CDStarGatewayThread(const std::string& logDir, const std::string& name); + CDStarGatewayThread(const std::string& logDir, const std::string& dataDir, const std::string& name); virtual ~CDStarGatewayThread(); virtual void setGateway(GATEWAY_TYPE type, const std::string& callsign, const std::string& address); - 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_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 #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); @@ -82,13 +86,13 @@ public: virtual CIRCDDBGatewayStatusData* getStatus() const; virtual void kill(); - - - void* Entry(); + protected: + void* Entry(); private: std::string m_logDir; + std::string m_dataDir; std::string m_name; bool m_killed; bool m_stopped; diff --git a/Defs.h b/Defs.h index 5c6be96..d298712 100644 --- a/Defs.h +++ b/Defs.h @@ -142,7 +142,15 @@ const unsigned int TIME_PER_TIC_MS = 5U; typedef struct { std::string callsign; std::string address; - unsigned int port; + std::string hbAddress; + unsigned int hbPort; + std::string icomAddress; + unsigned int icomPort; + double latitude; + double longitude; + std::string description1; + std::string description2; + std::string url; } TGateway; typedef struct { @@ -151,6 +159,24 @@ typedef struct { std::string reflector; std::string address; unsigned int port; + HW_TYPE hwType; + bool reflectorAtStartup; + RECONNECT reflectorReconnect; +#ifdef USE_DRATS + bool dRatsEnabled; +#endif + double frequency; + double offset; + double range; + double latitude; + double longitude; + double agl; + std::string description1; + std::string description2; + std::string url; + char band1; + char band2; + char band3; } TRepeater; typedef struct { @@ -158,4 +184,9 @@ typedef struct { std::string username; std::string password; bool isQuadNet; -} TircDDB; \ No newline at end of file +} TircDDB; + +typedef struct { + std::string logDir; + std::string dataDir; +} Tpaths; \ No newline at end of file diff --git a/Makefile b/Makefile index dd45cd1..0ebedef 100644 --- a/Makefile +++ b/Makefile @@ -3,10 +3,9 @@ # if you change these locations, make sure the dstargateway.service file is updated! BIN_DIR=/usr/local/bin CFG_DIR=/usr/local/etc/dstargateway.d/ -DATA_DIR=/usr/local/share/dstargateway.d/ # choose this if you want debugging help -CPPFLAGS=-g -ggdb -W -Wall -std=c++14 -DCFG_DIR=\"$(CFG_DIR)\" -DDATA_DIR=\"$(DATA_DIR)\" +CPPFLAGS=-g -ggdb -W -Wall -std=c++14 -DCFG_DIR=\"$(CFG_DIR)\" # or, you can choose this for a much smaller executable without debugging help #CPPFLAGS=-W -Wall -std=c++14 -DCFG_DIR=\"$(CFGDIR)\" -DDATA_DIR=\"$(DATA_DIR)" diff --git a/RepeaterProtocolHandlerFactory.cpp b/RepeaterProtocolHandlerFactory.cpp new file mode 100644 index 0000000..7e8a86f --- /dev/null +++ b/RepeaterProtocolHandlerFactory.cpp @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2021 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 "RepeaterProtocolHandlerFactory.h" +#include "Log.h" + +CRepeaterHandlerFactory::CRepeaterHandlerFactory() : +m_icomRepeaterHandler(NULL), +m_hbRepeaterHandler(NULL), +m_dummyRepeaterHandler(NULL) +{ + +} + +IRepeaterProtocolHandler * CRepeaterHandlerFactory::getRepeaterProtocolHandler(HW_TYPE hwType, const TGateway & gatewayConfig, const std::string & repeaterAddress, unsigned int repeaterPort) +{ + IRepeaterProtocolHandler * handler = NULL; + switch (hwType) + { + case HW_ICOM: + if(m_icomRepeaterHandler == NULL) { + auto icomRepeaterHandler = new CIcomRepeaterProtocolHandler(gatewayConfig.icomAddress, gatewayConfig.icomPort, repeaterAddress, repeaterPort); + bool res = icomRepeaterHandler->open(); + if (!res) { + wxLogError("Cannot open the Icom repeater protocol handler"); + delete icomRepeaterHandler; + icomRepeaterHandler = NULL; + } + m_icomRepeaterHandler = icomRepeaterHandler; + } + handler = m_icomRepeaterHandler; + break; + case HW_HOMEBREW: + if(m_hbRepeaterHandler == NULL) { + auto hbRepeaterHandler = new CHBRepeaterProtocolHandler(gatewayConfig.hbAddress, gatewayConfig.hbPort); + bool res = hbRepeaterHandler->open(); + if (!res) { + wxLogError("Cannot open the Homebrew repeater protocol handler"); + delete hbRepeaterHandler; + hbRepeaterHandler = NULL; + } + m_hbRepeaterHandler = hbRepeaterHandler; + } + handler = m_hbRepeaterHandler; + break; + case HW_DUMMY: + if(m_dummyRepeaterHandler == NULL) { + auto dummyRepeaterHandler = new CDummyRepeaterProtocolHandler; + bool res = dummyRepeaterHandler->open(); + if (!res) { + wxLogError("Cannot open the Dummy repeater protocol handler"); + delete dummyRepeaterHandler; + dummyRepeaterHandler = NULL; + } + m_dummyRepeaterHandler = dummyRepeaterHandler; + handler = m_dummyRepeaterHandler; + } + break; + default: + break; + } + + return handler; +} \ No newline at end of file diff --git a/RepeaterProtocolHandlerFactory.h b/RepeaterProtocolHandlerFactory.h new file mode 100644 index 0000000..7cb9921 --- /dev/null +++ b/RepeaterProtocolHandlerFactory.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2021 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 + +#include "IcomRepeaterProtocolHandler.h" +#include "HBRepeaterProtocolHandler.h" +#include "DummyRepeaterProtocolHandler.h" +#include "RepeaterProtocolHandler.h" +#include "Defs.h" + +class CRepeaterHandlerFactory +{ +public: + CRepeaterHandlerFactory(); + + IRepeaterProtocolHandler * getRepeaterProtocolHandler(HW_TYPE hwType, const TGateway & gatewyaConfig, const std::string & repeaterAddress, unsigned int repeaterPort); + +private: + CIcomRepeaterProtocolHandler* m_icomRepeaterHandler; + CHBRepeaterProtocolHandler* m_hbRepeaterHandler; + CDummyRepeaterProtocolHandler* m_dummyRepeaterHandler; +}; \ No newline at end of file diff --git a/example.cfg b/example.cfg index 794928d..6a5240a 100644 --- a/example.cfg +++ b/example.cfg @@ -1,8 +1,16 @@ gateway = { callsign = "N0CALL" - #address = "" # this is the computer interface for the outgoing connection. Usually leave it blank and it will use whatever is avaiable. - port=20010 + address = "" # this is the computer interface for the outgoing connection. Usually leave it blank and it will use whatever is avaiable. + icomAddress=172.16.0.20 + icomPort=20000 + hbAddress=127.0.0.1 #address to use for connectin with homebrew repeaters (MMDVMHost, DStarRepeater) + hbPort=20010 + latitude= + longitude= + description1= + description2= + url= } # NOTHING usually needs to be specified in the ircddb section @@ -33,6 +41,22 @@ repeaters = ( # The modules list is contained in parentheses callsign = "" # Has to be less than 8 characters, if empty gateway call will be used address = "" # address where the repeater can be found, if left empty defaults to 127.0.0.1 port=20011 + type="hb" # hb or icom + reflector= + reflectorAtStartup=true + reflectorReconnect= # never, fixed, 5, 10, 15, 20, 25, 30, 60, 90, 120, 180 + frequency=434.00000 + offset=9.00000 + rangeKm=0.1 + latitude= + longitude= + agl= + description1= + description2= + url= + band1= + band2= + band3= # }, # be sure there is a comma between repeaters # { # Up to 15 different modules can be specified, each in curly brackets # band = "C" # Each module has to have a band letter @@ -41,3 +65,10 @@ repeaters = ( # The modules list is contained in parentheses # } } ) # close paren to close out the module defines + +paths = ( + { + log=/var/log/dstargateway/ + data=/usr/local/share/dstargateway/ #Path where the data (hostfiles, audio files etc) can be found + } +) \ No newline at end of file