diff --git a/bin/Makefile b/bin/Makefile index c93983a..70a9584 100644 --- a/bin/Makefile +++ b/bin/Makefile @@ -10,7 +10,7 @@ STATIC = ../src/libhexagram.a OBJS = capture.o can2dump.o replay.o pcapreplay.o pcap2can.o main.o NAME = hexagram -RM = /bin/rm +RM = rm all: $(NAME) diff --git a/bin/can2dump.c b/bin/can2dump.c index 84e1527..50ee6e4 100644 --- a/bin/can2dump.c +++ b/bin/can2dump.c @@ -14,7 +14,7 @@ char *hexagram_arglist_can2dump(void) { return "ifname [file.can] [candump.txt]"; } -static void usage(int argc, char **argv, const char *message, ...) { +static int usage(int argc, char **argv, const char *message, ...) { if (message) { va_list args; @@ -25,34 +25,22 @@ static void usage(int argc, char **argv, const char *message, ...) { fprintf(stderr, "usage: hexagram %s %s\n", argv[0], hexagram_arglist_can2dump()); - exit(1); -} - -static int convert(hexagram_capture *capture, const char *file, const char *ifname) { - struct timeval timestamp; - struct can_frame frame; - - FILE *fh; - - if ((fh = fopen(file, "w")) == NULL) { - goto error_fopen; - } - - while (hexagram_capture_read(capture, ×tamp, &frame) >= 0) { - - } - - fclose(fh); - - return 0; - -error_fopen: - return -1; + return 1; } int hexagram_main_can2dump(int argc, char **argv) { - hexagram_can_if *can_if; hexagram_capture *capture; + const char *ifname; + FILE *fh; + + struct timeval timestamp; + struct can_frame frame; + + if (argc <= 1) { + return usage(argc, argv, "No CAN interface name provided"); + } + + ifname = argv[1]; if (argc == 2) { if ((capture = hexagram_capture_open_fd(fileno(stdin), O_RDONLY)) == NULL) { @@ -60,47 +48,51 @@ int hexagram_main_can2dump(int argc, char **argv) { goto error_capture_open; } + + fh = stdout; } else if (argc == 3) { if ((capture = hexagram_capture_open_file(argv[2], O_RDONLY)) == NULL) { perror("hexagram_capture_open_file()"); goto error_capture_open; } + + fh = stdout; + } else if (argc == 4) { + if ((capture = hexagram_capture_open_file(argv[2], O_RDONLY)) == NULL) { + perror("hexagram_capture_open_file()"); + + goto error_capture_open; + } + + if ((fh = fopen(argv[3], "w")) == NULL) { + goto error_fopen; + } } else { usage(argc, argv, NULL); exit(1); } - if ((can_if = hexagram_can_if_open(argv[1])) == NULL) { - perror("hexagram_can_if_open()"); - - goto error_can_if_open; + while (hexagram_capture_read(capture, ×tamp, &frame) >= 0) { + fprintf(fh, "%s 0x%x %02x %02x %02x %02x %02x %02x %02x %02x\n", + ifname, frame.can_id, + frame.data[0], frame.data[1], frame.data[2], frame.data[3], + frame.data[4], frame.data[5], frame.data[6], frame.data[7]); } - if (hexagram_capture_can2dump(capture, can_if, 1.0) < 0) { - perror("hexagram_capture_can2dump()"); - - goto error_capture_can2dump; - } - - hexagram_can_if_close(can_if); - - if (argc == 3) { - hexagram_capture_close(capture); - } else { + if (argc == 2) { hexagram_capture_destroy(capture); + } else if (argc >= 3) { + hexagram_capture_close(capture); } return 0; -error_capture_can2dump: - hexagram_can_if_close(can_if); - -error_can_if_open: - if (argc == 3) { - hexagram_capture_close(capture); - } else { +error_fopen: + if (argc == 2) { hexagram_capture_destroy(capture); + } else if (argc >= 3) { + hexagram_capture_close(capture); } error_capture_open: diff --git a/examples/Makefile b/examples/Makefile index cb2a172..9a51fd1 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -10,7 +10,7 @@ STATIC = ../src/libhexagram.a EXAMPLES = view -RM = /bin/rm +RM = rm all: $(EXAMPLES) diff --git a/include/hexagram/can.h b/include/hexagram/can.h index ac97a5a..7ff6fdc 100644 --- a/include/hexagram/can.h +++ b/include/hexagram/can.h @@ -1,6 +1,7 @@ #ifndef _HEXAGRAM_CAN_H #define _HEXAGRAM_CAN_H +#include #include #include diff --git a/src/Makefile b/src/Makefile index e2194d9..c0f97d9 100644 --- a/src/Makefile +++ b/src/Makefile @@ -23,10 +23,10 @@ HEADERS_BUILD = $(addprefix $(INCLUDE_PATH)/$(HEADER_SUBDIR)/, $(HEADERS)) AR = $(CROSS)ar RANLIB = $(CROSS)ranlib -RM = /bin/rm -LN = /bin/ln -RMDIR = /bin/rmdir -INSTALL = /usr/bin/install +RM = rm +LN = ln +RMDIR = rmdir +INSTALL = install all: $(STATIC) $(SONAME_FULL) $(SONAME) $(SONAME_SHORT)