35 #define CAN_CLOSE rt_dev_close |
35 #define CAN_CLOSE rt_dev_close |
36 #define CAN_RECV rt_dev_recv |
36 #define CAN_RECV rt_dev_recv |
37 #define CAN_SEND rt_dev_send |
37 #define CAN_SEND rt_dev_send |
38 #define CAN_BIND rt_dev_bind |
38 #define CAN_BIND rt_dev_bind |
39 #define CAN_IOCTL rt_dev_ioctl |
39 #define CAN_IOCTL rt_dev_ioctl |
|
40 #define CAN_SETSOCKOPT rt_dev_setsockopt |
40 #define CAN_ERRNO(err) (-err) |
41 #define CAN_ERRNO(err) (-err) |
41 #else |
42 #else |
42 #include <sys/socket.h> |
43 #include <sys/socket.h> |
43 #include <sys/ioctl.h> |
44 #include <sys/ioctl.h> |
44 #include "linux/can.h" |
45 #include "linux/can.h" |
53 #define CAN_RECV recv |
54 #define CAN_RECV recv |
54 #define CAN_SEND send |
55 #define CAN_SEND send |
55 #define CAN_BIND bind |
56 #define CAN_BIND bind |
56 #define CAN_IOCTL ioctl |
57 #define CAN_IOCTL ioctl |
57 #define CAN_ERRNO(err) errno |
58 #define CAN_ERRNO(err) errno |
|
59 #define CAN_SETSOCKOPT setsockopt |
58 #endif |
60 #endif |
59 |
61 |
60 #include "can_driver.h" |
62 #include "can_driver.h" |
61 |
63 |
62 /*********functions which permit to communicate with the board****************/ |
64 /*********functions which permit to communicate with the board****************/ |
192 goto error_close; |
194 goto error_close; |
193 } |
195 } |
194 |
196 |
195 { |
197 { |
196 int loopback = 1; |
198 int loopback = 1; |
197 setsockopt(*(int *)fd0, SOL_CAN_RAW, CAN_RAW_LOOPBACK, |
199 err = CAN_SETSOCKOPT(*(int *)fd0, SOL_CAN_RAW, CAN_RAW_LOOPBACK, |
198 &loopback, sizeof(loopback)); |
200 &loopback, sizeof(loopback)); |
|
201 if (err) { |
|
202 fprintf(stderr, "rt_dev_setsockopt: %s\n", strerror (CAN_ERRNO (err))); |
|
203 goto failure; |
|
204 } |
199 } |
205 } |
200 |
206 |
|
207 #ifndef RTCAN_SOCKET /*CAN_RAW_RECV_OWN_MSGS not supported in rtsocketcan*/ |
201 { |
208 { |
202 int recv_own_msgs = 0; /* 0 = disabled (default), 1 = enabled */ |
209 int recv_own_msgs = 0; /* 0 = disabled (default), 1 = enabled */ |
203 |
210 err = CAN_SETSOCKOPT(*(int *)fd0, SOL_CAN_RAW, CAN_RAW_RECV_OWN_MSGS, |
204 setsockopt(*(int *)fd0, SOL_CAN_RAW, CAN_RAW_RECV_OWN_MSGS, |
|
205 &recv_own_msgs, sizeof(recv_own_msgs)); |
211 &recv_own_msgs, sizeof(recv_own_msgs)); |
|
212 if (err) { |
|
213 fprintf(stderr, "rt_dev_setsockopt: %s\n", strerror (CAN_ERRNO (err))); |
|
214 goto failure; |
|
215 } |
206 } |
216 } |
|
217 #endif |
207 |
218 |
208 addr.can_family = AF_CAN; |
219 addr.can_family = AF_CAN; |
209 addr.can_ifindex = ifr.ifr_ifindex; |
220 addr.can_ifindex = ifr.ifr_ifindex; |
210 err = CAN_BIND (*(int *) fd0, (struct sockaddr *) &addr, sizeof (addr)); |
221 err = CAN_BIND (*(int *) fd0, (struct sockaddr *) &addr, sizeof (addr)); |
211 if (err) |
222 if (err) |