我有一个包含多个can总线消息的.blf文件,我可以像这样使用python-can读取这些消息
import can
can_log = can.BLFReader("./test.blf")
for msg in can_log:
print(msg)
根据python-can文档,标准.blf文件头有144个字节,包含整个记录本身的开始和结束时间戳。
我想直接读取这个开始和结束时间戳,这是可能的吗?
我知道我也可以使用msg.timestamp从第一条消息中读取时间戳,但它与我想要提取的开始时间戳略有不同。
发布于 2019-05-24 21:15:44
从python的source code可以:
[...]
class BLFReader(object):
"""
Iterator of CAN messages from a Binary Logging File.
Only CAN messages and error frames are supported. Other object types are
silently ignored.
"""
def __init__(self, filename):
self.fp = open(filename, "rb")
data = self.fp.read(FILE_HEADER_STRUCT.size)
header = FILE_HEADER_STRUCT.unpack(data)
#print(header)
assert header[0] == b"LOGG", "Unknown file format"
self.file_size = header[10]
self.uncompressed_size = header[11]
self.object_count = header[12]
self.start_timestamp = systemtime_to_timestamp(header[14:22])
self.stop_timestamp = systemtime_to_timestamp(header[22:30])
[...]
您可以这样使用start_timestamp和stop_timestamp:
can_log.start_timestamp
https://stackoverflow.com/questions/56293298
复制相似问题