Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions j1939/electronic_control_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 13 additions & 0 deletions test/test_ecu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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