From 70bdffbf3fa0df598a5a15a21366b6100c2b0825 Mon Sep 17 00:00:00 2001 From: Tom Early Date: Thu, 27 Dec 2018 09:52:59 -0700 Subject: [PATCH] qndvap uses QnetConfigure --- DVAPDongle.cpp | 4 +- DVAPDongle.h | 4 +- QnetDVAP.cpp | 223 +++++++++++++++---------------------------------- defaults | 22 +++-- 4 files changed, 86 insertions(+), 167 deletions(-) diff --git a/DVAPDongle.cpp b/DVAPDongle.cpp index 6971ca8..c5f3059 100644 --- a/DVAPDongle.cpp +++ b/DVAPDongle.cpp @@ -36,7 +36,7 @@ CDVAPDongle::~CDVAPDongle() { } -bool CDVAPDongle::Initialize(char *serialno, int frequency, int offset, int power, int squelch) +bool CDVAPDongle::Initialize(const char *serialno, const int frequency, const int offset, int const power, const int squelch) { bool ok = false; char device[128]; @@ -276,7 +276,7 @@ bool CDVAPDongle::syncit() return false; } -bool CDVAPDongle::get_ser(char *dvp, char *dvap_serial_number) +bool CDVAPDongle::get_ser(const char *dvp, const char *dvap_serial_number) { unsigned cnt = 0; REPLY_TYPE reply; diff --git a/DVAPDongle.h b/DVAPDongle.h index 78f6fce..0c2c542 100644 --- a/DVAPDongle.h +++ b/DVAPDongle.h @@ -88,7 +88,7 @@ class CDVAPDongle public: CDVAPDongle(); ~CDVAPDongle(); - bool Initialize(char *serialno, int frequency, int offset, int power, int squelch); + bool Initialize(const char *serialno, const int frequency, const int offset, const int power, const int squelch); REPLY_TYPE GetReply(SDVAP_REGISTER &dr); void Stop(); int KeepAlive(); @@ -107,7 +107,7 @@ class CDVAPDongle int read_from_dvp(void* buf, unsigned int len); int write_to_dvp(const void* buf, const unsigned int len); bool syncit(); - bool get_ser(char *dvp, char *dvap_serial_number); + bool get_ser(const char *dvp, const char *dvap_serial_number); bool get_name(); bool get_fw(); bool set_modu(); diff --git a/QnetDVAP.cpp b/QnetDVAP.cpp index 73adb7e..d62e5a0 100644 --- a/QnetDVAP.cpp +++ b/QnetDVAP.cpp @@ -45,17 +45,15 @@ #include #include #include -#include -using namespace libconfig; #include "DVAPDongle.h" #include "QnetTypeDefs.h" #include "Random.h" #include "UnixDgramSocket.h" +#include "QnetConfigure.h" #define VERSION DVAP_VERSION #define CALL_SIZE 8 -#define RPTR_SIZE 8 #define IP_SIZE 15 typedef struct dvap_ack_arg_tag { @@ -71,10 +69,10 @@ static std::string modem2gate, gate2modem; static CUnixDgramReader Gate2Modem; static CUnixDgramWriter Modem2Gate; /* Default configuration data */ -static char RPTR[RPTR_SIZE + 1]; -static char OWNER[RPTR_SIZE + 1]; +static std::string RPTR; +static std::string OWNER; static char RPTR_MOD; -static char DVP_SERIAL[64]; /* APxxxxxx */ +static std::string DVP_SERIAL; /* APxxxxxx */ static int DVP_FREQ; /* between 144000000 and 148000000 */ static int DVP_PWR; /* between -12 and 10 */ static int DVP_SQL; /* between -128 and -45 */ @@ -98,7 +96,7 @@ static unsigned int space = 0; static unsigned int aseed = 0; /* helper routines */ -static int read_config(const char *cfgFile); +static bool read_config(const char *cfgFile); static void sig_catch(int signum); static int open_sock(); static void readFrom20000(); @@ -157,152 +155,68 @@ static void sig_catch(int signum) exit(0); } -static bool get_value(const Config &cfg, const char *path, int &value, int min, int max, int default_value) -{ - if (cfg.lookupValue(path, value)) { - if (value < min || value > max) - value = default_value; - } else - value = default_value; - printf("%s = [%d]\n", path, value); - return true; -} - -static bool get_value(const Config &cfg, const char *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; - printf("%s = [%lg]\n", path, value); - return true; -} - -static bool get_value(const Config &cfg, const char *path, bool &value, bool default_value) -{ - if (! cfg.lookupValue(path, value)) - value = default_value; - printf("%s = [%s]\n", path, value ? "true" : "false"); - return true; -} - -static bool get_value(const Config &cfg, const char *path, std::string &value, int min, int max, const char *default_value) -{ - if (cfg.lookupValue(path, value)) { - int l = value.length(); - if (lmax) { - printf("%s is invalid\n", path); - return false; - } - } else - value = default_value; - printf("%s = [%s]\n", path, value.c_str()); - return true; -} - /* process configuration file */ -static int read_config(const char *cfgFile) +static bool read_config(const char *cfgFile) { - Config cfg; + CQnetConfigure cfg; printf("Reading file %s\n", cfgFile); - // Read the file. If there is an error, report it and exit. - try { - cfg.readFile(cfgFile); - } - catch(const FileIOException &fioex) { - fprintf(stderr, "Can't read %s\n", cfgFile); - return 1; - } - catch(const ParseException &pex) { - fprintf(stderr, "Parse error at %s:%d - %s\n", pex.getFile(), pex.getLine(), pex.getError()); - return 1; - } + if (cfg.Initialize(cfgFile)) + return true; - std::string value; - std::string dvap_path("module."); + const std::string estr; // an empty string + std::string type; + std::string dvap_path("module_"); dvap_path.append(1, 'a' + assigned_module); - if (cfg.lookupValue(dvap_path + ".type", value)) { - if (value.compare("dvap")) { + if (cfg.KeyExists(dvap_path)) { + cfg.GetValue(dvap_path, estr, type, 1, 16); + if (type.compare("dvap")) { fprintf(stderr, "assigned module '%c' type is not 'dvap'\n", 'a' + assigned_module); - return 1; + return true; } } else { fprintf(stderr, "%s is not defined!\n", dvap_path.c_str()); - return 1; + return true; } RPTR_MOD = 'A' + assigned_module; - char unixsockname[16]; - snprintf(unixsockname, 16, "gate2modem%d", assigned_module); - get_value(cfg, std::string(dvap_path+".fromgateway").c_str(), gate2modem, 1, FILENAME_MAX, unixsockname); - snprintf(unixsockname, 16, "modem2gate%d", assigned_module); - get_value(cfg, std::string(dvap_path+".togateway").c_str(), modem2gate, 1, FILENAME_MAX, unixsockname); - - if (cfg.lookupValue(std::string(dvap_path+".callsign").c_str(), value) || cfg.lookupValue("ircddb.login", value)) { - int l = value.length(); - if (l<3 || l>CALL_SIZE-2) { - printf("Call '%s' is invalid length!\n", value.c_str()); - return 1; - } else { - for (int i=0; iCALL_SIZE-2) { - printf("Call '%s' is invalid length!\n", value.c_str()); - return 1; - } else { - for (int i=0; i 60) { spack.counter = C_COUNTER++; - memcpy(spack.spkt.mycall, OWNER, 7); + memcpy(spack.spkt.mycall, OWNER.c_str(), 7); spack.spkt.mycall[7] = 'S'; - memcpy(spack.spkt.rpt, OWNER, 7); + memcpy(spack.spkt.rpt, OWNER.c_str(), 7); spack.spkt.rpt[7] = 'S'; Modem2Gate.Write(spack.pkt_id, 26); S_ctrl_msg_time = tnow; @@ -955,7 +868,7 @@ static void ReadDVAPThread() (net_buf.vpkt.hdr.r2[7] == 'B') || (net_buf.vpkt.hdr.r2[7] == 'C') || (net_buf.vpkt.hdr.r2[7] == 'G')) - memcpy(net_buf.vpkt.hdr.r2, RPTR, 7); + memcpy(net_buf.vpkt.hdr.r2, RPTR.c_str(), 7); else memset(net_buf.vpkt.hdr.r2, ' ', 8); @@ -973,9 +886,9 @@ static void ReadDVAPThread() that means that mycall, rpt1, rpt2 must be equal to RPTR otherwise we drop the rf data */ - if (memcmp(RPTR, OWNER, RPTR_SIZE) != 0) { - if (memcmp(net_buf.vpkt.hdr.my, RPTR, RPTR_SIZE) != 0) { - printf("mycall=[%.8s], not equal to %s\n", net_buf.vpkt.hdr.my, RPTR); + if (RPTR.compare(OWNER)) { + if (memcmp(net_buf.vpkt.hdr.my, RPTR.c_str(), CALL_SIZE) != 0) { + printf("mycall=[%.8s], not equal to %s\n", net_buf.vpkt.hdr.my, RPTR.c_str()); ok = false; } } else if (memcmp(net_buf.vpkt.hdr.my, " ", 8) == 0) { @@ -1034,15 +947,15 @@ static void ReadDVAPThread() /* for icom g2 */ spack.counter = C_COUNTER++; memcpy(spack.spkt.mycall, net_buf.vpkt.hdr.my, 8); - memcpy(spack.spkt.rpt, OWNER, 7); + memcpy(spack.spkt.rpt, OWNER.c_str(), 7); spack.spkt.rpt[7] = RPTR_MOD; Modem2Gate.Write(spack.pkt_id, 26); // Before we send the data to the local gateway, // set RPT1, RPT2 to be the local gateway - memcpy(net_buf.vpkt.hdr.r1, OWNER, 7); + memcpy(net_buf.vpkt.hdr.r1, OWNER.c_str(), 7); if (net_buf.vpkt.hdr.r2[7] != ' ') - memcpy(net_buf.vpkt.hdr.r2, OWNER, 7); + memcpy(net_buf.vpkt.hdr.r2, OWNER.c_str(), 7); memcpy(net_buf.pkt_id, "DSTR", 4); net_buf.counter = C_COUNTER++; diff --git a/defaults b/defaults index 7a15238..a5c09ed 100644 --- a/defaults +++ b/defaults @@ -102,14 +102,6 @@ module_x_modem2gate1='modem2gate1' module_x_modem2gate2='modem2gate2' module_x_url='github.com/n7tae/g2_ircddb' # 80 characters max -########################################################################################################################## -# -# DVAP - Special parameters when: module.x='dvap' -# -dvap_power=10 # TX power level: -12 to 10, 10 is maximum power -dvap_squelch=-100 # RX Squelch: -128 to -45, -100 to -80 usually works best -dvap_serial_number='APXXXXXX' # The serial number of your DVAP is visible through the bottom of the case - ########################################################################################################################## # # MMDVM - Special parameters when: module_x='mmdvm' @@ -118,6 +110,20 @@ mmdvm_internal_ip='0.0.0.0' # where MMDVMHost will find the QnetRelay program mmdvm_gateway_port=20010 # which port will QnetRelay be sending on mmdvm_local_port=20011 # which port will MMDVMHost be sending on +########################################################################################################################## +# +# ITAP - Special parameters when: module_x='itap' +# +device='/dev/ttyUSB0' # where the serial-to-USB cable show up + +########################################################################################################################## +# +# DVAP - Special parameters when: module.x='dvap' +# +dvap_power=10 # TX power level: -12 to 10, 10 is maximum power +dvap_squelch=-100 # RX Squelch: -128 to -45, -100 to -80 usually works best +dvap_serial_number='APXXXXXX' # The serial number of your DVAP is visible through the bottom of the case + ########################################################################################################################## # # DVRPTR - Special parameters when: module_x='dvrptr'