总线出现错误帧或负载帧

on errorFrame
{
const int bufferSize = 256; //bufferSize不可以再被赋值
char buffer[bufferSize];
char cdirection[2][3] = {"RX","TX"};
int ndir;
word ecc;
word extInfo;//byte: 声明一个字节的变量 word: 声明两个字节的变量 dword: 声明四个字节的变量
int isProtocoleException;

ecc = (this.ErrorCode >> 6) &0x23;
extInfo = (this.ErrorCode >> 12) &0x3;
isProtocoleException = (this.ErrorCode & (1 << 15)) != 0;//2的15次方????
ndir = extInfo == 0 || extInfo == 2 ? 0 : 1;
//CAN控制器类型:(1,SJA1000)、(2,CAN Core)、(3、未知)
if(this.CtrlType == 1){
switch(ecc)
{
case 0 : snprintf(buffer,bufferSize,"bit error");break;//将bit error格式化后写入buffer数组中
case 1 : snprintf(buffer,bufferSize,"Form error");break;
case 2 : snprintf(buffer,bufferSize,"Stuff error");break;
case 3 : snprintf(buffer,bufferSize,"Other error");break;
default: snprintf(buffer,bufferSize,"Unkown error code");
}
}
else if(this.CtrlType == 2){
switch(ecc)
{
case 0 : snprintf(buffer,bufferSize,"bit error");break;//将bit error格式化后写入buffer数组中
case 1 : snprintf(buffer,bufferSize,"Form error");break;
case 2 : snprintf(buffer,bufferSize,"Stuff error");break;
case 3 : snprintf(buffer,bufferSize,"Other error");break;
case 4 : snprintf(buffer,bufferSize,"CRC error");break;
case 5 : snprintf(buffer,bufferSize,"ACK Del. error");break;
case 7 :
{
switch(extInfo)
{
case 0 : snprintf(buffer,bufferSize,"RX NACK error (recessive error flag)");break;
case 1 : snprintf(buffer,bufferSize,"TX NACK error (recessive error flag)");break;
case 2 : snprintf(buffer,bufferSize,"RX NACK error (dominant error flag)");break;
case 3 : snprintf(buffer,bufferSize,"TX NACK error (dominant error flag)");break;
}
break;
}
case 8: snprintf(buffer,bufferSize,"Overload frame");break;
case 9: snprintf(buffer,bufferSize,"FDF or res recessive");break;
default: snprintf(buffer,bufferSize,"Unkown error code"); break;
}
}
else snprintf(buffer,bufferSize,"Unsupported CAN controller");
if(isProtocoleException){
write("Protocel exception on CAN%d at %fs :%s",this.can,this.time/1e5,buffer);
}
else{
write("%s ERROR Psi5SensorFrameStruct on CAN%d at %f: %s",this.can,this.time/1e5,buffer);
}
}

  

posted @ 2023-12-09 15:01  韩昊  阅读(77)  评论(0编辑  收藏  举报