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 UNS8 canChangeBaudRate_driver( CAN_HANDLE fd, char* baud)
95 printf("canChangeBaudRate not yet supported by this driver\n");
99 /***************************************************************************/
100 static const char lnx_can_dev_prefix[] = "/dev/can";
102 CAN_HANDLE canOpen_driver(s_BOARD *board)
104 int name_len = strlen(board->busname);
105 int prefix_len = strlen(lnx_can_dev_prefix);
106 char dev_name[prefix_len+name_len+1];
110 fd0=malloc(sizeof(*fd0));
114 /*o_flags = O_NONBLOCK;*/
116 memcpy(dev_name,lnx_can_dev_prefix,prefix_len);
117 memcpy(dev_name+prefix_len,board->busname,name_len);
118 dev_name[prefix_len+name_len] = 0;
120 fd0 = open(dev_name, O_RDWR|o_flags);
122 fprintf(stderr,"!!! Board %s is unknown. See can_lincan.c\n", board->busname);
133 /***************************************************************************/
134 int canClose_driver(CAN_HANDLE fd0)