From e987e6c6393e1e1432ba6bb740eb2c1b80542043 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Mon, 3 Oct 2022 16:05:16 -0700 Subject: [PATCH] add pandaState.safetyRxChecksInvalid field (#1083) * add fault for invalid safety RX checks * fix test build * debug * fix debug * fix test * just a bool in health --- board/health.h | 3 ++- board/main_comms.h | 1 + board/safety.h | 8 ++++++++ board/safety_declarations.h | 1 + python/__init__.py | 5 +++-- 5 files changed, 15 insertions(+), 3 deletions(-) diff --git a/board/health.h b/board/health.h index 947fdb40..6e783280 100644 --- a/board/health.h +++ b/board/health.h @@ -1,6 +1,6 @@ // When changing these structs, python/__init__.py needs to be kept up to date! -#define HEALTH_PACKET_VERSION 10 +#define HEALTH_PACKET_VERSION 11 struct __attribute__((packed)) health_t { uint32_t uptime_pkt; @@ -25,6 +25,7 @@ struct __attribute__((packed)) health_t { uint16_t alternative_experience_pkt; float interrupt_load; uint8_t fan_power; + uint8_t safety_rx_checks_invalid; }; #define CAN_HEALTH_PACKET_VERSION 2 diff --git a/board/main_comms.h b/board/main_comms.h index 71488de6..c08f0b14 100644 --- a/board/main_comms.h +++ b/board/main_comms.h @@ -29,6 +29,7 @@ int get_health_pkt(void *dat) { health->alternative_experience_pkt = alternative_experience; health->power_save_enabled_pkt = (uint8_t)(power_save_status == POWER_SAVE_STATUS_ENABLED); health->heartbeat_lost_pkt = (uint8_t)(heartbeat_lost); + health->safety_rx_checks_invalid = safety_rx_checks_invalid; health->fault_status_pkt = fault_status; health->faults_pkt = faults; diff --git a/board/safety.h b/board/safety.h index 590d43d8..b96947fa 100644 --- a/board/safety.h +++ b/board/safety.h @@ -164,6 +164,7 @@ int get_addr_check_index(CANPacket_t *to_push, AddrCheckStruct addr_list[], cons // 1Hz safety function called by main. Now just a check for lagging safety messages void safety_tick(const addr_checks *rx_checks) { + bool rx_checks_invalid = false; uint32_t ts = microsecond_timer_get(); if (rx_checks != NULL) { for (int i=0; i < rx_checks->len; i++) { @@ -176,8 +177,14 @@ void safety_tick(const addr_checks *rx_checks) { if (lagging) { controls_allowed = 0; } + + if (lagging || !is_msg_valid(rx_checks->check, i)) { + rx_checks_invalid = true; + } } } + + safety_rx_checks_invalid = rx_checks_invalid; } void update_counter(AddrCheckStruct addr_list[], int index, uint8_t counter) { @@ -339,6 +346,7 @@ int set_safety_hooks(uint16_t mode, uint16_t param) { controls_allowed = false; relay_malfunction_reset(); + safety_rx_checks_invalid = false; int set_status = -1; // not set int hook_config_count = sizeof(safety_hook_registry) / sizeof(safety_hook_config); diff --git a/board/safety_declarations.h b/board/safety_declarations.h index f38512e0..f0c1dff2 100644 --- a/board/safety_declarations.h +++ b/board/safety_declarations.h @@ -146,6 +146,7 @@ float vehicle_speed = 0; bool vehicle_moving = false; bool acc_main_on = false; // referred to as "ACC off" in ISO 15622:2018 int cruise_button_prev = 0; +bool safety_rx_checks_invalid = false; // for safety modes with torque steering control int desired_torque_last = 0; // last desired steer torque diff --git a/python/__init__.py b/python/__init__.py index 2b35ceb6..1c85b04c 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -185,9 +185,9 @@ class Panda: HW_TYPE_RED_PANDA_V2 = b'\x08' CAN_PACKET_VERSION = 2 - HEALTH_PACKET_VERSION = 10 + HEALTH_PACKET_VERSION = 11 CAN_HEALTH_PACKET_VERSION = 2 - HEALTH_STRUCT = struct.Struct("