コード例 #1
0
ファイル: can_cpc.c プロジェクト: uqs/avalon
int can_send_message(can_message_t* message) {
	static CPC_CAN_MSG_T cmsg = {0x00L, 0, {0, 0, 0, 0, 0, 0, 0, 0}};
	int i, retval = 0;

	cmsg.id=message->id;                          //put the can id of the device in cmsg
	cmsg.length=8;                                //put the lenght of the message in cmsg
	for(i = 0; i < cmsg.length; i++) {
		cmsg.msg[i] = message->content[i];          //put the message in cmsg
	}

	SELECT_WR;                                     //enable write en read
	if (FD_ISSET(cpcfd, &writefds)) {             //if chanel open and writable (???)
		//send the message of lenght 8 to the device of id can_id
		while ((retval = CPC_SendMsg(handle, 0, &cmsg)) == CPC_ERR_CAN_NO_TRANSMIT_BUF) {
			usleep(10);
		}

		if (retval == 0) {
			//wait for the reply
			PDEBUG("Sent CAN message, now waiting for reply...\n");
			can_read_message();
			PDEBUG("Received CAN reply\n");
		} else {
			PDEBUG_ERR("%s\n", CPC_DecodeErrorMsg(retval));
			return -1;
		}
	}
	return 0;
}
コード例 #2
0
ファイル: poti.cpp プロジェクト: uqs/avalon
int main (int argc, const char * argv[])
{
    double angle;
    int num_tick;
    can_init("/dev/ttyUSB4");
    
	//can_send_message(&msg_poti_set_counterclockwise);
	can_send_message(&msg_poti_save);
	rtx_message("0x%X 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X", message.id, message.content[0], message.content[1], message.content[2], message.content[3], message.content[4], message.content[5], message.content[6], message.content[7]);
    while (0)
    {
		can_send_message(&msg_poti_pos_request);
	can_read_message();
	num_tick = int(message.content[4])+int(message.content[5])*256+int(message.content[6])*256*256 + int(message.content[7])*256*256*256;
	angle = remainder((num_tick%AV_POTI_RESOLUTION)*360.0/AV_POTI_RESOLUTION,360.0);
	rtx_message("angle: %f",angle);
	}
	// The destructors will take care of cleaning up the memory
    return (0);

}
コード例 #3
0
ファイル: canix.c プロジェクト: hcanchristian/openHCAN
void canix_process_messages(void)
{
	uint8_t i;

	for (i = 0; i < MAX_IDLE_CALLBACKS; i++)
	{
		if (can_message_available())
		{
			uint32_t extid;
			canix_frame frame;

			// Frame einlesen
			frame.size = can_read_message(&extid, (char *) &(frame.data[0]));
			frame.dst = (extid >> 10) & ADDR_MASK;
			frame.src = extid & ADDR_MASK;
			frame.proto = (extid >> 20) & PROTO_MASK;

			canix_deliver_frame(&frame);
		}
		else if (idle_callback[i])
				idle_callback[i]();
	}