diff --git a/can/interfaces/etas/__init__.py b/can/interfaces/etas/__init__.py index 924e4a8b1..5f2570c7d 100644 --- a/can/interfaces/etas/__init__.py +++ b/can/interfaces/etas/__init__.py @@ -240,9 +240,10 @@ def _apply_filters(self, filters: can.typechecking.CanFilters | None) -> None: else: # enable the SR bit in the mask. since the bit is 0 in flagsValue -> do not self-receive f.flagsMask = OCI_CAN_MSG_FLAG_SELFRECEPTION - if filter_.get("extended"): - f.flagsValue |= OCI_CAN_MSG_FLAG_EXTENDED + if "extended" in filter_: f.flagsMask |= OCI_CAN_MSG_FLAG_EXTENDED + if filter_["extended"]: + f.flagsValue |= OCI_CAN_MSG_FLAG_EXTENDED self._oci_filters[i] = ctypes.pointer(f) OCI_AddCANFrameFilterEx(self.rxQueue, self._oci_filters, len(self._oci_filters)) diff --git a/doc/changelog.d/2177.fixed.rst b/doc/changelog.d/2177.fixed.rst new file mode 100644 index 000000000..df01c7f9c --- /dev/null +++ b/doc/changelog.d/2177.fixed.rst @@ -0,0 +1 @@ +Fixed ``EtasBus`` ignoring ``"extended": False`` in a receive filter, so extended frames whose ID matched ``can_id`` and ``can_mask`` were still received. diff --git a/test/test_etas.py b/test/test_etas.py index bc976f888..34ffeca3d 100644 --- a/test/test_etas.py +++ b/test/test_etas.py @@ -128,6 +128,27 @@ def test_set_filters_replaces_constructor_filters(self): [(0x456, 0x7FF, 0, self.etas.OCI_CAN_MSG_FLAG_SELFRECEPTION)], ) + def test_extended_false_filter_rejects_extended_frames(self): + """ + Test Scope: + A filter with "extended": False installs a BOA filter that + requires the extended flag to be clear. + Preconditions: + An EtasBus created with a standard-ID filter that sets "extended": False. + Events: + The constructor installs the filter. + Evaluate: + The extended flag is in flagsMask and not in flagsValue, so the + controller drops extended frames whose ID matches can_id and can_mask. + """ + selfreception = self.etas.OCI_CAN_MSG_FLAG_SELFRECEPTION + extended = self.etas.OCI_CAN_MSG_FLAG_EXTENDED + self._bus(can_filters=[{"can_id": 0x123, "can_mask": 0x7FF, "extended": False}]) + self.assertEqual( + self.installed, + [(0x123, 0x7FF, 0, selfreception | extended)], + ) + if __name__ == "__main__": unittest.main()