mirror of
https://github.com/oliverschmidt/contiki.git
synced 2025-02-11 23:31:10 +00:00
Merge pull request #1048 from cmorty/pull/serialdump
Fix and clean up serialdump.c
This commit is contained in:
commit
f45c6ad1b0
@ -22,4 +22,4 @@ endif
|
||||
all: $(SERIALDUMP)
|
||||
|
||||
$(SERIALDUMP): serialdump.c
|
||||
$(CC) -o $@ $<
|
||||
$(CC) -O2 -o $@ $<
|
||||
|
Binary file not shown.
@ -1,3 +1,4 @@
|
||||
#define _GNU_SOURCE
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <termios.h>
|
||||
@ -6,9 +7,10 @@
|
||||
#include <sys/time.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#define BAUDRATE B57600
|
||||
#define BAUDRATE_S "57600"
|
||||
#define BAUDRATE B115200
|
||||
#define BAUDRATE_S "115200"
|
||||
#ifdef linux
|
||||
#define MODEMDEVICE "/dev/ttyS0"
|
||||
#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;
|
||||
fd_set mask, smask;
|
||||
@ -161,14 +164,17 @@ int main(int argc, char **argv)
|
||||
}
|
||||
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);
|
||||
if(fd < 0 && errno == EINVAL){ // O_SYNC not supported (e.g. raspberian)
|
||||
fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY | O_DIRECT);
|
||||
}
|
||||
#else
|
||||
fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY | O_SYNC );
|
||||
#endif
|
||||
if(fd < 0) {
|
||||
fprintf(stderr, "\n");
|
||||
perror(device);
|
||||
perror("open");
|
||||
exit(-1);
|
||||
}
|
||||
fprintf(stderr, " [OK]\n");
|
||||
@ -215,8 +221,7 @@ int main(int argc, char **argv)
|
||||
index = 0;
|
||||
for(;;) {
|
||||
smask = mask;
|
||||
nfound = select(FD_SETSIZE, &smask, (fd_set *) 0, (fd_set *) 0,
|
||||
(struct timeval *) 0);
|
||||
nfound = select(FD_SETSIZE, &smask, (fd_set *) 0, (fd_set *) 0, (struct timeval *) 0);
|
||||
if(nfound < 0) {
|
||||
if(errno == EINTR) {
|
||||
fprintf(stderr, "interrupted system call\n");
|
||||
@ -320,8 +325,7 @@ int main(int argc, char **argv)
|
||||
if(index > 0) {
|
||||
if(flags != 2 && mode != MODE_SLIP_HIDE) {
|
||||
/* not overflowed: show packet */
|
||||
print_hex_line("SLIP: ", rxbuf,
|
||||
index > HCOLS ? HCOLS : index);
|
||||
print_hex_line("SLIP: ", rxbuf, index > HCOLS ? HCOLS : index);
|
||||
printf("\n");
|
||||
}
|
||||
lastc = '\0';
|
||||
|
Loading…
x
Reference in New Issue
Block a user