From b5120f6427551345c543b490fe47da189c1e48e1 Mon Sep 17 00:00:00 2001 From: wocsor Date: Fri, 25 Sep 2020 09:43:30 -0400 Subject: [PATCH] forward the distance button to 2FF and limit rate of send_spoof_id() --- board/main.c | 4 ++-- board/safety/safety_defaults.h | 11 ++++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/board/main.c b/board/main.c index 2f143efd27..54fd8b9172 100644 --- a/board/main.c +++ b/board/main.c @@ -92,8 +92,8 @@ void send_spoof_acc(void){ CAN->sTxMailBox[0].TIR = (0x343U << 21) | 1U; } -void send_id(void){ - CAN->sTxMailBox[0].TDLR = 0x00; +void send_id(uint8_t button_state){ + CAN->sTxMailBox[0].TDLR = (button_state << 7) | (0x00 << 8) | (0x00 << 16) | (0x00 << 24); CAN->sTxMailBox[0].TDTR = 4; CAN->sTxMailBox[0].TIR = (0x2FFU << 21) | 1U; } diff --git a/board/safety/safety_defaults.h b/board/safety/safety_defaults.h index e167797f4c..98de2086b0 100644 --- a/board/safety/safety_defaults.h +++ b/board/safety/safety_defaults.h @@ -8,7 +8,7 @@ void send_spoof_acc(void); uint32_t startedtime = 0; bool onboot = 0; bool boot_done = 0; -void send_id(void); +void send_id(uint8_t button_state); // *** no output safety mode *** @@ -28,7 +28,7 @@ static int nooutput_tx_lin_hook(int lin_num, uint8_t *data, int len) { UNUSED(len); return false; } - +uint8_t button_state = 0; // TODO: make this only happen on Toyotas. write some kind of detection static int default_fwd_hook(int bus_num, CAN_FIFOMailBox_TypeDef *to_fwd) { // UNUSED(bus_num); @@ -48,15 +48,20 @@ static int default_fwd_hook(int bus_num, CAN_FIFOMailBox_TypeDef *to_fwd) { block = 1; eon_detected_last = ts; } - send_id(); bus_fwd = 2; } if(bus_num == 2){ + // lock rate to stock 0x343. better have a working DSU! + if (addr == 0x343){ + button_state = (GET_BYTE(to_fwd, 2) >> 4U); + send_id(button_state); + } // block cruise message only if it's already being sent on bus 0 if(!onboot){ startedtime = TIM2->CNT; onboot = 1; } + // DSU normally sends nothing for 2 sec, causing the cruise fault so spam the fake msg boot_done = (TIM2->CNT > (startedtime + 2000000)); if (!boot_done){ send_spoof_acc();