gpt4 book ai didi

python - 读取.blf CAN文件的 header

转载 作者:行者123 更新时间:2023-12-01 07:49:51 57 4
gpt4 key购买 nike

我有一个包含多个 CAN 总线消息的 .blf 文件,我可以像这样使用 python-can 读取该消息

import can
can_log = can.BLFReader("./test.blf")
for msg in can_log:
print(msg)

根据 python-can 文档,标准 .blf 文件的 header 有 144 个字节,包含整个记录本身的开始和结束时间戳。

我想直接读取这个开始和结束时间戳,可以吗?

我知道我也可以使用 msg.timestamp 从第一条消息中读取时间戳,但它与我想要提取的开始时间戳略有不同。

最佳答案

来自 source code python 可以:

[...]
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

关于python - 读取.blf CAN文件的 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56293298/

57 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com