From f0526beb43567f4f793779ba2b8a2d3edaebf08b Mon Sep 17 00:00:00 2001 From: Tom Early Date: Wed, 30 Jan 2019 11:26:50 -0700 Subject: [PATCH] New feature: find routes --- QnetGateway.cpp | 47 ++++++++++++++++++++++++++++++++++++++++++++++- QnetGateway.h | 8 +++++++- defaults | 1 + qnconfig | 7 ++++++- 4 files changed, 60 insertions(+), 3 deletions(-) diff --git a/QnetGateway.cpp b/QnetGateway.cpp index 4e02321..cebc8dd 100644 --- a/QnetGateway.cpp +++ b/QnetGateway.cpp @@ -51,7 +51,6 @@ #include #include #include -#include #include "IRCDDB.h" #include "IRCutils.h" @@ -75,6 +74,37 @@ static void sigCatch(int signum) return; } + +void CQnetGateway::UnpackCallsigns(const std::string &str, std::set &set, const std::string &delimiters) +{ + std::string::size_type lastPos = str.find_first_not_of(delimiters, 0); // Skip delimiters at beginning. + std::string::size_type pos = str.find_first_of(delimiters, lastPos); // Find first non-delimiter. + + while (std::string::npos != pos || std::string::npos != lastPos) { + std::string element = str.substr(lastPos, pos-lastPos); + if (element.length()>=3 && element.length()<=6) { + ToUpper(element); + element.resize(CALL_SIZE, ' '); + set.insert(element); // Found a token, add it to the list. + } else + fprintf(stderr, "found bad callsign in list: %s\n", str.c_str()); + lastPos = str.find_first_not_of(delimiters, pos); // Skip delimiters. + pos = str.find_first_of(delimiters, lastPos); // Find next non-delimiter. + } +} + +void CQnetGateway::PrintCallsigns(const std::string &key, const std::set &set) +{ + printf("%s = [ ", key.c_str()); + for (auto it=set.begin(); it!=set.end(); it++) { + if (it != set.begin()) + printf(", "); + printf("%s", (*it).c_str()); + } + printf(" ]"); +} + + void CQnetGateway::set_dest_rptr(int mod_ndx, char *dest_rptr) { FILE *statusfp = fopen(status_file.c_str(), "r"); @@ -257,6 +287,13 @@ bool CQnetGateway::read_config(char *cfgFile) cfg.GetValue(path+"url", estr, rptr.mod[m].url, 0, 80); } } + path.append("_find_route"); + if (cfg.KeyExists(path)) { + std::string csv; + cfg.GetValue(path, estr, csv, 0, 10240); + UnpackCallsigns(csv, findRoute); + PrintCallsigns(path, findRoute); + } // APRS path.assign("aprs_"); @@ -357,6 +394,7 @@ void CQnetGateway::GetIRCDataThread() for (int i=0; i<3; i++) not_announced[i] = this->rptr.mod[i].defined; // announce to all modules that are defined! bool is_quadnet = (0 == ircddb.ip.compare("rr.openquad.net")); + bool doFind = true; while (keep_running) { int rc = ii->getConnectionState(); if (rc > 5 && rc < 8 && is_quadnet) { @@ -381,6 +419,13 @@ void CQnetGateway::GetIRCDataThread() fprintf(stderr, "could not open %s\n", qnvoicefile.c_str()); } } + if (doFind) { + printf("Finding Routes"); + for (auto it=findRoute.begin(); it!=findRoute.end(); it++) { + ii->findUser(*it); + } + doFind = false; + } } threshold++; if (threshold >= 100) { diff --git a/QnetGateway.h b/QnetGateway.h index 507bbc8..6cb8b7c 100644 --- a/QnetGateway.h +++ b/QnetGateway.h @@ -16,6 +16,9 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#include +#include + #include "QnetTypeDefs.h" #include "SEcho.h" #include "UnixDgramSocket.h" @@ -103,7 +106,8 @@ private: unsigned int vPacketCount; - std::map portmap; + std::map portmap; + std::set findRoute; // data needed for aprs login and aprs beacon // RPTR defined in aprs.h @@ -172,6 +176,8 @@ private: void ProcessG2(const ssize_t g2buflen, const SDSVT &g2buf, const bool is_from_g2); void ProcessModem(); bool Flag_is_ok(unsigned char flag); + void UnpackCallsigns(const std::string &str, std::set &set, const std::string &delimiters = ","); + void PrintCallsigns(const std::string &key, const std::set &set); // read configuration file bool read_config(char *); diff --git a/defaults b/defaults index 06ec75d..64061e9 100644 --- a/defaults +++ b/defaults @@ -58,6 +58,7 @@ gateway_longitude_d=0 # like the latitude gateway_desc1_d='' # maximum of 20 characters, most special symbols are not allowed gateway_desc2_d='' # just like desc1 gateway_url_d='github.com/n7tae/QnetGateway' # 80 characters max +gateway_find_route_d='' # CSV list of route(s) to load on boot-up (prevents the "not in cache" message) ########################################################################################################################## # diff --git a/qnconfig b/qnconfig index b65fe4d..bc45130 100755 --- a/qnconfig +++ b/qnconfig @@ -252,7 +252,10 @@ GateMenu () { echo -n "lo : Longitude (-180.0 to 180.0) = "; EvaluateVar gateway_longitude{,_d} echo -n "d1 : Description #1 (20 chars max) = "; EvaluateVar gateway_desc1{,_d} echo -n "d2 : Description #1 (20 chars max) = "; EvaluateVar gateway_desc2{,_d} - echo -n "w ; URL (80 char max) = "; EvaluateVar gateway_url{,_d} + echo -n "w : URL (80 char max) = "; EvaluateVar gateway_url{,_d} + echo -n "fr : Find Route(s) = "; EvaluateVar gateway_find_route{,_d} + echo " Find Route(s) is a comma-separated list of common routing callsigns." + echo " These will be added in your local cache on boot-up." echo echo " APRS - Repeater/User position tracking" echo -n "e : Enable APRS Tracking = "; EvaluateVar aprs_enable{,_d} @@ -280,6 +283,7 @@ GateMenu () { elif [[ "$key" == d1* ]]; then gateway_desc1="${value:0:20}" elif [[ "$key" == d2* ]]; then gateway_desc2="${value:0:20}" elif [[ "$key" == w* ]]; then gateway_url="${value:0:80}" + elif [[ "$key" == fr* ]]; then gateway_find_route="$value" elif [[ "$key" == e* ]]; then SetBooleanValue aprs_enable "$value" elif [[ "$key" == h* ]]; then aprs_host="$value" elif [[ "$key" == ap* ]]; then aprs_port="$value" @@ -518,6 +522,7 @@ WriteCFGFile () { [ -z "${gateway_desc1+x}" ] || echo "gateway_desc1='${gateway_desc1}'" >> $outFile [ -z "${gateway_desc2+x}" ] || echo "gateway_desc2='${gateway_desc2}'" >> $outFile [ -z "${gateway_url+x}" ] || echo "gateway_url='${gateway_url}'" >> $outFile + [ -z "${gateway_find_route+x}" ] || echo "gateway_find_route='${gateway_find_route}'" >> $outFile # arps_ section [ -z "${aprs_enable+x}" ] || echo "aprs_enable=${aprs_enable}" >> $outFile [ -z "${aprs_host+x}" ] || echo "aprs_host='${aprs_host}'" >> $outFile