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 ); } } }
/** * 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)); } }
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]; } }