-
Notifications
You must be signed in to change notification settings - Fork 9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hyundai: added initial safety files which just fwd bus 0 to 2 and vic…
…eversa, except for lkas msgs
- Loading branch information
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
int hyundai_giraffe_switch_1 = 0; // is giraffe switch 1 high? | ||
|
||
|
||
static void hyundai_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { | ||
|
||
int bus = (to_push->RDTR >> 4) & 0xF; | ||
// 832 is lkas cmd. If it is on bus 0, then giraffe switch 1 is high | ||
if ((to_push->RIR>>21) == 832 && (bus == 0)) { | ||
hyundai_giraffe_switch_1 = 1; | ||
} | ||
} | ||
|
||
static void hyundai_init(int16_t param) { | ||
controls_allowed = 0; | ||
hyundai_giraffe_switch_1 = 0; | ||
} | ||
|
||
static int hyundai_fwd_hook(int bus_num, CAN_FIFOMailBox_TypeDef *to_fwd) { | ||
|
||
// forward cam to radar and viceversa if car is dsu-less, except lkas cmd and hud | ||
if ((bus_num == 0 || bus_num == 2) && !hyundai_giraffe_switch_1) { | ||
int addr = to_fwd->RIR>>21; | ||
bool is_lkas_msg = (addr == 832 || addr == 1342) && bus_num == 2; | ||
return is_lkas_msg? -1 : (uint8_t)(~bus_num & 0x2); | ||
} | ||
return -1; | ||
} | ||
|
||
const safety_hooks hyundai_hooks = { | ||
.init = hyundai_init, | ||
.rx = hyundai_rx_hook, | ||
.tx = nooutput_tx_hook, | ||
.tx_lin = nooutput_tx_lin_hook, | ||
.ignition = default_ign_hook, | ||
.fwd = hyundai_fwd_hook, | ||
}; |