Contineu implementation of config and main thread

master
Geoffrey Merck 4 years ago
parent 7f3b742c01
commit 35beaf8feb

@ -1,6 +1,6 @@
/* /*
* Copyright (C) 2010,2011 by Jonathan Naylor G4KLX * 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 * 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 * it under the terms of the GNU General Public License as published by
@ -22,6 +22,7 @@
#include <fcntl.h> #include <fcntl.h>
#include <string> #include <string>
#include <iostream> #include <iostream>
#include <vector>
#include "DStarGatewayDefs.h" #include "DStarGatewayDefs.h"
#include "DStarGatewayConfig.h" #include "DStarGatewayConfig.h"
@ -31,6 +32,7 @@
#include "IRCDDBClient.h" #include "IRCDDBClient.h"
#include "Utils.h" #include "Utils.h"
#include "GitVersion.h" #include "GitVersion.h"
#include "RepeaterProtocolHandlerFactory.h"
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
@ -92,34 +94,63 @@ bool CDStarGatewayApp::createThread()
printf("FATAL: Invalid configuration"); printf("FATAL: Invalid configuration");
return false; return false;
} }
// m_thread = new CDStarGatewayThread(config.getLinkCount("XRF"), config.getLinkCount("DCS"));
// std::string CallSign, address; Tpaths paths;
// config.getGateway(CallSign, address); config.getPaths(paths);
m_thread = new CDStarGatewayThread(paths.logDir, paths.dataDir, "");
// CallSign.resize(7, ' '); TGateway gatewayConfig;
// CallSign.push_back('G'); config.getGateway(gatewayConfig);
// printf("Gateway callsign set to %s, local address set to %s\n", CallSign.c_str(), address.c_str()); // printf("Gateway callsign set to %s, local address set to %s\n", CallSign.c_str(), address.c_str());
// CIRCDDB_Array clients; std::vector<CIRCDDB *> clients;
// for(unsigned int i=0; i < config.getIrcDDBCount(); i++) { for(unsigned int i=0; i < config.getIrcDDBCount(); i++) {
// std::string hostname, username, password; TircDDB ircDDBConfig;
// bool isQuadNet; config.getIrcDDB(i, ircDDBConfig);
// config.getIrcDDB(i, hostname, username, password, isQuadNet); std::cout << "ircDDB " << i + 1 << " set to " << ircDDBConfig.hostname << " username set to " << ircDDBConfig.username << " QuadNet " << ircDDBConfig.isQuadNet << std::endl;
// 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);
// }
// CIRCDDBMultiClient* multiClient = new CIRCDDBMultiClient(clients); CIRCDDB * ircDDB = new CIRCDDBClient(ircDDBConfig.hostname, 9007U, ircDDBConfig.username, ircDDBConfig.password, std::string("DStarGateway") + std::string("-") + VERSION, gatewayConfig.address, ircDDBConfig.isQuadNet);
// bool res = multiClient->open(); clients.push_back(ircDDB);
// if (!res) { }
// printf("Cannot initialise the ircDDB protocol handler\n");
// return false;
// }
// m_thread->setIRC(multiClient); 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);
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; i<config.getModCount(); i++) { // for (unsigned int i=0; i<config.getModCount(); i++) {
// std::string band, callsign, logoff, info, permanent, reflector; // std::string band, callsign, logoff, info, permanent, reflector;

@ -45,14 +45,32 @@ bool CDStarGatewayConfig::load()
return false; return false;
} }
bool CDStarGatewayConfig::loadRepeaters(Config & cfg) bool CDStarGatewayConfig::loadPaths(const Config & cfg)
{
get_value(cfg, "paths.log", m_paths.logDir, 0, 2048, "/var/log/dstargateway/", true);
get_value(cfg, "paths.data", m_paths.dataDir, 0, 2048, "/var/log/dstargateway/", true);
if(m_paths.logDir[m_paths.logDir.length() - 1] != '/') {
m_paths.logDir.push_back('/');
}
if(m_paths.dataDir[m_paths.dataDir.length() - 1] != '/') {
m_paths.dataDir.push_back('/');
}
//TODO 20211226 check if directory are accessible
return true;
}
bool CDStarGatewayConfig::loadRepeaters(const Config & cfg)
{ {
cfg.lookup("repeaters"); cfg.lookup("repeaters");
// repeater parameters // repeater parameters
for (int i=0; i<cfg.lookup("repeaters").getLength(); i++) { for (int i=0; i<cfg.lookup("repeaters").getLength(); i++) {
std::stringstream key; std::stringstream key;
bool isOk = false; bool isOk = false;
TRepeater * repeater = new TRepeater({"", m_gateway.callsign, "", "127.0.0.1", 20011U}); TRepeater * repeater = new TRepeater;
key << "repeaters.[" << i << "]"; key << "repeaters.[" << i << "]";
if (get_value(cfg, key.str() + ".callsign", repeater->callsign, 0, 7, m_gateway.callsign, true)) { if (get_value(cfg, key.str() + ".callsign", repeater->callsign, 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 // We have read a complete repeater record, validate it
if(repeater->callsign.length() > 0) { if(repeater->callsign.length() > 0) {
isOk = true; isOk = true;
@ -99,7 +195,7 @@ bool CDStarGatewayConfig::loadRepeaters(Config & cfg)
return m_repeaters.size() > 0; return m_repeaters.size() > 0;
} }
bool CDStarGatewayConfig::loadIrcDDB(Config & cfg) bool CDStarGatewayConfig::loadIrcDDB(const Config & cfg)
{ {
//ircDDB Networks //ircDDB Networks
for(int i = 0; i < cfg.lookup("ircddb").getLength(); i++) { for(int i = 0; i < cfg.lookup("ircddb").getLength(); i++) {
@ -144,7 +240,7 @@ bool CDStarGatewayConfig::loadIrcDDB(Config & cfg)
return true; return true;
} }
bool CDStarGatewayConfig::loadGateway(Config & cfg) bool CDStarGatewayConfig::loadGateway(const Config & cfg)
{ {
if (! get_value(cfg, "gateway.callsign", m_gateway.callsign, 3, 8, "") if (! get_value(cfg, "gateway.callsign", m_gateway.callsign, 3, 8, "")
|| 0 == m_gateway.callsign.size()) || 0 == m_gateway.callsign.size())
@ -154,8 +250,21 @@ bool CDStarGatewayConfig::loadGateway(Config & cfg)
} }
CUtils::ToUpper(m_gateway.callsign); CUtils::ToUpper(m_gateway.callsign);
get_value(cfg, "gateway.address", m_gateway.address, 0, 20, "0.0.0.0", true); 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); get_value(cfg, "gateway.hbaddress", m_gateway.hbAddress, 0, 20, "127.0.0.1", true);
std::cout << "GATEWAY: callsign='" << m_gateway.callsign << "' listen address='" << m_gateway.address << ":" << m_gateway.port << std::endl; 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 //properly size values
m_gateway.callsign.resize(LONG_CALLSIGN_LENGTH - 1U, ' '); 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) 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; value = default_value;
@ -231,6 +330,16 @@ bool CDStarGatewayConfig::get_value(const Config &cfg, const std::string &path,
return true; 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) bool CDStarGatewayConfig::get_value(const Config &cfg, const std::string &path, bool &value, bool default_value)
{ {
if (! cfg.lookupValue(path, value)) if (! cfg.lookupValue(path, value))
@ -261,26 +370,58 @@ bool CDStarGatewayConfig::get_value(const Config &cfg, const std::string &path,
return true; 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<std::string>& 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 void CDStarGatewayConfig::getGateway(TGateway & gateway) const
{ {
gateway.callsign = m_gateway.callsign; gateway = m_gateway;
gateway.address = m_gateway.address;
gateway.port = m_gateway.port;
} }
void CDStarGatewayConfig::getIrcDDB(unsigned int ircddb, TircDDB & ircDDB) const void CDStarGatewayConfig::getIrcDDB(unsigned int ircddb, TircDDB & ircDDB) const
{ {
ircDDB.hostname = m_ircDDB[ircddb]->hostname; ircDDB = *(m_ircDDB[ircddb]);
ircDDB.username = m_ircDDB[ircddb]->username; }
ircDDB.password = m_ircDDB[ircddb]->password;
ircDDB.isQuadNet = m_ircDDB[ircddb]->isQuadNet; 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 void CDStarGatewayConfig::getRepeater(unsigned int index, TRepeater & repeater) const
{ {
repeater.address = m_repeaters[index]->address; repeater = *(m_repeaters[index]);
repeater.band = m_repeaters[index]->band; }
repeater.callsign = m_repeaters[index]->callsign;
repeater.port = m_repeaters[index]->port; void CDStarGatewayConfig::getPaths(Tpaths & paths) const
repeater.reflector = m_repeaters[index]->reflector; {
paths = m_paths;
} }

@ -33,22 +33,27 @@ public:
void getGateway(TGateway & gateway) const; void getGateway(TGateway & gateway) const;
void getIrcDDB(unsigned int ircddbIndex, TircDDB & ircddb) const; void getIrcDDB(unsigned int ircddbIndex, TircDDB & ircddb) const;
void getRepeater(unsigned int repeaterIndex, TRepeater & repeater) const; void getRepeater(unsigned int repeaterIndex, TRepeater & repeater) const;
unsigned int getRepeaterCount(); void getPaths(Tpaths & paths) const;
unsigned int getIrcDDBCount(); unsigned int getRepeaterCount() const;
unsigned int getIrcDDBCount() const;
private: private:
bool open(Config & cfg); bool open(Config & cfg);
bool loadGateway(Config & cfg); bool loadGateway(const Config & cfg);
bool loadIrcDDB(Config & cfg); bool loadIrcDDB(const Config & cfg);
bool loadRepeaters(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, 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, 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, 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 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);
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<std::string>& allowedValues);
std::string m_fileName; std::string m_fileName;
TGateway m_gateway; TGateway m_gateway;
Tpaths m_paths;
std::vector<TRepeater *> m_repeaters; std::vector<TRepeater *> m_repeaters;
std::vector<TircDDB *> m_ircDDB; std::vector<TircDDB *> m_ircDDB;
}; };

@ -59,9 +59,10 @@ const std::string LOOPBACK_ADDRESS("127.0.0.1");
const unsigned int REMOTE_DUMMY_PORT = 65016U; 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(), CThread(),
m_logDir(logDir), m_logDir(logDir),
m_dataDir(dataDir),
m_name(name), m_name(name),
m_killed(false), m_killed(false),
m_stopped(true), m_stopped(true),
@ -508,11 +509,13 @@ void CDStarGatewayThread::setGateway(GATEWAY_TYPE gatewayType, const std::string
m_gatewayAddress = gatewayAddress; 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) 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); 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 #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); CRepeaterHandler::add(callsign, band, address, port, hwType, reflector, atStartup, reconnect, frequency, offset, range, latitude, longitude, agl, description1, description2, url, handler, band1, band2, band3);
#endif #endif
@ -616,7 +619,7 @@ void CDStarGatewayThread::setCCS(bool enabled, const std::string& host)
#if defined(__WINDOWS__) #if defined(__WINDOWS__)
fileName.Assign(::wxGetCwd(), CCS_HOSTS_FILE_NAME); fileName.Assign(::wxGetCwd(), CCS_HOSTS_FILE_NAME);
#else #else
fileName.Assign(wxT(DATA_DIR), CCS_HOSTS_FILE_NAME); fileName.Assign(wxT(m_dataDir), CCS_HOSTS_FILE_NAME);
#endif #endif
if (!fileName.IsFileReadable()) { if (!fileName.IsFileReadable()) {
wxLogMessage(wxT("File %s not readable"), fileName.GetFullPath().c_str()); wxLogMessage(wxT("File %s not readable"), fileName.GetFullPath().c_str());
@ -1101,7 +1104,7 @@ void CDStarGatewayThread::processDD()
void CDStarGatewayThread::loadGateways() 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); loadReflectors(fileName, DP_DEXTRA);
} }
@ -1112,17 +1115,17 @@ void CDStarGatewayThread::loadAllReflectors()
} }
if (m_dplusEnabled) { 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); loadReflectors(fileName, DP_DPLUS);
} }
if (m_dextraEnabled) { 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); loadReflectors(fileName, DP_DEXTRA);
} }
if (m_dcsEnabled) { 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); loadReflectors(fileName, DP_DCS);
} }
} }

@ -43,11 +43,15 @@
class CDStarGatewayThread : public CThread{ class CDStarGatewayThread : public CThread{
public: 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 ~CDStarGatewayThread();
virtual void setGateway(GATEWAY_TYPE type, const std::string& callsign, const std::string& address); 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 #ifdef USE_STARNET
#if defined(DEXTRA_LINK) || defined(DCS_LINK) #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); 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);
@ -83,12 +87,12 @@ public:
virtual void kill(); virtual void kill();
void* Entry();
protected: protected:
void* Entry();
private: private:
std::string m_logDir; std::string m_logDir;
std::string m_dataDir;
std::string m_name; std::string m_name;
bool m_killed; bool m_killed;
bool m_stopped; bool m_stopped;

@ -142,7 +142,15 @@ const unsigned int TIME_PER_TIC_MS = 5U;
typedef struct { typedef struct {
std::string callsign; std::string callsign;
std::string address; 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; } TGateway;
typedef struct { typedef struct {
@ -151,6 +159,24 @@ typedef struct {
std::string reflector; std::string reflector;
std::string address; std::string address;
unsigned int port; 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; } TRepeater;
typedef struct { typedef struct {
@ -159,3 +185,8 @@ typedef struct {
std::string password; std::string password;
bool isQuadNet; bool isQuadNet;
} TircDDB; } TircDDB;
typedef struct {
std::string logDir;
std::string dataDir;
} Tpaths;

@ -3,10 +3,9 @@
# if you change these locations, make sure the dstargateway.service file is updated! # if you change these locations, make sure the dstargateway.service file is updated!
BIN_DIR=/usr/local/bin BIN_DIR=/usr/local/bin
CFG_DIR=/usr/local/etc/dstargateway.d/ CFG_DIR=/usr/local/etc/dstargateway.d/
DATA_DIR=/usr/local/share/dstargateway.d/
# choose this if you want debugging help # 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 # 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)" #CPPFLAGS=-W -Wall -std=c++14 -DCFG_DIR=\"$(CFGDIR)\" -DDATA_DIR=\"$(DATA_DIR)"

@ -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;
}

@ -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 <string>
#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;
};

@ -1,8 +1,16 @@
gateway = { gateway = {
callsign = "N0CALL" callsign = "N0CALL"
#address = "" # this is the computer interface for the outgoing connection. Usually leave it blank and it will use whatever is avaiable. address = "" # this is the computer interface for the outgoing connection. Usually leave it blank and it will use whatever is avaiable.
port=20010 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 # 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 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 address = "" # address where the repeater can be found, if left empty defaults to 127.0.0.1
port=20011 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 # }, # be sure there is a comma between repeaters
# { # Up to 15 different modules can be specified, each in curly brackets # { # Up to 15 different modules can be specified, each in curly brackets
# band = "C" # Each module has to have a band letter # 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 ) # 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
}
)
Loading…
Cancel
Save

Powered by TurnKey Linux.