Beispiel #1
0
int CAN_listen(const CAN_Node *node, void (*callback)(void *, struct can_frame *), void *cookie, int *done)
{
	int status;
	struct can_frame frame;
	
	while(!*done)
	{
		/*
		struct timeval tv;
		fd_set set;
		
		FD_ZERO(&set);
		FD_SET(node->fd, &set);
		tv.tv_sec = 0;
		tv.tv_usec = 10*1000;
		
		int s = select(node->fd + 1, &set, NULL, NULL, &tv);
		if(s < 0)
			perror("Error select CAN raw socket");
			return 1;
		if(s == 0)
			continue;
		*/
		
		status = CAN_receive(node, &frame);
		if(status != 0)
			return 2;
		
		callback(cookie, &frame);
	}
	
	return 0;
}
Beispiel #2
0
/**
 * @brief      Put the controller in normal mode and make it receive incoming
 *             messages
 */
void CAN_test_normal_receive()
{
    CAN_init(MCP_MODE_NORMAL);

    CanMessage_t resp;

    while (1)
    {
        _delay_ms(200);
        resp = CAN_receive();
        CAN_print_message(&resp);
    }
}
Beispiel #3
0
/**
 * @brief    Put the CAN controller in loopback mode and test local features
 */
void CAN_test_loopback()
{
    CAN_init(MCP_MODE_LOOPBACK);

    CanMessage_t message;
    CanMessage_t resp;
    message.id      = 15;
    message.length  = 4;
    message.data[0] = 'T';
    message.data[1] = 'E';
    message.data[2] = 'S';
    message.data[3] = 'T';
    while (1)
    {
        CAN_send(&message);
        _delay_ms(200);
        resp = CAN_receive();
        CAN_print_message(&resp);
    }
}