Skip to content

Commit

Permalink
Cadillac ascm proxy (commaai#155)
Browse files Browse the repository at this point in the history
* added safety_ascm

* better using one funciton

* GM_ASCM safety mode by default

* fixced ign bug and passing everything for now

* blocking 0x152-0x154 and reforwarding 0x153

* gotta fwd 152 as well on CH bus

* adding braking message block

* blocking gas cmd as well

* allow cadillac supercruise to pass through

* no more hardcoded ascm safety mode
  • Loading branch information
rbiasini authored Feb 6, 2019
1 parent 064446f commit 1218d09
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions board/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,7 @@ int main() {
usb_init();

// default to silent mode to prevent issues with Ford
// hardcode a specific safety mode if you want to force the panda to be in a specific mode
safety_set_mode(SAFETY_NOOUTPUT, 0);
can_silent = ALL_CAN_SILENT;
can_init_all();
Expand Down
3 changes: 3 additions & 0 deletions board/safety.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ int controls_allowed = 0;
#ifdef PANDA
#include "safety/safety_toyota_ipas.h"
#include "safety/safety_tesla.h"
#include "safety/safety_gm_ascm.h"
#endif
#include "safety/safety_gm.h"
#include "safety/safety_ford.h"
Expand Down Expand Up @@ -106,6 +107,7 @@ typedef struct {
#define SAFETY_TESLA 8
#define SAFETY_CHRYSLER 9
#define SAFETY_SUBARU 10
#define SAFETY_GM_ASCM 0x1334
#define SAFETY_TOYOTA_IPAS 0x1335
#define SAFETY_TOYOTA_NOLIMITS 0x1336
#define SAFETY_ALLOUTPUT 0x1337
Expand All @@ -125,6 +127,7 @@ const safety_hook_config safety_hook_registry[] = {
{SAFETY_TOYOTA_NOLIMITS, &toyota_nolimits_hooks},
#ifdef PANDA
{SAFETY_TOYOTA_IPAS, &toyota_ipas_hooks},
{SAFETY_GM_ASCM, &gm_ascm_hooks},
{SAFETY_TESLA, &tesla_hooks},
#endif
{SAFETY_ALLOUTPUT, &alloutput_hooks},
Expand Down
52 changes: 52 additions & 0 deletions board/safety/safety_gm_ascm.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// BUS 0 is on the LKAS module (ASCM) side
// BUS 2 is on the actuator (EPS) side

static int gm_ascm_fwd_hook(int bus_num, CAN_FIFOMailBox_TypeDef *to_fwd) {

uint32_t addr = to_fwd->RIR>>21;

if (bus_num == 0) {

// do not propagate lkas messages from ascm to actuators
// block 0x152 and 0x154, which are the lkas command from ASCM1 and ASCM2
// block 0x315 and 0x2cb, which are the brake and accel commands from ASCM1
//if ((addr == 0x152) || (addr == 0x154) || (addr == 0x315) || (addr == 0x2cb)) {
if ((addr == 0x152) || (addr == 0x154)) {
int supercruise_on = (to_fwd->RDHR>>4) & 0x1; // bit 36
if (!supercruise_on) return -1;
}

// on the chassis bus, the OBDII port is on the module side, so we need to read
// the lkas messages sent by openpilot (put on unused 0x151 ane 0x153 addrs) and send it to
// the actuator as 0x152 and 0x154
if (addr == 0x151) {
to_fwd->RIR = (0x152 << 21) | (to_fwd->RIR & 0x1fffff);
}
if (addr == 0x153) {
to_fwd->RIR = (0x154 << 21) | (to_fwd->RIR & 0x1fffff);
}

// brake
//if (addr == 0x314) {
// to_fwd->RIR = (0x315 << 21) | (to_fwd->RIR & 0x1fffff);
//}

return 2;
}

if (bus_num == 2) {
return 0;
}

return -1;
}

const safety_hooks gm_ascm_hooks = {
.init = nooutput_init,
.rx = default_rx_hook,
.tx = alloutput_tx_hook,
.tx_lin = nooutput_tx_lin_hook,
.ignition = default_ign_hook,
.fwd = gm_ascm_fwd_hook,
};

0 comments on commit 1218d09

Please sign in to comment.