diff --git a/Makefile b/Makefile index 03afad2..40aca0f 100644 --- a/Makefile +++ b/Makefile @@ -61,16 +61,16 @@ qnlink : QnetLink.o DPlusAuthenticator.o TCPReaderWriterClient.o Random.o UnixDg g++ $(CPPFLAGS) -o qnlink QnetLink.o DPlusAuthenticator.o TCPReaderWriterClient.o Random.o UnixDgramSocket.o $(LDFLAGS) -pthread qnrelay : QnetRelay.o UnixDgramSocket.o - g++ $(CPPFLAGS) -o qnrelay QnetRelay.o $(LDFLAGS) + g++ $(CPPFLAGS) -o qnrelay QnetRelay.o UnixDgramSocket.o $(LDFLAGS) qnitap : QnetITAP.o Random.o UnixDgramSocket.o - g++ $(CPPFLAGS) -o qnitap QnetITAP.o Random.o $(LDFLAGS) + g++ $(CPPFLAGS) -o qnitap QnetITAP.o Random.o UnixDgramSocket.o $(LDFLAGS) qndvap : QnetDVAP.o DVAPDongle.o Random.o $(DSTROBJS) UnixDgramSocket.o 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) + g++ $(CPPFLAGS) -o qndvrptr QnetDVRPTR.o Random.o UnixDgramSocket.o $(DSTROBJS) $(LDFLAGS) qnremote : QnetRemote.o Random.o g++ $(CPPFLAGS) -o qnremote QnetRemote.o Random.o $(LDFLAGS) diff --git a/QnetDVAP.cpp b/QnetDVAP.cpp index c210657..73adb7e 100644 --- a/QnetDVAP.cpp +++ b/QnetDVAP.cpp @@ -67,7 +67,7 @@ typedef struct dvap_ack_arg_tag { static int assigned_module; // unix sockets -static std::string modem2gate("modem2gate"), gate2modem("gate2modem"); +static std::string modem2gate, gate2modem; static CUnixDgramReader Gate2Modem; static CUnixDgramWriter Modem2Gate; /* Default configuration data */ @@ -616,7 +616,7 @@ int main(int argc, const char **argv) rc = read_config(argv[2]); if (rc != 0) { - printf("Failed to process config file %s\n", argv[1]); + printf("Failed to process config file %s\n", argv[2]); return 1; } diff --git a/QnetDVRPTR.cpp b/QnetDVRPTR.cpp index 84533bd..44f6ccf 100644 --- a/QnetDVRPTR.cpp +++ b/QnetDVRPTR.cpp @@ -26,6 +26,7 @@ #include #include "Random.h" +#include "UnixDgramSocket.h" using namespace libconfig; @@ -58,7 +59,6 @@ static int rqst_count = 6; static unsigned streamid[2] = {0x00, 0x00}; static unsigned char start_Header[8]= {0xD0,0x03,0x00,0x16,0x01,0x00,0x00,0x00}; static unsigned char ptt_off[8]= {0xD0,0x03,0x00,0x1A,0x01,0xff,0x00,0x00}; -static int insock = -1; static int read_config(const char *cfgFile); static void readFrom20000(); @@ -82,13 +82,14 @@ static unsigned char Modem_Init2[12]= {0xD0,0x07,0x00,0x14,0xC0,0x04,0x00,0x57,0 static unsigned char Modem_STATUS[6]= {0xD0,0x01,0x00,0x10,0x00,0x00}; // Status Abfragr static unsigned char Modem_SERIAL[6]= {0xD0,0x01,0x00,0x12,0x00,0x00}; +static int assigned_module; +static std::string gate2modem, modem2gate; +CUnixDgramWriter Modem2Gate; +CUnixDgramReader Gate2Modem; + static char DVRPTR_SERIAL[16]; static char DVCALL[RPTR_SIZE + 1] = {"ABCDEF"}; static char RPTR[RPTR_SIZE + 1] = {"ABCDEF"}; -static char GATEWAY_IP[IP_SIZE + 1] = {"127.0.0.1"}; -static int GATEWAY_PORT = 20000; -static char DVRPTR_INTERNAL_IP[IP_SIZE + 1] = {"127.0.0.1"}; -static int DVRPTR_INTERNAL_PORT = 20000; static char DVRPTR_MOD = 'B'; static int RF_AUDIO_Level = 10; static bool DUPLEX = true; @@ -102,7 +103,6 @@ static bool ok = false; static bool RX_Inverse = 0; static bool TX_Inverse = 0; static int TX_DELAY = 250; /* in milliseconds */ -static struct sockaddr_in outaddr; static unsigned char SND_TERM_ID = 0x00; static char DVCALL_and_G[9]; static char DVCALL_and_MOD[9]; @@ -114,7 +114,6 @@ static char myRPT1[10]; //RX from HF RPT1 static char myUR[10]; static char myCall[10]; static char myCall2[10]; -static char INVALID_YRCALL_KEY[CALL_SIZE + 1] = { "" }; char Ergebnis[250]; @@ -1805,7 +1804,7 @@ static void calcPFCS(unsigned char packet[58])//Netzwerk CRC return; } -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) @@ -1816,18 +1815,18 @@ 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) -{ - 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; -} - -bool get_value(const Config &cfg, const char *path, bool &value, bool 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) +// 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; @@ -1835,7 +1834,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(); @@ -1861,28 +1860,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 path, value; - for (i=0; i<3; i++) { - path = "module."; - path += ('a' + i); - if (cfg.lookupValue(path + ".type", value)) { - if (0 == strcasecmp(value.c_str(), "dvrptr")) - break; + std::string value; + std::string path("module."); + path += ('a' + assigned_module); + if (cfg.lookupValue(path + ".type", value)) { + if (value.compare("dvrptr")) { + fprintf(stderr, "module %c is not type 'dvrptr'\n", 'a' + assigned_module); + return 1; } - } - if (i >= 3) { - printf("dvrptr not defined in any module!\n"); + } else { + fprintf(stderr, "module %c is not defined\n", 'a' + assigned_module); return 1; } DVRPTR_MOD = 'A' + i; + char unixsockname[16]; + snprintf(unixsockname, 16, "gate2modem%d", assigned_module); + get_value(cfg, std::string(path+".fromgateway").c_str(), gate2modem, 1, FILENAME_MAX, unixsockname); + snprintf(unixsockname, 16, "modem2gate%d", assigned_module); + get_value(cfg, std::string(path+".togateway").c_str(), modem2gate, 1, FILENAME_MAX, unixsockname); if (cfg.lookupValue(std::string(path+".callsign").c_str(), value) || cfg.lookupValue("ircddb.login", value)) { int l = value.length(); @@ -1940,18 +1943,6 @@ static int read_config(const char *cfgFile) REMOTE_TIMEOUT = 3; printf("timing.timeout.remote_g2 = [%d]\n", REMOTE_TIMEOUT); - if (get_value(cfg, std::string(path+".invalid_prefix").c_str(), value, 1, CALL_SIZE, "XXX")) { - value.resize(CALL_SIZE, ' '); - for (i=0; i