28 #ifndef _icl_hardware_can_UsePeakCan_h_ 29 #define _icl_hardware_can_UsePeakCan_h_ 34 # include <sys/ioctl.h> 50 return can_device != 0;
83 LOGGING_ERROR( CAN,
"Peak Can baud rate " << baud_rate <<
" not valid. Setting the baud rate to 1MB " <<
endl);
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)
111 printf(
"flags:%i\n",flags);
113 handle = LINUX_CAN_Open((
char*) device_name, flags);
120 if ( CAN_Init(handle, br , CAN_INIT_TYPE_ST ))
122 printf(
"Invalid CanDescriptor!\n");
127 printf(
"Can Init successful!\n");
134 return CAN_Close(_can_device);
146 pmsg.MSGTYPE = MSGTYPE_STANDARD;
153 return CAN_Write(_can_device, &pmsg);
173 int ret = LINUX_CAN_Read_Timeout(_can_device, &pmsg, 0);
181 LOGGING_ERROR( CAN,
"CAN DEVICE HANDLE CRITICAL ERROR. COULD NOT READ PROPERLY FROM DEVICE. Error Code: " << ret <<
endl);
186 if (ret == CAN_ERR_QRCVEMPTY)
193 if (pmsg.Msg.MSGTYPE == MSGTYPE_STATUS )
199 if (pmsg.Msg.DATA[3] == CAN_ERR_QRCVEMPTY)
206 switch (pmsg.Msg.DATA[3])
209 LOGGING_ERROR( CAN,
"no error code given in an error message....check protocol" <<
endl);
211 case CAN_ERR_XMTFULL:
215 case CAN_ERR_OVERRUN:
219 case CAN_ERR_BUSLIGHT:
220 LOGGING_ERROR( CAN,
"BUSLIGHT, errorcounter limit reached, please check your cable setup" <<
endl);
223 case CAN_ERR_BUSHEAVY:
224 LOGGING_ERROR( CAN,
"BUSHEAVY, errorcounter limit reached, please check your cable setup" <<
endl);
231 case CAN_ERR_QOVERRUN:
235 case CAN_ERR_QXMTFULL:
284 msg.
id = pmsg.Msg.ID;
285 msg.
dlc = pmsg.Msg.LEN;
286 if (pmsg.Msg.MSGTYPE == MSGTYPE_EXTENDED || pmsg.Msg.MSGTYPE == MSGTYPE_STATUS)
293 msg.
rtr = pmsg.Msg.MSGTYPE;
296 memcpy(msg.
data, pmsg.Msg.DATA, pmsg.Msg.LEN);
int CanDeviceClose(tCanDescriptor)
WORD BaudRateSpecifier(unsigned int baud_rate)
Implements a struct representing a can message.
void * memcpy(void *dest, void *src, size_t count)
bool CanDescriptorValid(tCanDescriptor can_device)
int CanDeviceReset(tCanDescriptor)
#define LOGGING_ERROR(streamname, arg)
unsigned int sleep(unsigned int seconds)
const char * CanDriverName()
Contains CAN driver interface functions.
ThreadStream & endl(ThreadStream &stream)
tCanDescriptor InvalidCanDescriptor()
Contains CAN driver interface functions.
tCanDescriptor CanDeviceOpen(const char *, int, unsigned char, unsigned char, unsigned int, unsigned, unsigned)
Open a can device and set parameters.
int CanDeviceSend(tCanDescriptor, const tCanMessage &)
int CanDeviceReceive(tCanDescriptor, tCanMessage &)