Skip to content

Commit

Permalink
forward the distance button to 2FF and limit rate of send_spoof_id()
Browse files Browse the repository at this point in the history
  • Loading branch information
wocsor committed Sep 25, 2020
1 parent c25207e commit b5120f6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions board/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
11 changes: 8 additions & 3 deletions board/safety/safety_defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 ***

Expand All @@ -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);
Expand All @@ -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();
Expand Down

1 comment on commit b5120f6

@ErichMoraga
Copy link

@ErichMoraga ErichMoraga commented on b5120f6 Sep 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you get a chance, please post the updated, pre-compiled .bin files too. I'ved submitted this PR...
#2

Please sign in to comment.