Skip to content

Commit 51dd03d

Browse files
committed
fix for #471
1 parent 5915980 commit 51dd03d

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/canmatrix/copy.py

+18-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def copy_ecu(ecu_or_glob, source_db, target_db):
6969
target_db.ecu_defines[attribute].update()
7070

7171

72-
def copy_ecu_with_frames(ecu_or_glob, source_db, target_db, rx=True, tx=True):
72+
def copy_ecu_with_frames(ecu_or_glob, source_db, target_db, rx=True, tx=True, direct_ecu_only=True):
7373
# type: (typing.Union[canmatrix.Ecu, str], canmatrix.CanMatrix, canmatrix.CanMatrix) -> None
7474
"""
7575
Copy ECU(s) identified by Name or as Object from source CAN matrix to target CAN matrix.
@@ -78,6 +78,8 @@ def copy_ecu_with_frames(ecu_or_glob, source_db, target_db, rx=True, tx=True):
7878
:param ecu_or_glob: Ecu instance or glob pattern for Ecu name
7979
:param source_db: Source CAN matrix
8080
:param target_db: Destination CAN matrix
81+
:param rx: copy rx-Frames (default: True)
82+
:param tx: copy tx-Frames (default: True)
8183
"""
8284
# check whether ecu_or_glob is object or symbolic name
8385
if isinstance(ecu_or_glob, canmatrix.Ecu):
@@ -103,6 +105,21 @@ def copy_ecu_with_frames(ecu_or_glob, source_db, target_db, rx=True, tx=True):
103105
copy_frame(frame.arbitration_id, source_db, target_db)
104106
break
105107

108+
target_db.update_ecu_list()
109+
110+
if direct_ecu_only:
111+
# delete ecu-names if not direct in communication to ecu
112+
ecus_to_delete = []
113+
for ecu in target_db.ecus:
114+
if ecu not in ecu_list: # ecu is not a wanted ecu
115+
found = False
116+
for frame in target_db.frames:
117+
if ecu.name in frame.transmitters:
118+
found = True # ecu is a sender of a received frame
119+
if not found:
120+
ecus_to_delete.append(ecu)
121+
for ecu in ecus_to_delete:
122+
target_db.del_ecu(ecu)
106123

107124
def copy_signal(signal_glob, source_db, target_db):
108125
# type: (str, canmatrix.CanMatrix, canmatrix.CanMatrix) -> None

0 commit comments

Comments
 (0)