Skip to content

Commit

Permalink
Honda safety: fixed bug and properly abstracted gas_interceptor_detec…
Browse files Browse the repository at this point in the history
…ted variable
  • Loading branch information
rbiasini committed Jun 4, 2019
1 parent 220cc8f commit 436b203
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
1 change: 1 addition & 0 deletions board/safety.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ typedef struct {

// This can be set by the safety hooks.
int controls_allowed = 0;
int gas_interceptor_detected = 0;

// Include the actual safety policies.
#include "safety/safety_defaults.h"
Expand Down
6 changes: 2 additions & 4 deletions board/safety/safety_honda.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
// brake rising edge
// brake > 0mph

// these are set in the Honda safety hooks...this is the wrong place
const int HONDA_GAS_INTERCEPTOR_THRESHOLD = 328;
int honda_gas_interceptor_detected = 0;
int honda_brake_prev = 0;
int honda_gas_prev = 0;
int honda_gas_interceptor_prev = 0;
Expand Down Expand Up @@ -58,7 +56,7 @@ static void honda_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
// exit controls on rising edge of gas press if interceptor (0x201 w/ len = 6)
// length check because bosch hardware also uses this id (0x201 w/ len = 8)
if ((to_push->RIR>>21) == 0x201 && (to_push->RDTR & 0xf) == 6) {
honda_gas_interceptor_detected = 1;
gas_interceptor_detected = 1;
int gas_interceptor = ((to_push->RDLR & 0xFF) << 8) | ((to_push->RDLR & 0xFF00) >> 8);
if ((gas_interceptor > HONDA_GAS_INTERCEPTOR_THRESHOLD) &&
(honda_gas_interceptor_prev <= HONDA_GAS_INTERCEPTOR_THRESHOLD)) {
Expand All @@ -68,7 +66,7 @@ static void honda_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
}

// exit controls on rising edge of gas press if no interceptor
if (!honda_gas_interceptor_detected) {
if (!gas_interceptor_detected) {
if ((to_push->RIR>>21) == 0x17C) {
int gas = to_push->RDLR & 0xFF;
if (gas && !(honda_gas_prev)) {
Expand Down
2 changes: 1 addition & 1 deletion tests/safety/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ void init_tests_subaru(void){

void init_tests_honda(void){
honda_ego_speed = 0;
honda_gas_interceptor_detected = 0;
gas_interceptor_detected = 0;
honda_brake_prev = 0;
honda_gas_prev = 0;
}
Expand Down

0 comments on commit 436b203

Please sign in to comment.