Skip to content

Commit 9358ee6

Browse files
authored
Revert "Move relay malfunction check to fwd hook" (commaai#2089)
Revert "Move relay malfunction check to fwd hook (commaai#2087)" This reverts commit 5a24ffe.
1 parent 5a24ffe commit 9358ee6

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

opendbc/safety/safety.h

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,18 @@ bool safety_rx_hook(const CANPacket_t *to_push) {
219219
// Handles gas, brake, and regen paddle
220220
generic_rx_checks();
221221

222+
// the relay malfunction hook runs on all incoming rx messages.
223+
// check all tx msgs for liveness on sending bus if specified.
224+
// used to detect a relay malfunction or control messages from disabled ECUs like the radar
225+
const int bus = GET_BUS(to_push);
226+
const int addr = GET_ADDR(to_push);
227+
for (int i = 0; i < current_safety_config.tx_msgs_len; i++) {
228+
const CanMsg *m = &current_safety_config.tx_msgs[i];
229+
if (m->check_relay) {
230+
stock_ecu_check((m->addr == addr) && (m->bus == bus));
231+
}
232+
}
233+
222234
// reset mismatches on rising edge of controls_allowed to avoid rare race condition
223235
if (controls_allowed && !controls_allowed_prev) {
224236
heartbeat_engaged_mismatches = 0;
@@ -269,16 +281,6 @@ static int get_fwd_bus(int bus_num) {
269281
}
270282

271283
int safety_fwd_hook(int bus_num, int addr) {
272-
// the relay malfunction hook runs on all incoming rx messages.
273-
// check all tx msgs for liveness on sending bus if specified.
274-
// used to detect a relay malfunction or control messages from disabled ECUs like the radar
275-
for (int i = 0; i < current_safety_config.tx_msgs_len; i++) {
276-
const CanMsg *m = &current_safety_config.tx_msgs[i];
277-
if (m->check_relay) {
278-
stock_ecu_check((m->addr == addr) && (m->bus == bus_num));
279-
}
280-
}
281-
282284
bool blocked = relay_malfunction || current_safety_config.disable_forwarding;
283285

284286
if (!blocked && (current_hooks->fwd != NULL)) {

opendbc/safety/tests/common.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,6 @@ class PandaSafetyTest(PandaSafetyTestBase):
751751
*range(0x18DA00F1, 0x18DB00F1, 0x100), # 29-bit UDS physical addressing
752752
*range(0x18DB00F1, 0x18DC00F1, 0x100), # 29-bit UDS functional addressing
753753
*range(0x3300, 0x3400)] # Honda
754-
RELAY_MALFUNCTION_ADDRS: dict[int, tuple[int, ...]] | None = {}
755754
FWD_BLACKLISTED_ADDRS: dict[int, list[int]] = {} # {bus: [addr]}
756755
FWD_BUS_LOOKUP: dict[int, int] = {0: 2, 2: 0}
757756

@@ -775,13 +774,10 @@ def test_fwd_hook(self):
775774
# some safety modes don't forward anything, while others blacklist msgs
776775
for bus in range(3):
777776
for addr in self.SCANNED_ADDRS:
778-
self.safety.set_relay_malfunction(False)
779777
# assume len 8
780778
fwd_bus = self.FWD_BUS_LOOKUP.get(bus, -1)
781779
if bus in self.FWD_BLACKLISTED_ADDRS and addr in self.FWD_BLACKLISTED_ADDRS[bus]:
782780
fwd_bus = -1
783-
if bus in self.RELAY_MALFUNCTION_ADDRS and addr in self.RELAY_MALFUNCTION_ADDRS[bus]:
784-
fwd_bus = -1
785781
self.assertEqual(fwd_bus, self.safety.safety_fwd_hook(bus, addr), f"{addr=:#x} from {bus=} to {fwd_bus=}")
786782

787783
def test_spam_can_buses(self):
@@ -882,6 +878,7 @@ def test_tx_hook_on_wrong_safety_mode(self):
882878
class PandaCarSafetyTest(PandaSafetyTest):
883879
STANDSTILL_THRESHOLD: float = 0.0
884880
GAS_PRESSED_THRESHOLD = 0
881+
RELAY_MALFUNCTION_ADDRS: dict[int, tuple[int, ...]] | None = None
885882

886883
@classmethod
887884
def setUpClass(cls):
@@ -922,7 +919,7 @@ def test_relay_malfunction(self):
922919
for bus in range(3):
923920
for addr in self.SCANNED_ADDRS:
924921
self.safety.set_relay_malfunction(False)
925-
self.safety.safety_fwd_hook(bus, addr)
922+
self._rx(make_msg(bus, addr, 8))
926923
should_relay_malfunction = addr in self.RELAY_MALFUNCTION_ADDRS.get(bus, ())
927924
self.assertEqual(should_relay_malfunction, self.safety.get_relay_malfunction(), (bus, hex(addr)))
928925

opendbc/safety/tests/hyundai_common.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import opendbc.safety.tests.common as common
44
from opendbc.safety.tests.libsafety import libsafety_py
5+
from opendbc.safety.tests.common import make_msg
56

67

78
class Buttons:
@@ -150,5 +151,5 @@ def test_disabled_ecu_alive(self):
150151

151152
addr, bus = self.DISABLED_ECU_ACTUATION_MSG
152153
self.assertFalse(self.safety.get_relay_malfunction())
153-
self.safety.safety_fwd_hook(bus, addr)
154+
self._rx(make_msg(bus, addr, 8))
154155
self.assertTrue(self.safety.get_relay_malfunction())

0 commit comments

Comments
 (0)