Implement hexagram_capture_save(); use SIOCGTSTAMP

This commit is contained in:
XANTRONIX Development 2019-02-27 20:19:31 -06:00
parent ff59b0c936
commit 07e138dac8
3 changed files with 29 additions and 6 deletions

View file

@ -27,7 +27,6 @@ static void usage(int argc, char **argv, const char *message, ...) {
int main(int argc, char **argv) {
hexagram_can_if *can_if;
hexagram_capture *capture;
struct can_frame frame;
if (argc == 2) {
if ((capture = hexagram_capture_open_fd(fileno(stdin), O_WRONLY)) == NULL) {
@ -52,10 +51,8 @@ int main(int argc, char **argv) {
goto error_can_if_open;
}
while (hexagram_can_if_read(can_if, &frame) >= 0) {
if (hexagram_capture_write(capture, NULL, &frame) < 0) {
goto error_capture_write;
}
if (hexagram_capture_save(capture, can_if) < 0) {
goto error_capture_save;
}
hexagram_can_if_close(can_if);
@ -68,7 +65,7 @@ int main(int argc, char **argv) {
return 0;
error_capture_write:
error_capture_save:
hexagram_can_if_close(can_if);
error_can_if_open:

View file

@ -41,6 +41,9 @@ ssize_t hexagram_capture_write(hexagram_capture *capture,
struct timeval *timestamp,
struct can_frame *frame);
int hexagram_capture_save(hexagram_capture *capture,
hexagram_can_if *can_if);
int hexagram_capture_replay(hexagram_capture *capture,
hexagram_can_if *can_if,
float speed);

View file

@ -4,6 +4,7 @@
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <hexagram/capture.h>
@ -137,6 +138,28 @@ error_gettimeofday:
return -1;
}
int hexagram_capture_save(hexagram_capture *capture,
hexagram_can_if *can_if) {
struct can_frame frame;
while (hexagram_can_if_read(can_if, &frame) >= 0) {
struct timeval timestamp;
if (ioctl(can_if->sock, SIOCGSTAMP, &timestamp) < 0) {
goto error_io;
}
if (hexagram_capture_write(capture, &timestamp, &frame) < 0) {
goto error_io;
}
}
return 0;
error_io:
return -1;
}
int hexagram_capture_replay(hexagram_capture *capture,
hexagram_can_if *can_if,
float speed) {