forked from commaai/panda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsafety_toyota.h
45 lines (37 loc) · 937 Bytes
/
safety_toyota.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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,
};