Vector提供了两种记录数据格式的格式规范:BLF和ASC。
先讲讲ASC。
参看:图文详解CAN Log文件 - ASC文件格式
一、ASC文件格式
在Vector提供的 CAN_LOG_TRIGGER_ASC_Format.pdf 提取码:ltjv 文件中,规定了CANoe/CANalyzer ASC记录中CAN、Log和Trigger event的格式。
1、Header
一个ASCII格式的日志文件以一个header开始。header包含关于日志文件的一般信息。
- base:表示记录的数值是hex十六进制或dec十进制的符号。
- timestamps:表示时间戳是absolute绝对写入测量的开始时间还是relative相对于前一个事件。
- internal:events logged表示是否记录了内部事件。
2、版本编号
从CANalyzer/CANoe v7.0开始,版本号以注释的形式写在Header之后:
- < major >.< minor >表示CANalyzer/CANoe的版本号
- < patch >表示CANalyzer/CANoe主版本中的修改版本(如服务包中的修改)。
3、经典CAN网络中的描述
二、C语言组包ASC文件
CAN2.0格式 ASC
double timeStamps = 0;
FILE* fp1 = fopen(FileName[filecnt], "a");
if (fp1 != NULL)
{if (timeStamps == 0){fprintf(fp1, "base hex timestamps absolute\n");fprintf(fp1, "internal events logged\n");fprintf(fp1, "// version 8.2.1\n");}timeStamps += 0.03;const char* tail = " 244000 126 200000 7e04 51200550 4b140250";//ASCfor (int i = 0; i < 3; i++){fprintf(fp1, " %0.6f CANFD 1 Rx %x 0 0 8 8 %02x %02x %02x %02x %02x %02x %02x %02x %s\n", (timeStamps + i * 0.0001f), (0x750 + i * 3), \SendBuffer[(i * 3)][0], SendBuffer[(i * 3)][1], SendBuffer[(i * 3)][2], SendBuffer[(i * 3)][3], SendBuffer[(i * 3)][4], SendBuffer[(i * 3)][5], SendBuffer[(i * 3)][6], SendBuffer[(i * 3)][7], tail);timeStamps += 0.0002;fprintf(fp1, " %0.6f CANFD 1 Rx %x 0 0 8 8 %02x %02x %02x %02x %02x %02x %02x %02x %s\n", (timeStamps + i * 0.0001f), (0x751 + i * 3), \SendBuffer[(i * 3) + 1][0], SendBuffer[(i * 3) + 1][1], SendBuffer[(i * 3) + 1][2], SendBuffer[(i * 3) + 1][3], SendBuffer[(i * 3) + 1][4], SendBuffer[(i * 3) + 1][5], SendBuffer[(i * 3) + 1][6], SendBuffer[(i * 3) + 1][7], tail);timeStamps += 0.0002;fprintf(fp1, " %0.6f CANFD 1 Rx %x 0 0 8 8 %02x %02x %02x %02x %02x %02x %02x %02x %s\n", (timeStamps + i * 0.0001f), (0x752 + i * 3), \SendBuffer[(i * 3) + 2][0], SendBuffer[(i * 3) + 2][1], SendBuffer[(i * 3) + 2][2], SendBuffer[(i * 3) + 2][3], SendBuffer[(i * 3) + 2][4], SendBuffer[(i * 3) + 2][5], SendBuffer[(i * 3) + 2][6], SendBuffer[(i * 3) + 2][7], tail);timeStamps += 0.0002;}/* In order to be compatible with the final result and make a unified interface, the selection target is taken as the clustering result here, and the selection cluster is set to a fixed value */fclose(fp1);
生成ASC:
base hex timestamps absolute
internal events logged
// version 8.2.10.030000 CANFD 1 Rx 700 0 0 8 8 00 ff 00 ff ff ff 03 00 244000 126 200000 7e04 51200550 4b1402500.030200 CANFD 1 Rx 701 0 0 8 8 00 ff ff ff ff ff ff 03 244000 126 200000 7e04 51200550 4b1402500.030400 CANFD 1 Rx 702 0 0 8 8 00 ff ff 00 00 00 00 00 244000 126 200000 7e04 51200550 4b1402500.030700 CANFD 1 Rx 703 0 0 8 8 00 ff 00 ff ff ff 01 00 244000 126 200000 7e04 51200550 4b140250
CAN FD格式 ASC
double timeStamps = 0;
/* 将结果输出 */
FILE* fp1 = fopen(FileName[filecnt], "a");
if (fp1 != NULL)
{if (timeStamps == 0){fprintf(fp1, "base hex timestamps absolute\n");fprintf(fp1, "internal events logged\n");fprintf(fp1, "// version 8.2.1\n");}timeStamps += 0.0014;const char* tail = " 0 665 303000 a8093377 46500250 4b280150";fprintf(fp1, " %0.6f CANFD 1 Rx %x 1 0 f 64 %02x %02x %02x %02x %02x %02x %02x %02x ", (timeStamps + i * 0.0001f), tempCAN.ID, \tempCAN.Data[0], tempCAN.Data[1], tempCAN.Data[2], tempCAN.Data[3], tempCAN.Data[4], tempCAN.Data[5], tempCAN.Data[6], tempCAN.Data[7]);fprintf(fp1, "%02x %02x %02x %02x %02x %02x %02x %02x ", \tempCAN.Data[8], tempCAN.Data[9], tempCAN.Data[10], tempCAN.Data[11], tempCAN.Data[12], tempCAN.Data[13], tempCAN.Data[14], tempCAN.Data[15]);fprintf(fp1, "%02x %02x %02x %02x %02x %02x %02x %02x ", \tempCAN.Data[16], tempCAN.Data[17], tempCAN.Data[18], tempCAN.Data[19], tempCAN.Data[20], tempCAN.Data[21], tempCAN.Data[22], tempCAN.Data[23]);fprintf(fp1, "%02x %02x %02x %02x %02x %02x %02x %02x ", \tempCAN.Data[24], tempCAN.Data[25], tempCAN.Data[26], tempCAN.Data[27], tempCAN.Data[28], tempCAN.Data[29], tempCAN.Data[30], tempCAN.Data[31]);fprintf(fp1, "%02x %02x %02x %02x %02x %02x %02x %02x ", \tempCAN.Data[32], tempCAN.Data[33], tempCAN.Data[34], tempCAN.Data[35], tempCAN.Data[36], tempCAN.Data[37], tempCAN.Data[38], tempCAN.Data[39]);fprintf(fp1, "%02x %02x %02x %02x %02x %02x %02x %02x ", \tempCAN.Data[40], tempCAN.Data[41], tempCAN.Data[42], tempCAN.Data[43], tempCAN.Data[44], tempCAN.Data[45], tempCAN.Data[46], tempCAN.Data[47]);fprintf(fp1, "%02x %02x %02x %02x %02x %02x %02x %02x ", \tempCAN.Data[48], tempCAN.Data[49], tempCAN.Data[50], tempCAN.Data[51], tempCAN.Data[52], tempCAN.Data[53], tempCAN.Data[54], tempCAN.Data[55]);fprintf(fp1, "%02x %02x %02x %02x %02x %02x %02x %02x%s\n", \tempCAN.Data[56], tempCAN.Data[57], tempCAN.Data[58], tempCAN.Data[59], tempCAN.Data[60], tempCAN.Data[61], tempCAN.Data[62], tempCAN.Data[63], tail);/* In order to be compatible with the final result and make a unified interface, the selection target is taken as the clustering result here, and the selection cluster is set to a fixed value */fclose(fp1);
生成ASC:
base hex timestamps absolute
internal events logged
// version 8.2.10.007800 CANFD 1 Rx 400 1 0 f 64 8e 00 67 24 01 f3 18 00 a1 1a fe c0 08 00 40 00 8e 01 67 24 01 ff fc 00 87 8b 58 80 08 00 40 00 8e 02 67 24 01 f5 20 00 83 bb 8e 40 08 00 40 00 8e 03 e4 f4 00 10 04 00 b4 93 11 00 08 00 40 00 0 665 303000 a8093377 46500250 4b2801500.009200 CANFD 1 Rx 401 1 0 f 64 8e 04 e4 c4 00 50 e8 00 ae 13 8d c0 07 ff bf fc 8e 05 e4 3c 00 70 2c 00 b2 a2 fa 00 07 ff bf fc 8e 06 66 ec 00 11 10 00 f5 6c 3b 00 08 00 3f fc 8e 07 e7 ec 00 10 08 00 9b 55 61 80 08 00 40 00 0 665 303000 a8093377 46500250 4b2801500.010600 CANFD 1 Rx 402 1 0 f 64 8e 08 66 a4 01 10 70 00 c4 33 a4 40 07 ff bf f0 8e 09 65 bc 00 50 40 00 b5 93 95 80 07 ff bf f8 8e 0a 67 24 01 10 c0 00 c4 13 9f 40 08 00 40 00 8e 0b e4 cc 00 10 10 00 c8 64 55 40 08 00 40 00 0 665 303000 a8093377 46500250 4b2801500.012000 CANFD 1 Rx 403 1 0 f 64 8e 0c 67 24 01 ff fc 00 84 3b 8a 80 08 00 40 00 8e 0d 67 24 01 ef fc 00 88 4b 24 80 08 00 40 00 8e 0e e7 b4 00 30 34 00 c4 03 9c 00 08 00 40 00 8e 0f eb ec 00 60 20 00 cb 94 f1 00 08 7e 41 90 0 665 303000 a8093377 46500250 4b280150