From 5bd3b081eb4e8520c7b6fcd67e3e9c930ed2851f Mon Sep 17 00:00:00 2001 From: "Theodore A. Roth" Date: Mon, 24 Mar 2003 01:57:31 +0000 Subject: [PATCH] * ser_posix.c: Add verbose level > 3 output for send and recv functions. git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk@297 81a1dc3b-b13d-400b-aceb-764788c761c2 --- avrdude/ChangeLog | 4 +++ avrdude/ser_posix.c | 68 +++++++++++++++++++++++++++++++++++++++------ 2 files changed, 63 insertions(+), 9 deletions(-) diff --git a/avrdude/ChangeLog b/avrdude/ChangeLog index 1544e00c..10e1d139 100644 --- a/avrdude/ChangeLog +++ b/avrdude/ChangeLog @@ -1,3 +1,7 @@ +2003-03-23 Theodore A. Roth + + * ser_posix.c: Add verbose level > 3 output for send and recv functions. + 2003-03-23 Theodore A. Roth * avr.c: Add avr_read_byte_default(). diff --git a/avrdude/ser_posix.c b/avrdude/ser_posix.c index fea1c9b8..143308d1 100644 --- a/avrdude/ser_posix.c +++ b/avrdude/ser_posix.c @@ -34,6 +34,7 @@ #include extern char *progname; +extern int verbose; struct baud_mapping { long baud; @@ -156,13 +157,37 @@ int serial_send(int fd, char * buf, size_t buflen) int nfds; int rc; - if (!buflen) + char * p = buf; + size_t len = buflen; + + if (!len) 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_usec = 500000; - while (buflen) { + while (len) { FD_ZERO(&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) { fprintf(stderr, "%s: serial_send(): write error: %s\n", progname, strerror(errno)); exit(1); } - buf++; - buflen--; + p++; + len--; } return 0; @@ -206,10 +231,13 @@ int serial_recv(int fd, char * buf, size_t buflen) int nfds; int rc; + char * p = buf; + size_t len = 0; + timeout.tv_sec = 5; timeout.tv_usec = 0; - while (buflen) { + while (len < buflen) { FD_ZERO(&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) { fprintf(stderr, "%s: serial_recv(): read error: %s\n", progname, strerror(errno)); exit(1); } - buf++; - buflen--; + p++; + 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;