diff --git a/j1939/electronic_control_unit.py b/j1939/electronic_control_unit.py index 16fb98e..8a1622d 100644 --- a/j1939/electronic_control_unit.py +++ b/j1939/electronic_control_unit.py @@ -288,6 +288,17 @@ def notify(self, can_id, data, timestamp): """ self.j1939_dll.notify(can_id, data, timestamp) + def add_bus_filters(self, fitlers: can.typechecking.CanFilters | None): + """Add bus filters to the underlying CAN bus. + + :param filters: + An iterable of dictionaries each containing a "can_id", + a "can_mask", and an optional "extended" key + """ + if self._bus is None: + raise RuntimeError("Not connected to CAN bus") + self._bus.set_filters(fitlers) + def _async_job_thread(self): """Asynchronous thread for handling various jobs diff --git a/test/test_ecu.py b/test/test_ecu.py index ad91d45..6e0930e 100644 --- a/test/test_ecu.py +++ b/test/test_ecu.py @@ -187,3 +187,16 @@ def test_add_notfier(feeder): assert feeder.ecu._notifier == notifier feeder.ecu.remove_notifier() assert feeder.ecu._notifier == None + +def test_add_bus_filters(feeder): + """ + Test adding bus filters to the ECU + """ + bus = can.interface.Bus(interface="virtual", channel=1) + feeder.ecu.add_bus(bus) + filters = [ + {'can_id': 0x123, 'can_mask': 0x7FF, 'extended': True}, + {'can_id': 0x456, 'can_mask': 0x7FF} + ] + feeder.ecu.add_bus_filters(filters) + assert feeder.ecu._bus.filters == filters