@@ -59,6 +59,9 @@ def __init__(
59
59
log_level : int = logging .INFO ,
60
60
log_to_file : bool = False ,
61
61
log_filename : str | None = None ,
62
+ ignore_ids : list [tuple [int | None , int | None ]]
63
+ | tuple [int | None , int | None ]
64
+ | None = None ,
62
65
) -> None :
63
66
"""
64
67
Construct MavSwarm interface.
@@ -73,13 +76,43 @@ def __init__(
73
76
:type log_to_file: bool, optional
74
77
:param log_filename: name of the file to log messages to, defaults to None
75
78
:type log_filename: str | None, optional
79
+ :param ignore_ids: agent IDs that should be ignored. This can be a list of agent
80
+ IDs or a single agent ID. To specify a system ID that should be ignored, use
81
+ (SYSTEM_ID, None). To specify a component ID that should be ignored, use
82
+ (None, COMPONENT_ID). Note that if messages are being logged, messages from
83
+ the blocked agents will still be logged, defaults to None
84
+ :type ignore_ids: list[tuple[int | None, int | None]] |
85
+ tuple[int | None, int | None] | None, optional
76
86
"""
77
87
super ().__init__ ()
78
88
79
89
self ._logger = init_logger (__name__ , log_level = log_level )
80
90
self .__agent_list_changed = Event ()
81
91
self ._agents = NotifierDict (self .__agent_list_changed )
82
92
93
+ # Create a list of IDs to ignore
94
+ self .__ignore_agent_ids : list [tuple [int | None , int | None ]] = []
95
+ self .__ignore_system_ids : list [int | None ] = []
96
+ self .__ignore_component_ids : list [int | None ] = []
97
+
98
+ # Populate the list of IDs specified by the user
99
+ if ignore_ids is not None :
100
+ if isinstance (ignore_ids , list ):
101
+ for agent_id in ignore_ids :
102
+ if agent_id [1 ] is None :
103
+ self .__ignore_system_ids .append (agent_id [0 ])
104
+ elif agent_id [0 ] is None :
105
+ self .__ignore_component_ids .append (agent_id [1 ])
106
+ else :
107
+ self .__ignore_agent_ids .append (agent_id )
108
+ else :
109
+ if ignore_ids [1 ] is None :
110
+ self .__ignore_system_ids .append (ignore_ids [0 ])
111
+ elif ignore_ids [0 ] is None :
112
+ self .__ignore_component_ids .append (ignore_ids [1 ])
113
+ else :
114
+ self .__ignore_agent_ids .append (ignore_ids )
115
+
83
116
# Register a listener to update the system time publish rate
84
117
self .__agent_list_changed .add_listener (self .__request_system_time )
85
118
@@ -2401,6 +2434,16 @@ def __receive_message(self) -> None:
2401
2434
message .to_dict (),
2402
2435
)
2403
2436
2437
+ # Don't handle the message if it's from an ignored agent
2438
+ agent_id = (message .get_srcSystem (), message .get_srcComponent ())
2439
+
2440
+ if (
2441
+ agent_id [0 ] in self .__ignore_system_ids
2442
+ or agent_id [1 ] in self .__ignore_component_ids
2443
+ or agent_id in self .__ignore_agent_ids
2444
+ ):
2445
+ continue
2446
+
2404
2447
# Execute the respective message handler(s)
2405
2448
if message .get_type () in self .__message_receivers .receivers :
2406
2449
for function in self .__message_receivers .receivers [message .get_type ()]:
0 commit comments