From 20419fa3c56f6040b2ead5d5d2c983a34afef7d7 Mon Sep 17 00:00:00 2001 From: Tom Early Date: Sat, 15 Dec 2018 12:07:46 -0700 Subject: [PATCH] qndvap uses unix sockets --- Makefile | 2 +- QnetDVAP.cpp | 191 +++++++++++++++++++++------------------------------ 2 files changed, 78 insertions(+), 115 deletions(-) diff --git a/Makefile b/Makefile index 51ca862..03afad2 100644 --- a/Makefile +++ b/Makefile @@ -67,7 +67,7 @@ qnitap : QnetITAP.o Random.o UnixDgramSocket.o g++ $(CPPFLAGS) -o qnitap QnetITAP.o Random.o $(LDFLAGS) qndvap : QnetDVAP.o DVAPDongle.o Random.o $(DSTROBJS) UnixDgramSocket.o - g++ $(CPPFLAGS) -o qndvap QnetDVAP.o DVAPDongle.o Random.o $(DSTROBJS) $(LDFLAGS) -pthread + g++ $(CPPFLAGS) -o qndvap QnetDVAP.o DVAPDongle.o Random.o UnixDgramSocket.o $(DSTROBJS) $(LDFLAGS) -pthread qndvrptr : QnetDVRPTR.o $(DSTROBJS) Random.o UnixDgramSocket.o g++ $(CPPFLAGS) -o qndvrptr QnetDVRPTR.o Random.o $(DSTROBJS) $(LDFLAGS) diff --git a/QnetDVAP.cpp b/QnetDVAP.cpp index e202bb8..c210657 100644 --- a/QnetDVAP.cpp +++ b/QnetDVAP.cpp @@ -51,6 +51,7 @@ using namespace libconfig; #include "DVAPDongle.h" #include "QnetTypeDefs.h" #include "Random.h" +#include "UnixDgramSocket.h" #define VERSION DVAP_VERSION #define CALL_SIZE 8 @@ -62,15 +63,17 @@ typedef struct dvap_ack_arg_tag { float ber; } SDVAP_ACK_ARG; +// assigned module, must be A, B or C +static int assigned_module; +// unix sockets +static std::string modem2gate("modem2gate"), gate2modem("gate2modem"); +static CUnixDgramReader Gate2Modem; +static CUnixDgramWriter Modem2Gate; /* Default configuration data */ static char RPTR[RPTR_SIZE + 1]; static char OWNER[RPTR_SIZE + 1]; static char RPTR_MOD; -static char RPTR_VIRTUAL_IP[IP_SIZE + 1]; -static int RPTR_PORT; -static char G2_INTERNAL_IP[IP_SIZE + 1]; -static int G2_PORT; static char DVP_SERIAL[64]; /* APxxxxxx */ static int DVP_FREQ; /* between 144000000 and 148000000 */ static int DVP_PWR; /* between -12 and 10 */ @@ -81,15 +84,12 @@ static int REMOTE_TIMEOUT; /* 1 second */ static int DELAY_BETWEEN; static int DELAY_BEFORE; static bool RPTR_ACK; -static char INVALID_YRCALL_KEY[CALL_SIZE + 1]; static int inactiveMax = 25; /* helper data */ static unsigned char SND_TERM_ID; static char RPTR_and_G[9]; static char RPTR_and_MOD[9]; -static int insock = -1; -static struct sockaddr_in outaddr; static int serfd = -1; static bool busy20000 = false; std::atomic keep_running(true); @@ -157,7 +157,7 @@ static void sig_catch(int signum) exit(0); } -bool get_value(const Config &cfg, const char *path, int &value, int min, int max, int default_value) +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) @@ -168,7 +168,7 @@ bool get_value(const Config &cfg, const char *path, int &value, int min, int max return true; } -bool get_value(const Config &cfg, const char *path, double &value, double min, double max, double default_value) +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) @@ -179,7 +179,7 @@ bool get_value(const Config &cfg, const char *path, double &value, double min, d return true; } -bool get_value(const Config &cfg, const char *path, bool &value, bool default_value) +static bool get_value(const Config &cfg, const char *path, bool &value, bool default_value) { if (! cfg.lookupValue(path, value)) value = default_value; @@ -187,7 +187,7 @@ bool get_value(const Config &cfg, const char *path, bool &value, bool default_va return true; } -bool get_value(const Config &cfg, const char *path, std::string &value, int min, int max, const char *default_value) +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(); @@ -204,7 +204,6 @@ bool get_value(const Config &cfg, const char *path, std::string &value, int min, /* process configuration file */ static int read_config(const char *cfgFile) { - int i; Config cfg; printf("Reading file %s\n", cfgFile); @@ -213,28 +212,32 @@ static int read_config(const char *cfgFile) cfg.readFile(cfgFile); } catch(const FileIOException &fioex) { - printf("Can't read %s\n", cfgFile); + fprintf(stderr, "Can't read %s\n", cfgFile); return 1; } catch(const ParseException &pex) { - printf("Parse error at %s:%d - %s\n", pex.getFile(), pex.getLine(), pex.getError()); + fprintf(stderr, "Parse error at %s:%d - %s\n", pex.getFile(), pex.getLine(), pex.getError()); return 1; } - std::string dvap_path, value; - for (i=0; i<3; i++) { - dvap_path = "module."; - dvap_path += ('a' + i); - if (cfg.lookupValue(dvap_path + ".type", value)) { - if (0 == strcasecmp(value.c_str(), "dvap")) - break; + std::string value; + std::string dvap_path("module."); + dvap_path.append(1, 'a' + assigned_module); + if (cfg.lookupValue(dvap_path + ".type", value)) { + if (value.compare("dvap")) { + fprintf(stderr, "assigned module '%c' type is not 'dvap'\n", 'a' + assigned_module); + return 1; } - } - if (i >= 3) { - printf("dvap not defined in any module!\n"); + } else { + fprintf(stderr, "%s is not defined!\n", dvap_path.c_str()); return 1; } - RPTR_MOD = 'A' + i; + 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(); @@ -242,7 +245,7 @@ static int read_config(const char *cfgFile) printf("Call '%s' is invalid length!\n", value.c_str()); return 1; } else { - for (i=0; i r2 memcpy(net_buf.vpkt.hdr.r2, dr.frame.hdr.rpt2, 8); // Internet Labs DVAP Dongle Tech. Ref. V 1.01 has it backwards! @@ -1073,7 +1036,7 @@ static void ReadDVAPThread() memcpy(spack.spkt.mycall, net_buf.vpkt.hdr.my, 8); memcpy(spack.spkt.rpt, OWNER, 7); spack.spkt.rpt[7] = RPTR_MOD; - sendto(insock, spack.pkt_id, 26, 0, (struct sockaddr *)&outaddr, sizeof(outaddr)); + Modem2Gate.Write(spack.pkt_id, 26); // Before we send the data to the local gateway, // set RPT1, RPT2 to be the local gateway @@ -1096,7 +1059,7 @@ static void ReadDVAPThread() net_buf.vpkt.ctrl = 0x80; sequence = 0; calcPFCS((unsigned char *)&(net_buf.vpkt.hdr), net_buf.vpkt.hdr.pfcs); - sendto(insock, &net_buf, 58, 0, (struct sockaddr *)&outaddr, sizeof(outaddr)); + Modem2Gate.Write(net_buf.pkt_id, 58); // local RF user keying up, start timer dvap_busy = true; @@ -1117,7 +1080,7 @@ static void ReadDVAPThread() if (the_end) net_buf.vpkt.ctrl = sequence | 0x40; memcpy(&net_buf.vpkt.vasd, &dr.frame.vad.voice, 12); - sendto(insock, &net_buf, 29, 0, (struct sockaddr *)&outaddr, sizeof(outaddr)); + Modem2Gate.Write(net_buf.pkt_id, 29); int ber_data[3]; int ber_errs = dstar_dv_decode(net_buf.vpkt.vasd.voice, ber_data);