/** * Wait for specific message * @param handle * @param mtype * @return NULL or a pointer to the message */ CPC_MSG_T *CPC_WaitForMType(int handle, int mtype) { CPC_MSG_T *pMsg; struct timeval tv; unsigned long sec; gettimeofday(&tv, NULL); sec = tv.tv_sec; do { pMsg = CPC_Handle(handle); if ((pMsg != NULL) && (pMsg->type == mtype)) return pMsg; gettimeofday(&tv, NULL); } while (tv.tv_sec - sec < 5); /* wait 5 sec. */ return NULL; }
int can_cpc_receive(can_cpc_device_p dev, can_message_p message) { struct timeval time; fd_set set; int error; time.tv_sec = 0; time.tv_usec = dev->timeout*1e6; FD_ZERO(&set); FD_SET(dev->fd, &set); error = select(dev->fd+1, &set, NULL, NULL, &time); if (error == 0) return CAN_CPC_ERROR_TIMEOUT; while (CPC_Handle(dev->handle)) usleep(10); *message = dev->msg_received; return CAN_CPC_ERROR_NONE; }