I'm trying to create a MF4 file to be decoded by a 'J1939.dbc' as the same way of CSS electronics
My code to generate a example file is like this:
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')
On the picture:
1) The file generated is this
2) CAN logging is disable - when I use a file from CSS electronics the 'CAN logging' is enable-
But if a try to generate the decode by hand, it returns a blank file
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')
Probably is need to specify the ID and DataByte column to the decode, but I have tried many things but is not working.
What I can do ?
The meta-data for bus logging has to be added as well to the new channel group:
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')