drivers/can_socket/can_socket.c
changeset 802 82e8646d08f5
parent 799 6d3ad380dcd3
child 804 4657af9ede34
equal deleted inserted replaced
801:32d146b64a35 802:82e8646d08f5
    29 #include "config.h"
    29 #include "config.h"
    30 
    30 
    31 #ifdef RTCAN_SOCKET
    31 #ifdef RTCAN_SOCKET
    32 #include "rtdm/can.h"
    32 #include "rtdm/can.h"
    33 #define CAN_IFNAME     "rtcan%s"
    33 #define CAN_IFNAME     "rtcan%s"
    34 #define CAN_SOCKET     rt_dev_socket
       
    35 #define CAN_CLOSE      rt_dev_close
       
    36 #define CAN_RECV       rt_dev_recv
       
    37 #define CAN_SEND       rt_dev_send
       
    38 #define CAN_BIND       rt_dev_bind
       
    39 #define CAN_IOCTL      rt_dev_ioctl
       
    40 #define CAN_SETSOCKOPT rt_dev_setsockopt
       
    41 #define CAN_ERRNO(err) (-err)
       
    42 #else
    34 #else
    43 #include <unistd.h>
    35 #include <unistd.h>
    44 #include <sys/socket.h>
    36 #include <sys/socket.h>
    45 #include <sys/ioctl.h>
    37 #include <sys/ioctl.h>
    46 #include "linux/can.h"
    38 #include "linux/can.h"
    52 #ifndef AF_CAN
    44 #ifndef AF_CAN
    53 #define AF_CAN PF_CAN
    45 #define AF_CAN PF_CAN
    54 #endif
    46 #endif
    55 //#include "af_can.h"
    47 //#include "af_can.h"
    56 #define CAN_IFNAME     "can%s"
    48 #define CAN_IFNAME     "can%s"
       
    49 #endif
       
    50 
    57 #define CAN_SOCKET     socket
    51 #define CAN_SOCKET     socket
    58 #define CAN_CLOSE      close
    52 #define CAN_CLOSE      close
    59 #define CAN_RECV       recv
    53 #define CAN_RECV       recv
    60 #define CAN_SEND       send
    54 #define CAN_SEND       send
    61 #define CAN_BIND       bind
    55 #define CAN_BIND       bind
    62 #define CAN_IOCTL      ioctl
    56 #define CAN_IOCTL      ioctl
       
    57 #define CAN_SETSOCKOPT setsockopt
    63 #define CAN_ERRNO(err) errno
    58 #define CAN_ERRNO(err) errno
    64 #define CAN_SETSOCKOPT setsockopt
       
    65 #endif
       
    66 
    59 
    67 #include "can_driver.h"
    60 #include "can_driver.h"
    68 
    61 
    69 /*********functions which permit to communicate with the board****************/
    62 /*********functions which permit to communicate with the board****************/
    70 UNS8
    63 UNS8
   208   {
   201   {
   209     int loopback = 1;
   202     int loopback = 1;
   210     err = CAN_SETSOCKOPT(*(int *)fd0, SOL_CAN_RAW, CAN_RAW_LOOPBACK,
   203     err = CAN_SETSOCKOPT(*(int *)fd0, SOL_CAN_RAW, CAN_RAW_LOOPBACK,
   211                &loopback, sizeof(loopback));
   204                &loopback, sizeof(loopback));
   212     if (err) {
   205     if (err) {
   213         fprintf(stderr, "rt_dev_setsockopt: %s\n", strerror (CAN_ERRNO (err)));
   206         fprintf(stderr, "setsockopt: %s\n", strerror (CAN_ERRNO (err)));
   214         goto error_close;
   207         goto error_close;
   215     }
   208     }
   216   }
   209   }
   217   
   210   
   218 #ifndef RTCAN_SOCKET /*CAN_RAW_RECV_OWN_MSGS not supported in rtsocketcan*/
   211 #ifndef RTCAN_SOCKET /*CAN_RAW_RECV_OWN_MSGS not supported in rtsocketcan*/
   219   {
   212   {
   220     int recv_own_msgs = 0; /* 0 = disabled (default), 1 = enabled */
   213     int recv_own_msgs = 0; /* 0 = disabled (default), 1 = enabled */
   221     err = CAN_SETSOCKOPT(*(int *)fd0, SOL_CAN_RAW, CAN_RAW_RECV_OWN_MSGS,
   214     err = CAN_SETSOCKOPT(*(int *)fd0, SOL_CAN_RAW, CAN_RAW_RECV_OWN_MSGS,
   222                &recv_own_msgs, sizeof(recv_own_msgs));
   215                &recv_own_msgs, sizeof(recv_own_msgs));
   223     if (err) {
   216     if (err) {
   224         fprintf(stderr, "rt_dev_setsockopt: %s\n", strerror (CAN_ERRNO (err)));
   217         fprintf(stderr, "setsockopt: %s\n", strerror (CAN_ERRNO (err)));
   225         goto error_close;
   218         goto error_close;
   226     }
   219     }
   227   }
   220   }
   228 #endif
   221 #endif
   229   
   222