New feature: find routes

pull/12/head
Tom Early 7 years ago
parent 5cc285d146
commit f0526beb43

@ -51,7 +51,6 @@
#include <string> #include <string>
#include <thread> #include <thread>
#include <chrono> #include <chrono>
#include <map>
#include "IRCDDB.h" #include "IRCDDB.h"
#include "IRCutils.h" #include "IRCutils.h"
@ -75,6 +74,37 @@ static void sigCatch(int signum)
return; return;
} }
void CQnetGateway::UnpackCallsigns(const std::string &str, std::set<std::string> &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<std::string> &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) void CQnetGateway::set_dest_rptr(int mod_ndx, char *dest_rptr)
{ {
FILE *statusfp = fopen(status_file.c_str(), "r"); 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); 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 // APRS
path.assign("aprs_"); path.assign("aprs_");
@ -357,6 +394,7 @@ void CQnetGateway::GetIRCDataThread()
for (int i=0; i<3; i++) for (int i=0; i<3; i++)
not_announced[i] = this->rptr.mod[i].defined; // announce to all modules that are defined! 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 is_quadnet = (0 == ircddb.ip.compare("rr.openquad.net"));
bool doFind = true;
while (keep_running) { while (keep_running) {
int rc = ii->getConnectionState(); int rc = ii->getConnectionState();
if (rc > 5 && rc < 8 && is_quadnet) { if (rc > 5 && rc < 8 && is_quadnet) {
@ -381,6 +419,13 @@ void CQnetGateway::GetIRCDataThread()
fprintf(stderr, "could not open %s\n", qnvoicefile.c_str()); 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++; threshold++;
if (threshold >= 100) { if (threshold >= 100) {

@ -16,6 +16,9 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
#include <map>
#include <set>
#include "QnetTypeDefs.h" #include "QnetTypeDefs.h"
#include "SEcho.h" #include "SEcho.h"
#include "UnixDgramSocket.h" #include "UnixDgramSocket.h"
@ -103,7 +106,8 @@ private:
unsigned int vPacketCount; unsigned int vPacketCount;
std::map <uint32_t, uint16_t> portmap; std::map<uint32_t, uint16_t> portmap;
std::set<std::string> findRoute;
// data needed for aprs login and aprs beacon // data needed for aprs login and aprs beacon
// RPTR defined in aprs.h // 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 ProcessG2(const ssize_t g2buflen, const SDSVT &g2buf, const bool is_from_g2);
void ProcessModem(); void ProcessModem();
bool Flag_is_ok(unsigned char flag); bool Flag_is_ok(unsigned char flag);
void UnpackCallsigns(const std::string &str, std::set<std::string> &set, const std::string &delimiters = ",");
void PrintCallsigns(const std::string &key, const std::set<std::string> &set);
// read configuration file // read configuration file
bool read_config(char *); bool read_config(char *);

@ -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_desc1_d='' # maximum of 20 characters, most special symbols are not allowed
gateway_desc2_d='' # just like desc1 gateway_desc2_d='' # just like desc1
gateway_url_d='github.com/n7tae/QnetGateway' # 80 characters max 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)
########################################################################################################################## ##########################################################################################################################
# #

@ -252,7 +252,10 @@ GateMenu () {
echo -n "lo : Longitude (-180.0 to 180.0) = "; EvaluateVar gateway_longitude{,_d} 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 "d1 : Description #1 (20 chars max) = "; EvaluateVar gateway_desc1{,_d}
echo -n "d2 : Description #1 (20 chars max) = "; EvaluateVar gateway_desc2{,_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
echo " APRS - Repeater/User position tracking" echo " APRS - Repeater/User position tracking"
echo -n "e : Enable APRS Tracking = "; EvaluateVar aprs_enable{,_d} 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" == d1* ]]; then gateway_desc1="${value:0:20}"
elif [[ "$key" == d2* ]]; then gateway_desc2="${value:0:20}" elif [[ "$key" == d2* ]]; then gateway_desc2="${value:0:20}"
elif [[ "$key" == w* ]]; then gateway_url="${value:0:80}" 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" == e* ]]; then SetBooleanValue aprs_enable "$value"
elif [[ "$key" == h* ]]; then aprs_host="$value" elif [[ "$key" == h* ]]; then aprs_host="$value"
elif [[ "$key" == ap* ]]; then aprs_port="$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_desc1+x}" ] || echo "gateway_desc1='${gateway_desc1}'" >> $outFile
[ -z "${gateway_desc2+x}" ] || echo "gateway_desc2='${gateway_desc2}'" >> $outFile [ -z "${gateway_desc2+x}" ] || echo "gateway_desc2='${gateway_desc2}'" >> $outFile
[ -z "${gateway_url+x}" ] || echo "gateway_url='${gateway_url}'" >> $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 # arps_ section
[ -z "${aprs_enable+x}" ] || echo "aprs_enable=${aprs_enable}" >> $outFile [ -z "${aprs_enable+x}" ] || echo "aprs_enable=${aprs_enable}" >> $outFile
[ -z "${aprs_host+x}" ] || echo "aprs_host='${aprs_host}'" >> $outFile [ -z "${aprs_host+x}" ] || echo "aprs_host='${aprs_host}'" >> $outFile

Loading…
Cancel
Save

Powered by TurnKey Linux.