0

我正在尝试创建一个 MF4 文件以由“J1939.dbc”解码,就像CSS 电子设备一样

我生成示例文件的代码是这样的:

from asammdf import MDF, SUPPORTED_VERSIONS, Signal
import numpy as np

sigs = []
mdf = MDF()

samples = [
    np.array([1,1,1,1,1], dtype=np.uint32),
    np.array([217056256,217056256,217056256,217056256,217056256], dtype=np.uint32),
    np.array([1,1,1,1,1], dtype=np.uint32),
    np.array([1,1,1,1,1], dtype=np.uint32),
    np.array([1,1,1,1,1], dtype=np.uint32),
    np.ones(5, dtype=np.dtype('(8,)u1'))*111,
    np.array([1,1,1,1,1], dtype=np.uint32),
    np.array([1,1,1,1,1], dtype=np.uint32),
    np.array([1,1,1,1,1], dtype=np.uint32)
]   

types = [('CAN_DataFrame.BusChannel', 'u1'),
        ('CAN_DataFrame.ID', '<u4'), 
        ('CAN_DataFrame.IDE', 'u1'), 
        ('CAN_DataFrame.DLC', 'u1'), 
        ('CAN_DataFrame.DataLength', 'u1'),
        ('CAN_DataFrame.DataBytes', 'u1', (8,)), 
        ('CAN_DataFrame.Dir', 'u1'),
        ('CAN_DataFrame.EDL', 'u1'), 
        ('CAN_DataFrame.BRS', 'u1')]

t = np.arange(5, dtype=np.float64)

sig = Signal(
    np.core.records.fromarrays(samples, dtype=np.dtype(types)),
    t+10,
    name='Channel_structure_composition',
    comment='Structure channel composition',
)
sigs.append(sig)

mdf.append(sigs, comment='arrays', common_timebase=True)

mdf.save('demo.mf4', overwrite=True)
print('save')

图片上:

1)生成的文件是这个

2) CAN 日志记录被禁用 - 当我使用来自CSS 电子设备的文件时,“CAN 日志记录”被启用 -

在此处输入图像描述

但是如果尝试手动生成解码,它会返回一个空白文件

import numpy as np
from asammdf import MDF, SUPPORTED_VERSIONS, Signal


mdf = MDF(r'demo.mf4')
databases = {
     "CAN": ["j1939.dbc"]
    }
extracted = mdf.extract_bus_logging(database_files=databases)
extracted.save('sorted.mf4')

可能需要为解码指定 ID 和 DataByte 列,但我尝试了很多东西但没有工作。

我可以做什么 ?

4

1 回答 1

1

总线记录的元数据也必须添加到新的通道组中:

from asammdf import MDF, SUPPORTED_VERSIONS, Signal
import numpy as np
from asammdf.blocks.source_utils import Source

sigs = []
mdf = MDF()

samples = [
    np.array([1,1,1,1,1], dtype=np.uint32),
    np.array([217056256,217056256,217056256,217056256,217056256], dtype=np.uint32),
    np.array([1,1,1,1,1], dtype=np.uint32),
    np.array([1,1,1,1,1], dtype=np.uint32),
    np.array([1,1,1,1,1], dtype=np.uint32),
    np.ones(5, dtype=np.dtype('(8,)u1'))*111,
    np.array([1,1,1,1,1], dtype=np.uint32),
    np.array([1,1,1,1,1], dtype=np.uint32),
    np.array([1,1,1,1,1], dtype=np.uint32)
]

types = [('CAN_DataFrame.BusChannel', 'u1'),
        ('CAN_DataFrame.ID', '<u4'),
        ('CAN_DataFrame.IDE', 'u1'),
        ('CAN_DataFrame.DLC', 'u1'),
        ('CAN_DataFrame.DataLength', 'u1'),
        ('CAN_DataFrame.DataBytes', 'u1', (8,)),
        ('CAN_DataFrame.Dir', 'u1'),
        ('CAN_DataFrame.EDL', 'u1'),
        ('CAN_DataFrame.BRS', 'u1')]

t = np.arange(5, dtype=np.float64)

sig = Signal(
    np.core.records.fromarrays(samples, dtype=np.dtype(types)),
    t+10,
    name='Channel_structure_composition',
    comment='Structure channel composition',
    source=Source(
        source_type=Source.SOURCE_BUS,
        bus_type=Source.BUS_TYPE_CAN,
        name="CAN bus",
        path="CAN bus",
        comment="",
    )
)
sigs.append(sig)

mdf.append(sigs, comment='arrays', common_timebase=True)

mdf.save('demo.mf4', overwrite=True)
print('save')
于 2021-03-17T22:07:19.320 回答