diff --git a/QnetITAP.cpp b/QnetITAP.cpp index 07efd32..a24029a 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; } @@ -246,55 +239,44 @@ 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); - if (rt == RT_ERROR) - break; - - if (rt == RT_TIMEOUT) - continue; + if (keep_running && FD_ISSET(serfd, &readfds)) { + lastdata = std::chrono::steady_clock::now(); + 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; + default: + break; + } + FD_CLR(serfd, &readfds); + } - } else if (FD_ISSET(ug2m, &readfds)) { - len = Gate2Modem.Read(buf, 100); + if (keep_running && FD_ISSET(ug2m, &readfds)) { + ssize_t 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) { - if (ProcessITAP(buf)) + if (0 == memcmp(buf, "DSTR", 4)) { + //printf("read %d bytes from QnetGateway\n", (int)len); + if (ProcessGateway(len, buf)) 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_PONG: - if (! is_alive) { - printf("Icom Radio is connected.\n"); - is_alive = true; - } - break; - default: - break; - } } - } else if (0 == ::memcmp(buf, "DSTR", 4)) { - //printf("read %d bytes from QnetGateway\n", (int)len); - if (ProcessGateway(len, buf)) - break; + FD_CLR(ug2m, &readfds); } } diff --git a/QnetITAP.h b/QnetITAP.h index f60f8fd..0bb7961 100644 --- a/QnetITAP.h +++ b/QnetITAP.h @@ -36,8 +36,7 @@ enum REPLY_TYPE { RT_DATA, RT_HEADER_ACK, RT_DATA_ACK, - RT_PONG, - RT_NOTHING + RT_PONG }; // Icom Terminal and Access Point Mode data structure 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 diff --git a/versions.h b/versions.h index 5061559..6e9bc7e 100644 --- a/versions.h +++ b/versions.h @@ -3,6 +3,6 @@ #define LINK_VERSION "QnetLink7.0.1" #define DVAP_VERSION "QnetDVAP-6.0.0" #define RELAY_VERSION "QnetRelay-1.0.1" -#define ITAP_VERSION "QnetITAP-1.0.0" +#define ITAP_VERSION "QnetITAP-1.0.1" #define DVRPTR_VERSION "QnetDVRPTR-6.0.1" #define MMDVM_VERSION "QnetGateway-MMDVM-1.0.0"