Thanks Gemini!

This commit is contained in:
XANTRONIX Development 2019-05-23 01:20:05 -05:00
parent ebad5379dd
commit f1388e93bd
5 changed files with 46 additions and 53 deletions

View file

@ -10,7 +10,7 @@ STATIC = ../src/libhexagram.a
OBJS = capture.o can2dump.o replay.o pcapreplay.o pcap2can.o main.o OBJS = capture.o can2dump.o replay.o pcapreplay.o pcap2can.o main.o
NAME = hexagram NAME = hexagram
RM = /bin/rm RM = rm
all: $(NAME) all: $(NAME)

View file

@ -14,7 +14,7 @@ char *hexagram_arglist_can2dump(void) {
return "ifname [file.can] [candump.txt]"; 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) { if (message) {
va_list args; 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()); fprintf(stderr, "usage: hexagram %s %s\n", argv[0], hexagram_arglist_can2dump());
exit(1); return 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, &timestamp, &frame) >= 0) {
}
fclose(fh);
return 0;
error_fopen:
return -1;
} }
int hexagram_main_can2dump(int argc, char **argv) { int hexagram_main_can2dump(int argc, char **argv) {
hexagram_can_if *can_if;
hexagram_capture *capture; 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 (argc == 2) {
if ((capture = hexagram_capture_open_fd(fileno(stdin), O_RDONLY)) == NULL) { 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; goto error_capture_open;
} }
fh = stdout;
} else if (argc == 3) { } else if (argc == 3) {
if ((capture = hexagram_capture_open_file(argv[2], O_RDONLY)) == NULL) { if ((capture = hexagram_capture_open_file(argv[2], O_RDONLY)) == NULL) {
perror("hexagram_capture_open_file()"); perror("hexagram_capture_open_file()");
goto error_capture_open; 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 { } else {
usage(argc, argv, NULL); usage(argc, argv, NULL);
exit(1); exit(1);
} }
if ((can_if = hexagram_can_if_open(argv[1])) == NULL) { while (hexagram_capture_read(capture, &timestamp, &frame) >= 0) {
perror("hexagram_can_if_open()"); fprintf(fh, "%s 0x%x %02x %02x %02x %02x %02x %02x %02x %02x\n",
ifname, frame.can_id,
goto error_can_if_open; 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) { if (argc == 2) {
perror("hexagram_capture_can2dump()");
goto error_capture_can2dump;
}
hexagram_can_if_close(can_if);
if (argc == 3) {
hexagram_capture_close(capture);
} else {
hexagram_capture_destroy(capture); hexagram_capture_destroy(capture);
} else if (argc >= 3) {
hexagram_capture_close(capture);
} }
return 0; return 0;
error_capture_can2dump: error_fopen:
hexagram_can_if_close(can_if); if (argc == 2) {
error_can_if_open:
if (argc == 3) {
hexagram_capture_close(capture);
} else {
hexagram_capture_destroy(capture); hexagram_capture_destroy(capture);
} else if (argc >= 3) {
hexagram_capture_close(capture);
} }
error_capture_open: error_capture_open:

View file

@ -10,7 +10,7 @@ STATIC = ../src/libhexagram.a
EXAMPLES = view EXAMPLES = view
RM = /bin/rm RM = rm
all: $(EXAMPLES) all: $(EXAMPLES)

View file

@ -1,6 +1,7 @@
#ifndef _HEXAGRAM_CAN_H #ifndef _HEXAGRAM_CAN_H
#define _HEXAGRAM_CAN_H #define _HEXAGRAM_CAN_H
#include <sys/select.h>
#include <net/if.h> #include <net/if.h>
#include <linux/can.h> #include <linux/can.h>

View file

@ -23,10 +23,10 @@ HEADERS_BUILD = $(addprefix $(INCLUDE_PATH)/$(HEADER_SUBDIR)/, $(HEADERS))
AR = $(CROSS)ar AR = $(CROSS)ar
RANLIB = $(CROSS)ranlib RANLIB = $(CROSS)ranlib
RM = /bin/rm RM = rm
LN = /bin/ln LN = ln
RMDIR = /bin/rmdir RMDIR = rmdir
INSTALL = /usr/bin/install INSTALL = install
all: $(STATIC) $(SONAME_FULL) $(SONAME) $(SONAME_SHORT) all: $(STATIC) $(SONAME_FULL) $(SONAME) $(SONAME_SHORT)