42 if (((
unsigned int) iErrorState & 0xFFFF) & CAN_ERR_QRCVEMPTY) {
43 warning(
"receive queue is empty");
46 if (iErrorState & CAN_ERR_OVERRUN) {
47 warning(
"receive buffer overrun");
50 if (iErrorState & CAN_ERR_XMTFULL) {
51 warning(
"transmit buffer full");
54 if (iErrorState & CAN_ERR_BUSOFF) {
58 if (iErrorState & CAN_ERR_ILLPARAMTYPE) {
59 warning(
"CAN_ERR_ILLPARAMTYPE");
62 if (((
unsigned int) iErrorState & 0xFFFF) & CAN_ERR_QXMTFULL) {
66 if (iErrorState & CAN_ERR_BUSLIGHT) {
70 if (((
unsigned int) iErrorState & 0xFFFF) & CAN_ERR_BUSHEAVY) {
74 if (((
unsigned int) iErrorState & 0xFFFF) & CAN_ERR_RESOURCE) {
75 warning(
"can't create resource");
99 debug(1,
"entering SocketCANDevice::clearReadQueue()...\n");
102 debug(1,
"Trying to read messages ...");
103 iRetVal = read(
m_iDeviceId, &frame,
sizeof(frame));
104 debug(0,
" 0x%04x\n", iRetVal);
106 }
while (iRetVal != CAN_ERR_QRCVEMPTY);
128 int bRet = 1, iRet = 0;
131 debug(1,
"Trying to read Device");
139 debug(1,
"bytes read: %d", iRet);
154 printf(
"error in SocketCANDevice::readDevice()");
159 debug(1,
"bRet before return from SocketCANDevice::readDevice: %d ", bRet);
166 debug(1,
"SocketCANDevice::writeDevice ");
178 debug(1,
"clProtocolMessage.m_ucMessageLength: %d",
184 debug(1,
"rclProtocolMessage.m_uiMessageId: %d ",
192 debug(1,
"rclProtocolMessage.m_aucMessageData: %c ",
194 debug(1,
"frame data[%d]: %c", i,
frame.data);
203 if (bytes_sent < 0) {
204 debug(1,
"error in SocketCANDevice::writeDevice: ");
208 if (bytes_sent > 0) {
210 debug(1,
"bytes sent in SocketCANDevice::writeDevice: %d ", bytes_sent);
228 error(-1,
"Sorry constructor is not implemented");
243 error(-1,
"Sorry operator= is not implemented");
289 printf(
"Trying to open CAN on can0 ...");
294 struct timeval timeout;
298 if (setsockopt(
m_iDeviceId, SOL_SOCKET, SO_RCVTIMEO, (
char *) &timeout,
299 sizeof(
struct timeval)) < 0)
300 error(
"setsockopt failed\n");
306 strncpy(acString, acInitString, 128);
307 pcToken = strtok(acString,
",");
308 std::string pcTokenStrInit(pcToken);
309 pcToken = strtok(pcToken,
":");
314 if (strcmp(pcToken,
"SOCKETCAN") != 0) {
318 std::string pcTokenStr(pcToken);
319 std::string devName = pcTokenStrInit.substr(pcTokenStr.length() + 1, 4);
320 strcpy(ifr.ifr_name, devName.c_str());
322 debug(1,
"name: %x",*m_DeviceName);
324 struct sockaddr_can addr;
326 addr.can_ifindex = ifr.ifr_ifindex;
327 int ret1 = bind(
m_iDeviceId, (
struct sockaddr*) &addr,
sizeof(addr));
332 printf(
"Cannot open CAN on USB:\n");
334 printf(
"Open CAN on USB suceeded!\n");
340 debug(1,
"finished updateModuleIdMap");
342 "m_iErrorState before returning of SocketCANDevice::init(const char* acInitString): %d",
351 warning(
"exit:device not initialized");
356 iRetVal = CAN_ERR_OK;
357 if (iRetVal != CAN_ERR_OK) {
358 warning(
"can close failed Errorcode: %d", iRetVal);
372 TPCMsg.Msg.MSGTYPE = 0;
374 bool bRecieved =
false;
377 iRetVal = read(
m_iDeviceId, &frame,
sizeof(frame));
381 iRetVal = read(
m_iDeviceId, &frame,
sizeof(frame));
382 if (iRetVal != CAN_ERR_OK) {
383 warning(
"can read failed Errorcode: 0x%04x", iRetVal);
389 debug(1,
"received CAN-ID %x, expected %x", TPCMsg.Msg.ID,
394 debug(1,
"wrong command ID");
397 }
while (!bRecieved);
#define ERRID_DEV_BADINITSTRING
unsigned char m_aucMessageData[8]
int getDeviceError(int iErrorState)
CRITICAL_SECTION m_csDevice
void error(const int iErrorCode, const char *pcErrorMessage,...) const
#define ERRID_DEV_WRITEERROR
void setTimeOut(unsigned long uiTimeOut)
unsigned short m_uiQueueSize
int waitForStartMotionAll()
#define ERRID_DEV_NOTINITIALIZED
unsigned char m_ucMessageLength
void setQueueSize(unsigned short uiQueueSize)
unsigned long m_uiMessageId
void warning(const char *pcWarningMessage,...) const
int setMessageId(unsigned long uiMessageId)
int readDevice(CProtocolMessage &rclProtocolMessage)
#define ERRID_DEV_EXITERROR
void debug(const int iDebugLevel, const char *pcDebugMessage,...) const
int reinit(unsigned char ucBaudRateId)
SocketCANDevice & operator=(const SocketCANDevice &rclSocketCANDevice)
unsigned long m_uiTimeOut
#define ERRID_DEV_READERROR
int writeDevice(CProtocolMessage &rclProtocolMessage)