drivers/can_socket/can_socket.c
author Edouard Tisserant
Thu, 24 Jan 2019 13:49:40 +0100
changeset 807 46027bb24429
parent 805 570e3a444023
permissions -rw-r--r--
Rewrite of timer_xeno.c to use POSIX API instead of Alchemy.
47
8a1047ab51f4 SOCKET-CAN support added. Many thanks to Jan Kiszka !
etisserant
parents:
diff changeset
     1
/*
8a1047ab51f4 SOCKET-CAN support added. Many thanks to Jan Kiszka !
etisserant
parents:
diff changeset
     2
This file is part of CanFestival, a library implementing CanOpen Stack.
8a1047ab51f4 SOCKET-CAN support added. Many thanks to Jan Kiszka !
etisserant
parents:
diff changeset
     3
8a1047ab51f4 SOCKET-CAN support added. Many thanks to Jan Kiszka !
etisserant
parents:
diff changeset
     4
Copyright (C): Edouard TISSERANT and Francis DUPIN
8a1047ab51f4 SOCKET-CAN support added. Many thanks to Jan Kiszka !
etisserant
parents:
diff changeset
     5
8a1047ab51f4 SOCKET-CAN support added. Many thanks to Jan Kiszka !
etisserant
parents:
diff changeset
     6
See COPYING file for copyrights details.
8a1047ab51f4 SOCKET-CAN support added. Many thanks to Jan Kiszka !
etisserant
parents:
diff changeset
     7
8a1047ab51f4 SOCKET-CAN support added. Many thanks to Jan Kiszka !
etisserant
parents:
diff changeset
     8
This library is free software; you can redistribute it and/or
8a1047ab51f4 SOCKET-CAN support added. Many thanks to Jan Kiszka !
etisserant
parents:
diff changeset
     9
modify it under the terms of the GNU Lesser General Public
8a1047ab51f4 SOCKET-CAN support added. Many thanks to Jan Kiszka !
etisserant
parents:
diff changeset
    10
License as published by the Free Software Foundation; either
8a1047ab51f4 SOCKET-CAN support added. Many thanks to Jan Kiszka !
etisserant
parents:
diff changeset
    11
version 2.1 of the License, or (at your option) any later version.
8a1047ab51f4 SOCKET-CAN support added. Many thanks to Jan Kiszka !
etisserant
parents:
diff changeset
    12
8a1047ab51f4 SOCKET-CAN support added. Many thanks to Jan Kiszka !
etisserant
parents:
diff changeset
    13
This library is distributed in the hope that it will be useful,
8a1047ab51f4 SOCKET-CAN support added. Many thanks to Jan Kiszka !
etisserant
parents:
diff changeset
    14
but WITHOUT ANY WARRANTY; without even the implied warranty of
8a1047ab51f4 SOCKET-CAN support added. Many thanks to Jan Kiszka !
etisserant
parents:
diff changeset
    15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
8a1047ab51f4 SOCKET-CAN support added. Many thanks to Jan Kiszka !
etisserant
parents:
diff changeset
    16
Lesser General Public License for more details.
8a1047ab51f4 SOCKET-CAN support added. Many thanks to Jan Kiszka !
etisserant
parents:
diff changeset
    17
8a1047ab51f4 SOCKET-CAN support added. Many thanks to Jan Kiszka !
etisserant
parents:
diff changeset
    18
You should have received a copy of the GNU Lesser General Public
8a1047ab51f4 SOCKET-CAN support added. Many thanks to Jan Kiszka !
etisserant
parents:
diff changeset
    19
License along with this library; if not, write to the Free Software
8a1047ab51f4 SOCKET-CAN support added. Many thanks to Jan Kiszka !
etisserant
parents:
diff changeset
    20
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
8a1047ab51f4 SOCKET-CAN support added. Many thanks to Jan Kiszka !
etisserant
parents:
diff changeset
    21
*/
8a1047ab51f4 SOCKET-CAN support added. Many thanks to Jan Kiszka !
etisserant
parents:
diff changeset
    22
8a1047ab51f4 SOCKET-CAN support added. Many thanks to Jan Kiszka !
etisserant
parents:
diff changeset
    23
#include <stdio.h>
8a1047ab51f4 SOCKET-CAN support added. Many thanks to Jan Kiszka !
etisserant
parents:
diff changeset
    24
#include <string.h>
8a1047ab51f4 SOCKET-CAN support added. Many thanks to Jan Kiszka !
etisserant
parents:
diff changeset
    25
