Skip to content

Commit a8d0559

Browse files
authored
Merge pull request #881 from SabrineBH/add_baudrate_attribute
Support baudrate custom attribute
2 parents bae280f + 0ffded9 commit a8d0559

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

src/canmatrix/formats/dbc.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,11 @@ def add_frame_by_id(new_frame): # type: (canmatrix.Frame) -> None
871871
temp = regexp.match(decoded)
872872
if temp:
873873
db.add_attribute("BusType", f'"{temp.group(1)}"')
874+
elif '"Baudrate"' in decoded:
875+
regexp = re.compile(r"^BA_ +\"Baudrate\" +(.+?) *; *")
876+
temp = regexp.match(decoded)
877+
if temp:
878+
db.add_attribute("Baudrate", f'{temp.group(1)}')
874879
else:
875880
regexp = re.compile(
876881
r"^BA_ +\"([A-Za-z0-9\-_]+)\" +([\"\S\-\.]+) *; *")

src/canmatrix/formats/fibex.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,14 +470,21 @@ def dump(db, f, **options):
470470
# add the file name as a suffix in the cluster name
471471
cluster_name = f"cluster_{os.path.basename(f.name).split('.')[0]}"
472472
create_short_name_desc(cluster, cluster_name, "clusterDesc")
473-
create_sub_element_fx(cluster, "SPEED", "500")
474473
create_sub_element_fx(cluster, "IS-HIGH-LOW-BIT-ORDER", "true")
475474
create_sub_element_fx(cluster, "BIT-COUNTING-POLICY", "MONOTONE")
476475
if 'BusType' in db.attributes and db.attributes['BusType'] == "CAN FD":
477476
protocol = create_sub_element_fx(cluster, "PROTOCOL", "CAN-FD")
478-
create_sub_element_fx(cluster, "CAN-FD-SPEED", "2000000")
477+
if 'Baudrate' in db.attributes:
478+
create_sub_element_fx(cluster, "CAN-FD-SPEED", db.attributes['Baudrate'])
479+
else:
480+
create_sub_element_fx(cluster, "CAN-FD-SPEED", "2000000")
481+
create_sub_element_fx(cluster, "SPEED", "500")
479482
else:
480483
protocol = create_sub_element_fx(cluster, "PROTOCOL", "CAN")
484+
if 'Baudrate' in db.attributes:
485+
create_sub_element_fx(cluster, "SPEED", db.attributes['Baudrate'])
486+
else:
487+
create_sub_element_fx(cluster, "SPEED", "500")
481488
protocol.attrib['{{{pre}}}type'.format(pre=xsi)] = "can:PROTOCOL-TYPE"
482489
create_sub_element_fx(cluster, "PROTOCOL-VERSION", "20")
483490
channel_refs = create_sub_element_fx(cluster, "CHANNEL-REFS")

0 commit comments

Comments
 (0)