Skip to content

Commit

Permalink
Safety: Utilize boolean values for message block checks in forward hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnyhaibin committed Aug 30, 2023
1 parent d41a0ab commit ee9809d
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 28 deletions.
8 changes: 4 additions & 4 deletions board/safety/safety_gm.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,17 +217,17 @@ static int gm_fwd_hook(int bus_num, int addr) {
if (gm_hw == GM_CAM) {
if (bus_num == 0) {
// block PSCMStatus; forwarded through openpilot to hide an alert from the camera
bool is_pscm_msg = (addr == 388);
const bool is_pscm_msg = (addr == 388);
if (!is_pscm_msg) {
bus_fwd = 2;
}
}

if (bus_num == 2) {
// block lkas message and acc messages if gm_cam_long, forward all others
bool is_lkas_msg = (addr == 384);
bool is_acc_msg = (addr == 789) || (addr == 715) || (addr == 880);
int block_msg = is_lkas_msg || (is_acc_msg && gm_cam_long);
const bool is_lkas_msg = (addr == 384);
const bool is_acc_msg = (addr == 789) || (addr == 715) || (addr == 880);
const bool block_msg = is_lkas_msg || (is_acc_msg && gm_cam_long);
if (!block_msg) {
bus_fwd = 0;
}
Expand Down
6 changes: 3 additions & 3 deletions board/safety/safety_honda.h
Original file line number Diff line number Diff line change
Expand Up @@ -441,9 +441,9 @@ static int honda_bosch_fwd_hook(int bus_num, int addr) {
bus_fwd = 2;
}
if (bus_num == 2) {
int is_lkas_msg = (addr == 0xE4) || (addr == 0xE5) || (addr == 0x33D) || (addr == 0x33DA) || (addr == 0x33DB);
int is_acc_msg = ((addr == 0x1C8) || (addr == 0x30C)) && honda_bosch_radarless && honda_bosch_long;
bool block_msg = is_lkas_msg || is_acc_msg;
const bool is_lkas_msg = (addr == 0xE4) || (addr == 0xE5) || (addr == 0x33D) || (addr == 0x33DA) || (addr == 0x33DB);
const bool is_acc_msg = ((addr == 0x1C8) || (addr == 0x30C)) && honda_bosch_radarless && honda_bosch_long;
const bool block_msg = is_lkas_msg || is_acc_msg;
if (!block_msg) {
bus_fwd = 0;
}
Expand Down
10 changes: 5 additions & 5 deletions board/safety/safety_hyundai_canfd.h
Original file line number Diff line number Diff line change
Expand Up @@ -320,16 +320,16 @@ static int hyundai_canfd_fwd_hook(int bus_num, int addr) {
}
if (bus_num == 2) {
// LKAS for HDA2, LFA for HDA1
int is_lkas_msg = (((addr == 0x50) || (addr == 0x2a4)) && hyundai_canfd_hda2);
int is_lfa_msg = ((addr == 0x12a) && !hyundai_canfd_hda2);
const bool is_lkas_msg = (((addr == 0x50) || (addr == 0x2a4)) && hyundai_canfd_hda2);
const bool is_lfa_msg = ((addr == 0x12a) && !hyundai_canfd_hda2);

// HUD icons
int is_lfahda_msg = ((addr == 0x1e0) && !hyundai_canfd_hda2);
const bool is_lfahda_msg = ((addr == 0x1e0) && !hyundai_canfd_hda2);

// CRUISE_INFO for non-HDA2, we send our own longitudinal commands
int is_scc_msg = ((addr == 0x1a0) && hyundai_longitudinal && !hyundai_canfd_hda2);
const bool is_scc_msg = ((addr == 0x1a0) && hyundai_longitudinal && !hyundai_canfd_hda2);

int block_msg = is_lkas_msg || is_lfa_msg || is_lfahda_msg || is_scc_msg;
const bool block_msg = is_lkas_msg || is_lfa_msg || is_lfahda_msg || is_scc_msg;
if (!block_msg) {
bus_fwd = 0;
}
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 @@ -114,7 +114,7 @@ static int mazda_fwd_hook(int bus, int addr) {
if (bus == MAZDA_MAIN) {
bus_fwd = MAZDA_CAM;
} else if (bus == MAZDA_CAM) {
bool block = (addr == MAZDA_LKAS) || (addr == MAZDA_LKAS_HUD);
const bool block = (addr == MAZDA_LKAS) || (addr == MAZDA_LKAS_HUD);
if (!block) {
bus_fwd = MAZDA_MAIN;
}
Expand Down
4 changes: 2 additions & 2 deletions board/safety/safety_nissan.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,15 @@ static int nissan_fwd_hook(int bus_num, int addr) {
int bus_fwd = -1;

if (bus_num == 0) {
int block_msg = (addr == 0x280); // CANCEL_MSG
const bool block_msg = (addr == 0x280); // CANCEL_MSG
if (!block_msg) {
bus_fwd = 2; // ADAS
}
}

if (bus_num == 2) {
// 0x169 is LKAS, 0x2b1 LKAS_HUD, 0x4cc LKAS_HUD_INFO_MSG
int block_msg = ((addr == 0x169) || (addr == 0x2b1) || (addr == 0x4cc));
const bool block_msg = ((addr == 0x169) || (addr == 0x2b1) || (addr == 0x4cc));
if (!block_msg) {
bus_fwd = 0; // V-CAN
}
Expand Down
18 changes: 9 additions & 9 deletions board/safety/safety_subaru.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ static int subaru_tx_hook(CANPacket_t *to_send) {
if (addr == MSG_SUBARU_ES_Distance) {
int cruise_throttle = (GET_BYTES(to_send, 2, 2) & 0xFFFU);
bool cruise_cancel = GET_BIT(to_send, 56U) != 0U;

if (subaru_longitudinal) {
violation |= longitudinal_gas_checks(cruise_throttle, SUBARU_LONG_LIMITS);
} else {
Expand Down Expand Up @@ -234,16 +234,16 @@ static int subaru_fwd_hook(int bus_num, int addr) {

if (bus_num == SUBARU_CAM_BUS) {
// Global platform
bool block_lkas = ((addr == MSG_SUBARU_ES_LKAS) ||
(addr == MSG_SUBARU_ES_DashStatus) ||
(addr == MSG_SUBARU_ES_LKAS_State) ||
(addr == MSG_SUBARU_ES_Infotainment));
const bool block_lkas = ((addr == MSG_SUBARU_ES_LKAS) ||
(addr == MSG_SUBARU_ES_DashStatus) ||
(addr == MSG_SUBARU_ES_LKAS_State) ||
(addr == MSG_SUBARU_ES_Infotainment));

bool block_long = ((addr == MSG_SUBARU_ES_Brake) ||
(addr == MSG_SUBARU_ES_Distance) ||
(addr == MSG_SUBARU_ES_Status));
const bool block_long = ((addr == MSG_SUBARU_ES_Brake) ||
(addr == MSG_SUBARU_ES_Distance) ||
(addr == MSG_SUBARU_ES_Status));

bool block_msg = block_lkas || (subaru_longitudinal && block_long);
const bool block_msg = block_lkas || (subaru_longitudinal && block_long);
if (!block_msg) {
bus_fwd = SUBARU_MAIN_BUS; // Main CAN
}
Expand Down
2 changes: 1 addition & 1 deletion board/safety/safety_subaru_preglobal.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ static int subaru_preglobal_fwd_hook(int bus_num, int addr) {
}

if (bus_num == SUBARU_PG_CAM_BUS) {
int block_msg = ((addr == MSG_SUBARU_PG_ES_Distance) || (addr == MSG_SUBARU_PG_ES_LKAS));
const bool block_msg = ((addr == MSG_SUBARU_PG_ES_Distance) || (addr == MSG_SUBARU_PG_ES_LKAS));
if (!block_msg) {
bus_fwd = SUBARU_PG_MAIN_BUS; // Main CAN
}
Expand Down
6 changes: 3 additions & 3 deletions board/safety/safety_toyota.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,10 @@ static int toyota_fwd_hook(int bus_num, int addr) {
if (bus_num == 2) {
// block stock lkas messages and stock acc messages (if OP is doing ACC)
// in TSS2, 0x191 is LTA which we need to block to avoid controls collision
int is_lkas_msg = ((addr == 0x2E4) || (addr == 0x412) || (addr == 0x191));
const bool is_lkas_msg = ((addr == 0x2E4) || (addr == 0x412) || (addr == 0x191));
// in TSS2 the camera does ACC as well, so filter 0x343
int is_acc_msg = (addr == 0x343);
int block_msg = is_lkas_msg || (is_acc_msg && !toyota_stock_longitudinal);
const bool is_acc_msg = (addr == 0x343);
const bool block_msg = is_lkas_msg || (is_acc_msg && !toyota_stock_longitudinal);
if (!block_msg) {
bus_fwd = 0;
}
Expand Down

0 comments on commit ee9809d

Please sign in to comment.