#include <stdlib.h>
196
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
    26
#include <stddef.h>		/* for NULL */
192
9dd6f17ef7e5 Wolfgang enhancements for RT-socket-CAN support
etisserant
parents: 189
diff changeset
    27
#include <errno.h>
47
8a1047ab51f4 SOCKET-CAN support added. Many thanks to Jan Kiszka !
etisserant
parents:
diff changeset
    28
8a1047ab51f4 SOCKET-CAN support added. Many thanks to Jan Kiszka !
etisserant
parents:
diff changeset
    29
#include "config.h"
8a1047ab51f4 SOCKET-CAN support added. Many thanks to Jan Kiszka !
etisserant
parents:
diff changeset
    30
8a1047ab51f4 SOCKET-CAN support added. Many thanks to Jan Kiszka !
etisserant
parents:
diff changeset
    31
#ifdef RTCAN_SOCKET
799
6d3ad380dcd3 Update can_socket.c to Xenomai 3 API
Edouard Tisserant
parents: 796
diff changeset
    32
#include "rtdm/can.h"
47
8a1047ab51f4 SOCKET-CAN support added. Many thanks to Jan Kiszka !
etisserant
parents:
diff changeset
    33
#define CAN_IFNAME     "rtcan%s"
8a1047ab51f4 SOCKET-CAN support added. Many thanks to Jan Kiszka !
etisserant
parents:
diff changeset
    34
#else
631
08b6b903f84a Piotr Trojanek (ptroja) cleanup patche. Thanks.
edouard
parents: 603
diff changeset
    35
#include <unistd.h>
187
d3930d3f1323 Fixed can_socket compilation bugs
etisserant
parents: 145
diff changeset
    36
#include <sys/socket.h>
d3930d3f1323 Fixed can_socket compilation bugs
etisserant
parents: 145
diff changeset
    37
#include <sys/ioctl.h>
d3930d3f1323 Fixed can_socket compilation bugs
etisserant
parents: 145
diff changeset
    38
#include "linux/can.h"
d3930d3f1323 Fixed can_socket compilation bugs
etisserant
parents: 145
diff changeset
    39
#include "linux/can/raw.h"
d3930d3f1323 Fixed can_socket compilation bugs
etisserant
parents: 145
diff changeset
    40
#include "net/if.h"
631
08b6b903f84a Piotr Trojanek (ptroja) cleanup patche. Thanks.
edouard
parents: 603
diff changeset
    41
#ifndef PF_CAN
187
d3930d3f1323 Fixed can_socket compilation bugs
etisserant
parents: 145
diff changeset
    42
#define PF_CAN 29
631
08b6b903f84a Piotr Trojanek (ptroja) cleanup patche. Thanks.
edouard
parents: 603
diff changeset
    43
#endif
08b6b903f84a Piotr Trojanek (ptroja) cleanup patche. Thanks.
edouard
parents: 603
diff changeset
    44
#ifndef AF_CAN
187
d3930d3f1323 Fixed can_socket compilation bugs
etisserant
parents: 145
diff changeset
    45
#define AF_CAN PF_CAN
631
08b6b903f84a Piotr Trojanek (ptroja) cleanup patche. Thanks.
edouard
parents: 603
diff changeset
    46
#endif
187
d3930d3f1323 Fixed can_socket compilation bugs
etisserant
parents: 145
diff changeset
    47
//#include "af_can.h"
47
8a1047ab51f4 SOCKET-CAN support added. Many thanks to Jan Kiszka !
etisserant
parents:
diff changeset
    48
#define CAN_IFNAME     "can%s"
802
82e8646d08f5 Quick fix for new RTDM interface in Xemomai 3, now posix
Edouard Tisserant
parents: 799
diff changeset
    49
#endif
82e8646d08f5 Quick fix for new RTDM interface in Xemomai 3, now posix
Edouard Tisserant
parents: 799
diff changeset
    50
47
8a1047ab51f4 SOCKET-CAN support added. Many thanks to Jan Kiszka !
etisserant
parents:
diff changeset
    51
#include "can_driver.h"
8a1047ab51f4 SOCKET-CAN support added. Many thanks to Jan Kiszka !
etisserant
parents:
diff changeset
    52
8a1047ab51f4 SOCKET-CAN support added. Many thanks to Jan Kiszka !
etisserant
parents:
diff changeset
    53
/*********functions which permit to communicate with the board****************/
196
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
    54
