Merge pull request #1866 from yschroeder/pull-req/serialdump

Improved serialdump.c
This commit is contained in:
Antonio Lignan 2016-12-04 13:17:39 +01:00 committed by GitHub
commit af4f1e1c30

View File

@ -8,6 +8,7 @@
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <signal.h>
#define BAUDRATE B115200
#define BAUDRATE_S "115200"
@ -82,9 +83,17 @@ print_hex_line(char *prefix, unsigned char *outbuf, int index)
}
}
static void
intHandler(int sig)
{
exit(0);
}
int
main(int argc, char **argv)
{
signal(SIGINT, intHandler);
struct termios options;
fd_set mask, smask;
int fd;
@ -208,6 +217,8 @@ main(int argc, char **argv)
options.c_cflag |= CS8;
/* Raw input */
options.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP
| INLCR | IGNCR | ICRNL | IXON);
options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
/* Raw output */
options.c_oflag &= ~OPOST;
@ -279,6 +290,11 @@ main(int argc, char **argv)
perror("could not read");
exit(-1);
}
if(n == 0) {
errno = EBADF;
perror("serial device disconnected");
exit(-1);
}
for(i = 0; i < n; i++) {
switch(mode) {