Merge pull request #1866 from yschroeder/pull-req/serialdump
Improved serialdump.c
This commit is contained in:
commit
af4f1e1c30
|
@ -8,6 +8,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
#define BAUDRATE B115200
|
#define BAUDRATE B115200
|
||||||
#define BAUDRATE_S "115200"
|
#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
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
signal(SIGINT, intHandler);
|
||||||
|
|
||||||
struct termios options;
|
struct termios options;
|
||||||
fd_set mask, smask;
|
fd_set mask, smask;
|
||||||
int fd;
|
int fd;
|
||||||
|
@ -208,6 +217,8 @@ main(int argc, char **argv)
|
||||||
options.c_cflag |= CS8;
|
options.c_cflag |= CS8;
|
||||||
|
|
||||||
/* Raw input */
|
/* Raw input */
|
||||||
|
options.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP
|
||||||
|
| INLCR | IGNCR | ICRNL | IXON);
|
||||||
options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
|
options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
|
||||||
/* Raw output */
|
/* Raw output */
|
||||||
options.c_oflag &= ~OPOST;
|
options.c_oflag &= ~OPOST;
|
||||||
|
@ -279,6 +290,11 @@ main(int argc, char **argv)
|
||||||
perror("could not read");
|
perror("could not read");
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
if(n == 0) {
|
||||||
|
errno = EBADF;
|
||||||
|
perror("serial device disconnected");
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
for(i = 0; i < n; i++) {
|
for(i = 0; i < n; i++) {
|
||||||
switch(mode) {
|
switch(mode) {
|
||||||
|
|
Loading…
Reference in a new issue