2017-04-17 16:28:28 -06:00
|
|
|
// board enforces
|
|
|
|
// in-state
|
|
|
|
// accel set/resume
|
|
|
|
// out-state
|
|
|
|
// cancel button
|
|
|
|
|
2017-07-21 12:48:03 -06:00
|
|
|
// these are set in the Honda safety hooks...this is the wrong place
|
|
|
|
int gas_interceptor_detected = 0;
|
2017-04-17 16:28:28 -06:00
|
|
|
|
|
|
|
// all commands: brake and steering
|
|
|
|
// if controls_allowed
|
|
|
|
// allow all commands up to limit
|
|
|
|
// else
|
|
|
|
// block all commands that produce actuation
|
2017-07-12 12:25:10 -06:00
|
|
|
|
2017-07-17 11:20:08 -06:00
|
|
|
static void honda_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
|
2017-04-06 19:11:36 -06:00
|
|
|
// state machine to enter and exit controls
|
|
|
|
// 0x1A6 for the ILX, 0x296 for the Civic Touring
|
|
|
|
if ((to_push->RIR>>21) == 0x1A6 || (to_push->RIR>>21) == 0x296) {
|
|
|
|
int buttons = (to_push->RDLR & 0xE0) >> 5;
|
|
|
|
if (buttons == 4 || buttons == 3) {
|
|
|
|
controls_allowed = 1;
|
|
|
|
} else if (buttons == 2) {
|
|
|
|
controls_allowed = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// exit controls on brake press
|
|
|
|
if ((to_push->RIR>>21) == 0x17C) {
|
2017-08-10 18:28:42 -06:00
|
|
|
// bit 53
|
|
|
|
if (to_push->RDHR & 0x200000) {
|
2017-04-06 19:11:36 -06:00
|
|
|
controls_allowed = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// exit controls on gas press if interceptor
|
|
|
|
if ((to_push->RIR>>21) == 0x201) {
|
|
|
|
gas_interceptor_detected = 1;
|
|
|
|
int gas = ((to_push->RDLR & 0xFF) << 8) | ((to_push->RDLR & 0xFF00) >> 8);
|
|
|
|
if (gas > 328) {
|
|
|
|
controls_allowed = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// exit controls on gas press if no interceptor
|
|
|
|
if (!gas_interceptor_detected) {
|
|
|
|
if ((to_push->RIR>>21) == 0x17C) {
|
|
|
|
if (to_push->RDLR & 0xFF) {
|
|
|
|
controls_allowed = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-21 00:36:06 -06:00
|
|
|
static int honda_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
|
2017-04-06 19:11:36 -06:00
|
|
|
// BRAKE: safety check
|
|
|
|
if ((to_send->RIR>>21) == 0x1FA) {
|
|
|
|
if (controls_allowed) {
|
2017-07-17 19:54:50 -06:00
|
|
|
if ((to_send->RDLR & 0xFFFFFF3F) != to_send->RDLR) return 0;
|
2017-04-06 19:11:36 -06:00
|
|
|
} else {
|
2017-07-17 19:54:50 -06:00
|
|
|
if ((to_send->RDLR & 0xFFFF0000) != to_send->RDLR) return 0;
|
2017-04-06 19:11:36 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// STEER: safety check
|
2017-06-13 08:03:38 -06:00
|
|
|
if ((to_send->RIR>>21) == 0xE4 || (to_send->RIR>>21) == 0x194) {
|
2017-04-06 19:11:36 -06:00
|
|
|
if (controls_allowed) {
|
2017-07-17 19:54:50 -06:00
|
|
|
// all messages are fine here
|
2017-04-06 19:11:36 -06:00
|
|
|
} else {
|
2017-07-17 19:54:50 -06:00
|
|
|
if ((to_send->RDLR & 0xFFFF0000) != to_send->RDLR) return 0;
|
2017-04-06 19:11:36 -06:00
|
|
|
}
|
2017-07-14 22:17:32 -06:00
|
|
|
}
|
2017-04-06 19:11:36 -06:00
|
|
|
|
|
|
|
// GAS: safety check
|
|
|
|
if ((to_send->RIR>>21) == 0x200) {
|
|
|
|
if (controls_allowed) {
|
2017-07-17 19:54:50 -06:00
|
|
|
// all messages are fine here
|
2017-04-06 19:11:36 -06:00
|
|
|
} else {
|
2017-07-17 19:54:50 -06:00
|
|
|
if ((to_send->RDLR & 0xFFFF0000) != to_send->RDLR) return 0;
|
2017-04-06 19:11:36 -06:00
|
|
|
}
|
2017-07-14 22:17:32 -06:00
|
|
|
}
|
2017-04-06 19:11:36 -06:00
|
|
|
|
2017-04-28 10:56:01 -06:00
|
|
|
// 1 allows the message through
|
2017-07-21 00:36:06 -06:00
|
|
|
return true;
|
2017-04-06 19:11:36 -06:00
|
|
|
}
|
|
|
|
|
2017-07-21 00:36:06 -06:00
|
|
|
static int honda_tx_lin_hook(int lin_num, uint8_t *data, int len) {
|
|
|
|
// TODO: add safety if using LIN
|
|
|
|
return true;
|
2017-05-01 21:22:19 -06:00
|
|
|
}
|
|
|
|
|
2017-07-17 11:20:08 -06:00
|
|
|
static void honda_init() {
|
2017-07-14 22:17:32 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
const safety_hooks honda_hooks = {
|
2017-07-17 11:20:08 -06:00
|
|
|
.init = honda_init,
|
|
|
|
.rx = honda_rx_hook,
|
|
|
|
.tx = honda_tx_hook,
|
|
|
|
.tx_lin = honda_tx_lin_hook,
|
2017-07-14 22:17:32 -06:00
|
|
|
};
|
2017-07-17 11:20:08 -06:00
|
|
|
|