Make hexagram_can_if opaque
This commit is contained in:
parent
b0c23e7413
commit
6a4c99bce3
3 changed files with 30 additions and 9 deletions
|
@ -6,11 +6,7 @@
|
||||||
#include <linux/can.h>
|
#include <linux/can.h>
|
||||||
#include <linux/can/raw.h>
|
#include <linux/can/raw.h>
|
||||||
|
|
||||||
typedef struct _hexagram_can_if {
|
typedef struct _hexagram_can_if hexagram_can_if;
|
||||||
struct sockaddr_can addr;
|
|
||||||
struct ifreq ifr;
|
|
||||||
int sock;
|
|
||||||
} hexagram_can_if;
|
|
||||||
|
|
||||||
hexagram_can_if *hexagram_can_if_open(const char *name);
|
hexagram_can_if *hexagram_can_if_open(const char *name);
|
||||||
|
|
||||||
|
@ -22,4 +18,10 @@ int hexagram_can_if_read(hexagram_can_if *can_if,
|
||||||
int hexagram_can_if_write(hexagram_can_if *can_if,
|
int hexagram_can_if_write(hexagram_can_if *can_if,
|
||||||
struct can_frame *frame);
|
struct can_frame *frame);
|
||||||
|
|
||||||
|
int hexagram_can_if_fd(hexagram_can_if *can_if);
|
||||||
|
|
||||||
|
void hexagram_can_if_fd_set(hexagram_can_if *can_if, fd_set *fds);
|
||||||
|
|
||||||
|
int hexagram_can_if_fd_isset(hexagram_can_if *can_if, fd_set *fds);
|
||||||
|
|
||||||
#endif /* _HEXAGRAM_CAN_H */
|
#endif /* _HEXAGRAM_CAN_H */
|
||||||
|
|
18
src/can.c
18
src/can.c
|
@ -6,6 +6,12 @@
|
||||||
|
|
||||||
#include <hexagram/can.h>
|
#include <hexagram/can.h>
|
||||||
|
|
||||||
|
struct _hexagram_can_if {
|
||||||
|
struct sockaddr_can addr;
|
||||||
|
struct ifreq ifr;
|
||||||
|
int sock;
|
||||||
|
};
|
||||||
|
|
||||||
hexagram_can_if *hexagram_can_if_open(const char *name) {
|
hexagram_can_if *hexagram_can_if_open(const char *name) {
|
||||||
hexagram_can_if *can_if;
|
hexagram_can_if *can_if;
|
||||||
|
|
||||||
|
@ -65,3 +71,15 @@ int hexagram_can_if_write(hexagram_can_if *can_if,
|
||||||
struct can_frame *frame) {
|
struct can_frame *frame) {
|
||||||
return write(can_if->sock, frame, sizeof(*frame));
|
return write(can_if->sock, frame, sizeof(*frame));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int hexagram_can_if_fd(hexagram_can_if *can_if) {
|
||||||
|
return can_if->sock;
|
||||||
|
}
|
||||||
|
|
||||||
|
void hexagram_can_if_fd_set(hexagram_can_if *can_if, fd_set *fds) {
|
||||||
|
FD_SET(can_if->sock, fds);
|
||||||
|
}
|
||||||
|
|
||||||
|
int hexagram_can_if_fd_isset(hexagram_can_if *can_if, fd_set *fds) {
|
||||||
|
return FD_ISSET(can_if->sock, fds);
|
||||||
|
}
|
||||||
|
|
|
@ -141,11 +141,12 @@ error_gettimeofday:
|
||||||
int hexagram_capture_save(hexagram_capture *capture,
|
int hexagram_capture_save(hexagram_capture *capture,
|
||||||
hexagram_can_if *can_if) {
|
hexagram_can_if *can_if) {
|
||||||
struct can_frame frame;
|
struct can_frame frame;
|
||||||
|
int sock = hexagram_can_if_fd(can_if);
|
||||||
|
|
||||||
while (hexagram_can_if_read(can_if, &frame) > 0) {
|
while (hexagram_can_if_read(can_if, &frame) > 0) {
|
||||||
struct timeval timestamp;
|
struct timeval timestamp;
|
||||||
|
|
||||||
if (ioctl(can_if->sock, SIOCGSTAMP, ×tamp) < 0) {
|
if (ioctl(sock, SIOCGSTAMP, ×tamp) < 0) {
|
||||||
goto error_io;
|
goto error_io;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,12 +164,12 @@ error_io:
|
||||||
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) {
|
||||||
struct timeval timestamp;
|
|
||||||
|
|
||||||
uint64_t usec_last = 0,
|
uint64_t usec_last = 0,
|
||||||
usec;
|
usec;
|
||||||
|
|
||||||
|
struct timeval timestamp;
|
||||||
struct can_frame frame;
|
struct can_frame frame;
|
||||||
|
int sock = hexagram_can_if_fd(can_if);
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
ssize_t len = hexagram_capture_read(capture,
|
ssize_t len = hexagram_capture_read(capture,
|
||||||
|
@ -188,7 +189,7 @@ int hexagram_capture_replay(hexagram_capture *capture,
|
||||||
usleep(speed * (useconds_t)(usec - usec_last));
|
usleep(speed * (useconds_t)(usec - usec_last));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (write(can_if->sock, &frame, sizeof(struct can_frame)) < 0) {
|
if (write(sock, &frame, sizeof(struct can_frame)) < 0) {
|
||||||
goto error_io;
|
goto error_io;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue