Skip to content

Commit

Permalink
solve race condition is relay_malfunction right after changing the re…
Browse files Browse the repository at this point in the history
…lay status by adding a counter
  • Loading branch information
rbiasini committed Nov 27, 2019
1 parent 2d4cb05 commit 878dd00
Show file tree
Hide file tree
Showing 10 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion board/safety/safety_chrysler.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ static void chrysler_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
}

// check if stock camera ECU is on bus 0
if ((bus == 0) && (addr == 0x292)) {
if ((safety_mode_cnt > 1) && (bus == 0) && (addr == 0x292)) {
relay_malfunction = true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion board/safety/safety_ford.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ static void ford_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
ford_gas_prev = gas;
}

if ((bus == 0) && (addr == 0x3CA)) {
if ((safety_mode_cnt > 1) && (bus == 0) && (addr == 0x3CA)) {
relay_malfunction = true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion board/safety/safety_gm.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ static void gm_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
// on powertrain bus.
// 384 = ASCMLKASteeringCmd
// 715 = ASCMGasRegenCmd
if ((bus == 0) && ((addr == 384) || (addr == 715))) {
if ((safety_mode_cnt > 1) && (bus == 0) && ((addr == 384) || (addr == 715))) {
relay_malfunction = true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion board/safety/safety_honda.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ static void honda_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
// if steering controls messages are received on the destination bus, it's an indication
// that the relay might be malfunctioning
int bus_rdr_car = (board_has_relay()) ? 0 : 2; // radar bus, car side
if ((addr == 0xE4) || (addr == 0x194)) {
if ((safety_mode_cnt > 1) && ((addr == 0xE4) || (addr == 0x194))) {
if ((honda_bosch_hardware && (bus == bus_rdr_car)) ||
(!honda_bosch_hardware && (bus == 0))) {
relay_malfunction = true;
Expand Down
2 changes: 1 addition & 1 deletion board/safety/safety_hyundai.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ static void hyundai_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
}

// check if stock camera ECU is on bus 0
if ((bus == 0) && (addr == 832)) {
if ((safety_mode_cnt > 1) && (bus == 0) && (addr == 832)) {
relay_malfunction = true;
}

Expand Down
2 changes: 1 addition & 1 deletion board/safety/safety_mazda.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void mazda_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
}

// if we see wheel speed msgs on MAZDA_CAM bus then relay is closed
if ((bus == MAZDA_CAM) && (addr == MAZDA_WHEEL_SPEED)) {
if ((safety_mode_cnt > 1) && (bus == MAZDA_CAM) && (addr == MAZDA_WHEEL_SPEED)) {
relay_malfunction = true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion board/safety/safety_subaru.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ static void subaru_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
subaru_cruise_engaged_last = cruise_engaged;
}

if ((bus == 0) && ((addr == 0x122) || (addr == 0x164))) {
if ((safety_mode_cnt > 1) && (bus == 0) && ((addr == 0x122) || (addr == 0x164))) {
relay_malfunction = true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion board/safety/safety_toyota.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ static void toyota_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
}

// 0x2E4 is lkas cmd. If it is on bus 0, then relay is unexpectedly closed
if ((addr == 0x2E4) && (bus == 0)) {
if ((safety_mode_cnt > 1) && (addr == 0x2E4) && (bus == 0)) {
relay_malfunction = true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion board/safety/safety_volkswagen.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static void volkswagen_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
volkswagen_gas_prev = gas;
}

if ((bus == 0) && (addr == MSG_HCA_01)) {
if ((safety_mode_cnt > 1) && (bus == 0) && (addr == MSG_HCA_01)) {
relay_malfunction = true;
}
}
Expand Down
1 change: 1 addition & 0 deletions tests/safety/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ void set_honda_fwd_brake(bool c){
void init_tests(void){
// get HW_TYPE from env variable set in test.sh
hw_type = atoi(getenv("HW_TYPE"));
safety_mode_cnt = 2U; // avoid ignoring relay_malfunction logic
}

void init_tests_toyota(void){
Expand Down

0 comments on commit 878dd00

Please sign in to comment.