UNS8
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
    55
canReceive_driver (CAN_HANDLE fd0, Message * m)
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
    56
{
807
46027bb24429 Rewrite of timer_xeno.c to use POSIX API instead of Alchemy.
Edouard Tisserant
parents: 805
diff changeset
    57
  int res = 0;
196
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
    58
  struct can_frame frame;
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
    59
807
46027bb24429 Rewrite of timer_xeno.c to use POSIX API instead of Alchemy.
Edouard Tisserant
parents: 805
diff changeset
    60
  while (res <= 0) {
46027bb24429 Rewrite of timer_xeno.c to use POSIX API instead of Alchemy.
Edouard Tisserant
parents: 805
diff changeset
    61
    res = recv (*(int *) fd0, &frame, sizeof (frame), 0);
46027bb24429 Rewrite of timer_xeno.c to use POSIX API instead of Alchemy.
Edouard Tisserant
parents: 805
diff changeset
    62
    if (res < 0)
46027bb24429 Rewrite of timer_xeno.c to use POSIX API instead of Alchemy.
Edouard Tisserant
parents: 805
diff changeset
    63
    {
46027bb24429 Rewrite of timer_xeno.c to use POSIX API instead of Alchemy.
Edouard Tisserant
parents: 805
diff changeset
    64
        if (errno == EBADF)
46027bb24429 Rewrite of timer_xeno.c to use POSIX API instead of Alchemy.
Edouard Tisserant
parents: 805
diff changeset
    65
        {
46027bb24429 Rewrite of timer_xeno.c to use POSIX API instead of Alchemy.
Edouard Tisserant
parents: 805
diff changeset
    66
            /* this will exit recieve loop */
46027bb24429 Rewrite of timer_xeno.c to use POSIX API instead of Alchemy.
Edouard Tisserant
parents: 805
diff changeset
    67
            return 1;
46027bb24429 Rewrite of timer_xeno.c to use POSIX API instead of Alchemy.
Edouard Tisserant
parents: 805
diff changeset
    68
        }
46027bb24429 Rewrite of timer_xeno.c to use POSIX API instead of Alchemy.
Edouard Tisserant
parents: 805
diff changeset
    69
        else if (errno == EINTR) continue; /* retry immediatly */
46027bb24429 Rewrite of timer_xeno.c to use POSIX API instead of Alchemy.
Edouard Tisserant
parents: 805
diff changeset
    70
        else
46027bb24429 Rewrite of timer_xeno.c to use POSIX API instead of Alchemy.
Edouard Tisserant
parents: 805
diff changeset
    71
        {
46027bb24429 Rewrite of timer_xeno.c to use POSIX API instead of Alchemy.
Edouard Tisserant
parents: 805
diff changeset
    72
            /* print error and retry after 20ms, arbitrary */
46027bb24429 Rewrite of timer_xeno.c to use POSIX API instead of Alchemy.
Edouard Tisserant
parents: 805
diff changeset
    73
            fprintf (stderr, "Recv failed: %s\n", strerror (errno));
46027bb24429 Rewrite of timer_xeno.c to use POSIX API instead of Alchemy.
Edouard Tisserant
parents: 805
diff changeset
    74
            usleep(20000);
46027bb24429 Rewrite of timer_xeno.c to use POSIX API instead of Alchemy.
Edouard Tisserant
parents: 805
diff changeset
    75
            continue;
46027bb24429 Rewrite of timer_xeno.c to use POSIX API instead of Alchemy.
Edouard Tisserant
parents: 805
diff changeset
    76
        }
46027bb24429 Rewrite of timer_xeno.c to use POSIX API instead of Alchemy.
Edouard Tisserant
parents: 805
diff changeset
    77
    }
46027bb24429 Rewrite of timer_xeno.c to use POSIX API instead of Alchemy.
Edouard Tisserant
parents: 805
diff changeset
    78
    else if (res == 0)
46027bb24429 Rewrite of timer_xeno.c to use POSIX API instead of Alchemy.
Edouard Tisserant
parents: 805
diff changeset
    79
    {
46027bb24429 Rewrite of timer_xeno.c to use POSIX API instead of Alchemy.
Edouard Tisserant
parents: 805
diff changeset
    80
        /* this will exit recieve loop */
46027bb24429 Rewrite of timer_xeno.c to use POSIX API instead of Alchemy.
Edouard Tisserant
parents: 805
diff changeset
    81
        return 1;
46027bb24429 Rewrite of timer_xeno.c to use POSIX API instead of Alchemy.
Edouard Tisserant
parents: 805
diff changeset
    82
    }
46027bb24429 Rewrite of timer_xeno.c to use POSIX API instead of Alchemy.
Edouard Tisserant
parents: 805
diff changeset
    83
  } 
365
9b76e0881beb Changed cob_id from struct{UNS32} to UNS16
etisserant
parents: 330
diff changeset
    84
  m->cob_id = frame.can_id & CAN_EFF_MASK;
196
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
    85
  m->len = frame.can_dlc;
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
    86
  if (frame.can_id & CAN_RTR_FLAG)
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
    87
    m->rtr = 1;
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
    88
  else
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
    89
    m->rtr = 0;
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
    90
  memcpy (m->data, frame.data, 8);
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
    91
330
04b92f78d7bb debug=MSG -> print CAN messages
etisserant
parents: 301
diff changeset
    92
#if defined DEBUG_MSG_CONSOLE_ON
454
bc000083297a - add RTAI support
greg
parents: 384
diff changeset
    93
  MSG("in : ");
290
43c3b2bf3e32 Added debug message printing. Added socket option : CAN_RAW_LOOPBACK=1 and CAN_RAW_RECV_OWN_MSGS=0.
etisserant
parents: 196
diff changeset
    94
  print_message(m);
43c3b2bf3e32 Added debug message printing. Added socket option : CAN_RAW_LOOPBACK=1 and CAN_RAW_RECV_OWN_MSGS=0.
etisserant
parents: 196
diff changeset
    95
#endif
196
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
    96
  return 0;
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
    97
}
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
    98
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
    99
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   100
/***************************************************************************/
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   101
UNS8
631
08b6b903f84a Piotr Trojanek (ptroja) cleanup patche. Thanks.
edouard
parents: 603
diff changeset
   102
