From 57d13e046f528b4035881678d4b68f7c4335d024 Mon Sep 17 00:00:00 2001 From: Tom Early Date: Sun, 27 Jan 2019 14:14:32 -0700 Subject: [PATCH 1/7] better Run()? --- QnetITAP.cpp | 50 +++++++++++++++++++++++++++++--------------------- QnetITAP.h | 3 +-- 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/QnetITAP.cpp b/QnetITAP.cpp index 07efd32..d0472e6 100644 --- a/QnetITAP.cpp +++ b/QnetITAP.cpp @@ -247,10 +247,9 @@ void CQnetITAP::Run(const char *cfgfile) // there is something to read! unsigned char buf[100]; ssize_t len; - REPLY_TYPE rt = RT_NOTHING; if (FD_ISSET(serfd, &readfds)) { - rt = GetITAPData(buf); + REPLY_TYPE rt = GetITAPData(buf); if (rt == RT_ERROR) break; @@ -258,16 +257,6 @@ void CQnetITAP::Run(const char *cfgfile) if (rt == RT_TIMEOUT) continue; - } else if (FD_ISSET(ug2m, &readfds)) { - len = Gate2Modem.Read(buf, 100); - - if (len < 0) { - printf("ERROR: Run: recvfrom(gsock) returned error %d, %s\n", errno, strerror(errno)); - break; - } - } - - if (rt != RT_NOTHING) { lastdata = std::chrono::steady_clock::now(); //printf("read %d bytes from ITAP\n", (int)buf[0]); if (RT_DATA==rt || RT_HEADER==rt) { @@ -275,12 +264,18 @@ void CQnetITAP::Run(const char *cfgfile) break; } else { switch (rt) { - //case RT_HEADER_ACK: - // printf("DEBUG: Run: got header acknowledgement\n"); - // break; - //case RT_DATA_ACK: - // printf("DEBUG: Run: got data acknowledgement\n"); - // break; + case RT_HEADER_ACK: + printf("HEADER_ACK"); + for (int i=0; i Date: Sun, 27 Jan 2019 15:07:08 -0700 Subject: [PATCH 2/7] less DATA_ACK msgs. --- QnetITAP.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/QnetITAP.cpp b/QnetITAP.cpp index d0472e6..8f75083 100644 --- a/QnetITAP.cpp +++ b/QnetITAP.cpp @@ -205,6 +205,7 @@ void CQnetITAP::Run(const char *cfgfile) bool is_alive = false; std::chrono::steady_clock::time_point lastdata = std::chrono::steady_clock::now(); + bool wasone = false; while (keep_running) { fd_set readfds; FD_ZERO(&readfds); @@ -271,10 +272,13 @@ void CQnetITAP::Run(const char *cfgfile) printf("\n"); break; case RT_DATA_ACK: - printf("DATA_ACK"); - for (int i=0; i Date: Sun, 27 Jan 2019 18:03:38 -0700 Subject: [PATCH 3/7] no ack logging --- QnetITAP.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/QnetITAP.cpp b/QnetITAP.cpp index 8f75083..639d259 100644 --- a/QnetITAP.cpp +++ b/QnetITAP.cpp @@ -266,19 +266,19 @@ void CQnetITAP::Run(const char *cfgfile) } else { switch (rt) { case RT_HEADER_ACK: - printf("HEADER_ACK"); - for (int i=0; i Date: Sun, 27 Jan 2019 18:11:50 -0700 Subject: [PATCH 4/7] remove warning about wasone --- QnetITAP.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/QnetITAP.cpp b/QnetITAP.cpp index 639d259..d4646b3 100644 --- a/QnetITAP.cpp +++ b/QnetITAP.cpp @@ -205,7 +205,7 @@ void CQnetITAP::Run(const char *cfgfile) bool is_alive = false; std::chrono::steady_clock::time_point lastdata = std::chrono::steady_clock::now(); - bool wasone = false; +// bool wasone = false; while (keep_running) { fd_set readfds; FD_ZERO(&readfds); From 48380cc587b211b2ab9fed69ee879335c3df4de8 Mon Sep 17 00:00:00 2001 From: Tom Early Date: Sun, 27 Jan 2019 22:08:18 -0700 Subject: [PATCH 5/7] streamlined Run() --- QnetITAP.cpp | 69 +++++++++++++++------------------------------------- versions.h | 2 +- 2 files changed, 20 insertions(+), 51 deletions(-) diff --git a/QnetITAP.cpp b/QnetITAP.cpp index d4646b3..6816e51 100644 --- a/QnetITAP.cpp +++ b/QnetITAP.cpp @@ -130,7 +130,8 @@ REPLY_TYPE CQnetITAP::GetITAPData(unsigned char *buf) { // Shamelessly adapted from Jonathan G4KLX's CIcomController::GetResponse() // and CSerialController::read() - // Get the start of the frame or nothing at all + + // Get the buffer size or nothing at all int ret = ::read(serfd, buf, 1U); if (ret < 0) { printf("Error when reading first byte from the Icom radio %d: %s", errno, strerror(errno)); @@ -153,17 +154,9 @@ REPLY_TYPE CQnetITAP::GetITAPData(unsigned char *buf) unsigned int offset = 1U; while (offset < length) { - fd_set fds; - FD_ZERO(&fds); - FD_SET(serfd, &fds); - int n = ::select(serfd+1, &fds, NULL, NULL, NULL); // wait untill it's ready. won't return a zero. - if (n < 0) { - printf("ERROR: GetITAPData: select returned error %d: %s\n", errno, strerror(errno)); - return RT_ERROR; - } ret = ::read(serfd, buf + offset, length - offset); - if (ret < 0 && errno!=EAGAIN) { + if (ret<0 && errno!=EAGAIN) { printf("Error when reading buffer from the Icom radio %d: %s\n", errno, strerror(errno)); return RT_ERROR; } @@ -205,7 +198,6 @@ void CQnetITAP::Run(const char *cfgfile) bool is_alive = false; std::chrono::steady_clock::time_point lastdata = std::chrono::steady_clock::now(); -// bool wasone = false; while (keep_running) { fd_set readfds; FD_ZERO(&readfds); @@ -249,51 +241,28 @@ void CQnetITAP::Run(const char *cfgfile) unsigned char buf[100]; ssize_t len; - if (FD_ISSET(serfd, &readfds)) { - REPLY_TYPE rt = GetITAPData(buf); - - if (rt == RT_ERROR) - break; - - if (rt == RT_TIMEOUT) - continue; - + if (keep_running && FD_ISSET(serfd, &readfds)) { lastdata = std::chrono::steady_clock::now(); - //printf("read %d bytes from ITAP\n", (int)buf[0]); - if (RT_DATA==rt || RT_HEADER==rt) { - if (ProcessITAP(buf)) + switch(GetITAPData(buf) { + case RT_ERROR: + keep_running = false; + break; + case RT_DATA: + case RT_HEADER: + if (ProcessITAP(buf)) + keep_running = false; + break; + case RT_PONG: + if (! is_alive) { + printf("Icom Radio is connected.\n"); + is_alive = true; + } break; - } else { - switch (rt) { - case RT_HEADER_ACK: - //printf("HEADER_ACK"); - //for (int i=0; i Date: Sun, 27 Jan 2019 22:17:36 -0700 Subject: [PATCH 6/7] added default to switch --- QnetITAP.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/QnetITAP.cpp b/QnetITAP.cpp index 6816e51..a24029a 100644 --- a/QnetITAP.cpp +++ b/QnetITAP.cpp @@ -239,11 +239,10 @@ void CQnetITAP::Run(const char *cfgfile) // there is something to read! unsigned char buf[100]; - ssize_t len; if (keep_running && FD_ISSET(serfd, &readfds)) { lastdata = std::chrono::steady_clock::now(); - switch(GetITAPData(buf) { + switch (GetITAPData(buf)) { case RT_ERROR: keep_running = false; break; @@ -258,12 +257,14 @@ void CQnetITAP::Run(const char *cfgfile) is_alive = true; } break; + default: + break; } FD_CLR(serfd, &readfds); } if (keep_running && FD_ISSET(ug2m, &readfds)) { - len = Gate2Modem.Read(buf, 100); + ssize_t len = Gate2Modem.Read(buf, 100); if (len < 0) { printf("ERROR: Run: recvfrom(gsock) returned error %d, %s\n", errno, strerror(errno)); From 6cf9c9755f3cbc747c6702436abdbb9479270e97 Mon Sep 17 00:00:00 2001 From: Tom Early Date: Mon, 28 Jan 2019 07:32:30 -0700 Subject: [PATCH 7/7] sn is now forced to uppercase and you can't write qn.cfg unless you set ircddb_login --- qnconfig | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/qnconfig b/qnconfig index f0008e1..b65fe4d 100755 --- a/qnconfig +++ b/qnconfig @@ -397,7 +397,7 @@ ModuleMenu () { elif [[ "$key" == ad* ]]; then eval ${mod}_ack_delay="$value" elif [[ "$key" == po* ]]; then eval ${mod}_power="$value" elif [[ "$key" == sq* ]]; then eval ${mod}_squelch="$value" - elif [[ "$key" == sn* ]]; then eval ${mod}_serial_number="$value" + elif [[ "$key" == sn* ]]; then eval ${mod}_serial_number="${value^^}" elif [[ "$key" == rn* ]]; then eval ${mod}_rf_on="$value" elif [[ "$key" == rf* ]]; then eval ${mod}_rf_off="$value" elif [[ "$key" == rl* ]]; then eval ${mod}_rx_level="$value" @@ -449,10 +449,15 @@ ModuleMenu () { WriteCFGFile () { local m p q outFile + if [ -z "$ircddb_login" ]; then + echo "You MUST set your ircddb login callsign (in the ircddb section)!" + read -p "Press to continue: " ans + return + fi outFile='./qn.cfg' echo "# Created on `date`" > $outFile # gateway_ section - echo "ircddb_login='$ircddb_login'" >> $outFile + echo "ircddb_login='$ircddb_login'" >> $outFile [ -z "${ircddb_host+x}" ] || echo "ircddb_host='${ircddb_host}'" >> $outFile [ -z "${ircddb_port+x}" ] || echo "ircddb_host=${ircddb_port}" >> $outFile [ -z "${ircddb_password+x}" ] || echo "ircddb_password='${ircddb_password}'" >> $outFile