2019-02-12 00:00:13 -06:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
2019-02-12 20:55:40 -06:00
|
|
|
#include <hexagram/can.h>
|
2019-02-12 00:00:13 -06:00
|
|
|
#include <hexagram/capture.h>
|
|
|
|
|
|
|
|
static void usage(int argc, char **argv, const char *message, ...) {
|
|
|
|
if (message) {
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args, message);
|
|
|
|
vfprintf(stderr, message, args);
|
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(stderr, "usage: %s canif [file.can]\n", argv[0]);
|
|
|
|
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
2019-02-12 20:55:40 -06:00
|
|
|
hexagram_can_if *can_if;
|
2019-02-12 00:00:13 -06:00
|
|
|
hexagram_capture *capture;
|
|
|
|
|
|
|
|
if (argc == 2) {
|
|
|
|
if ((capture = hexagram_capture_open_fd(fileno(stdin), O_RDONLY)) == NULL) {
|
2019-02-12 20:55:40 -06:00
|
|
|
perror("hexagram_capture_open_fd()");
|
|
|
|
|
2019-02-12 00:00:13 -06:00
|
|
|
goto error_capture_open;
|
|
|
|
}
|
|
|
|
} else if (argc == 3) {
|
|
|
|
if ((capture = hexagram_capture_open_file(argv[2], O_RDONLY)) == NULL) {
|
|
|
|
perror("hexagram_capture_open_file()");
|
|
|
|
|
|
|
|
goto error_capture_open;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
usage(argc, argv, NULL);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2019-02-12 20:55:40 -06:00
|
|
|
if ((can_if = hexagram_can_if_open(argv[1])) == NULL) {
|
|
|
|
perror("hexagram_can_if_open()");
|
2019-02-12 00:00:13 -06:00
|
|
|
|
2019-02-12 20:55:40 -06:00
|
|
|
goto error_can_if_open;
|
2019-02-12 00:00:13 -06:00
|
|
|
}
|
|
|
|
|
2019-02-20 21:44:40 -06:00
|
|
|
if (hexagram_capture_replay(capture, can_if, 1.0) < 0) {
|
2019-02-12 20:55:40 -06:00
|
|
|
perror("hexagram_capture_replay()");
|
2019-02-12 00:00:13 -06:00
|
|
|
|
|
|
|
goto error_capture_replay;
|
|
|
|
}
|
|
|
|
|
2019-02-12 20:55:40 -06:00
|
|
|
hexagram_can_if_close(can_if);
|
2019-02-12 00:00:13 -06:00
|
|
|
|
|
|
|
if (argc == 3) {
|
|
|
|
hexagram_capture_close(capture);
|
2019-02-12 20:55:40 -06:00
|
|
|
} else {
|
|
|
|
hexagram_capture_destroy(capture);
|
2019-02-12 00:00:13 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
error_capture_replay:
|
2019-02-12 20:55:40 -06:00
|
|
|
hexagram_can_if_close(can_if);
|
2019-02-12 00:00:13 -06:00
|
|
|
|
2019-02-12 20:55:40 -06:00
|
|
|
error_can_if_open:
|
2019-02-12 00:00:13 -06:00
|
|
|
if (argc == 3) {
|
|
|
|
hexagram_capture_close(capture);
|
2019-02-12 20:55:40 -06:00
|
|
|
} else {
|
|
|
|
hexagram_capture_destroy(capture);
|
2019-02-12 00:00:13 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
error_capture_open:
|
|
|
|
return 1;
|
|
|
|
}
|