canSend_driver (CAN_HANDLE fd0, Message const * m)
196
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   103
{
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   104
  int res;
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   105
  struct can_frame frame;
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   106
365
9b76e0881beb Changed cob_id from struct{UNS32} to UNS16
etisserant
parents: 330
diff changeset
   107
  frame.can_id = m->cob_id;
196
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   108
  if (frame.can_id >= 0x800)
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   109
    frame.can_id |= CAN_EFF_FLAG;
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   110
  frame.can_dlc = m->len;
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   111
  if (m->rtr)
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   112
    frame.can_id |= CAN_RTR_FLAG;
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   113
  else
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   114
    memcpy (frame.data, m->data, 8);
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   115
330
04b92f78d7bb debug=MSG -> print CAN messages
etisserant
parents: 301
diff changeset
   116
#if defined DEBUG_MSG_CONSOLE_ON
454
bc000083297a - add RTAI support
greg
parents: 384
diff changeset
   117
  MSG("out : ");
290
43c3b2bf3e32 Added debug message printing. Added socket option : CAN_RAW_LOOPBACK=1 and CAN_RAW_RECV_OWN_MSGS=0.
etisserant
parents: 196
diff changeset
   118
  print_message(m);
43c3b2bf3e32 Added debug message printing. Added socket option : CAN_RAW_LOOPBACK=1 and CAN_RAW_RECV_OWN_MSGS=0.
etisserant
parents: 196
diff changeset
   119
#endif
804
4657af9ede34 Removed legacy dead code from ex-rtdm rt-socketcan API, added shutdown() call to force recv() to unblock on CanClose()
Edouard Tisserant
parents: 802
diff changeset
   120
  res = send (*(int *) fd0, &frame, sizeof (frame), 0);
805
570e3a444023 Workaround Alchemy task not beeing waken up when closing file descriptor it is waiting on, sequel of Xenomai3 all posix file ops
Edouard Tisserant
parents: 804
diff changeset
   121
  if (res <= 0)
196
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   122
    {
804
4657af9ede34 Removed legacy dead code from ex-rtdm rt-socketcan API, added shutdown() call to force recv() to unblock on CanClose()
Edouard Tisserant
parents: 802
diff changeset
   123
      fprintf (stderr, "Send failed: %s\n", strerror (errno));
196
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   124
      return 1;
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   125
    }
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   126
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   127
  return 0;
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   128
}
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   129
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   130
/***************************************************************************/
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   131
#ifdef RTCAN_SOCKET
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   132
int
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   133
TranslateBaudRate (const char *optarg)
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   134
{
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   135
  int baudrate;
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   136
  int val, len;
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   137
  char *pos = NULL;
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   138
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   139
  len = strlen (optarg);
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   140
  if (!len)
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   141
    return 0;
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   142
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   143
  switch ((int) optarg[len - 1])
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   144
    {
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   145
    case 'M':
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   146
      baudrate = 1000000;
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   147
      break;
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   148
    case 'K':
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   149
      baudrate = 1000;
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   150
      break;
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   151
    default:
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   152
      baudrate = 1;
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   153
      break;
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   154
    }
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   155
  if ((sscanf (optarg, "%i", &val)) == 1)
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   156
    baudrate *= val;
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   157
  else
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   158
    baudrate = 0;;
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   159
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   160
  return baudrate;
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   161
}
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   162
#endif
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   163
384
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 365
diff changeset
   164
