Skip to content

Commit

Permalink
safety: common interceptor checks (commaai#1178)
Browse files Browse the repository at this point in the history
* interceptor checks

* only one line needed for now

* whoops

* misra

* misread as |
  • Loading branch information
sshane committed Dec 1, 2022
1 parent b19a74f commit cb8fc6b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
4 changes: 4 additions & 0 deletions board/safety.h
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,10 @@ bool longitudinal_brake_checks(int desired_brake, const LongitudinalLimits limit
return violation;
}

bool longitudinal_interceptor_checks(CANPacket_t *to_send, bool longitudinal_allowed) {
return !longitudinal_allowed && (GET_BYTE(to_send, 0) || GET_BYTE(to_send, 1));
}

// Safety checks for torque-based steering commands
bool steer_torque_cmd_checks(int desired_torque, int steer_req, const SteeringLimits limits) {
bool violation = false;
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 @@ -333,10 +333,8 @@ static int honda_tx_hook(CANPacket_t *to_send, bool longitudinal_allowed) {

// GAS: safety check (interceptor)
if (addr == 0x200) {
if (!longitudinal_allowed) {
if (GET_BYTE(to_send, 0) || GET_BYTE(to_send, 1)) {
tx = 0;
}
if (longitudinal_interceptor_checks(to_send, longitudinal_allowed)) {
tx = 0;
}
}

Expand Down
6 changes: 2 additions & 4 deletions board/safety/safety_toyota.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,8 @@ static int toyota_tx_hook(CANPacket_t *to_send, bool longitudinal_allowed) {

// GAS PEDAL: safety check
if (addr == 0x200) {
if (!longitudinal_allowed) {
if (GET_BYTE(to_send, 0) || GET_BYTE(to_send, 1)) {
tx = 0;
}
if (longitudinal_interceptor_checks(to_send, longitudinal_allowed)) {
tx = 0;
}
}

Expand Down
1 change: 1 addition & 0 deletions board/safety_declarations.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ bool steer_torque_cmd_checks(int desired_torque, int steer_req, const SteeringLi
bool longitudinal_accel_checks(int desired_accel, const LongitudinalLimits limits, const bool longitudinal_allowed);
bool longitudinal_gas_checks(int desired_gas, const LongitudinalLimits limits, const bool longitudinal_allowed);
bool longitudinal_brake_checks(int desired_brake, const LongitudinalLimits limits, const bool longitudinal_allowed);
bool longitudinal_interceptor_checks(CANPacket_t *to_send, const bool longitudinal_allowed);
void pcm_cruise_check(bool cruise_engaged);

typedef const addr_checks* (*safety_hook_init)(uint16_t param);
Expand Down

0 comments on commit cb8fc6b

Please sign in to comment.