2 This file is part of CanFestival, a library implementing CanOpen Stack.
4 Copyright (C): Edouard TISSERANT and Francis DUPIN
6 See COPYING file for copyrights details.
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #include "can_driver.h"
33 /*********functions which permit to communicate with the board****************/
34 UNS8 canReceive_driver(CAN_HANDLE fd0, Message *m)
37 struct canmsg_t canmsg;
39 canmsg.flags = 0; /* Ensure standard receive, not required for LinCAN>=0.3.1 */
42 res = read(fd0,&canmsg,sizeof(canmsg_t));
43 if((res<0)&&(errno == -EAGAIN)) res = 0;
46 if(res != sizeof(canmsg_t)) // No new message
49 if(canmsg.flags&MSG_EXT){
50 /* There is no mark for extended messages in CanFestival */;
53 m->cob_id = canmsg.id;
54 m->len = canmsg.length;
55 if(canmsg.flags&MSG_RTR){
59 memcpy(m->data,canmsg.data,8);
65 /***************************************************************************/
66 UNS8 canSend_driver(CAN_HANDLE fd0, Message *m)
69 struct canmsg_t canmsg;
73 canmsg.id = m->cob_id;
74 canmsg.length = m->len;
76 canmsg.flags |= MSG_RTR;
78 memcpy(canmsg.data,m->data,8);
81 if(canmsg.id >= 0x800){
82 canmsg.flags |= MSG_EXT;
85 res = write(fd0,&canmsg,sizeof(canmsg_t));
86 if(res!=sizeof(canmsg_t))
92 /***************************************************************************/
93 static const char lnx_can_dev_prefix[] = "/dev/can";
95 CAN_HANDLE canOpen_driver(s_BOARD *board)
97 int name_len = strlen(board->busname);
98 int prefix_len = strlen(lnx_can_dev_prefix);
99 char dev_name[prefix_len+name_len+1];
103 fd0=malloc(sizeof(*fd0));
107 /*o_flags = O_NONBLOCK;*/
109 memcpy(dev_name,lnx_can_dev_prefix,prefix_len);
110 memcpy(dev_name+prefix_len,board->busname,name_len);
111 dev_name[prefix_len+name_len] = 0;
113 fd0 = open(dev_name, O_RDWR|o_flags);
115 fprintf(stderr,"!!! Board %s is unknown. See can_lincan.c\n", board->busname);
126 /***************************************************************************/
127 int canClose_driver(CAN_HANDLE fd0)