Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
211883a
Add panda safety code
fredyshox Feb 22, 2025
a283cd1
Support for gen1 angle
fredyshox Feb 22, 2025
0b774e5
Gen2 test
fredyshox Feb 22, 2025
a04f3d3
Whitespace
fredyshox Feb 22, 2025
61dcf65
Refactored code from @bravochar
fredyshox Feb 22, 2025
3b9dae0
Signal3 test
fredyshox Feb 22, 2025
8852fd3
Fix compilation
fredyshox Feb 22, 2025
f6c1f1b
Fix 2
fredyshox Feb 22, 2025
f2c46a4
Merge remote-tracking branch 'origin/master' into subaru-angle-commahack
fredyshox Feb 22, 2025
322e14a
Use .value
fredyshox Feb 22, 2025
22236d2
Angle limits
fredyshox Feb 23, 2025
5698320
Add latActive
fredyshox Feb 23, 2025
cd158a2
Revert "Signal3 test"
Armandpl Feb 23, 2025
a27ebfc
Revert "Add latActive"
Armandpl Feb 23, 2025
e80dcd4
match safety
Armandpl Feb 23, 2025
4cfe598
disable dashcam mode for angle
Armandpl Feb 23, 2025
afa9c02
ES_CruiseControl message
fredyshox Feb 23, 2025
ba3c178
Fix the dbc
fredyshox Feb 23, 2025
a579d33
Remove duplicate field name
fredyshox Feb 23, 2025
820d3af
MISRA
fredyshox Feb 23, 2025
a158839
()
fredyshox Feb 23, 2025
c9ef3a1
Use different message
fredyshox Feb 23, 2025
43a47cb
Fix test
fredyshox Feb 23, 2025
51efbb5
Fix angle values
fredyshox Feb 23, 2025
9215c47
Fix carstate for hybrids
fredyshox Feb 23, 2025
db0ffd0
limit angle diff
Armandpl Feb 23, 2025
9180aa8
Carstate updates
fredyshox Feb 23, 2025
70013c1
Merge remote-tracking branch 'origin/subaru-angle-commahack' into sub…
fredyshox Feb 23, 2025
ade5272
Fix rx checks
fredyshox Feb 23, 2025
c6e2b39
Try to tune
fredyshox Feb 23, 2025
2281bed
Remove bad cond
fredyshox Feb 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 35 additions & 19 deletions opendbc/car/subaru/carcontroller.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np
from opendbc.can.packer import CANPacker
from opendbc.car import Bus, apply_driver_steer_torque_limits, common_fault_avoidance, make_tester_present_msg
from opendbc.car import Bus, apply_driver_steer_torque_limits, apply_std_steer_angle_limits, common_fault_avoidance, make_tester_present_msg
from opendbc.car.interfaces import CarControllerBase
from opendbc.car.subaru import subarucan
from opendbc.car.subaru.values import DBC, GLOBAL_ES_ADDR, CanBus, CarControllerParams, SubaruFlags
Expand Down Expand Up @@ -31,28 +31,41 @@ def update(self, CC, CS, now_nanos):

# *** steering ***
if (self.frame % self.p.STEER_STEP) == 0:
apply_steer = int(round(actuators.steer * self.p.STEER_MAX))
if self.CP.flags & SubaruFlags.LKAS_ANGLE:
apply_steer = apply_std_steer_angle_limits(actuators.steeringAngleDeg, self.apply_steer_last, CS.out.vEgoRaw, self.p)

# limits due to driver torque
MAX_ANGLE_DIFF = 19 # deg
# limit diff between current angle and command else ecu faults # TODO is this the correct place to do this?
# TODO is there a max angle too?
apply_steer = float(np.clip(apply_steer, apply_steer - MAX_ANGLE_DIFF, apply_steer + MAX_ANGLE_DIFF))

new_steer = int(round(apply_steer))
apply_steer = apply_driver_steer_torque_limits(new_steer, self.apply_steer_last, CS.out.steeringTorque, self.p)
if not CC.latActive:
apply_steer = CS.out.steeringAngleDeg

