28 #include <boost/thread/thread.hpp> 37 #define MLOGPK(LEVEL,THIS) LOG(Log::LEVEL, THIS->logItHandle()) << __FUNCTION__ << " " << " peak bus= " << THIS->getBusName() << " " 54 m_CanScanThreadRunEnableFlag(false)
56 m_statistics.beginNewRun();
70 MLOGPK(
TRC,
this) <<
" try finishing thread...calling CAN_Uninitialize";
72 MLOGPK(
TRC,
this) <<
"CAN_Uninitialize returns " << (int) tpcanStatus;
102 TPCANMsg tpcanMessage;
103 TPCANTimestamp tpcanTimestamp;
104 TPCANStatus tpcanStatus = CAN_Read(tpcanHandler,&tpcanMessage,&tpcanTimestamp);
105 if (tpcanStatus == PCAN_ERROR_OK) {
107 for(
int i=0; i < 8; i++)
115 unsigned long long mmsec = 0xFFFFFFFFUL;
116 mmsec = mmsec * 1000;
117 mmsec = mmsec * tpcanTimestamp.millis_overflow;
118 mmsec = mmsec + tpcanTimestamp.micros;
119 mmsec = mmsec + 1000 * tpcanTimestamp.millis;
126 if (tpcanStatus & PCAN_ERROR_QRCVEMPTY) {
130 if (tpcanStatus | PCAN_ERROR_ANYBUSERR) {
131 CAN_Initialize(tpcanHandler,pkCanScanPointer->
m_baudRate);
136 MLOGPK(
TRC, pkCanScanPointer) <<
"exiting thread...";
164 LogItInstance* logItInstance = CCanAccess::getLogItInstance();
166 std::cout << __FILE__ <<
" " << __LINE__ <<
" " << __FUNCTION__
167 <<
" could not set LogIt instance" << std::endl;
170 std::cout << __FILE__ <<
" " << __LINE__ <<
" " << __FUNCTION__
173 MLOGPK(
DBG,
this) <<
" name= " <<
name <<
" parameters= " << parameters <<
", configuring CAN board";
177 MLOGPK(
ERR,
this ) <<
" name= " <<
name <<
" parameters= " << parameters <<
", failed to configure CAN board";
181 bool skipMainThreadCreation =
false;
190 LOG(
Log::WRN) << __FUNCTION__ <<
" bus exists already [" <<
name <<
", " << parameters <<
"], not creating another main thread";
191 skipMainThreadCreation =
true;
195 if ( skipMainThreadCreation ){
228 vector<string> vectorString;
230 MLOGPK(
DBG,
this) <<
" calling getHandle vectorString[1]= " << vectorString[1] << std::endl;
233 int ich = atoi(vectorString[1].c_str());
234 stringstream channel;
237 string interface = "USB";
238 string humanReadableCode =
interface + channel.str();
240 MLOGPK(
DBG,
this ) <<
"PEAK handle for vectorString[1]= " << vectorString[1]
242 <<
" human readable code= " << humanReadableCode << std::endl;
245 if (strcmp(parameters.c_str(),
"Unspecified") != 0)
281 MLOGPK(
ERR,
this) <<
"Error while parsing parameters: this syntax is incorrect: [" << parameters <<
"]";
286 MLOGPK(
DBG,
this) <<
"Unspecified parameters, default values will be used.";
306 MLOGPK(
TRC,
this) <<
"calling CAN_Initialize";
307 TPCANStatus tpcanStatus = 99;
309 while ( tpcanStatus != 0 && counter > 0 ){
311 MLOGPK(
TRC,
this) <<
"CAN_Initialize returns " << (int) tpcanStatus <<
" counter= " << counter;
312 if ( tpcanStatus == 0 ) {
313 MLOGPK(
TRC,
this) <<
"CAN_Initialize returns " << (int) tpcanStatus <<
" OK";
317 MLOGPK(
TRC,
this) <<
"try again... calling Can_Uninitialize " ;
332 return tpcanStatus == PCAN_ERROR_OK;
346 if (status != PCAN_ERROR_OK)
361 MLOGPK(
DBG,
this) <<
"Sending message: [" << ( message == 0 ?
"" : (
const char *) message) <<
"], cobID: [" << cobID <<
"], Message Length: [" <<
static_cast<int>(len) <<
"]";
363 TPCANStatus tpcanStatus;
364 TPCANMsg tpcanMessage;
365 tpcanMessage.ID = cobID;
366 tpcanMessage.MSGTYPE = PCAN_MESSAGE_STANDARD;
368 tpcanMessage.MSGTYPE = PCAN_MESSAGE_RTR;
370 int lengthOfUnsentData, lengthToBeSent;
371 lengthOfUnsentData = len;
375 if (lengthOfUnsentData > 8) {
377 lengthOfUnsentData = lengthOfUnsentData - 8;
379 lengthToBeSent = lengthOfUnsentData;
381 tpcanMessage.LEN = lengthToBeSent;
383 memcpy(tpcanMessage.DATA,message,lengthToBeSent);
385 if (tpcanStatus != PCAN_ERROR_OK) {
389 message = message + lengthToBeSent;
391 while (lengthOfUnsentData > 8);
397 TPCANMsg tpcanMessage;
398 tpcanMessage.ID = cobID;
399 tpcanMessage.MSGTYPE = PCAN_MESSAGE_RTR;
407 CAN_GetErrorText((TPCANStatus)
error,0, tmp);
408 *message =
new char[strlen(tmp)+1];
409 strcpy(*message,tmp);
420 const char *channelNameArray[] = {
421 "ISA1",
"ISA2",
"ISA3",
"ISA4",
"ISA5",
"ISA6",
"ISA7",
"ISA8",
423 "PCI1",
"PCI2",
"PCI3",
"PCI4",
"PCI5",
"PCI6",
"PCI7",
"PCI8",
424 "USB1",
"USB2",
"USB3",
"USB4",
"USB5",
"USB6",
"USB7",
"USB8",
428 const TPCANHandle handlerArray[] = {
461 int chn =
sizeof(channelNameArray)/
sizeof(channelNameArray[0]);
462 char tmpName[] =
"temp";
463 for (
unsigned int j=0; j < 4; j++) {
464 tmpName[j] = toupper(
name[j]);
466 for (
int i = 0; i < chn; i++) {
467 if (strcmp(channelNameArray[i],tmpName) == 0) {
468 return handlerArray[i];