From 00138a7f667ea6152a673764332fe4be756e63fb Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Thu, 27 Jan 2022 17:46:24 -0800 Subject: [PATCH] Add blocked message counter to health packet (#841) * Add blocked message counter to health packet * move that * update python * fix struct Co-authored-by: Comma Device --- board/drivers/can_common.h | 2 ++ board/main.c | 2 ++ board/safety.h | 4 ++-- board/usb_comms.h | 4 +++- python/__init__.py | 8 +++++--- 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/board/drivers/can_common.h b/board/drivers/can_common.h index f22ab979..ef2a8df5 100644 --- a/board/drivers/can_common.h +++ b/board/drivers/can_common.h @@ -18,6 +18,7 @@ uint32_t can_rx_errs = 0; uint32_t can_send_errs = 0; uint32_t can_fwd_errs = 0; uint32_t gmlan_send_errs = 0; +uint32_t blocked_msg_cnt = 0; extern int can_live; extern int pending_can_live; @@ -242,6 +243,7 @@ void can_send(CANPacket_t *to_push, uint8_t bus_number, bool skip_tx_hook) { } } } else { + blocked_msg_cnt += 1U; to_push->rejected = 1U; can_send_errs += can_push(&can_rx_q, to_push) ? 0U : 1U; } diff --git a/board/main.c b/board/main.c index 664a8b88..3682d1b7 100644 --- a/board/main.c +++ b/board/main.c @@ -83,6 +83,8 @@ void set_safety_mode(uint16_t mode, int16_t param) { } } } + blocked_msg_cnt = 0; + switch (mode_copy) { case SAFETY_SILENT: set_intercept_relay(false); diff --git a/board/safety.h b/board/safety.h index 875fe9ef..b53f3958 100644 --- a/board/safety.h +++ b/board/safety.h @@ -1,6 +1,6 @@ -// include first, needed by safety policies #include "safety_declarations.h" -// Include the actual safety policies. + +// include the safety policies. #include "safety/safety_defaults.h" #include "safety/safety_honda.h" #include "safety/safety_toyota.h" diff --git a/board/usb_comms.h b/board/usb_comms.h index aa5af6e8..8a14ede7 100644 --- a/board/usb_comms.h +++ b/board/usb_comms.h @@ -3,7 +3,7 @@ extern int _app_start[0xc000]; // Only first 3 sectors of size 0x4000 are used // When changing this struct, boardd and python/__init__.py needs to be kept up to date! -#define HEALTH_PACKET_VERSION 2 +#define HEALTH_PACKET_VERSION 3 struct __attribute__((packed)) health_t { uint32_t uptime_pkt; uint32_t voltage_pkt; @@ -25,6 +25,7 @@ struct __attribute__((packed)) health_t { uint8_t power_save_enabled_pkt; uint8_t heartbeat_lost_pkt; uint16_t unsafe_mode_pkt; + uint32_t blocked_msg_cnt_pkt; }; // Prototypes @@ -56,6 +57,7 @@ int get_health_pkt(void *dat) { health->unsafe_mode_pkt = unsafe_mode; health->power_save_enabled_pkt = (uint8_t)(power_save_status == POWER_SAVE_STATUS_ENABLED); health->heartbeat_lost_pkt = (uint8_t)(heartbeat_lost); + health->blocked_msg_cnt_pkt = blocked_msg_cnt; health->fault_status_pkt = fault_status; health->faults_pkt = faults; diff --git a/python/__init__.py b/python/__init__.py index 6804d7a7..89e81e43 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -160,7 +160,8 @@ class Panda(object): HW_TYPE_RED_PANDA = b'\x07' CAN_PACKET_VERSION = 2 - HEALTH_PACKET_VERSION = 2 + HEALTH_PACKET_VERSION = 3 + HEALTH_STRUCT = struct.Struct("