Skip to content

Commit b38d1cb

Browse files
authored
Merge pull request #108 from khauersp/feature/add-bus-filtering
feat: add ability to utilize bus filtering
2 parents e39a525 + a2304ba commit b38d1cb

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

j1939/electronic_control_unit.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,17 @@ def notify(self, can_id, data, timestamp):
288288
"""
289289
self.j1939_dll.notify(can_id, data, timestamp)
290290

291+
def add_bus_filters(self, fitlers: can.typechecking.CanFilters | None):
292+
"""Add bus filters to the underlying CAN bus.
293+
294+
:param filters:
295+
An iterable of dictionaries each containing a "can_id",
296+
a "can_mask", and an optional "extended" key
297+
"""
298+
if self._bus is None:
299+
raise RuntimeError("Not connected to CAN bus")
300+
self._bus.set_filters(fitlers)
301+
291302
def _async_job_thread(self):
292303
"""Asynchronous thread for handling various jobs
293304

test/test_ecu.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,3 +187,16 @@ def test_add_notfier(feeder):
187187
assert feeder.ecu._notifier == notifier
188188
feeder.ecu.remove_notifier()
189189
assert feeder.ecu._notifier == None
190+
191+
def test_add_bus_filters(feeder):
192+
"""
193+
Test adding bus filters to the ECU
194+
"""
195+
bus = can.interface.Bus(interface="virtual", channel=1)
196+
feeder.ecu.add_bus(bus)
197+
filters = [
198+
{'can_id': 0x123, 'can_mask': 0x7FF, 'extended': True},
199+
{'can_id': 0x456, 'can_mask': 0x7FF}
200+
]
201+
feeder.ecu.add_bus_filters(filters)
202+
assert feeder.ecu._bus.filters == filters

0 commit comments

Comments
 (0)