From 3c75a8bc00f503f59a32fead3098afa88139ba07 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Thu, 20 Apr 2023 13:30:56 -0700 Subject: [PATCH] add fan stall count to health (#1355) * add fan stall count to health * fix misra --------- Co-authored-by: Comma Device --- board/drivers/fan.h | 2 ++ board/health.h | 3 ++- board/main_comms.h | 1 + python/__init__.py | 5 +++-- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/board/drivers/fan.h b/board/drivers/fan.h index da6361c4..d34efbb0 100644 --- a/board/drivers/fan.h +++ b/board/drivers/fan.h @@ -5,6 +5,7 @@ struct fan_state_t { uint8_t power; float error_integral; uint8_t stall_counter; + uint8_t total_stall_count; uint8_t cooldown_counter; } fan_state_t; struct fan_state_t fan_state; @@ -46,6 +47,7 @@ void fan_tick(void){ if (fan_state.stall_counter > FAN_STALL_THRESHOLD) { // Stall detected, power cycling fan controller current_board->set_fan_enabled(false); + fan_state.total_stall_count += 1U; // clip integral, can't fully reset otherwise we may always be stuck in stall detection fan_state.error_integral = MIN(0.0f, fan_state.error_integral); diff --git a/board/health.h b/board/health.h index 7f822401..de6f0e34 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 12 +#define HEALTH_PACKET_VERSION 13 struct __attribute__((packed)) health_t { uint32_t uptime_pkt; uint32_t voltage_pkt; @@ -26,6 +26,7 @@ struct __attribute__((packed)) health_t { uint8_t fan_power; uint8_t safety_rx_checks_invalid; uint16_t spi_checksum_error_count; + uint8_t fan_stall_count; }; #define CAN_HEALTH_PACKET_VERSION 4 diff --git a/board/main_comms.h b/board/main_comms.h index 4a011cf7..3ccb07cd 100644 --- a/board/main_comms.h +++ b/board/main_comms.h @@ -39,6 +39,7 @@ int get_health_pkt(void *dat) { health->interrupt_load = interrupt_load; health->fan_power = fan_state.power; + health->fan_stall_count = fan_state.total_stall_count; return sizeof(*health); } diff --git a/python/__init__.py b/python/__init__.py index eca478db..ee09a55c 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -182,9 +182,9 @@ class Panda: HW_TYPE_TRES = b'\x09' CAN_PACKET_VERSION = 4 - HEALTH_PACKET_VERSION = 12 + HEALTH_PACKET_VERSION = 13 CAN_HEALTH_PACKET_VERSION = 4 - HEALTH_STRUCT = struct.Struct("