// here all is done int main(int argc, char *argv[]) { char *ptr; int i; const char *szDeviceNode = DEFAULT_NODE; errno = 0; current_release = CURRENT_RELEASE; disclaimer("bitratetest"); // decode command line arguments for (i = 1; i < argc; i++) { char c; ptr = argv[i]; while (*ptr == '-') ptr++; c = *ptr; ptr++; if (*ptr == '=') ptr++; switch(tolower(c)) { case 'f': szDeviceNode = ptr; break; case '?': case 'h': hlpMsg(); my_private_exit(0); break; default: errno = EINVAL; perror("bitratetest: unknown command line argument"); my_private_exit(errno); break; } } // open the CAN port // please use what is appropriate // HW_DONGLE_SJA // HW_DONGLE_SJA_EPP // HW_ISA_SJA // HW_PCI h = LINUX_CAN_Open(szDeviceNode, O_RDWR); if (h) { char txt[VERSIONSTRING_LEN]; // get version info errno = CAN_VersionInfo(h, txt); if (!errno) printf("bitratetest: driver version = %s\n", txt); else { perror("bitratetest: CAN_VersionInfo()"); my_private_exit(errno); } printf("\n"); // calculate BTR0BTR1 from bitrates for (i = 1000000; i > 2500; i /= 2) { if (i == 62500) i = 100000; if (i == 6250) i = 10000; printf("bitratetest: %d bits/sec \t->BTR0BTR1=0x%04x\n", i + 1, LINUX_CAN_BTR0BTR1(h, i + 1)); printf(" %d bits/sec \t->BTR0BTR1=0x%04x\n", i , LINUX_CAN_BTR0BTR1(h, i)); printf(" %d bits/sec \t->BTR0BTR1=0x%04x\n", i - 1, LINUX_CAN_BTR0BTR1(h, i - 1)); }; printf("\n"); } else { errno = nGetLastError(); perror("bitratetest: CAN_Open()"); } my_private_exit(errno); return errno; }
void BVCan::initializeCan( ){ #ifdef USE_CAN WORD awBTR0BTR1=0x0014; int aCANMsgType=0; h = NULL; errno = 0; device = string("/dev/pcan32"); // open the device // // O_RDWR which request opening the file read/write h = LINUX_CAN_Open((char*)(device.c_str()), O_RDWR); if (h==0) { device = string("/dev/pcan0"); h = LINUX_CAN_Open((char*)(device.c_str()), O_RDWR); } if(h==0){ cerr<< "PCan_Device nicht gefunden !!!"<<endl; exit(37); } if(h){ PCAN_DESCRIPTOR *desc= (PCAN_DESCRIPTOR *)h; BV_ASSERT( desc->nFileNo>0 ); BV_DEBUGINFO4NNL("BVCan::ctor device=[" << desc->szDevicePath << "]"); BV_DEBUGINFO4C(" fd=[" << desc->nFileNo << "]" << endl); setfd(desc->nFileNo); CAN_Status(h); // ----------------------------------------------------------- // returns a text string with driver version info errno = CAN_VersionInfo(h, info); if (!errno){ string infostr( string(info) ); BV_DEBUGINFO4("BVCan::ctor driver version=[" << infostr << "]"); } else perror("BVCan::ctor CAN_VersionInfo()"); wBTR0BTR1 = 0x401c; if(LINUX_CAN_BTR0BTR1(h,wBTR0BTR1)==0) BV_WARNING("BVCan::ctor 0x" << hex << wBTR0BTR1 << dec << " is not possible" ); else BV_DEBUGINFO4("BVCan::ctor baudrate changes to 0x" << hex << wBTR0BTR1 << dec ); } else BV_DEBUGINFO4("BVCan::ctor cannot open the can device"); BV_WARNING("BVCan::initializeCan ....................."); if(h){ // init to a user defined bit rate //nExtended = CAN_INIT_TYPE_ST; //wBTR0BTR1 = CAN_BAUD_500K; canMsgType = aCANMsgType; wBTR0BTR1 = awBTR0BTR1; errno = CAN_Init(h, wBTR0BTR1, canMsgType); if (errno) perror("BVCan::initializeCan CAN_Init failed"); else BV_WARNING("BVCan::initializeCan baudrate=0x" << hex << wBTR0BTR1 << dec << " msgType=" << canMsgType ); } else BV_WARNING("BVCan::initializeCan can HANDLE is NULL"); #endif }