drivers/can_socket/can_socket.c
changeset 807 46027bb24429
parent 805 570e3a444023
equal deleted inserted replaced
806:b9f1fcda7d30 807:46027bb24429
    52 
    52 
    53 /*********functions which permit to communicate with the board****************/
    53 /*********functions which permit to communicate with the board****************/
    54 UNS8
    54 UNS8
    55 canReceive_driver (CAN_HANDLE fd0, Message * m)
    55 canReceive_driver (CAN_HANDLE fd0, Message * m)
    56 {
    56 {
    57   int res;
    57   int res = 0;
    58   struct can_frame frame;
    58   struct can_frame frame;
    59 
    59 
    60   res = recv (*(int *) fd0, &frame, sizeof (frame), 0);
    60   while (res <= 0) {
    61   if (res <= 0)
    61     res = recv (*(int *) fd0, &frame, sizeof (frame), 0);
    62     {
    62     if (res < 0)
    63       fprintf (stderr, "Recv failed: %s\n", strerror (errno));
    63     {
    64       return 1;
    64         if (errno == EBADF)
    65     }
    65         {
    66 
    66             /* this will exit recieve loop */
       
    67             return 1;
       
    68         }
       
    69         else if (errno == EINTR) continue; /* retry immediatly */
       
    70         else
       
    71         {
       
    72             /* print error and retry after 20ms, arbitrary */
       
    73             fprintf (stderr, "Recv failed: %s\n", strerror (errno));
       
    74             usleep(20000);
       
    75             continue;
       
    76         }
       
    77     }
       
    78     else if (res == 0)
       
    79     {
       
    80         /* this will exit recieve loop */
       
    81         return 1;
       
    82     }
       
    83   } 
    67   m->cob_id = frame.can_id & CAN_EFF_MASK;
    84   m->cob_id = frame.can_id & CAN_EFF_MASK;
    68   m->len = frame.can_dlc;
    85   m->len = frame.can_dlc;
    69   if (frame.can_id & CAN_RTR_FLAG)
    86   if (frame.can_id & CAN_RTR_FLAG)
    70     m->rtr = 1;
    87     m->rtr = 1;
    71   else
    88   else