From f72596b6c09b0faeb23b619c365b78fdbe423b59 Mon Sep 17 00:00:00 2001 From: Tom Early Date: Sun, 8 Apr 2018 13:36:44 -0700 Subject: [PATCH] another attempt... --- dvap_rptr.cpp | 2 +- dvrptr.cpp | 2 +- g2.everything.cfg | 2 +- g2_ircddb.cpp | 2 +- mmdvm_modem.cpp | 45 +++++++++++++++++++++++++++++++++------------ mmdvm_modem.h | 2 +- 6 files changed, 38 insertions(+), 17 deletions(-) diff --git a/dvap_rptr.cpp b/dvap_rptr.cpp index 8ada44b..bcfd26e 100644 --- a/dvap_rptr.cpp +++ b/dvap_rptr.cpp @@ -295,7 +295,7 @@ static int read_config(const char *cfgFile) return 1; } - get_value(cfg, "gateway.internal.port", G2_PORT, 10000, 65535, 20010); + get_value(cfg, "gateway.internal.port", G2_PORT, 10000, 65535, 19000); if (get_value(cfg, std::string(dvap_path+".serial_number").c_str(), value, 8, 10, "APXXXXXX")) strcpy(DVP_SERIAL, value.c_str()); diff --git a/dvrptr.cpp b/dvrptr.cpp index 48176ea..a298126 100644 --- a/dvrptr.cpp +++ b/dvrptr.cpp @@ -1976,7 +1976,7 @@ static int read_config(const char *cfgFile) return 1; } - get_value(cfg, "gateway.internal.port", GATEWAY_PORT, 10000, 65535, 20010); + get_value(cfg, "gateway.internal.port", GATEWAY_PORT, 10000, 65535, 19000); get_value(cfg, std::string(path+".rf_tx_level").c_str(), RF_AUDIO_Level, 1, 100, 80); diff --git a/g2.everything.cfg b/g2.everything.cfg index 527cc7f..8f92122 100644 --- a/g2.everything.cfg +++ b/g2.everything.cfg @@ -21,7 +21,7 @@ gateway = { internal = { # ip = "0.0.0.0" -# port = 20010 +# port = 19000 } } diff --git a/g2_ircddb.cpp b/g2_ircddb.cpp index 1c24f4d..7c81951 100644 --- a/g2_ircddb.cpp +++ b/g2_ircddb.cpp @@ -313,7 +313,7 @@ bool CG2_ircddb::read_config(char *cfgFile) if (! get_value(cfg, "gateway.internal.ip", g2_internal.ip, 7, IP_SIZE, "0.0.0.0")) return true; - get_value(cfg, "gateway.internal.port", g2_internal.port, 16000, 65535, 20010); + get_value(cfg, "gateway.internal.port", g2_internal.port, 16000, 65535, 19000); if (! get_value(cfg, "g2_link.outgoing_ip", g2_link.ip, 7, IP_SIZE, "127.0.0.1")) return true; diff --git a/mmdvm_modem.cpp b/mmdvm_modem.cpp index 02f53d7..0e08f87 100644 --- a/mmdvm_modem.cpp +++ b/mmdvm_modem.cpp @@ -125,24 +125,33 @@ void CMMDVMModem::Run(const char *cfgfile) if (msock < 0) return; + gsock = OpenSocket(G2_INTERNAL_IP, G2_INTERNAL_PORT); + if (gsock < 0) { + ::close(msock); + return; + } + printf("msock=%d\n", msock); keep_running = true; while (keep_running) { struct timeval tv; - fd_set readfds; - tv.tv_sec = 0; tv.tv_usec = 1000; // wait 1ms for some input + fd_set readfds; FD_ZERO(&readfds); FD_SET(msock, &readfds); + FD_SET(gsock, &readfds); + int maxfs = (msock > gsock) ? msock : gsock; // don't care about writefds and exceptfds: - int ret = ::select(msock+1, &readfds, NULL, NULL, &tv); - if (ret < 0) + int ret = ::select(maxfs+1, &readfds, NULL, NULL, &tv); + if (ret < 0) { + printf("ERROR: Run: select returned err=%d, %s\n", errno, strerror(errno)); break; + } if (ret == 0) continue; @@ -156,12 +165,23 @@ void CMMDVMModem::Run(const char *cfgfile) len = ::recvfrom(msock, buf, 100, 0, (sockaddr *)&addr, &size); if (len < 0) { - printf("ERROR: RUN: recvfrom(mmdvm) return error %d, %s\n", errno, strerror(errno)); + printf("ERROR: Run: recvfrom(mmdvm) return error %d, %s\n", errno, strerror(errno)); + break; + } + + if (ntohs(addr.sin_port) != 20010U) + printf("DEBUG: Run: reading from msock but port was %u, expected 20010.\n", ntohs(addr.sin_port)); + + } else if (FD_ISSET(gsock, &readfds)) { + len = ::recvfrom(gsock, buf, 100, 0, (sockaddr *)&addr, &size); + + if (len < 0) { + printf("ERROR: Run: recvfrom(gsock) returned error %d, %s\n", errno, strerror(errno)); break; } - if (ntohs(addr.sin_port) == G2_INTERNAL_PORT) - printf("DEBUG: Run: reading from msock but port was %u.\n", ntohs(addr.sin_port)); + if (ntohs(addr.sin_port)>20000u || ntohs(addr.sin_port)<19998) + printf("DEBUG: Run: reading from gsock but the port was %u, expected 19998-20000\n", ntohs(addr.sin_port)); } else { printf("ERROR: Run: Input from unknown fd!\n"); @@ -170,12 +190,13 @@ void CMMDVMModem::Run(const char *cfgfile) if (len == 0) continue; - if (ntohs(addr.sin_port) == MMDVM_PORT) { - printf("read %d bytes from MMDVMHost\n", (int)len); +// if (ntohs(addr.sin_port) == MMDVM_PORT) { if (0 == memcmp(buf, "DSRP", 4)) { + printf("read %d bytes from MMDVMHost\n", (int)len); if (ProcessMMDVM(len, buf)) break; } else if (0 == ::memcmp(buf, "DSTR", 4)) { + printf("read %d bytes from MMDVMHost\n", (int)len); if (ProcessGateway(len, buf)) break; } else { @@ -185,8 +206,8 @@ void CMMDVMModem::Run(const char *cfgfile) title[4] = '\0'; printf("DEBUG: Run: received unknow packet '%s' len=%d\n", title, (int)len); } - } else - printf("read %d bytes from unknown port %u!\n", (int)len, ntohs(addr.sin_port)); +// } else +// printf("read %d bytes from unknown port %u!\n", (int)len, ntohs(addr.sin_port)); } ::close(msock); @@ -428,7 +449,7 @@ bool CMMDVMModem::ReadConfig(const char *cfgFile) } else return true; - GetValue(cfg, "gateway.internal.port", i, 10000, 65535, 20010); + GetValue(cfg, "gateway.internal.port", i, 10000, 65535, 19000); G2_INTERNAL_PORT = (unsigned short)i; GetValue(cfg, "timing.play.delay", DELAY_BETWEEN, 9, 25, 19); diff --git a/mmdvm_modem.h b/mmdvm_modem.h index ebe0d0c..672c64c 100644 --- a/mmdvm_modem.h +++ b/mmdvm_modem.h @@ -66,7 +66,7 @@ private: bool RPTR_ACK; // parameters - int msock; + int msock, gsock; unsigned int seed; unsigned short COUNTER; };