Important fixes for attribute handling. 1.) Fix for missing key when a signal attribute is loaded without a previous message attribute for an id. 2.) Fix for dumping attributes when the dbc object does not exist.
@@ -544,6 +544,7 @@ def _dump_attributes(database):
return result
+ if database.dbc is not None:
if database.dbc.attributes is not None:
for name, attribute in database.dbc.attributes.items():
fmt = 'BA_ "{name}" {value};'
@@ -551,6 +552,7 @@ def _dump_attributes(database):
value=get_value(attribute)))
for node in database.nodes:
+ if node.dbc is not None:
if node.dbc.attributes is not None:
for name, attribute in node.dbc.attributes.items():
fmt = 'BA_ "{name}" {kind} {node_name} {value};'
@@ -560,6 +562,7 @@ def _dump_attributes(database):
value=get_value(attribute)))
for message in database.messages:
+ if message.dbc is not None:
if message.dbc.attributes is not None:
for name, attribute in message.dbc.attributes.items():
fmt = 'BA_ "{name}" {kind} {frame_id} {value};'
@@ -569,6 +572,7 @@ def _dump_attributes(database):
value=get_value(attribute)))
for signal in message.signals[::-1]:
+ if signal.dbc is not None:
if signal.dbc.attributes is not None:
for name, attribute in signal.dbc.attributes.items():
fmt = 'BA_ "{name}" {kind} {frame_id} {signal_name} {value};'
@@ -696,6 +700,10 @@ def _load_attributes(tokens, definitions):
frame_id_dbc = attribute[2][1]
signal = attribute[2][2]
+ if frame_id_dbc not in attributes:
+ attributes[frame_id_dbc] = {}
+ attributes[frame_id_dbc]['message'] = OrderedDict()
+
if 'signal' not in attributes[frame_id_dbc]:
attributes[frame_id_dbc]['signal'] = OrderedDict()
