diff --git a/board/drivers/can_common.h b/board/drivers/can_common.h index cefba6e8..1c578a62 100644 --- a/board/drivers/can_common.h +++ b/board/drivers/can_common.h @@ -166,6 +166,9 @@ void ignition_can_hook(CANPacket_t *to_push) { int addr = GET_ADDR(to_push); int len = GET_LEN(to_push); + // Check counter position on cars with overlap + static int prev_counter = -1; + // GM exception if ((addr == 0x1F1) && (len == 8)) { // SystemPowerMode (2=Run, 3=Crank Request) @@ -175,15 +178,20 @@ void ignition_can_hook(CANPacket_t *to_push) { // Rivian R1S/T GEN1 exception if ((addr == 0x152) && (len == 8)) { - // VDM_OutputSignals - ignition_can = GET_BIT(to_push, 60U); - ignition_can_cnt = 0U; + // 0x152 overlaps with Subaru pre-global which has this bit as the high beam + int counter = GET_BYTE(to_push, 1) & 0xFU; // max is only 14 + + if ((counter == ((prev_counter + 1) % 15)) && (prev_counter != -1)) { + // VDM_OutputSignals + ignition_can = GET_BIT(to_push, 60U); + ignition_can_cnt = 0U; + } + prev_counter = counter; } // Tesla Model 3/Y exception if ((addr == 0x221) && (len == 8)) { // 0x221 overlaps with Rivian which has random data on byte 0 - static int prev_counter = -1; int counter = GET_BYTE(to_push, 6) >> 4; if ((counter == ((prev_counter + 1) % 16)) && (prev_counter != -1)) {