1

I might be misunderstanding something about asammdf in general, but I'm not really sure how to go about decoding a CAN frame.

Supposing I have a dbc with relevant messages defined, I get that I can use mdf.extract_bus_logging() to parse the signals, but I'm not really sure what to do from there.

I'm sending a raw payload + can frame ID, and I think I could get away with using cantools to parse the raw data (and then passing that data into an asammdf signal), but it feels like there's some degree of support here within asammdf.

I have an example here along the lines of what I want to do (using this motohawk.dbc file from the cantools examples here 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")


Henry
  • 495
  • 3
  • 11
  • Hello Henry, I don't understand your setup at all. Do you a mf4 file that contains can data? Do you send data and want to log it to a mf4 file? – danielhrisca Dec 15 '20 at 20:39
  • Hi @danielhrisca I'm trying to make something that can receive raw CAN frames and log it to an mf4 file. I have a dbc associated with these messages + signals (and can parse all relevant information using cantools). I was wondering if there's a way of converting the raw can frames to an mf4 file without using cantools. – Henry Dec 15 '20 at 21:38

1 Answers1

0

For logging CAN traffic to an MF4 file you can try this code from python-can

https://github.com/hardbyte/python-can/blob/mf4-io/can/io/mf4.py

danielhrisca
  • 665
  • 1
  • 5
  • 11