forked from commaai/panda
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
62 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,59 @@ | ||
// board enforces | ||
// in-state | ||
// accel set/resume | ||
// out-state | ||
// cancel button | ||
|
||
// these are set in the toyota safety hooks...this is the wrong place | ||
int gas_interceptor_detected = 0; | ||
|
||
// all commands: brake and steering | ||
// if controls_allowed | ||
// allow all commands up to limit | ||
// else | ||
// block all commands that produce actuation | ||
|
||
static void toyota_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { | ||
|
||
// exit controls on ACC off | ||
if ((to_push->RIR>>21) == 0x1D2) { | ||
// 4 bits: 55-52 | ||
if (to_push->RDHR & 0xF00000) { | ||
controls_allowed = 1; | ||
else { | ||
controls_allowed = 0; | ||
} | ||
} | ||
} | ||
|
||
static int toyota_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) { | ||
|
||
// STEER: safety check on bytes 2-3 | ||
if ((to_send->RIR>>21) == 0x2E4) { | ||
if (controls_allowed) { | ||
// all messages are fine here | ||
} else { | ||
if ((to_send->RDLR & 0xFFFF00) != to_send->RDLR) return 0; | ||
} | ||
} | ||
|
||
// 1 allows the message through | ||
return true; | ||
} | ||
|
||
static int toyota_tx_lin_hook(int lin_num, uint8_t *data, int len) { | ||
// TODO: add safety if using LIN | ||
return true; | ||
} | ||
|
||
static void toyota_init() { | ||
controls_allowed = 0; | ||
} | ||
|
||
const safety_hooks toyota_hooks = { | ||
.init = toyota_init, | ||
.rx = toyota_rx_hook, | ||
.tx = toyota_tx_hook, | ||
.tx_lin = toyota_tx_lin_hook, | ||
}; | ||
|