|
|
|
@ -130,7 +130,8 @@ REPLY_TYPE CQnetITAP::GetITAPData(unsigned char *buf)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Shamelessly adapted from Jonathan G4KLX's CIcomController::GetResponse()
|
|
|
|
// Shamelessly adapted from Jonathan G4KLX's CIcomController::GetResponse()
|
|
|
|
// and CSerialController::read()
|
|
|
|
// 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);
|
|
|
|
int ret = ::read(serfd, buf, 1U);
|
|
|
|
if (ret < 0) {
|
|
|
|
if (ret < 0) {
|
|
|
|
printf("Error when reading first byte from the Icom radio %d: %s", errno, strerror(errno));
|
|
|
|
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;
|
|
|
|
unsigned int offset = 1U;
|
|
|
|
|
|
|
|
|
|
|
|
while (offset < length) {
|
|
|
|
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);
|
|
|
|
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));
|
|
|
|
printf("Error when reading buffer from the Icom radio %d: %s\n", errno, strerror(errno));
|
|
|
|
return RT_ERROR;
|
|
|
|
return RT_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -205,7 +198,6 @@ void CQnetITAP::Run(const char *cfgfile)
|
|
|
|
bool is_alive = false;
|
|
|
|
bool is_alive = false;
|
|
|
|
std::chrono::steady_clock::time_point lastdata = std::chrono::steady_clock::now();
|
|
|
|
std::chrono::steady_clock::time_point lastdata = std::chrono::steady_clock::now();
|
|
|
|
|
|
|
|
|
|
|
|
// bool wasone = false;
|
|
|
|
|
|
|
|
while (keep_running) {
|
|
|
|
while (keep_running) {
|
|
|
|
fd_set readfds;
|
|
|
|
fd_set readfds;
|
|
|
|
FD_ZERO(&readfds);
|
|
|
|
FD_ZERO(&readfds);
|
|
|
|
@ -249,51 +241,28 @@ void CQnetITAP::Run(const char *cfgfile)
|
|
|
|
unsigned char buf[100];
|
|
|
|
unsigned char buf[100];
|
|
|
|
ssize_t len;
|
|
|
|
ssize_t len;
|
|
|
|
|
|
|
|
|
|
|
|
if (FD_ISSET(serfd, &readfds)) {
|
|
|
|
if (keep_running && FD_ISSET(serfd, &readfds)) {
|
|
|
|
REPLY_TYPE rt = GetITAPData(buf);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (rt == RT_ERROR)
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (rt == RT_TIMEOUT)
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lastdata = std::chrono::steady_clock::now();
|
|
|
|
lastdata = std::chrono::steady_clock::now();
|
|
|
|
//printf("read %d bytes from ITAP\n", (int)buf[0]);
|
|
|
|
switch(GetITAPData(buf) {
|
|
|
|
if (RT_DATA==rt || RT_HEADER==rt) {
|
|
|
|
case RT_ERROR:
|
|
|
|
if (ProcessITAP(buf))
|
|
|
|
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;
|
|
|
|
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");
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RT_PONG:
|
|
|
|
|
|
|
|
if (! is_alive) {
|
|
|
|
|
|
|
|
printf("Icom Radio is connected.\n");
|
|
|
|
|
|
|
|
is_alive = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
FD_CLR(serfd, &readfds);
|
|
|
|
FD_CLR(serfd, &readfds);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (FD_ISSET(ug2m, &readfds)) {
|
|
|
|
if (keep_running && FD_ISSET(ug2m, &readfds)) {
|
|
|
|
len = Gate2Modem.Read(buf, 100);
|
|
|
|
len = Gate2Modem.Read(buf, 100);
|
|
|
|
|
|
|
|
|
|
|
|
if (len < 0) {
|
|
|
|
if (len < 0) {
|
|
|
|
|