我可能对asammdf有一些误解,但我真的不确定如何解码一个CAN帧。
假设我有一个定义了相关消息的dbc,我可以使用mdf.extract_bus_logging()
来解析信号,但我不确定从那里做什么。
我发送了一个原始有效负载+ can帧ID,我认为我可以使用cantools解析原始数据(然后将该数据传递到asammdf信号中),但感觉在asammdf中有一定程度的支持。
我在这里有一个关于我想要做什么的示例(使用cantools示例中的这个motohawk.dbc文件在这里https://cantools.readthedocs.io/en/latest/)
from asammdf import MDF
import cantools
filename = "~/mdf_dbc_play/tmp.dbc"
db = cantools.database.load_file(filename)
msg_bytes = [0,0,0xff,0x01,0x02,0x03,0x04,0x05]
# Temporary bogus timestamp
timestamps = [0.1]
# Use cantools to decode the raw bytes
msg = db.get_message_by_name("EEC1")
unpacked_signals = msg.decode(msg_bytes)
# Using version 3.10 just in case we have some versioning issues with old tooling.
with asammdf.MDF(version='3.10') as mdf:
# I assume there's some way of getting the actual value we care about from an unpacked message.
samples = unpacked_signals.get_values()
sig = asammdf.Signal(name="EEC1", samples=samples, timestamps=timestamps)
mdf.append(sig)
mdf.save("~/mdf_dbc_play/output.mdf")
发布于 2020-12-18 15:55:56
为了将CAN流量记录到MF4文件中,您可以尝试python-can
中的以下代码
https://github.com/hardbyte/python-can/blob/mf4-io/can/io/mf4.py
https://stackoverflow.com/questions/65294691
复制相似问题