UseMCACan.h
Go to the documentation of this file.
1 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2 
3 // -- BEGIN LICENSE BLOCK ----------------------------------------------
4 // This file is part of FZIs ic_workspace.
5 //
6 // This program is free software licensed under the LGPL
7 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
8 // You can find a copy of this license in LICENSE folder in the top
9 // directory of the source code.
10 //
11 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
12 //
13 // -- END LICENSE BLOCK ------------------------------------------------
14 
15 //----------------------------------------------------------------------
25 //----------------------------------------------------------------------
26 #ifndef _icl_hardware_can_UseMCACan_h_
27 #define _icl_hardware_can_UseMCACan_h_
28 
29 #ifdef _SYSTEM_LINUX_
30 # include <errno.h>
31 # include <fcntl.h>
32 # include <unistd.h>
33 # include <sys/ioctl.h>
34 # include <string.h>
35 # include <stdlib.h>
36 #endif
37 
40 
41 #ifdef _SYSTEM_LXRT_
42 # include "CAN-lxrt.h"
43 #else
45 #endif
46 
47 #ifdef _IC_BUILDER_CAN_MCA_HAS_IOCTL_H_
48 # include "CAN-ioctl.h"
49 #else
50 # define IOCTL_CAN_IOCRESET 0x01
51 # define IOCTL_CAN_SETBAUDRATE 0x02
52 # define IOCTL_CAN_IOCSETRMASK 0x03
53 # define IOCTL_CAN_SETSENDFIFOSIZE 0x04
54 # define IOCTL_CAN_SETRECEIVEFIFOSIZE 0x05
55 #endif
56 
57 namespace icl_hardware {
58 namespace can {
59 
60 typedef int tCanDescriptor;
61 
62 inline bool CanDescriptorValid(tCanDescriptor can_device)
63 {
64  return can_device >= 0;
65 }
66 
67 inline tCanDescriptor InvalidCanDescriptor()
68 {
69  return -1;
70 }
71 
72 inline const char* CanDriverName()
73 {
74  return "MCA-CAN";
75 }
76 
77 #ifdef _SYSTEM_LXRT_
78 inline bool CanDriverLxrtSupport()
80 {
81  return true;
82 }
83 #endif
84 
85 #ifdef _SYSTEM_LINUX_
86 
88 
107 inline tCanDescriptor CanDeviceOpen(const char *device_name, int flags,
108  unsigned char acceptance_code, unsigned char acceptance_mask, unsigned int baud_rate,
109  unsigned send_fifo_size, unsigned receive_fifo_size)
110 {
111  int can_device = open(device_name, flags);
112  if (can_device >= 0)
113  {
114  long value = receive_fifo_size;
115  if (ioctl(can_device, IOCTL_CAN_SETRECEIVEFIFOSIZE, value) < 0)
116  {
117  close(can_device);
118  return -1;
119  }
120  value = send_fifo_size;
121  if (ioctl(can_device, IOCTL_CAN_SETSENDFIFOSIZE, value) < 0)
122  {
123  close(can_device);
124  return -1;
125  }
126  value = acceptance_mask;
127  value = ((value << 8)) | (acceptance_code);
128  if (ioctl(can_device, IOCTL_CAN_IOCSETRMASK, value) < 0)
129  {
130  close(can_device);
131  return -1;
132  }
133  value = baud_rate;
134  if (ioctl(can_device, IOCTL_CAN_SETBAUDRATE, value) < 0)
135  {
136  close(can_device);
137  return -1;
138  }
139  }
140  return can_device;
141 }
142 
144 
149 inline int CanDeviceClose(tCanDescriptor can_device)
150 {
151  return close(can_device);
152 }
153 
154 inline int CanDeviceSend(tCanDescriptor can_device, const tCanMessage &msg)
155 {
156  return write(can_device, &msg, sizeof(tCanMessage));
157 }
158 
159 inline int CanDeviceReceive(tCanDescriptor can_device, tCanMessage &msg)
160 {
161  return read(can_device, &msg, sizeof(tCanMessage));
162 }
163 
165 
170 inline int CanDeviceReset(tCanDescriptor can_device)
171 {
172  long value = 0;
173  return ioctl(can_device, IOCTL_CAN_IOCRESET, value);
174 }
175 #endif
176 
177 }
178 }
179 
180 #endif
int CanDeviceClose(tCanDescriptor)
Definition: UseDummyCan.h:62
Implements a struct representing a can message.
Definition: tCanMessage.h:43
bool CanDescriptorValid(tCanDescriptor can_device)
Definition: UseDummyCan.h:38
int CanDeviceReset(tCanDescriptor)
Definition: UseDummyCan.h:77
bool CanDriverLxrtSupport()
no support for LXRT available
Definition: UseCanNoLxrt.h:35
#define IOCTL_CAN_SETRECEIVEFIFOSIZE
Definition: UseMCACan.h:54
#define IOCTL_CAN_IOCSETRMASK
Definition: UseMCACan.h:52
const char * CanDriverName()
Definition: UseDummyCan.h:48
Contains CAN driver interface functions.
tCanDescriptor InvalidCanDescriptor()
Definition: UseDummyCan.h:43
#define IOCTL_CAN_SETSENDFIFOSIZE
Definition: UseMCACan.h:53
Contains CAN driver interface functions.
icl_hardware::can::tCanMessage tCanMessage
Definition: UseMCACan.h:39
#define IOCTL_CAN_IOCRESET
Definition: UseMCACan.h:50
tCanDescriptor CanDeviceOpen(const char *, int, unsigned char, unsigned char, unsigned int, unsigned, unsigned)
Open a can device and set parameters.
Definition: UseDummyCan.h:53
int CanDeviceSend(tCanDescriptor, const tCanMessage &)
Definition: UseDummyCan.h:67
#define IOCTL_CAN_SETBAUDRATE
Definition: UseMCACan.h:51
int CanDeviceReceive(tCanDescriptor, tCanMessage &)
Definition: UseDummyCan.h:72


fzi_icl_can
Author(s):
autogenerated on Mon Jun 10 2019 13:17:02