在打印数据过程中发现有数据错位的现象发送 /*打印函数*/ void printfMessage(struct ObjectMessage *Msg) { unsigned int i=0; unsigned char DLC=0; unsigned char buf[8]; memset(buf, 0, 8); DLC = Msg->RFS_TFI.Bits.DLC_BIT; //print("TFI=%#X ", Msg->RFS_TFI); print("ID=%#X: x0dx0a", Msg->ID); switch (DLC){ case 8: buf[7] = Msg->CANRDB.Bits.Data4_BIT; case 7: buf[6] = Msg->CANRDB.Bits.Data3_BIT; case 6: buf[5] = Msg->CANRDB.Bits.Data2_BIT; case 5: buf[4] = Msg->CANRDB.Bits.Data1_BIT; case 4: buf[3] = Msg->CANRDA.Bits.Data4_BIT; case 3: buf[2] = Msg->CANRDA.Bits.Data3_BIT; case 2: buf[1] = Msg->CANRDA.Bits.Data2_BIT; case 1: buf[0] = Msg->CANRDA.Bits.Data1_BIT; break; default: print("DLC=%dx0dx0ax0dx0a", DLC); return; } for(i=0;i<DLC;i++){ print("f%d=%#x,", i, buf); } print("x0dx0ax0dx0a"); }
void SendLow2HighData2Bus(void) { struct Low2High *ptr=&LowSpeed2Highbuf;
if (ptr->TxBusy) return; if ((ptr->start != ptr->end) || ptr->full == _FULL_) { //if (CANGSR(CAN2).Bits.TBS_BIT != 0){ if (BegainSend2CANBus(CAN2, &ptr->buf[ptr->end]) != 1){ //TCAN_LEDGlint(); ptr->TxBusy = 1;//开始向高速CAN口发送报文 //在此打印由5K总线收到并发送给20K的数据帧 printfMessage(&ptr->buf[ptr->end]); if (++ptr->end >= SIZEOF_LOW_HIGH) { ptr->end = 0; } ptr->full = 0; }else { print("2:busyx0dx0a"); } //} } }
/************************************************/ /*打印结果如下(出错即丢帧时)*/
//事件1,2帧 ID=0X1C880100: f0=0x5,f1=0x1,f2=0x9,f3=0xed,f4=0x2a,f5=0xb9,f6=0x49,f7=0x1,
ID=0XC840100: f0=0,f1=0,f2=0x1,f3=0,f4=0,f5=0,f6=0,f7=0,
//事件2,2帧 ID=0X1C888200: f0=0x5,f1=0x82,f2=0x9,f3=0xec,f4=0x2a,f5=0xb9,f6=0x49,f7=0x1,
ID=0XC848200: f0=0,f1=0,f2=0x1,f3=0,f4=0,f5=0,f6=0,f7=0,
//事件3,2帧 ID=0X1C888300: f0=0xb,f1=0x83,f2=0x9,f3=0xec,f4=0x2a,f5=0xb9,f6=0x49,f7=0x1,
ID=0XC848300: f0=0,f1=0,f2=0x1,f3=0,f4=0,f5=0,f6=0,f7=0,
//事件4,2帧 ID=0X1C888100: f0=0xb,f1=0x81,f2=0x9,f3=0xed,f4=0x2a,f5=0xb9,f6=0x49,f7=0x1,
ID=0XC848100: f0=0,f1=0,f2=0x1,f3=0,f4=0,f5=0,f6=0,f7=0,
//事件5,2帧 ID=0X1C880100: f0=0xb,f1=0x1,f2=0x9,f3=0xee,f4=0x2a,f5=0xb9,f6=0x49,f7=0x1,
ID=0XC840100: f0=0,f1=0,f2=0x1,f3=0,f4=0,f5=0,f6=0,f7=0,
//事件6,2帧 ID=0X1C888200: f0=0xb,f1=0x82,f2=0x9,f3=0xed,f4=0x2a,f5=0xb9,f6=0x49,f7=0x1,
ID=0XC848200: f0=0,f1=0,f2=0x1,f3=0,f4=0,f5=0,f6=0,f7=0,
//事件7,2帧 //本帧出错,f0~f7的内容应与其它事件信息一样即 //f0应为0xb,貌似f0数据丢失,而后续的向前移动了一个字节,导致节点 //无法正确识别数据帧格式,导致事件丢失 ID=0X44: f0=0x81,f1=0x9,f2=0xed,f3=0x2a,f4=0xb9,
ID=0XC848100: f0=0,f1=0,f2=0x1,f3=0,f4=0,f5=0,f6=0,f7=0,
//事件8,2帧 //同上,本节点正好丢失的2个事件,就是7,8 ID=0XC4: f0=0x83,f1=0x9,f2=0xed,f3=0x2a,f4=0xb9,
ID=0XC848300: f0=0,f1=0,f2=0x1,f3=0,f4=0,f5=0,f6=0,f7=0,
//不知道为什么帧内数据为出错 还有次打印出 DLC=11;不解中,收帧函数有bug??? |