Skip to content

Commit

Permalink
Hyundai: added initial safety files which just fwd bus 0 to 2 and vic…
Browse files Browse the repository at this point in the history
…eversa, except for lkas msgs
  • Loading branch information
rbiasini committed Aug 18, 2018
1 parent 905a935 commit 594863c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
3 changes: 3 additions & 0 deletions board/safety.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ int controls_allowed = 0;
#include "safety/safety_gm.h"
#include "safety/safety_ford.h"
#include "safety/safety_cadillac.h"
#include "safety/safety_hyundai.h"
#include "safety/safety_elm327.h"

const safety_hooks *current_hooks = &nooutput_hooks;
Expand Down Expand Up @@ -98,6 +99,7 @@ typedef struct {
#define SAFETY_HONDA_BOSCH 4
#define SAFETY_FORD 5
#define SAFETY_CADILLAC 6
#define SAFETY_HYUNDAI 7
#define SAFETY_TOYOTA_IPAS 0x1335
#define SAFETY_TOYOTA_NOLIMITS 0x1336
#define SAFETY_ALLOUTPUT 0x1337
Expand All @@ -111,6 +113,7 @@ const safety_hook_config safety_hook_registry[] = {
{SAFETY_GM, &gm_hooks},
{SAFETY_FORD, &ford_hooks},
{SAFETY_CADILLAC, &cadillac_hooks},
{SAFETY_HYUNDAI, &hyundai_hooks},
{SAFETY_TOYOTA_NOLIMITS, &toyota_nolimits_hooks},
#ifdef PANDA
{SAFETY_TOYOTA_IPAS, &toyota_ipas_hooks},
Expand Down
36 changes: 36 additions & 0 deletions board/safety/safety_hyundai.h
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,
};

0 comments on commit 594863c

Please sign in to comment.