Skip to content

Commit

Permalink
Read multiple bytes from serial port
Browse files Browse the repository at this point in the history
Don't read a single byte at a time from the serial port. Read
multiple (up to TTY_RD_SZ = 128) bytes with a single read(2) call. Also
write multiple bytes to the terminal (STO) with a single write(2) call.
  • Loading branch information
npat-efault committed Oct 23, 2015
1 parent 1b8a9e4 commit 764b86c
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions picocom.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ struct tty_q {
unsigned char buff[TTY_Q_SZ];
} tty_q;

#define TTY_RD_SZ 128

int tty_write_sz;

#define TTY_WRITE_SZ_DIV 10
Expand Down Expand Up @@ -1140,18 +1142,28 @@ loop(void)

if ( FD_ISSET(tty_fd, &rdset) ) {

char buff_rd[TTY_RD_SZ];
char buff_map[TTY_RD_SZ * M_MAXMAP];

/* read from port */

do {
n = read(tty_fd, &c, 1);
n = read(tty_fd, &buff_rd, sizeof(buff_rd));
} while (n < 0 && errno == EINTR);
if (n == 0) {
fatal("term closed");
} else if ( n < 0 ) {
if ( errno != EAGAIN && errno != EWOULDBLOCK )
fatal("read from term failed: %s", strerror(errno));
} else {
map_and_write(STO, opts.imap, c);
int i;
char *bmp = &buff_map[0];
for (i = 0; i < n; i++) {
bmp += do_map(bmp, opts.imap, buff_rd[i]);
}
n = bmp - buff_map;
if ( writen_ni(STO, buff_map, n) < n )
fatal("write to stdout failed: %s", strerror(errno));
}
}

Expand Down

0 comments on commit 764b86c

Please sign in to comment.