drivers/can_socket/can_socket.c
changeset 631 08b6b903f84a
parent 603 4dc76e662412
child 796 1c87f7a8cb8a
equal deleted inserted replaced
630:96919642e99c 631:08b6b903f84a
    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_SETSOCKOPT rt_dev_setsockopt
    41 #define CAN_ERRNO(err) (-err)
    41 #define CAN_ERRNO(err) (-err)
    42 #else
    42 #else
       
    43 #include <unistd.h>
    43 #include <sys/socket.h>
    44 #include <sys/socket.h>
    44 #include <sys/ioctl.h>
    45 #include <sys/ioctl.h>
    45 #include "linux/can.h"
    46 #include "linux/can.h"
    46 #include "linux/can/raw.h"
    47 #include "linux/can/raw.h"
    47 #include "net/if.h"
    48 #include "net/if.h"
       
    49 #ifndef PF_CAN
    48 #define PF_CAN 29
    50 #define PF_CAN 29
       
    51 #endif
       
    52 #ifndef AF_CAN
    49 #define AF_CAN PF_CAN
    53 #define AF_CAN PF_CAN
       
    54 #endif
    50 //#include "af_can.h"
    55 //#include "af_can.h"
    51 #define CAN_IFNAME     "can%s"
    56 #define CAN_IFNAME     "can%s"
    52 #define CAN_SOCKET     socket
    57 #define CAN_SOCKET     socket
    53 #define CAN_CLOSE      close
    58 #define CAN_CLOSE      close
    54 #define CAN_RECV       recv
    59 #define CAN_RECV       recv
    91 }
    96 }
    92 
    97 
    93 
    98 
    94 /***************************************************************************/
    99 /***************************************************************************/
    95 UNS8
   100 UNS8
    96 canSend_driver (CAN_HANDLE fd0, Message * m)
   101 canSend_driver (CAN_HANDLE fd0, Message const * m)
    97 {
   102 {
    98   int res;
   103   int res;
    99   struct can_frame frame;
   104   struct can_frame frame;
   100 
   105 
   101   frame.can_id = m->cob_id;
   106   frame.can_id = m->cob_id;
   171   CAN_HANDLE fd0 = malloc (sizeof (int));
   176   CAN_HANDLE fd0 = malloc (sizeof (int));
   172 #ifdef RTCAN_SOCKET
   177 #ifdef RTCAN_SOCKET
   173   can_baudrate_t *baudrate;
   178   can_baudrate_t *baudrate;
   174   can_mode_t *mode;
   179   can_mode_t *mode;
   175 #endif
   180 #endif
       
   181 
       
   182   if(!fd0)
       
   183     {
       
   184       return NULL;
       
   185     }
   176 
   186 
   177   *(int *) fd0 = CAN_SOCKET (PF_CAN, SOCK_RAW, CAN_RAW);
   187   *(int *) fd0 = CAN_SOCKET (PF_CAN, SOCK_RAW, CAN_RAW);
   178   if (*(int *) fd0 < 0)
   188   if (*(int *) fd0 < 0)
   179     {
   189     {
   180       fprintf (stderr, "Socket creation failed: %s\n",
   190       fprintf (stderr, "Socket creation failed: %s\n",