master
Geoffrey Merck 4 years ago
parent 40c257dd2c
commit b339a8649c

@ -38,13 +38,30 @@ bool CDStarGatewayConfig::load()
if(open(cfg)
&& loadGateway(cfg)
&& loadIrcDDB(cfg)
&& loadRepeaters(cfg)) {
&& loadRepeaters(cfg)
&& loadPaths(cfg)
&& loadAPRS(cfg)) {
//properly size values
m_gateway.callsign.resize(LONG_CALLSIGN_LENGTH - 1U, ' ');
m_gateway.callsign.push_back('G');
return true;
}
return false;
}
bool CDStarGatewayConfig::loadAPRS(const Config & cfg)
{
bool ret = get_value(cfg, "aprs.enabled", m_aprs.enabled, false);
ret = get_value(cfg, "aprs.port", m_aprs.port, 1U, 65535U, 14580U) && ret;
ret = get_value(cfg, "aprs.hostname", m_aprs.hostname, 0, 1024, "rotate.aprs2.net", true) && ret;
ret = get_value(cfg, "aprs.password", m_aprs.password, 0U, 30U, "", true) && ret;
return ret;
}
bool CDStarGatewayConfig::loadPaths(const Config & cfg)
{
get_value(cfg, "paths.log", m_paths.logDir, 0, 2048, "/var/log/dstargateway/", true);
@ -104,7 +121,7 @@ bool CDStarGatewayConfig::loadRepeaters(const Config & cfg)
}
std::string reconnect;
if (get_value(cfg, key.str() + ".reflectorReconnect", reconnect, 1, 5, "never", true,
if (get_value(cfg, key.str() + ".reflectorReconnect", reconnect, 0, 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;
@ -242,34 +259,46 @@ bool CDStarGatewayConfig::loadIrcDDB(const Config & cfg)
bool CDStarGatewayConfig::loadGateway(const Config & cfg)
{
if (! get_value(cfg, "gateway.callsign", m_gateway.callsign, 3, 8, "")
|| 0 == m_gateway.callsign.size())
{
printf("CONFIG: No gateway callsign specified");
return false;
}
CUtils::ToUpper(m_gateway.callsign);
get_value(cfg, "gateway.address", m_gateway.address, 0, 20, "0.0.0.0", true);
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, "");
bool ret = get_value(cfg, "gateway.callsign", m_gateway.callsign, 3, 8, "");
get_value(cfg, "gateway.address", m_gateway.address, 0, 20, "0.0.0.0", true) && ret;
get_value(cfg, "gateway.hbaddress", m_gateway.hbAddress, 0, 20, "127.0.0.1", true) && ret;
get_value(cfg, "gateway.hbport", m_gateway.hbPort, 1U, 65535U, 20010U) && ret;
get_value(cfg, "gateway.icomAddress", m_gateway.icomAddress, 0, 20, "127.0.0.1", true) && ret;
get_value(cfg, "gateway.icomPort", m_gateway.icomPort, 1U, 65535U, 20000U) && ret;
get_value(cfg, "gateway.latitude", m_gateway.latitude, -90.0, 90.0, 0.0) && ret;
get_value(cfg, "gateway.longitude", m_gateway.longitude, -180.0, 180.0, 0.0) && ret;
get_value(cfg, "gateway.description1", m_gateway.description1, 0, 1024, "") && ret;
get_value(cfg, "gateway.description2", m_gateway.description2, 0, 1024, "") && ret;
get_value(cfg, "gateway.url", m_gateway.url, 0, 1024, "") && ret;
std::string type;
get_value(cfg, "gateway.type", type, 0, 8, "repeater", true, {"repeater", "hotspot"}) && ret;
if(type == "repeater") m_gateway.type = GT_REPEATER;
if(type == "hotspot") m_gateway.type = GT_HOTSPOT;
std::string lang;
get_value(cfg, "gateway.language", lang, 0, 30, "english_uk", true, {"english_uk", "deutsch", "dansk", "francais", "italiano", "polski", "english_us", "espanol", "svenska", "nederlands_nl", "nederlands_be", "norsk", "portugues"});
if(lang == "english_uk") m_gateway.language = TL_ENGLISH_UK;
else if(lang == "deutsch") m_gateway.language = TL_DEUTSCH;
else if(lang == "dansk") m_gateway.language = TL_DANSK;
else if(lang == "francais") m_gateway.language = TL_FRANCAIS;
else if(lang == "italiano") m_gateway.language = TL_ITALIANO;
else if(lang == "polski") m_gateway.language = TL_POLSKI;
else if(lang == "english_us") m_gateway.language = TL_ENGLISH_US;
else if(lang == "espanol") m_gateway.language = TL_ESPANOL;
else if(lang == "svenska") m_gateway.language = TL_SVENSKA;
else if(lang == "nederlands_nl") m_gateway.language = TL_NEDERLANDS_NL;
else if(lang == "nederlands_be") m_gateway.language = TL_NEDERLANDS_BE;
else if(lang == "norsk") m_gateway.language = TL_NORSK;
else if(lang == "portugues") m_gateway.language = TL_PORTUGUES;
std::cout << "GATEWAY: callsign='" << m_gateway.callsign << "' listen address='" << m_gateway.address << std::endl;
CUtils::ToUpper(m_gateway.callsign);
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, ' ');
m_gateway.callsign.push_back('G');
return true;
}
@ -425,3 +454,8 @@ void CDStarGatewayConfig::getPaths(Tpaths & paths) const
{
paths = m_paths;
}
void CDStarGatewayConfig::getAPRS(TAPRS & aprs) const
{
aprs = m_aprs;
}

@ -26,6 +26,7 @@
using namespace libconfig;
typedef struct {
GATEWAY_TYPE type;
std::string callsign;
std::string address;
std::string hbAddress;
@ -37,6 +38,7 @@ typedef struct {
std::string description1;
std::string description2;
std::string url;
TEXT_LANG language;
} TGateway;
typedef struct {
@ -77,6 +79,13 @@ typedef struct {
std::string dataDir;
} Tpaths;
typedef struct {
bool enabled;
std::string hostname;
unsigned int port;
std::string password;
} TAPRS;
class CDStarGatewayConfig {
public:
CDStarGatewayConfig(const std::string &pathname);
@ -85,10 +94,11 @@ public:
bool load();
void getGateway(TGateway & gateway) const;
void getIrcDDB(unsigned int ircddbIndex, TircDDB & ircddb) const;
unsigned int getIrcDDBCount() const;
void getRepeater(unsigned int repeaterIndex, TRepeater & repeater) const;
void getPaths(Tpaths & paths) const;
unsigned int getRepeaterCount() const;
unsigned int getIrcDDBCount() const;
void getPaths(Tpaths & paths) const;
void getAPRS(TAPRS & aprs) const;
private:
bool open(Config & cfg);
@ -96,6 +106,7 @@ private:
bool loadIrcDDB(const Config & cfg);
bool loadRepeaters(const Config & cfg);
bool loadPaths(const Config & cfg);
bool loadAPRS(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);
@ -107,6 +118,7 @@ private:
std::string m_fileName;
TGateway m_gateway;
Tpaths m_paths;
TAPRS m_aprs;
std::vector<TRepeater *> m_repeaters;
std::vector<TircDDB *> m_ircDDB;
};

Loading…
Cancel
Save

Powered by TurnKey Linux.