Implement hexagram_capture_save(); use SIOCGTSTAMP
This commit is contained in:
parent
ff59b0c936
commit
07e138dac8
3 changed files with 29 additions and 6 deletions
|
@ -27,7 +27,6 @@ static void usage(int argc, char **argv, const char *message, ...) {
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
hexagram_can_if *can_if;
|
hexagram_can_if *can_if;
|
||||||
hexagram_capture *capture;
|
hexagram_capture *capture;
|
||||||
struct can_frame frame;
|
|
||||||
|
|
||||||
if (argc == 2) {
|
if (argc == 2) {
|
||||||
if ((capture = hexagram_capture_open_fd(fileno(stdin), O_WRONLY)) == NULL) {
|
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;
|
goto error_can_if_open;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (hexagram_can_if_read(can_if, &frame) >= 0) {
|
if (hexagram_capture_save(capture, can_if) < 0) {
|
||||||
if (hexagram_capture_write(capture, NULL, &frame) < 0) {
|
goto error_capture_save;
|
||||||
goto error_capture_write;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
hexagram_can_if_close(can_if);
|
hexagram_can_if_close(can_if);
|
||||||
|
@ -68,7 +65,7 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
error_capture_write:
|
error_capture_save:
|
||||||
hexagram_can_if_close(can_if);
|
hexagram_can_if_close(can_if);
|
||||||
|
|
||||||
error_can_if_open:
|
error_can_if_open:
|
||||||
|
|
|
@ -41,6 +41,9 @@ ssize_t hexagram_capture_write(hexagram_capture *capture,
|
||||||
struct timeval *timestamp,
|
struct timeval *timestamp,
|
||||||
struct can_frame *frame);
|
struct can_frame *frame);
|
||||||
|
|
||||||
|
int hexagram_capture_save(hexagram_capture *capture,
|
||||||
|
hexagram_can_if *can_if);
|
||||||
|
|
||||||
int hexagram_capture_replay(hexagram_capture *capture,
|
int hexagram_capture_replay(hexagram_capture *capture,
|
||||||
hexagram_can_if *can_if,
|
hexagram_can_if *can_if,
|
||||||
float speed);
|
float speed);
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
#include <net/if.h>
|
#include <net/if.h>
|
||||||
|
|
||||||
#include <hexagram/capture.h>
|
#include <hexagram/capture.h>
|
||||||
|
@ -137,6 +138,28 @@ error_gettimeofday:
|
||||||
return -1;
|
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, ×tamp) < 0) {
|
||||||
|
goto error_io;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hexagram_capture_write(capture, ×tamp, &frame) < 0) {
|
||||||
|
goto error_io;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
error_io:
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
int hexagram_capture_replay(hexagram_capture *capture,
|
int hexagram_capture_replay(hexagram_capture *capture,
|
||||||
hexagram_can_if *can_if,
|
hexagram_can_if *can_if,
|
||||||
float speed) {
|
float speed) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue