better error handling in serial comm, fix a bug in stream openning

git-svn-id: https://hamlib.svn.sourceforge.net/svnroot/hamlib/trunk@536 7ae35d74-ebe9-4afe-98af-79ac388436b8
Hamlib-1.1.2
Stéphane Fillod, F8CFE 2001-06-10 22:19:08 +00:00
rodzic c6f5318a1c
commit ed6bbc95a6
2 zmienionych plików z 38 dodań i 25 usunięć

Wyświetl plik

@ -2,7 +2,7 @@
Copyright (C) 2000,2001 Stephane Fillod and Frank Singleton Copyright (C) 2000,2001 Stephane Fillod and Frank Singleton
This file is part of the hamlib package. This file is part of the hamlib package.
$Id: rig.c,v 1.33 2001-06-05 18:08:30 f4cfe Exp $ $Id: rig.c,v 1.34 2001-06-10 22:19:07 f4cfe Exp $
Hamlib is free software; you can redistribute it and/or modify it Hamlib is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by under the terms of the GNU General Public License as published by
@ -393,9 +393,6 @@ int rig_open(RIG *rig)
return -RIG_EINVAL; return -RIG_EINVAL;
} }
if (rig->state.rigport.fd >= 0)
rig->state.rigport.stream = fdopen(rig->state.rigport.fd, "r+b");
/* /*
* FIXME: what to do if PTT open fails or PTT unsupported? * FIXME: what to do if PTT open fails or PTT unsupported?
* fail rig_open? remember unallocating.. * fail rig_open? remember unallocating..

Wyświetl plik

@ -10,7 +10,7 @@
* ham packet softmodem written by Thomas Sailer, HB9JNX. * ham packet softmodem written by Thomas Sailer, HB9JNX.
* *
* *
* $Id: serial.c,v 1.12 2001-06-05 18:08:30 f4cfe Exp $ * $Id: serial.c,v 1.13 2001-06-10 22:19:08 f4cfe Exp $
* *
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -326,6 +326,14 @@ int serial_open(port_t *rp) {
} }
#endif #endif
rp->stream = fdopen(fd, "r+b");
if (rp->stream == NULL) {
rig_debug(RIG_DEBUG_ERR, "open_serial: fdopen failed: %s\n",
strerror(errno));
close(fd);
return -RIG_EIO; /* arg, so close! */
}
rp->fd = fd; rp->fd = fd;
return RIG_OK; return RIG_OK;
@ -500,12 +508,16 @@ int read_block(port_t *p, char *rxbuffer, size_t count)
tv = tv_timeout; /* select may have updated it */ tv = tv_timeout; /* select may have updated it */
retval = select(p->fd+1, &rfds, NULL, NULL, &tv); retval = select(p->fd+1, &rfds, NULL, NULL, &tv);
if (!retval) { if (retval == 0) {
rig_debug(RIG_DEBUG_ERR,"rig timeout after %d chars or " rig_debug(RIG_DEBUG_WARN, "read_block: timedout after %d chars\n",
"select error - %s!\n", total_count);
total_count, strerror(errno));
return -RIG_ETIMEOUT; return -RIG_ETIMEOUT;
} }
if (retval < 0) {
rig_debug(RIG_DEBUG_ERR,"read_block: select error after %d chars: "
"%s\n", total_count, strerror(errno));
return -RIG_EIO;
}
/* /*
* grab bytes from the rig * grab bytes from the rig
@ -546,29 +558,33 @@ int fread_block(port_t *p, char *rxbuffer, size_t count)
tv_timeout.tv_usec = (p->timeout%1000)*1000; tv_timeout.tv_usec = (p->timeout%1000)*1000;
/* /*
* grab bytes from the rig * grab bytes from the rig
* The file descriptor must have been set up non blocking. * The file descriptor must have been set up non blocking.
*/ */
rd_count = fread(rxbuffer, 1, count, p->stream); rd_count = fread(rxbuffer, 1, count, p->stream);
if (rd_count < 0) { if (rd_count < 0) {
rig_debug(RIG_DEBUG_ERR, "read_block: read failed - %s\n", rig_debug(RIG_DEBUG_ERR, "read_block: read failed - %s\n",
strerror(errno)); strerror(errno));
return -RIG_EIO; return -RIG_EIO;
} }
total_count += rd_count; total_count += rd_count;
count -= rd_count; count -= rd_count;
while (count > 0) { while (count > 0) {
tv = tv_timeout; /* select may have updated it */ tv = tv_timeout; /* select may have updated it */
retval = select(fd+1, &rfds, NULL, NULL, &tv); retval = select(fd+1, &rfds, NULL, NULL, &tv);
if (!retval) { if (retval == 0) {
rig_debug(RIG_DEBUG_ERR,"rig timeout after %d chars or " rig_debug(RIG_DEBUG_WARN, "fread_block: timedout after %d chars\n",
"select error - %s!\n", total_count);
total_count, strerror(errno));
return -RIG_ETIMEOUT; return -RIG_ETIMEOUT;
} }
if (retval < 0) {
rig_debug(RIG_DEBUG_ERR,"fread_block: select error after %d chars: "
"%s\n", total_count, strerror(errno));
return -RIG_EIO;
}
/* /*
* grab bytes from the rig * grab bytes from the rig