if not CC.latActive:
apply_steer = 0

if self.CP.flags & SubaruFlags.PREGLOBAL:
can_sends.append(subarucan.create_preglobal_steering_control(self.packer, self.frame // self.p.STEER_STEP, apply_steer, CC.latActive))
can_sends.append(subarucan.create_steering_control_angle(self.packer, apply_steer, CC.latActive))
else:
apply_steer_req = CC.latActive
apply_steer = int(round(actuators.steer * self.p.STEER_MAX))

# limits due to driver torque

if self.CP.flags & SubaruFlags.STEER_RATE_LIMITED:
# Steering rate fault prevention
self.steer_rate_counter, apply_steer_req = \
common_fault_avoidance(abs(CS.out.steeringRateDeg) > MAX_STEER_RATE, apply_steer_req,
self.steer_rate_counter, MAX_STEER_RATE_FRAMES)
new_steer = int(round(apply_steer))
apply_steer = apply_driver_steer_torque_limits(new_steer, self.apply_steer_last, CS.out.steeringTorque, self.p)

can_sends.append(subarucan.create_steering_control(self.packer, apply_steer, apply_steer_req))
if not CC.latActive:
apply_steer = 0

if self.CP.flags & SubaruFlags.PREGLOBAL:
can_sends.append(subarucan.create_preglobal_steering_control(self.packer, self.frame // self.p.STEER_STEP, apply_steer, CC.latActive))
else:
apply_steer_req = CC.latActive

if self.CP.flags & SubaruFlags.STEER_RATE_LIMITED:
# Steering rate fault prevention
self.steer_rate_counter, apply_steer_req = \
common_fault_avoidance(abs(CS.out.steeringRateDeg) > MAX_STEER_RATE, apply_steer_req,
self.steer_rate_counter, MAX_STEER_RATE_FRAMES)

can_sends.append(subarucan.create_steering_control(self.packer, apply_steer, apply_steer_req))

self.apply_steer_last = apply_steer

Expand Down Expand Up @@ -136,8 +149,11 @@ def update(self, CC, CS, now_nanos):
can_sends.append(subarucan.create_es_static_2(self.packer))

new_actuators = actuators.as_builder()
new_actuators.steer = self.apply_steer_last / self.p.STEER_MAX
new_actuators.steerOutputCan = self.apply_steer_last
if self.CP.flags & SubaruFlags.LKAS_ANGLE:
new_actuators.steeringAngleDeg = self.apply_steer_last
else:
new_actuators.steer = self.apply_steer_last / self.p.STEER_MAX
new_actuators.steerOutputCan = self.apply_steer_last

self.frame += 1
return new_actuators, can_sends
10 changes: 8 additions & 2 deletions opendbc/car/subaru/carstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,11 @@ def update(self, can_parsers) -> structs.CarState:
ret.steeringPressed = abs(ret.steeringTorque) > steer_threshold

cp_cruise = cp_alt if self.CP.flags & SubaruFlags.GLOBAL_GEN2 else cp
if self.CP.flags & SubaruFlags.HYBRID:
ret.cruiseState.enabled = cp_cam.vl["ES_DashStatus"]['Cruise_Activated'] != 0
if self.CP.flags & SubaruFlags.LKAS_ANGLE:
ret.cruiseState.enabled = cp_cam.vl["ES_CruiseControl"]['Cruise_Activated'] != 0
ret.cruiseState.available = cp_cam.vl["ES_DashStatus"]['Cruise_On'] != 0
elif self.CP.flags & SubaruFlags.HYBRID:
ret.cruiseState.enabled = cp_cam.vl["ES_DashStatus"]['Cruise_Activated'] != 0 # FIXME: this is false on gas overrides
ret.cruiseState.available = cp_cam.vl["ES_DashStatus"]['Cruise_On'] != 0
else:
ret.cruiseState.enabled = cp_cruise.vl["CruiseControl"]["Cruise_Activated"] != 0
Expand Down Expand Up @@ -205,6 +208,9 @@ def get_can_parsers(CP):
if not (CP.flags & SubaruFlags.GLOBAL_GEN2):
cam_messages += CarState.get_common_global_es_messages(CP)

if CP.flags & SubaruFlags.LKAS_ANGLE:
cam_messages.append(("ES_CruiseControl", 20))

if CP.flags & SubaruFlags.SEND_INFOTAINMENT:
cam_messages.append(("ES_Infotainment", 10))

Expand Down
16 changes: 14 additions & 2 deletions opendbc/car/subaru/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def _get_params(ret: structs.CarParams, candidate: CAR, fingerprint, car_fw, exp
# - replacement for ES_Distance so we can cancel the cruise control
# - to find the Cruise_Activated bit from the car
# - proper panda safety setup (use the correct cruise_activated bit, throttle from Throttle_Hybrid, etc)
ret.dashcamOnly = bool(ret.flags & (SubaruFlags.PREGLOBAL | SubaruFlags.LKAS_ANGLE | SubaruFlags.HYBRID))
ret.dashcamOnly = bool(ret.flags & (SubaruFlags.PREGLOBAL | SubaruFlags.HYBRID))
ret.autoResumeSng = False

# Detect infotainment message sent from the camera
Expand All @@ -29,6 +29,8 @@ def _get_params(ret: structs.CarParams, candidate: CAR, fingerprint, car_fw, exp
ret.safetyConfigs = [get_safety_config(structs.CarParams.SafetyModel.subaru)]
if ret.flags & SubaruFlags.GLOBAL_GEN2:
ret.safetyConfigs[0].safetyParam |= SubaruSafetyFlags.GEN2.value
if ret.flags & SubaruFlags.LKAS_ANGLE:
ret.safetyConfigs[0].safetyParam |= SubaruSafetyFlags.ANGLE.value

ret.steerLimitTimer = 0.4
ret.steerActuatorDelay = 0.1
Expand Down Expand Up @@ -61,12 +63,22 @@ def _get_params(ret: structs.CarParams, candidate: CAR, fingerprint, car_fw, exp
elif candidate == CAR.SUBARU_CROSSTREK_HYBRID:
ret.steerActuatorDelay = 0.1

elif candidate in (CAR.SUBARU_FORESTER, CAR.SUBARU_FORESTER_2022, CAR.SUBARU_FORESTER_HYBRID):
elif candidate in (CAR.SUBARU_FORESTER, CAR.SUBARU_FORESTER_HYBRID):
ret.lateralTuning.init('pid')
ret.lateralTuning.pid.kf = 0.000038
ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0., 14., 23.], [0., 14., 23.]]
ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.01, 0.065, 0.2], [0.001, 0.015, 0.025]]

elif candidate == CAR.SUBARU_FORESTER_2022:
ret.dashcamOnly = False
ret.steerActuatorDelay = 0.3 # end-to-end angle controller
ret.lateralTuning.init('pid')
ret.lateralTuning.pid.kf = 0.00003
ret.lateralTuning.pid.kpBP = [0., 20.]
ret.lateralTuning.pid.kiBP = [0., 20.]
ret.lateralTuning.pid.kpV = [0.0025, 0.1]
ret.lateralTuning.pid.kiV = [0.00025, 0.01]

elif candidate in (CAR.SUBARU_OUTBACK, CAR.SUBARU_LEGACY, CAR.SUBARU_OUTBACK_2023):
ret.steerActuatorDelay = 0.1

Expand Down
6 changes: 5 additions & 1 deletion opendbc/car/subaru/values.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from dataclasses import dataclass, field
from enum import Enum, IntFlag

from opendbc.car import Bus, CarSpecs, DbcDict, PlatformConfig, Platforms, uds
from opendbc.car import Bus, CarSpecs, DbcDict, PlatformConfig, Platforms, AngleRateLimit, uds
from opendbc.car.structs import CarParams
from opendbc.car.docs_definitions import CarFootnote, CarHarness, CarDocs, CarParts, Tool, Column
from opendbc.car.fw_query_definitions import FwQueryConfig, Request, StdQueries, p16
Expand Down Expand Up @@ -52,11 +52,15 @@ def __init__(self, CP):
BRAKE_LOOKUP_BP = [-3.5, 0]
BRAKE_LOOKUP_V = [BRAKE_MAX, BRAKE_MIN]

ANGLE_RATE_LIMIT_UP = AngleRateLimit(speed_bp=[0., 15., 15.], angle_v=[5., .8, .8])
ANGLE_RATE_LIMIT_DOWN = AngleRateLimit(speed_bp=[0., 15., 15.], angle_v=[5., .4, .4])


class SubaruSafetyFlags(IntFlag):
GEN2 = 1
LONG = 2
PREGLOBAL_REVERSED_DRIVER_TORQUE = 4
ANGLE = 8


class SubaruFlags(IntFlag):
Expand Down
12 changes: 12 additions & 0 deletions opendbc/dbc/generator/subaru/subaru_global_2017.dbc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@ BO_ 576 CruiseControl: 8 XXX
SG_ Cruise_Activated : 41|1@1+ (1,0) [0|1] "" XXX
SG_ Signal2 : 42|22@1+ (1,0) [0|4194303] "" XXX


BO_ 556 ES_CruiseControl: 8 XXX
SG_ CHECKSUM : 0|8@1+ (1,0) [0|255] "" XXX
SG_ COUNTER : 8|4@1+ (1,0) [0|15] "" XXX
SG_ Signal1 : 12|44@1+ (1,0) [0|17592186044415] "" XXX
SG_ Cruise_Enable : 56|1@1+ (1,0) [0|1] "" XXX
SG_ Cruise_Set : 57|1@1+ (1,0) [0|1] "" XXX
SG_ Cruise_Resume : 58|1@1+ (1,0) [0|1] "" XXX
SG_ Signal2 : 59|4@1+ (1,0) [0|15] "" XXX
SG_ Cruise_Activated : 63|1@1+ (1,0) [0|1] "" XXX


CM_ SG_ 545 Cruise_Throttle "RPM-like output signal";
CM_ SG_ 545 Cruise_EPB "1 = Electric Parking Brake set";
CM_ SG_ 545 Distance_Swap "Switch from Close to Far distance";
Expand Down
99 changes: 84 additions & 15 deletions opendbc/safety/safety/safety_subaru.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@
#define MSG_SUBARU_Wheel_Speeds 0x13a

#define MSG_SUBARU_ES_LKAS 0x122
#define MSG_SUBARU_ES_LKAS_ANGLE 0x124
#define MSG_SUBARU_ES_Brake 0x220
#define MSG_SUBARU_ES_Distance 0x221
#define MSG_SUBARU_ES_Status 0x222
#define MSG_SUBARU_ES_DashStatus 0x321
#define MSG_SUBARU_ES_CruiseControl 0x22c
#define MSG_SUBARU_ES_LKAS_State 0x322
#define MSG_SUBARU_ES_Infotainment 0x323

Expand Down Expand Up @@ -61,15 +63,20 @@
{MSG_SUBARU_ES_STATIC_1, SUBARU_MAIN_BUS, 8}, \
{MSG_SUBARU_ES_STATIC_2, SUBARU_MAIN_BUS, 8}, \

#define SUBARU_COMMON_RX_CHECKS(alt_bus) \
{.msg = {{MSG_SUBARU_Throttle, SUBARU_MAIN_BUS, 8, .check_checksum = true, .max_counter = 15U, .frequency = 100U}, { 0 }, { 0 }}}, \
{.msg = {{MSG_SUBARU_Steering_Torque, SUBARU_MAIN_BUS, 8, .check_checksum = true, .max_counter = 15U, .frequency = 50U}, { 0 }, { 0 }}}, \
{.msg = {{MSG_SUBARU_Wheel_Speeds, alt_bus, 8, .check_checksum = true, .max_counter = 15U, .frequency = 50U}, { 0 }, { 0 }}}, \
{.msg = {{MSG_SUBARU_Brake_Status, alt_bus, 8, .check_checksum = true, .max_counter = 15U, .frequency = 50U}, { 0 }, { 0 }}}, \
{.msg = {{MSG_SUBARU_CruiseControl, alt_bus, 8, .check_checksum = true, .max_counter = 15U, .frequency = 20U}, { 0 }, { 0 }}}, \
#define SUBARU_COMMON_RX_CHECKS(alt_bus) \
{.msg = {{MSG_SUBARU_Throttle, SUBARU_MAIN_BUS, 8, .check_checksum = true, .max_counter = 15U, .frequency = 100U}, { 0 }, { 0 }}}, \
{.msg = {{MSG_SUBARU_Steering_Torque, SUBARU_MAIN_BUS, 8, .check_checksum = true, .max_counter = 15U, .frequency = 50U}, { 0 }, { 0 }}}, \
{.msg = {{MSG_SUBARU_Wheel_Speeds, alt_bus, 8, .check_checksum = true, .max_counter = 15U, .frequency = 50U}, { 0 }, { 0 }}}, \
{.msg = {{MSG_SUBARU_Brake_Status, alt_bus, 8, .check_checksum = true, .max_counter = 15U, .frequency = 50U}, { 0 }, { 0 }}}, \
{.msg = {{MSG_SUBARU_CruiseControl, alt_bus, 8, .check_checksum = true, .max_counter = 15U, .frequency = 20U}, { 0 }, { 0 }}}, \

#define SUBARU_ANGLE_RX_CHECKS() \
{.msg = {{MSG_SUBARU_ES_CruiseControl, SUBARU_CAM_BUS, 8, .check_checksum = true, .max_counter = 15U, .frequency = 20U}, { 0 }, { 0 }}}, \


static bool subaru_gen2 = false;
static bool subaru_longitudinal = false;
static bool subaru_lkas_angle = false;

static uint32_t subaru_get_checksum(const CANPacket_t *to_push) {
return (uint8_t)GET_BYTE(to_push, 0);
Expand All @@ -92,6 +99,7 @@ static uint32_t subaru_compute_checksum(const CANPacket_t *to_push) {
static void subaru_rx_hook(const CANPacket_t *to_push) {
const int bus = GET_BUS(to_push);
const int alt_main_bus = subaru_gen2 ? SUBARU_ALT_BUS : SUBARU_MAIN_BUS;
const int stock_lkas_msg = subaru_lkas_angle ? MSG_SUBARU_ES_LKAS_ANGLE : MSG_SUBARU_ES_LKAS;

int addr = GET_ADDR(to_push);
if ((addr == MSG_SUBARU_Steering_Torque) && (bus == SUBARU_MAIN_BUS)) {
Expand All @@ -107,9 +115,16 @@ static void subaru_rx_hook(const CANPacket_t *to_push) {
}

// enter controls on rising edge of ACC, exit controls on ACC off
if ((addr == MSG_SUBARU_CruiseControl) && (bus == alt_main_bus)) {
bool cruise_engaged = GET_BIT(to_push, 41U);
pcm_cruise_check(cruise_engaged);
if (subaru_lkas_angle) {
if ((addr == MSG_SUBARU_ES_CruiseControl) && (bus == SUBARU_CAM_BUS)) {
bool cruise_engaged = GET_BIT(to_push, 63U);
pcm_cruise_check(cruise_engaged);
}
} else {
if ((addr == MSG_SUBARU_CruiseControl) && (bus == alt_main_bus)) {
bool cruise_engaged = GET_BIT(to_push, 41U);
pcm_cruise_check(cruise_engaged);
}
}

// update vehicle moving with any non-zero wheel speed
Expand All @@ -132,13 +147,25 @@ static void subaru_rx_hook(const CANPacket_t *to_push) {
gas_pressed = GET_BYTE(to_push, 4) != 0U;
}

generic_rx_checks((addr == MSG_SUBARU_ES_LKAS) && (bus == SUBARU_MAIN_BUS));
generic_rx_checks((addr == stock_lkas_msg) && (bus == SUBARU_MAIN_BUS));
}

static bool subaru_tx_hook(const CANPacket_t *to_send) {
const SteeringLimits SUBARU_STEERING_LIMITS = SUBARU_STEERING_LIMITS_GENERATOR(2047, 50, 70);
const SteeringLimits SUBARU_GEN2_STEERING_LIMITS = SUBARU_STEERING_LIMITS_GENERATOR(1000, 40, 40);

const SteeringLimits SUBARU_ANGLE_STEERING_LIMITS = {
.angle_deg_to_can = 100.,
.angle_rate_up_lookup = {
{0., 15., 15.},
{5., .8, .8}
},
.angle_rate_down_lookup = {
{0., 15., 15.},
{5., .4, .4}
},
};

const LongitudinalLimits SUBARU_LONG_LIMITS = {
.min_gas = 808, // appears to be engine braking
.max_gas = 3400, // approx 2 m/s^2 when maxing cruise_rpm and cruise_throttle
Expand All @@ -164,6 +191,14 @@ static bool subaru_tx_hook(const CANPacket_t *to_send) {
violation |= steer_torque_cmd_checks(desired_torque, steer_req, limits);
}

if (addr == MSG_SUBARU_ES_LKAS_ANGLE) {
int desired_angle = (GET_BYTES(to_send, 5, 3) & 0x1FFFFU);
desired_angle = -1 * to_signed(desired_angle, 17);
bool lkas_request = GET_BIT(to_send, 12U);

violation |= steer_angle_cmd_checks(desired_angle, lkas_request, SUBARU_ANGLE_STEERING_LIMITS);
}

// check es_brake brake_pressure limits
if (addr == MSG_SUBARU_ES_Brake) {
int es_brake_pressure = GET_BYTES(to_send, 2, 2);
Expand Down Expand Up @@ -210,13 +245,15 @@ static bool subaru_tx_hook(const CANPacket_t *to_send) {
static int subaru_fwd_hook(int bus_num, int addr) {
int bus_fwd = -1;

const int stock_lkas_msg = subaru_lkas_angle ? MSG_SUBARU_ES_LKAS_ANGLE : MSG_SUBARU_ES_LKAS;

if (bus_num == SUBARU_MAIN_BUS) {
bus_fwd = SUBARU_CAM_BUS; // to the eyesight camera
}

if (bus_num == SUBARU_CAM_BUS) {
// Global platform
bool block_lkas = ((addr == MSG_SUBARU_ES_LKAS) ||
bool block_lkas = ((addr == stock_lkas_msg) ||
(addr == MSG_SUBARU_ES_DashStatus) ||
(addr == MSG_SUBARU_ES_LKAS_State) ||
(addr == MSG_SUBARU_ES_Infotainment));
Expand All @@ -239,6 +276,11 @@ static safety_config subaru_init(uint16_t param) {
SUBARU_COMMON_TX_MSGS(SUBARU_MAIN_BUS, MSG_SUBARU_ES_LKAS)
};

static const CanMsg SUBARU_LKAS_ANGLE_TX_MSGS[] = {
SUBARU_COMMON_TX_MSGS(SUBARU_MAIN_BUS, MSG_SUBARU_ES_LKAS_ANGLE)
SUBARU_COMMON_TX_MSGS(SUBARU_MAIN_BUS, MSG_SUBARU_ES_LKAS)
};

static const CanMsg SUBARU_LONG_TX_MSGS[] = {
SUBARU_COMMON_TX_MSGS(SUBARU_MAIN_BUS, MSG_SUBARU_ES_LKAS)
SUBARU_COMMON_LONG_TX_MSGS(SUBARU_MAIN_BUS)
Expand All @@ -248,6 +290,11 @@ static safety_config subaru_init(uint16_t param) {
SUBARU_COMMON_TX_MSGS(SUBARU_ALT_BUS, MSG_SUBARU_ES_LKAS)
};

static const CanMsg SUBARU_GEN2_LKAS_ANGLE_TX_MSGS[] = {
SUBARU_COMMON_TX_MSGS(SUBARU_ALT_BUS, MSG_SUBARU_ES_LKAS_ANGLE)
SUBARU_COMMON_TX_MSGS(SUBARU_ALT_BUS, MSG_SUBARU_ES_LKAS)
};

static const CanMsg SUBARU_GEN2_LONG_TX_MSGS[] = {
SUBARU_COMMON_TX_MSGS(SUBARU_ALT_BUS, MSG_SUBARU_ES_LKAS)
SUBARU_COMMON_LONG_TX_MSGS(SUBARU_ALT_BUS)
Expand All @@ -258,13 +305,25 @@ static safety_config subaru_init(uint16_t param) {
SUBARU_COMMON_RX_CHECKS(SUBARU_MAIN_BUS)
};

static RxCheck subaru_angle_rx_checks[] = {
SUBARU_COMMON_RX_CHECKS(SUBARU_MAIN_BUS)
SUBARU_ANGLE_RX_CHECKS()
};

static RxCheck subaru_gen2_rx_checks[] = {
SUBARU_COMMON_RX_CHECKS(SUBARU_ALT_BUS)
};

static RxCheck subaru_gen2_angle_rx_checks[] = {
SUBARU_COMMON_RX_CHECKS(SUBARU_ALT_BUS)
SUBARU_ANGLE_RX_CHECKS()
};

const uint16_t SUBARU_PARAM_GEN2 = 1;
const uint16_t SUBARU_PARAM_LKAS_ANGLE = 8;

subaru_gen2 = GET_FLAG(param, SUBARU_PARAM_GEN2);
subaru_lkas_angle = GET_FLAG(param, SUBARU_PARAM_LKAS_ANGLE);

#ifdef ALLOW_DEBUG
const uint16_t SUBARU_PARAM_LONGITUDINAL = 2;
Expand All @@ -273,11 +332,21 @@ static safety_config subaru_init(uint16_t param) {

safety_config ret;
if (subaru_gen2) {
ret = subaru_longitudinal ? BUILD_SAFETY_CFG(subaru_gen2_rx_checks, SUBARU_GEN2_LONG_TX_MSGS) : \
BUILD_SAFETY_CFG(subaru_gen2_rx_checks, SUBARU_GEN2_TX_MSGS);
if (subaru_lkas_angle) {
ret = BUILD_SAFETY_CFG(subaru_gen2_angle_rx_checks, SUBARU_GEN2_LKAS_ANGLE_TX_MSGS);
} else if (subaru_longitudinal) {
ret = BUILD_SAFETY_CFG(subaru_gen2_rx_checks, SUBARU_GEN2_LONG_TX_MSGS);
} else {
ret = BUILD_SAFETY_CFG(subaru_gen2_rx_checks, SUBARU_GEN2_TX_MSGS);
}
} else {
ret = subaru_longitudinal ? BUILD_SAFETY_CFG(subaru_rx_checks, SUBARU_LONG_TX_MSGS) : \
BUILD_SAFETY_CFG(subaru_rx_checks, SUBARU_TX_MSGS);
if (subaru_lkas_angle) {
ret = BUILD_SAFETY_CFG(subaru_angle_rx_checks, SUBARU_LKAS_ANGLE_TX_MSGS);
} else if (subaru_longitudinal) {
ret = BUILD_SAFETY_CFG(subaru_rx_checks, SUBARU_LONG_TX_MSGS);
} else {
ret = BUILD_SAFETY_CFG(subaru_rx_checks, SUBARU_TX_MSGS);
}
}
return ret;
}
Expand Down
Loading