mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-11-29 16:23:55 +08:00
safety tests: lagging RX checks (#3917)
This commit is contained in:
committed by
firestar5683
parent
fa1ceca721
commit
22a9840f8a
@@ -1245,3 +1245,18 @@ class CarSafetyTest(SafetyTest):
|
||||
self.safety.safety_tick()
|
||||
self.assertFalse(self.safety.get_controls_allowed())
|
||||
self.assertFalse(self.safety.safety_config_valid())
|
||||
|
||||
def test_rx_lagging(self):
|
||||
# a check lags after 10 missed messages or 1 s, whichever is longer. checks are at least 10 Hz, so it is always 1 s
|
||||
lag_us = 1000000
|
||||
self.assertGreater(self.safety.get_rx_checks_len(), 0)
|
||||
for stale in range(self.safety.get_rx_checks_len()):
|
||||
for age, allowed in ((lag_us, True), (lag_us + 1, False)):
|
||||
with self.subTest(stale=stale, age=age):
|
||||
self._reset_safety_hooks()
|
||||
self.safety.set_timer(2 * lag_us)
|
||||
self.safety.set_rx_checks_received(stale, age)
|
||||
self.assertTrue(self.safety.safety_config_valid())
|
||||
self.safety.set_controls_allowed(True)
|
||||
self.safety.safety_tick()
|
||||
self.assertEqual(allowed, self.safety.get_controls_allowed())
|
||||
|
||||
@@ -89,6 +89,21 @@ bool safety_test_rx_health_fixture(unsigned int variant, bool canfd) {
|
||||
return healthy;
|
||||
}
|
||||
|
||||
int get_rx_checks_len(void) {
|
||||
return current_safety_config.rx_checks_len;
|
||||
}
|
||||
|
||||
// all RX checks valid, check stale last received age us ago
|
||||
void set_rx_checks_received(int stale, uint32_t age) {
|
||||
for (int i = 0; i < current_safety_config.rx_checks_len; i++) {
|
||||
rx_status[i].msg_seen = true;
|
||||
rx_status[i].valid_checksum = true;
|
||||
rx_status[i].valid_quality_flag = true;
|
||||
rx_status[i].wrong_counters = 0;
|
||||
rx_status[i].last_timestamp = (i == stale) ? (timer_cnt - age) : timer_cnt;
|
||||
}
|
||||
}
|
||||
|
||||
void set_controls_allowed(bool c){
|
||||
controls_allowed = c;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user