Merge pull request #1048 from cmorty/pull/serialdump
Fix and clean up serialdump.c
This commit is contained in:
commit
f45c6ad1b0
3 changed files with 219 additions and 215 deletions
|
@ -22,4 +22,4 @@ endif
|
||||||
all: $(SERIALDUMP)
|
all: $(SERIALDUMP)
|
||||||
|
|
||||||
$(SERIALDUMP): serialdump.c
|
$(SERIALDUMP): serialdump.c
|
||||||
$(CC) -o $@ $<
|
$(CC) -O2 -o $@ $<
|
||||||
|
|
Binary file not shown.
|
@ -1,3 +1,4 @@
|
||||||
|
#define _GNU_SOURCE
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
|
@ -6,9 +7,10 @@
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
#define BAUDRATE B57600
|
#define BAUDRATE B115200
|
||||||
#define BAUDRATE_S "57600"
|
#define BAUDRATE_S "115200"
|
||||||
#ifdef linux
|
#ifdef linux
|
||||||
#define MODEMDEVICE "/dev/ttyS0"
|
#define MODEMDEVICE "/dev/ttyS0"
|
||||||
#else
|
#else
|
||||||
|
@ -80,7 +82,8 @@ print_hex_line(unsigned char *prefix, unsigned char *outbuf, int index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int
|
||||||
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
struct termios options;
|
struct termios options;
|
||||||
fd_set mask, smask;
|
fd_set mask, smask;
|
||||||
|
@ -161,14 +164,17 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
fprintf(stderr, "connecting to %s (%s)", device, speedname);
|
fprintf(stderr, "connecting to %s (%s)", device, speedname);
|
||||||
|
|
||||||
#ifndef __APPLE__
|
#ifdef O_SYNC
|
||||||
fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY | O_DIRECT | O_SYNC);
|
fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY | O_DIRECT | O_SYNC);
|
||||||
|
if(fd < 0 && errno == EINVAL){ // O_SYNC not supported (e.g. raspberian)
|
||||||
|
fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY | O_DIRECT);
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY | O_SYNC );
|
fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY | O_SYNC );
|
||||||
#endif
|
#endif
|
||||||
if(fd < 0) {
|
if(fd < 0) {
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
perror(device);
|
perror("open");
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
fprintf(stderr, " [OK]\n");
|
fprintf(stderr, " [OK]\n");
|
||||||
|
@ -215,8 +221,7 @@ int main(int argc, char **argv)
|
||||||
index = 0;
|
index = 0;
|
||||||
for(;;) {
|
for(;;) {
|
||||||
smask = mask;
|
smask = mask;
|
||||||
nfound = select(FD_SETSIZE, &smask, (fd_set *) 0, (fd_set *) 0,
|
nfound = select(FD_SETSIZE, &smask, (fd_set *) 0, (fd_set *) 0, (struct timeval *) 0);
|
||||||
(struct timeval *) 0);
|
|
||||||
if(nfound < 0) {
|
if(nfound < 0) {
|
||||||
if(errno == EINTR) {
|
if(errno == EINTR) {
|
||||||
fprintf(stderr, "interrupted system call\n");
|
fprintf(stderr, "interrupted system call\n");
|
||||||
|
@ -320,8 +325,7 @@ int main(int argc, char **argv)
|
||||||
if(index > 0) {
|
if(index > 0) {
|
||||||
if(flags != 2 && mode != MODE_SLIP_HIDE) {
|
if(flags != 2 && mode != MODE_SLIP_HIDE) {
|
||||||
/* not overflowed: show packet */
|
/* not overflowed: show packet */
|
||||||
print_hex_line("SLIP: ", rxbuf,
|
print_hex_line("SLIP: ", rxbuf, index > HCOLS ? HCOLS : index);
|
||||||
index > HCOLS ? HCOLS : index);
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
lastc = '\0';
|
lastc = '\0';
|
||||||
|
|
Loading…
Add table
Reference in a new issue