streamlined Run()

pull/12/head
Tom Early 7 years ago
parent f1e9f2786b
commit 48380cc587

@ -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,36 +241,16 @@ 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))
break;
} else {
switch (rt) {
case RT_HEADER_ACK:
//printf("HEADER_ACK");
//for (int i=0; i<int(buf[0]) && i<100; i++)
// printf(" %02X", buf[i]);
//printf("\n");
switch(GetITAPData(buf) {
case RT_ERROR:
keep_running = false;
break;
case RT_DATA_ACK:
//if (buf[3] || wasone) {
// wasone = buf[3] ? true : false;
// printf("DATA_ACK");
// for (int i=0; i<int(buf[0]) && i<100; i++)
// printf(" %02X", buf[i]);
// printf("\n");
//}
case RT_DATA:
case RT_HEADER:
if (ProcessITAP(buf))
keep_running = false;
break;
case RT_PONG:
if (! is_alive) {
@ -286,14 +258,11 @@ void CQnetITAP::Run(const char *cfgfile)
is_alive = true;
}
break;
default:
break;
}
}
FD_CLR(serfd, &readfds);
}
if (FD_ISSET(ug2m, &readfds)) {
if (keep_running && FD_ISSET(ug2m, &readfds)) {
len = Gate2Modem.Read(buf, 100);
if (len < 0) {

@ -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"

Loading…
Cancel
Save

Powered by TurnKey Linux.