diff --git a/src/canmatrix/formats/dbc.py b/src/canmatrix/formats/dbc.py index 1f023a5f..7f41829c 100644 --- a/src/canmatrix/formats/dbc.py +++ b/src/canmatrix/formats/dbc.py @@ -865,6 +865,11 @@ def add_frame_by_id(new_frame): # type: (canmatrix.Frame) -> None temp = regexp.match(decoded) if temp: db.add_attribute("BusType", f'"{temp.group(1)}"') + elif '"Baudrate"' in decoded: + regexp = re.compile(r"^BA_ +\"Baudrate\" +(.+?) *; *") + temp = regexp.match(decoded) + if temp: + db.add_attribute("Baudrate", f'{temp.group(1)}') else: regexp = re.compile( r"^BA_ +\"([A-Za-z0-9\-_]+)\" +([\"\S\-\.]+) *; *") diff --git a/src/canmatrix/formats/fibex.py b/src/canmatrix/formats/fibex.py index b67e867f..bb7f6239 100644 --- a/src/canmatrix/formats/fibex.py +++ b/src/canmatrix/formats/fibex.py @@ -464,15 +464,22 @@ def dump(db, f, **options): # add the file name as a suffix in the cluster name cluster_name = f"cluster_{os.path.basename(f.name).split('.')[0]}" create_short_name_desc(cluster, cluster_name, "clusterDesc") - create_sub_element_fx(cluster, "SPEED", "500") create_sub_element_fx(cluster, "IS-HIGH-LOW-BIT-ORDER", "true") create_sub_element_fx(cluster, "BIT-COUNTING-POLICY", "MONOTONE") attribute = db.attributes["BusType"] if attribute is not None and attribute == "CAN FD": protocol = create_sub_element_fx(cluster, "PROTOCOL", "CAN-FD") - create_sub_element_fx(cluster, "CAN-FD-SPEED", "2000000") + if 'Baudrate' in db.attributes: + create_sub_element_fx(cluster, "CAN-FD-SPEED", db.attributes['Baudrate']) + else: + create_sub_element_fx(cluster, "CAN-FD-SPEED", "2000000") + create_sub_element_fx(cluster, "SPEED", "500") else: protocol = create_sub_element_fx(cluster, "PROTOCOL", "CAN") + if 'Baudrate' in db.attributes: + create_sub_element_fx(cluster, "SPEED", db.attributes['Baudrate']) + else: + create_sub_element_fx(cluster, "SPEED", "500") protocol.attrib['{{{pre}}}type'.format(pre=xsi)] = "can:PROTOCOL-TYPE" create_sub_element_fx(cluster, "PROTOCOL-VERSION", "20") channel_refs = create_sub_element_fx(cluster, "CHANNEL-REFS")