コード例 #1
0
ファイル: hubo-esdcan.c プロジェクト: ARTLabPurdue/hubo-ach
void openAllCAN(int vCan) {
	for ( size_t i = 0; i < 2; i ++ ) {
		int r = canOpen( i, //net
				 0, // flags
				 10, //txqueue
				 10, //rxqueue
				 100, //txtimeout
				 100, //rxtimeout
				 &hubo_socket[i] //handle
			);
		if( NTCAN_SUCCESS != r ) {
			fprintf(stderr, "Unable to open CAN %d: %s\n", i, canResultString(r));
			exit( EXIT_FAILURE );
		}

		r = canSetBaudrate( hubo_socket[i], NTCAN_BAUD_1000 );
		if( NTCAN_SUCCESS != r ) {
			fprintf(stderr, "Unable to set CAN %d baud: %s\n", i, canResultString(r));
			exit( EXIT_FAILURE );
		}
	}

}
コード例 #2
0
ファイル: hubo-esdcan.c プロジェクト: andypark4/hubo-ach
/**
 * Sends CAN packet to desired channel
 *
 * @param $first
 *	"@param" is the socket you want to send to
 * @param $second
 *	CAN frame to send
 */
int sendCan(hubo_can_t skt, struct can_frame *f) {
    /*** Convert socketcan struct to NTCAN CMSG ***/
    CMSG esd_frame;
    // id
    esd_frame.id = f->can_id;
    // len
    esd_frame.len = f->can_dlc;
    // data
    for( size_t i = 0; i < esd_frame.len; i ++ ) {
        esd_frame.data[i] = f->data[i];
    }

    /*** Send the Message ***/
    int32_t num = 1;
    int r = canWrite( skt, &esd_frame, &num, NULL );
    // FIXME: check error and handle failure reasonably
    if (NTCAN_SUCCESS != r) {
        fprintf(stderr, "canWrite error: %s\n", canResultString(r));
    }

}
コード例 #3
0
ファイル: hubo-esdcan.c プロジェクト: ARTLabPurdue/hubo-ach
int readCan(hubo_can_t skt, struct can_frame *f, double timeoD) {
	(void) timeoD; // ignore this

	/*** Get the Message ***/
	CMSG esd_frame;
	int32_t num  = 1;
	int r = canRead( skt, &esd_frame, &num, NULL );
	// FIXME: check error and handle failure reasonably
	if (NTCAN_SUCCESS != r) {
		fprintf(stderr, "canRead error: %s\n", canResultString(r));
		return 0;
	}

	/*** Convert to socketcan struct ***/
	// id
	f->can_id = esd_frame.id;
	// len
	f->can_dlc = esd_frame.len;
	// data
	for( size_t i = 0; i < esd_frame.len; i ++ ) {
		f->data[i] = esd_frame.data[i];
	}

}