UNS8 canChangeBaudRate_driver( CAN_HANDLE fd, char* baud)
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 365
diff changeset
   165
{
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 365
diff changeset
   166
	printf("canChangeBaudRate not yet supported by this driver\n");
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 365
diff changeset
   167
	return 0;
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 365
diff changeset
   168
}
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 365
diff changeset
   169
196
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   170
/***************************************************************************/
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   171
CAN_HANDLE
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   172
canOpen_driver (s_BOARD * board)
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   173
{
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   174
  struct ifreq ifr;
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   175
  struct sockaddr_can addr;
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   176
  int err;
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   177
  CAN_HANDLE fd0 = malloc (sizeof (int));
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   178
#ifdef RTCAN_SOCKET
796
1c87f7a8cb8a Send timeout is set to 10 ms. Without timeout PLC can be blocked by CAN driver: if CAN bus is not connected to controller CAN driver never returns and therfore PLC application halts. This is a temporary solution.
bmakuc <blaz.makuc@smarteh.si>
parents: 631
diff changeset
   179
  nanosecs_rel_t tx_timeout;
196
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   180
  can_baudrate_t *baudrate;
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   181
  can_mode_t *mode;
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   182
#endif
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   183
631
08b6b903f84a Piotr Trojanek (ptroja) cleanup patche. Thanks.
edouard
parents: 603
diff changeset
   184
  if(!fd0)
08b6b903f84a Piotr Trojanek (ptroja) cleanup patche. Thanks.
edouard
parents: 603
diff changeset
   185
    {
08b6b903f84a Piotr Trojanek (ptroja) cleanup patche. Thanks.
edouard
parents: 603
diff changeset
   186
      return NULL;
08b6b903f84a Piotr Trojanek (ptroja) cleanup patche. Thanks.
edouard
parents: 603
diff changeset
   187
    }
08b6b903f84a Piotr Trojanek (ptroja) cleanup patche. Thanks.
edouard
parents: 603
diff changeset
   188
804
4657af9ede34 Removed legacy dead code from ex-rtdm rt-socketcan API, added shutdown() call to force recv() to unblock on CanClose()
Edouard Tisserant
parents: 802
diff changeset
   189
  *(int *) fd0 = socket (PF_CAN, SOCK_RAW, CAN_RAW);
196
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   190
  if (*(int *) fd0 < 0)
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   191
    {
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   192
      fprintf (stderr, "Socket creation failed: %s\n",
804
4657af9ede34 Removed legacy dead code from ex-rtdm rt-socketcan API, added shutdown() call to force recv() to unblock on CanClose()
Edouard Tisserant
parents: 802
diff changeset
   193
	       strerror (errno));
196
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   194
      goto error_ret;
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   195
    }
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   196
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   197
  if (*board->busname >= '0' && *board->busname <= '9')
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   198
    snprintf (ifr.ifr_name, IFNAMSIZ, CAN_IFNAME, board->busname);
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   199
  else
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   200
    strncpy (ifr.ifr_name, board->busname, IFNAMSIZ);
804
4657af9ede34 Removed legacy dead code from ex-rtdm rt-socketcan API, added shutdown() call to force recv() to unblock on CanClose()
Edouard Tisserant
parents: 802
diff changeset
   201
  err = ioctl (*(int *) fd0, SIOCGIFINDEX, &ifr);
196
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   202
  if (err)
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   203
    {
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   204
      fprintf (stderr, "Getting IF index for %s failed: %s\n",
804
4657af9ede34 Removed legacy dead code from ex-rtdm rt-socketcan API, added shutdown() call to force recv() to unblock on CanClose()
Edouard Tisserant
parents: 802
diff changeset
   205
	       ifr.ifr_name, strerror (errno));
196
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   206
      goto error_close;
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   207
    }
290
43c3b2bf3e32 Added debug message printing. Added socket option : CAN_RAW_LOOPBACK=1 and CAN_RAW_RECV_OWN_MSGS=0.
etisserant
parents: 196
diff changeset
   208
  
43c3b2bf3e32 Added debug message printing. Added socket option : CAN_RAW_LOOPBACK=1 and CAN_RAW_RECV_OWN_MSGS=0.
etisserant
parents: 196
diff changeset
   209
  {
43c3b2bf3e32 Added debug message printing. Added socket option : CAN_RAW_LOOPBACK=1 and CAN_RAW_RECV_OWN_MSGS=0.
etisserant
parents: 196
diff changeset
   210
    int loopback = 1;
804
4657af9ede34 Removed legacy dead code from ex-rtdm rt-socketcan API, added shutdown() call to force recv() to unblock on CanClose()
Edouard Tisserant
parents: 802
diff changeset
   211
    err = setsockopt(*(int *)fd0, SOL_CAN_RAW, CAN_RAW_LOOPBACK,
290
43c3b2bf3e32 Added debug message printing. Added socket option : CAN_RAW_LOOPBACK=1 and CAN_RAW_RECV_OWN_MSGS=0.
etisserant
parents: 196
diff changeset
   212
               &loopback, sizeof(loopback));
596
cb69a65bb88d Fiwed use of socketopt accross RT and non-RT implementation of SocketCan
edouard
parents: 454
diff changeset
   213
    if (err) {
804
4657af9ede34 Removed legacy dead code from ex-rtdm rt-socketcan API, added shutdown() call to force recv() to unblock on CanClose()
Edouard Tisserant
parents: 802
diff changeset
   214
        fprintf(stderr, "setsockopt: %s\n", strerror (errno));
603
4dc76e662412 Fixed typo in can_socket.c
edouard
parents: 596
diff changeset
   215
        goto error_close;
596
cb69a65bb88d Fiwed use of socketopt accross RT and non-RT implementation of SocketCan
edouard
parents: 454
diff changeset
   216
    }
290
43c3b2bf3e32 Added debug message printing. Added socket option : CAN_RAW_LOOPBACK=1 and CAN_RAW_RECV_OWN_MSGS=0.
etisserant
parents: 196
diff changeset
   217
  }
43c3b2bf3e32 Added debug message printing. Added socket option : CAN_RAW_LOOPBACK=1 and CAN_RAW_RECV_OWN_MSGS=0.
etisserant
parents: 196
diff changeset
   218
  
596
cb69a65bb88d Fiwed use of socketopt accross RT and non-RT implementation of SocketCan
edouard
parents: 454
diff changeset
   219
#ifndef RTCAN_SOCKET /*CAN_RAW_RECV_OWN_MSGS not supported in rtsocketcan*/
290
43c3b2bf3e32 Added debug message printing. Added socket option : CAN_RAW_LOOPBACK=1 and CAN_RAW_RECV_OWN_MSGS=0.
etisserant
parents: 196
diff changeset
   220
  {
43c3b2bf3e32 Added debug message printing. Added socket option : CAN_RAW_LOOPBACK=1 and CAN_RAW_RECV_OWN_MSGS=0.
etisserant
parents: 196
diff changeset
   221
    int recv_own_msgs = 0; /* 0 = disabled (default), 1 = enabled */
804
4657af9ede34 Removed legacy dead code from ex-rtdm rt-socketcan API, added shutdown() call to force recv() to unblock on CanClose()
Edouard Tisserant
parents: 802
diff changeset
   222
    err = setsockopt(*(int *)fd0, SOL_CAN_RAW, CAN_RAW_RECV_OWN_MSGS,
290
43c3b2bf3e32 Added debug message printing. Added socket option : CAN_RAW_LOOPBACK=1 and CAN_RAW_RECV_OWN_MSGS=0.
etisserant
parents: 196
diff changeset
   223
               &recv_own_msgs, sizeof(recv_own_msgs));
596
cb69a65bb88d Fiwed use of socketopt accross RT and non-RT implementation of SocketCan
edouard
parents: 454
diff changeset
   224
    if (err) {
804
4657af9ede34 Removed legacy dead code from ex-rtdm rt-socketcan API, added shutdown() call to force recv() to unblock on CanClose()
Edouard Tisserant
parents: 802
diff changeset
   225
        fprintf(stderr, "setsockopt: %s\n", strerror (errno));
603
4dc76e662412 Fixed typo in can_socket.c
edouard
parents: 596
diff changeset
   226
        goto error_close;
596
cb69a65bb88d Fiwed use of socketopt accross RT and non-RT implementation of SocketCan
edouard
parents: 454
diff changeset
   227
    }
290
43c3b2bf3e32 Added debug message printing. Added socket option : CAN_RAW_LOOPBACK=1 and CAN_RAW_RECV_OWN_MSGS=0.
etisserant
parents: 196
diff changeset
   228
  }
596
cb69a65bb88d Fiwed use of socketopt accross RT and non-RT implementation of SocketCan
edouard
parents: 454
diff changeset
   229
#endif
290
43c3b2bf3e32 Added debug message printing. Added socket option : CAN_RAW_LOOPBACK=1 and CAN_RAW_RECV_OWN_MSGS=0.
etisserant
parents: 196
diff changeset
   230
  
196
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   231
  addr.can_family = AF_CAN;
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   232
  addr.can_ifindex = ifr.ifr_ifindex;
804
4657af9ede34 Removed legacy dead code from ex-rtdm rt-socketcan API, added shutdown() call to force recv() to unblock on CanClose()
Edouard Tisserant
parents: 802
diff changeset
   233
  err = bind (*(int *) fd0, (struct sockaddr *) &addr, sizeof (addr));
4657af9ede34 Removed legacy dead code from ex-rtdm rt-socketcan API, added shutdown() call to force recv() to unblock on CanClose()
Edouard Tisserant
parents: 802
diff changeset
   234
  if (err)
4657af9ede34 Removed legacy dead code from ex-rtdm rt-socketcan API, added shutdown() call to force recv() to unblock on CanClose()
Edouard Tisserant
parents: 802
diff changeset
   235
    {
4657af9ede34 Removed legacy dead code from ex-rtdm rt-socketcan API, added shutdown() call to force recv() to unblock on CanClose()
Edouard Tisserant
parents: 802
diff changeset
   236
      fprintf (stderr, "Binding failed: %s\n", strerror (errno));
196
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   237
      goto error_close;
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   238
    }
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   239
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   240
#ifdef RTCAN_SOCKET
796
1c87f7a8cb8a Send timeout is set to 10 ms. Without timeout PLC can be blocked by CAN driver: if CAN bus is not connected to controller CAN driver never returns and therfore PLC application halts. This is a temporary solution.
bmakuc <blaz.makuc@smarteh.si>
parents: 631
diff changeset
   241
  tx_timeout = 10000000;    /* XXX Timeout is temporarily set to 10 ms */
804
4657af9ede34 Removed legacy dead code from ex-rtdm rt-socketcan API, added shutdown() call to force recv() to unblock on CanClose()
Edouard Tisserant
parents: 802
diff changeset
   242
  err = ioctl (*(int *) fd0, RTCAN_RTIOC_SND_TIMEOUT, &tx_timeout);
796
1c87f7a8cb8a Send timeout is set to 10 ms. Without timeout PLC can be blocked by CAN driver: if CAN bus is not connected to controller CAN driver never returns and therfore PLC application halts. This is a temporary solution.
bmakuc <blaz.makuc@smarteh.si>
parents: 631
diff changeset
   243
  if (err)
1c87f7a8cb8a Send timeout is set to 10 ms. Without timeout PLC can be blocked by CAN driver: if CAN bus is not connected to controller CAN driver never returns and therfore PLC application halts. This is a temporary solution.
bmakuc <blaz.makuc@smarteh.si>
parents: 631
diff changeset
   244
    {
1c87f7a8cb8a Send timeout is set to 10 ms. Without timeout PLC can be blocked by CAN driver: if CAN bus is not connected to controller CAN driver never returns and therfore PLC application halts. This is a temporary solution.
bmakuc <blaz.makuc@smarteh.si>
parents: 631
diff changeset
   245
      fprintf (stderr,
1c87f7a8cb8a Send timeout is set to 10 ms. Without timeout PLC can be blocked by CAN driver: if CAN bus is not connected to controller CAN driver never returns and therfore PLC application halts. This is a temporary solution.
bmakuc <blaz.makuc@smarteh.si>
parents: 631
diff changeset
   246
          "Setting TX timeout %d failed: %s\n",
804
4657af9ede34 Removed legacy dead code from ex-rtdm rt-socketcan API, added shutdown() call to force recv() to unblock on CanClose()
Edouard Tisserant
parents: 802
diff changeset
   247
          *baudrate, strerror (errno));
796
1c87f7a8cb8a Send timeout is set to 10 ms. Without timeout PLC can be blocked by CAN driver: if CAN bus is not connected to controller CAN driver never returns and therfore PLC application halts. This is a temporary solution.
bmakuc <blaz.makuc@smarteh.si>
parents: 631
diff changeset
   248
      goto error_close;
1c87f7a8cb8a Send timeout is set to 10 ms. Without timeout PLC can be blocked by CAN driver: if CAN bus is not connected to controller CAN driver never returns and therfore PLC application halts. This is a temporary solution.
bmakuc <blaz.makuc@smarteh.si>
parents: 631
diff changeset
   249
    }
1c87f7a8cb8a Send timeout is set to 10 ms. Without timeout PLC can be blocked by CAN driver: if CAN bus is not connected to controller CAN driver never returns and therfore PLC application halts. This is a temporary solution.
bmakuc <blaz.makuc@smarteh.si>
parents: 631
diff changeset
   250
196
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   251
  baudrate = (can_baudrate_t *) & ifr.ifr_ifru;
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   252
  *baudrate = TranslateBaudRate (board->baudrate);
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   253
  if (!*baudrate)
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   254
    goto error_close;
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   255
804
4657af9ede34 Removed legacy dead code from ex-rtdm rt-socketcan API, added shutdown() call to force recv() to unblock on CanClose()
Edouard Tisserant
parents: 802
diff changeset
   256
  err = ioctl (*(int *) fd0, SIOCSCANBAUDRATE, &ifr);
196
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   257
  if (err)
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   258
    {
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   259
      fprintf (stderr,
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   260
	       "Setting baudrate %d failed: %s\n",
804
4657af9ede34 Removed legacy dead code from ex-rtdm rt-socketcan API, added shutdown() call to force recv() to unblock on CanClose()
Edouard Tisserant
parents: 802
diff changeset
   261
	       *baudrate, strerror (errno));
196
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   262
      goto error_close;
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   263
    }
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   264
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   265
  mode = (can_mode_t *) & ifr.ifr_ifru;
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   266
  *mode = CAN_MODE_START;
804
4657af9ede34 Removed legacy dead code from ex-rtdm rt-socketcan API, added shutdown() call to force recv() to unblock on CanClose()
Edouard Tisserant
parents: 802
diff changeset
   267
  err = ioctl (*(int *) fd0, SIOCSCANMODE, &ifr);
196
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   268
  if (err)
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   269
    {
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   270
      fprintf (stderr, "Starting CAN device failed: %s\n",
804
4657af9ede34 Removed legacy dead code from ex-rtdm rt-socketcan API, added shutdown() call to force recv() to unblock on CanClose()
Edouard Tisserant
parents: 802
diff changeset
   271
	       strerror (errno));
196
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   272
      goto error_close;
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   273
    }
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   274
#endif
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   275
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   276
  return fd0;
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   277
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   278
error_close:
804
4657af9ede34 Removed legacy dead code from ex-rtdm rt-socketcan API, added shutdown() call to force recv() to unblock on CanClose()
Edouard Tisserant
parents: 802
diff changeset
   279
  close (*(int *) fd0);
196
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   280
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   281
error_ret:
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   282
  free (fd0);
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   283
  return NULL;
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   284
}
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   285
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   286
/***************************************************************************/
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   287
int
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   288
canClose_driver (CAN_HANDLE fd0)
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   289
{
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   290
  if (fd0)
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   291
    {
804
4657af9ede34 Removed legacy dead code from ex-rtdm rt-socketcan API, added shutdown() call to force recv() to unblock on CanClose()
Edouard Tisserant
parents: 802
diff changeset
   292
      shutdown (*(int *) fd0, SHUT_RDWR);
4657af9ede34 Removed legacy dead code from ex-rtdm rt-socketcan API, added shutdown() call to force recv() to unblock on CanClose()
Edouard Tisserant
parents: 802
diff changeset
   293
      close (*(int *) fd0);
196
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   294
      free (fd0);
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   295
    }
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   296
  return 0;
65aa7a664f6f Applied wolfgang changes, and re-indented socket_can.c file
etisserant
parents: 192
diff changeset
   297
}