From 7ffc916578af9373a165cf9df5974720d9a258a5 Mon Sep 17 00:00:00 2001 From: Daniel Koepping Date: Wed, 13 May 2026 11:58:17 -0700 Subject: [PATCH] move can ignition to opendbc (#2396) * move can ignition to opendbc temp: point to opendbc PR * rm * pyproject * run ci * fix * move --- board/drivers/can_common.h | 60 +------------------------------------- board/drivers/drivers.h | 3 +- 2 files changed, 2 insertions(+), 61 deletions(-) diff --git a/board/drivers/can_common.h b/board/drivers/can_common.h index ef03cdb5..6237c7ae 100644 --- a/board/drivers/can_common.h +++ b/board/drivers/can_common.h @@ -1,4 +1,5 @@ #include "board/drivers/drivers.h" +#include "opendbc/safety/ignition.h" uint32_t safety_tx_blocked = 0; uint32_t safety_rx_invalid = 0; @@ -7,10 +8,6 @@ uint32_t rx_buffer_overflow = 0; can_health_t can_health[PANDA_CAN_CNT] = {{0}, {0}, {0}}; -// Ignition detected from CAN meessages -bool ignition_can = false; -uint32_t ignition_can_cnt = 0U; - bool can_silent = true; bool can_loopback = false; @@ -155,61 +152,6 @@ void can_set_forwarding(uint8_t from, uint8_t to) { } #endif -void ignition_can_hook(CANPacket_t *msg) { - if (msg->bus == 0U) { - int len = GET_LEN(msg); - - // GM exception - if ((msg->addr == 0x1F1U) && (len == 8)) { - // SystemPowerMode (2=Run, 3=Crank Request) - ignition_can = (msg->data[0] & 0x2U) != 0U; - ignition_can_cnt = 0U; - } - - // Rivian R1S/T GEN1 exception - if ((msg->addr == 0x152U) && (len == 8)) { - // 0x152 overlaps with Subaru pre-global which has this bit as the high beam - int counter = msg->data[1] & 0xFU; // max is only 14 - - static int prev_counter_rivian = -1; - if ((counter == ((prev_counter_rivian + 1) % 15)) && (prev_counter_rivian != -1)) { - // VDM_OutputSignals->VDM_EpasPowerMode - ignition_can = ((msg->data[7] >> 4U) & 0x3U) == 1U; // VDM_EpasPowerMode_Drive_On=1 - ignition_can_cnt = 0U; - } - prev_counter_rivian = counter; - } - - // Tesla Model 3/Y exception - if ((msg->addr == 0x221U) && (len == 8)) { - // 0x221 overlaps with Rivian which has random data on byte 0 - int counter = msg->data[6] >> 4; - - static int prev_counter_tesla = -1; - if ((counter == ((prev_counter_tesla + 1) % 16)) && (prev_counter_tesla != -1)) { - // VCFRONT_LVPowerState->VCFRONT_vehiclePowerState - int power_state = (msg->data[0] >> 5U) & 0x3U; - ignition_can = power_state == 0x3; // VEHICLE_POWER_STATE_DRIVE=3 - ignition_can_cnt = 0U; - } - prev_counter_tesla = counter; - } - - // Mazda exception - if ((msg->addr == 0x9EU) && (len == 8)) { - ignition_can = (msg->data[0] >> 5) == 0x6U; - ignition_can_cnt = 0U; - } - } - - // TODO: this is too loose, Teslas have 0x222 - // body v2 exception - // if (((msg->bus == 0U) || (msg->bus == 2U)) && (msg->addr == 0x222U)) { - // ignition_can = true; - // ignition_can_cnt = 0U; - // } -} - bool can_tx_check_min_slots_free(uint32_t min) { return (can_slots_empty(&can_tx1_q) >= min) && diff --git a/board/drivers/drivers.h b/board/drivers/drivers.h index c6150670..91af64d7 100644 --- a/board/drivers/drivers.h +++ b/board/drivers/drivers.h @@ -41,7 +41,7 @@ extern uint32_t rx_buffer_overflow; extern can_health_t can_health[PANDA_CAN_CNT]; -// Ignition detected from CAN meessages +// Ignition detected from CAN messages extern bool ignition_can; extern uint32_t ignition_can_cnt; @@ -74,7 +74,6 @@ void can_set_orientation(bool flipped); #ifdef PANDA_JUNGLE void can_set_forwarding(uint8_t from, uint8_t to); #endif -void ignition_can_hook(CANPacket_t *to_push); bool can_tx_check_min_slots_free(uint32_t min); uint8_t calculate_checksum(const uint8_t *dat, uint32_t len); void can_set_checksum(CANPacket_t *packet);