* ser_posix.c: Add verbose level > 3 output for send and recv functions.

git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@297 81a1dc3b-b13d-400b-aceb-764788c761c2
This commit is contained in:
troth 2003-03-24 01:57:31 +00:00
parent 3a85c3c92a
commit eaa8c4444d
2 changed files with 63 additions and 9 deletions

View File

@ -1,3 +1,7 @@
2003-03-23 Theodore A. Roth <troth@openavr.org>
* ser_posix.c: Add verbose level > 3 output for send and recv functions.
2003-03-23 Theodore A. Roth <troth@openavr.org> 2003-03-23 Theodore A. Roth <troth@openavr.org>
* avr.c: Add avr_read_byte_default(). * avr.c: Add avr_read_byte_default().

View File

@ -34,6 +34,7 @@
#include <unistd.h> #include <unistd.h>
extern char *progname; extern char *progname;
extern int verbose;
struct baud_mapping { struct baud_mapping {
long baud; long baud;
@ -156,13 +157,37 @@ int serial_send(int fd, char * buf, size_t buflen)
int nfds; int nfds;
int rc; int rc;
if (!buflen) char * p = buf;
size_t len = buflen;
if (!len)
return 0; return 0;
if (verbose > 3)
{
fprintf(stderr, "%s: Send: ", progname);
while (buflen) {
char c = *buf;
if (isprint(c)) {
fprintf(stderr, "%c ", c);
}
else {
fprintf(stderr, ". ");
}
fprintf(stderr, "[%02x] ", (unsigned int)c);
buf++;
buflen--;
}
fprintf(stderr, "\n");
}
timeout.tv_sec = 0; timeout.tv_sec = 0;
timeout.tv_usec = 500000; timeout.tv_usec = 500000;
while (buflen) { while (len) {
FD_ZERO(&wfds); FD_ZERO(&wfds);
FD_SET(fd, &wfds); FD_SET(fd, &wfds);
@ -185,14 +210,14 @@ int serial_send(int fd, char * buf, size_t buflen)
} }
} }
rc = write(fd, buf, 1); rc = write(fd, p, 1);
if (rc < 0) { if (rc < 0) {
fprintf(stderr, "%s: serial_send(): write error: %s\n", fprintf(stderr, "%s: serial_send(): write error: %s\n",
progname, strerror(errno)); progname, strerror(errno));
exit(1); exit(1);
} }
buf++; p++;
buflen--; len--;
} }
return 0; return 0;
@ -206,10 +231,13 @@ int serial_recv(int fd, char * buf, size_t buflen)
int nfds; int nfds;
int rc; int rc;
char * p = buf;
size_t len = 0;
timeout.tv_sec = 5; timeout.tv_sec = 5;
timeout.tv_usec = 0; timeout.tv_usec = 0;
while (buflen) { while (len < buflen) {
FD_ZERO(&rfds); FD_ZERO(&rfds);
FD_SET(fd, &rfds); FD_SET(fd, &rfds);
@ -232,14 +260,36 @@ int serial_recv(int fd, char * buf, size_t buflen)
} }
} }
rc = read(fd, buf, 1); rc = read(fd, p, 1);
if (rc < 0) { if (rc < 0) {
fprintf(stderr, "%s: serial_recv(): read error: %s\n", fprintf(stderr, "%s: serial_recv(): read error: %s\n",
progname, strerror(errno)); progname, strerror(errno));
exit(1); exit(1);
} }
buf++; p++;
buflen--; len++;
}
p = buf;
if (verbose > 3)
{
fprintf(stderr, "%s: Recv: ", progname);
while (len) {
char c = *p;
if (isprint(c)) {
fprintf(stderr, "%c ", c);
}
else {
fprintf(stderr, ". ");
}
fprintf(stderr, "[%02x] ", ((unsigned int)c &0xff));
p++;
len--;
}
fprintf(stderr, "\n");
} }
return 0; return 0;