创建要由 J1939 DBC 解码的 MF4 - asammdf
Create MF4 to be decode by J1939 DBC - asammdf
我正在尝试创建一个 MF4 文件,由 'J1939.dbc' 以与 CSS electronics
相同的方式解码
我生成示例文件的代码是这样的:
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 electronics 的文件时 'CAN logging' 被启用 -
但是如果尝试手动生成解码,它 returns 一个空白文件
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 列来解码,但我尝试了很多方法但没有用。
我能做什么?
总线日志记录的元数据也必须添加到新的通道组中:
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')
我正在尝试创建一个 MF4 文件,由 'J1939.dbc' 以与 CSS electronics
相同的方式解码我生成示例文件的代码是这样的:
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 electronics 的文件时 'CAN logging' 被启用 -
但是如果尝试手动生成解码,它 returns 一个空白文件
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 列来解码,但我尝试了很多方法但没有用。
我能做什么?
总线日志记录的元数据也必须添加到新的通道组中:
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')