Skip to content

Commit

Permalink
added brake safety checks
Browse files Browse the repository at this point in the history
  • Loading branch information
gregjhogan committed Mar 6, 2018
1 parent d0c2634 commit f7226ff
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions board/safety/safety_honda.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ int brake_prev = 0;
int gas_prev = 0;
int gas_interceptor_prev = 0;
int ego_speed = 0;

// TODO: auto-detect bosch hardware based on CAN messages?
bool bosch_hardware = false;

Expand All @@ -36,11 +35,15 @@ static void honda_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
}
}

// user brake signal is different for nidec vs bosch hardware
// nidec hardware: 0x17C bit 53
// bosch hardware: 0x1BE bit 4
#define IS_USER_BRAKE_MSG(to_push) (!bosch_hardware ? to_push->RIR>>21 == 0x17C : to_push->RIR>>21 == 0x1BE)
#define USER_BRAKE_VALUE(to_push) (!bosch_hardware ? to_push->RDHR & 0x200000 : to_push->RDLR & 0x10)
// exit controls on rising edge of brake press or on brake press when
// speed > 0
if (!bosch_hardware && (to_push->RIR>>21) == 0x17C) {
// bit 53
int brake = to_push->RDHR & 0x200000;
if (IS_USER_BRAKE_MSG(to_push)) {
int brake = USER_BRAKE_VALUE(to_push);
if (brake && (!(brake_prev) || ego_speed)) {
controls_allowed = 0;
}
Expand Down

0 comments on commit f7226ff

Please sign in to comment.