需求
录制了一段CAN报文,数据log,要从中分析出某个信号的值,转换关系y=x*255 + 25
log数据
下面是一部分数据
can7 001 [8] 02 00 00 00 00 00 00 00
can7 002 [8] BC 06 10 73 00 00 00 00
can7 003 [8] 6E E3 05 00 07 00 DB FF
can7 004 [8] 50 0F 09 00 E5 FF F6 FF
can7 005 [8] 5C 23 00 00 00 00 00 00
can7 001 [8] 02 00 00 00 00 00 00 00
can7 002 [8] 44 1A 10 73 00 00 00 00
can7 003 [8] 6F E3 05 00 D8 FF F0 FF
can7 004 [8] 37 10 05 00 F5 FF FF FF
can7 005 [8] 5E 23 00 00 00 00 00 00
can7 001 [8] 02 00 00 00 00 00 00 00
can7 002 [8] CC 2D 10 73 00 00 00 00
can7 003 [8] 70 E3 05 00 EC FF B8 FF
can7 004 [8] 41 0F E5 FF D6 FF F7 FF
can7 005 [8] 5E 23 00 00 00 00 00 00
can7 001 [8] 02 00 00 00 00 00 00 00
can7 002 [8] 54 41 10 73 00 00 00 00
can7 003 [8] 71 E3 05 00 EE FF 0E 00
can7 004 [8] 42 10 21 00 FD FF FA FF
can7 005 [8] 5E 23 00 00 00 00 00 00
can7 001 [8] 02 00 00 00 00 00 00 00
can7 002 [8] DC 54 10 73 00 00 00 00
can7 003 [8] 72 E3 05 00 EE FF 8F FF
can7 004 [8] 31 0F C5 FF CC FF F9 FF
can7 005 [8] 5E 23 00 00 00 00 00 00
can7 001 [8] 02 00 00 00 00 00 00 00
can7 002 [8] 64 68 10 73 00 00 00 00
can7 003 [8] 73 E3 05 00 F7 FF 27 00
can7 004 [8] 48 10 40 00 01 00 F6 FF
can7 005 [8] 65 23 00 00 00 00 00 00
can7 001 [8] 02 00 00 00 00 00 00 00
can7 002 [8] EC 7B 10 73 00 00 00 00
can7 003 [8] 74 E3 05 00 DC FF 9E FF
can7 004 [8] 56 0F AE FF C8 FF FA FF
......
脚本源码
f = open('imu_can.log', 'r')
fout = open('imu_can.txt', 'w')
def calculate_tmp(input):
str_tmp = input[19:24]
tmp = (int(str_tmp[0:2],16) + int(str_tmp[3:5], 16)*255)/255 + 25
tmp = str(tmp) + '\n'
fout.write(tmp)
for line in f.readlines():
if(line[10] == '5'):
calculate_tmp(line)
解析后的数据
60.36078431372549
60.36862745098039
60.36862745098039
60.36862745098039
60.36862745098039
60.39607843137255
60.39607843137255
60.39607843137255
60.39607843137255
60.35294117647059
60.35294117647059
60.35294117647059
60.411764705882355
60.411764705882355
60.411764705882355
60.411764705882355
60.39607843137255
60.39607843137255
60.39607843137255
60.39607843137255
60.36078431372549
60.36078431372549
60.36078431372549
60.36078431372549
60.36862745098039
60.36862745098039
60.36862745098039
60.36862745098039
60.35294117647059
60.35294117647059
60.35294117647059
60.35294117647059
60.411764705882355
后记
在数据量很大的情况下,脚本分析很关键!