Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modular Assistive Driving System (MADS) #40

Merged
merged 109 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from 105 commits
Commits
Show all changes
109 commits
Select commit Hold shift + click to select a range
b23543d
alternative experience
sunnyhaibin Sep 18, 2024
035c78a
safety init
sunnyhaibin Sep 19, 2024
c3b7f82
fix
sunnyhaibin Sep 29, 2024
dcd226d
more update
sunnyhaibin Sep 29, 2024
4f40ae6
not really
sunnyhaibin Sep 29, 2024
5aaa664
Merge branch 'master' into mads-new
sunnyhaibin Sep 29, 2024
546f43f
misra
sunnyhaibin Sep 29, 2024
1ac593f
Add Custom MIT License (#38)
sunnyhaibin Oct 1, 2024
e46d040
Merge branch 'commaai:master' into master-new
devtekve Nov 2, 2024
9c62b7f
Merge branch 'master-new' into mads-new
sunnyhaibin Nov 11, 2024
80f23ae
brake check was not handled
sunnyhaibin Nov 13, 2024
d0653fb
revert
sunnyhaibin Nov 13, 2024
d843088
alt -> lkas
sunnyhaibin Nov 13, 2024
d379604
explicit checks
sunnyhaibin Nov 13, 2024
de6dae9
support toyota and ford
sunnyhaibin Nov 14, 2024
6e3a70c
rename
sunnyhaibin Nov 14, 2024
6c974d9
hyundai can-fd support
sunnyhaibin Nov 14, 2024
eb7a332
only allow lkas if enabled
sunnyhaibin Nov 14, 2024
7508579
hyundai: main button handling
sunnyhaibin Nov 15, 2024
48b177f
revert
sunnyhaibin Nov 15, 2024
f5807bc
hyundai: main button heartbeat
sunnyhaibin Nov 15, 2024
efc5c74
add logging for controls allowed lateral
sunnyhaibin Nov 15, 2024
1ae97c1
Merge remote-tracking branch 'origin/master-new' into mads-new
devtekve Nov 15, 2024
d9f6815
fix panda safety
sunnyhaibin Nov 15, 2024
63946db
Merge branch 'master-new' into mads-new
sunnyhaibin Nov 21, 2024
4213170
Merge branch 'master-new' into mads-new
sunnyhaibin Nov 22, 2024
ad4bf6e
ford btn
sunnyhaibin Nov 22, 2024
21b7a72
toyota btn
sunnyhaibin Nov 22, 2024
d99d410
fca btn
sunnyhaibin Nov 22, 2024
543864b
honda btn
sunnyhaibin Nov 22, 2024
b909db9
mads safety tests
sunnyhaibin Nov 22, 2024
dee9afc
more tests
sunnyhaibin Nov 22, 2024
4c33dca
safety misra
sunnyhaibin Nov 22, 2024
c3de776
safety mutation
sunnyhaibin Nov 22, 2024
bdbb674
misra
sunnyhaibin Nov 22, 2024
9fc1f6f
mutation experiment
sunnyhaibin Nov 23, 2024
688024f
fix
sunnyhaibin Nov 23, 2024
0de4310
ford test main button
sunnyhaibin Nov 23, 2024
a5f7f47
ford test lkas button
sunnyhaibin Nov 23, 2024
a910d33
more ford test
sunnyhaibin Nov 23, 2024
b54d020
hyundai lkas and main
sunnyhaibin Nov 23, 2024
a53240e
more ford
sunnyhaibin Nov 23, 2024
43ed51a
hyundai canfd
sunnyhaibin Nov 23, 2024
c55138c
rename
sunnyhaibin Nov 23, 2024
1c30859
rename
sunnyhaibin Nov 23, 2024
218ffe4
cleaner
sunnyhaibin Nov 23, 2024
79953cb
more fixes
sunnyhaibin Nov 23, 2024
3b1ebab
more hyundai tests
sunnyhaibin Nov 23, 2024
6b03941
no longer needed
sunnyhaibin Nov 23, 2024
b0ac850
Merge branch 'master-new' into mads-new
sunnyhaibin Nov 23, 2024
a033911
thanks for tests!
sunnyhaibin Nov 25, 2024
79ff2b0
more tests for lat
sunnyhaibin Nov 25, 2024
9d8d880
more explicit
sunnyhaibin Nov 25, 2024
3f2df0e
make sure to reset
sunnyhaibin Nov 25, 2024
a0ea527
try this out
sunnyhaibin Nov 25, 2024
6e5e967
probably needed
sunnyhaibin Nov 25, 2024
7d9218f
move
sunnyhaibin Nov 25, 2024
bf702b0
misra
sunnyhaibin Nov 25, 2024
486ddd0
not needed
sunnyhaibin Nov 26, 2024
c0c1cc2
move to safety_mads
sunnyhaibin Nov 26, 2024
3456b80
not really needed
sunnyhaibin Nov 26, 2024
d25cb1d
remove
sunnyhaibin Nov 26, 2024
01e8e55
MADS: Refactor MADS safety with improved state management (pull reque…
devtekve Dec 3, 2024
a541089
adding note
devtekve Dec 3, 2024
86f5205
adding ford (WIP)
devtekve Dec 3, 2024
306470a
adding honda (WIP)
devtekve Dec 3, 2024
db0a822
adding toyota (WIP)
devtekve Dec 3, 2024
cbb9ced
adding chrysler (WIP)
devtekve Dec 3, 2024
125763b
Standardize Button State Handling Across Platforms
devtekve Dec 4, 2024
268c761
Disable LKAS button press logic in Honda and Toyota safety.
devtekve Dec 4, 2024
d6b012c
Remove commented out code in toyota_rx_hook function
devtekve Dec 4, 2024
8223823
GM, mazda, nissan, subaru (global & preglobal)
sunnyhaibin Dec 4, 2024
df85110
Honda LKAS
sunnyhaibin Dec 4, 2024
b6a51d8
Revert "Remove commented out code in toyota_rx_hook function"
sunnyhaibin Dec 4, 2024
f10b3e2
Toyota, Subaru Global LKAS
sunnyhaibin Dec 4, 2024
b548ac2
nissan fix
sunnyhaibin Dec 5, 2024
3f22376
gm fix
sunnyhaibin Dec 5, 2024
7974170
use speed msg to force rx
sunnyhaibin Dec 5, 2024
f2136d4
im bored
sunnyhaibin Dec 5, 2024
b0b4cff
misra
sunnyhaibin Dec 5, 2024
4c8566a
subaru/toyota/honda
sunnyhaibin Dec 5, 2024
af86789
nope
sunnyhaibin Dec 5, 2024
fc2c55c
attempt
sunnyhaibin Dec 5, 2024
87639db
go through all buttons
sunnyhaibin Dec 5, 2024
649298e
try nissan
sunnyhaibin Dec 5, 2024
b3cbf0c
more nissan
sunnyhaibin Dec 5, 2024
5c8109e
nissan tests passed!
sunnyhaibin Dec 5, 2024
6ae1254
subaru lkas test (not sure why it's not passing 2 and 3 values)
sunnyhaibin Dec 5, 2024
e5a2cff
Improved code organization in safety_subaru.h and test_subaru.py
devtekve Dec 5, 2024
e71f084
Refactor tests to use _speed_msg instead of _user_brake_msg.
devtekve Dec 5, 2024
bf1ca4a
Reworking the tests a little for clarity
devtekve Dec 5, 2024
efe4a7e
disabling lkas again on toyota temporarily
devtekve Dec 5, 2024
90ca5a8
fix mads condition to engage
devtekve Dec 5, 2024
9b91dd5
hyundai and honda good with new tests
devtekve Dec 5, 2024
24ee2e9
Redoing more tests
devtekve Dec 5, 2024
1aba730
update for safety tick ensuring mads control is exited while lagging
devtekve Dec 5, 2024
34786d9
Updating tests for toyota
devtekve Dec 5, 2024
ec5b129
cleaning up tests on hkg
devtekve Dec 5, 2024
f31b815
commenting out temp_debug for future use
devtekve Dec 5, 2024
ae375f9
revert
sunnyhaibin Dec 5, 2024
af0fa54
constants
sunnyhaibin Dec 5, 2024
7851ac9
cleanup
sunnyhaibin Dec 5, 2024
4026ece
format!
sunnyhaibin Dec 5, 2024
df2452f
Merge branch 'master-new' into mads-new
sunnyhaibin Dec 5, 2024
4ed88ad
match yota
sunnyhaibin Dec 5, 2024
9ec1b66
Apply suggestions from code review
sunnyhaibin Dec 5, 2024
c62a1b2
force
sunnyhaibin Dec 6, 2024
1872a7b
explicit checks
sunnyhaibin Dec 6, 2024
c07a279
revert
sunnyhaibin Dec 6, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ jobs:
- name: Build Docker image
run: eval "$BUILD"
- name: Mutation tests
timeout-minutes: 5
timeout-minutes: 8
run: ${{ env.RUN }} "GIT_REF=${{ github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/master-new') && github.event.before || 'origin/master' }} cd tests/safety && ./mutation.sh"

static_analysis:
Expand Down
1 change: 1 addition & 0 deletions board/health.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ struct __attribute__((packed)) health_t {
uint8_t ignition_line_pkt;
uint8_t ignition_can_pkt;
uint8_t controls_allowed_pkt;
uint8_t controls_allowed_lat_pkt;
uint8_t car_harness_status_pkt;
uint8_t safety_mode_pkt;
uint16_t safety_param_pkt;
Expand Down
4 changes: 4 additions & 0 deletions board/main_comms.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ static int get_health_pkt(void *dat) {
health->ignition_can_pkt = ignition_can;

health->controls_allowed_pkt = controls_allowed;
health->controls_allowed_lat_pkt = mads_is_lateral_control_allowed_by_mads();
health->safety_tx_blocked_pkt = safety_tx_blocked;
health->safety_rx_invalid_pkt = safety_rx_invalid;
health->tx_buffer_overflow_pkt = tx_buffer_overflow;
Expand Down Expand Up @@ -247,6 +248,9 @@ int comms_control_handler(ControlPacket_t *req, uint8_t *resp) {
// you can only set this if you are in a non car safety mode
if (!is_car_safety_mode(current_safety_mode)) {
alternative_experience = req->param1;
bool mads_enabled = (alternative_experience & ALT_EXP_ENABLE_MADS) != 0;
bool disengage_lateral_on_brake = !(alternative_experience & ALT_EXP_DISABLE_DISENGAGE_LATERAL_ON_BRAKE);
mads_set_system_state(mads_enabled, disengage_lateral_on_brake);
}
break;
// **** 0xe0: uart read
Expand Down
18 changes: 13 additions & 5 deletions board/safety.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "safety_declarations.h"
#include "can.h"

#include "sunnypilot/safety_mads.h"

// include the safety policies.
#include "safety/safety_defaults.h"
#include "safety/safety_honda.h"
Expand Down Expand Up @@ -111,6 +113,10 @@ uint16_t current_safety_param = 0;
static const safety_hooks *current_hooks = &nooutput_hooks;
safety_config current_safety_config;

static bool is_lat_active(void) {
return controls_allowed || mads_is_lateral_control_allowed_by_mads();
}

static bool is_msg_valid(RxCheck addr_list[], int index) {
bool valid = true;
if (index != -1) {
Expand Down Expand Up @@ -301,6 +307,7 @@ void safety_tick(const safety_config *cfg) {
cfg->rx_checks[i].status.lagging = lagging;
if (lagging) {
controls_allowed = false;
mads_exit_controls();
}

if (lagging || !is_msg_valid(cfg->rx_checks, i)) {
Expand Down Expand Up @@ -343,6 +350,7 @@ void generic_rx_checks(bool stock_ecu_detected) {
if ((safety_mode_cnt > RELAY_TRNS_TIMEOUT) && stock_ecu_detected) {
relay_malfunction_set();
}
mads_state_update(&vehicle_moving, &acc_main_on, brake_pressed || regen_braking, cruise_engaged_prev);
}

static void relay_malfunction_reset(void) {
Expand Down Expand Up @@ -601,7 +609,7 @@ bool steer_torque_cmd_checks(int desired_torque, int steer_req, const SteeringLi
bool violation = false;
uint32_t ts = microsecond_timer_get();

if (controls_allowed) {
if (is_lat_active()) {
// *** global torque limit check ***
violation |= max_limit_check(desired_torque, limits.max_steer, -limits.max_steer);

Expand All @@ -628,7 +636,7 @@ bool steer_torque_cmd_checks(int desired_torque, int steer_req, const SteeringLi
}

// no torque if controls is not allowed
if (!controls_allowed && (desired_torque != 0)) {
if (!is_lat_active() && (desired_torque != 0)) {
violation = true;
}

Expand Down Expand Up @@ -670,7 +678,7 @@ bool steer_torque_cmd_checks(int desired_torque, int steer_req, const SteeringLi
}

// reset to 0 if either controls is not allowed or there's a violation
if (violation || !controls_allowed) {
if (violation || !is_lat_active()) {
valid_steer_req_count = 0;
invalid_steer_req_count = 0;
desired_torque_last = 0;
Expand All @@ -686,7 +694,7 @@ bool steer_torque_cmd_checks(int desired_torque, int steer_req, const SteeringLi
bool steer_angle_cmd_checks(int desired_angle, bool steer_control_enabled, const SteeringLimits limits) {
bool violation = false;

if (controls_allowed && steer_control_enabled) {
if (is_lat_active() && steer_control_enabled) {
// convert floating point angle rate limits to integers in the scale of the desired angle on CAN,
// add 1 to not false trigger the violation. also fudge the speed by 1 m/s so rate limits are
// always slightly above openpilot's in case we read an updated speed in between angle commands
Expand Down Expand Up @@ -729,7 +737,7 @@ bool steer_angle_cmd_checks(int desired_angle, bool steer_control_enabled, const
}

// No angle control allowed when controls are not allowed
violation |= !controls_allowed && steer_control_enabled;
violation |= !is_lat_active() && steer_control_enabled;

return violation;
}
Expand Down
2 changes: 2 additions & 0 deletions board/safety/safety_chrysler.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ static void chrysler_rx_hook(const CANPacket_t *to_push) {
if ((bus == das_3_bus) && (addr == chrysler_addrs->DAS_3)) {
bool cruise_engaged = GET_BIT(to_push, 21U);
pcm_cruise_check(cruise_engaged);

sunnyhaibin marked this conversation as resolved.
Show resolved Hide resolved
acc_main_on = GET_BIT(to_push, 20U);
}

// TODO: use the same message for both
Expand Down
5 changes: 5 additions & 0 deletions board/safety/safety_ford.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ static void ford_rx_hook(const CANPacket_t *to_push) {
unsigned int cruise_state = GET_BYTE(to_push, 1) & 0x07U;
bool cruise_engaged = (cruise_state == 4U) || (cruise_state == 5U);
pcm_cruise_check(cruise_engaged);
acc_main_on = (cruise_state == 3U) || cruise_engaged;
}

if (addr == FORD_Steering_Data_FD1) {
lkas_button_press = GET_BIT(to_push, 40U) ? MADS_BUTTON_PRESSED : MADS_BUTTON_NOT_PRESSED;
}

// If steering controls messages are received on the destination bus, it's an indication
Expand Down
4 changes: 4 additions & 0 deletions board/safety/safety_gm.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ static void gm_rx_hook(const CANPacket_t *to_push) {
regen_braking = (GET_BYTE(to_push, 0) >> 4) != 0U;
}

if (addr == 0xC9) {
acc_main_on = GET_BIT(to_push, 29U);
}

bool stock_ecu_detected = (addr == 0x180); // ASCMLKASteeringCmd

// Check ASCMGasRegenCmd only if we're blocking it
Expand Down
7 changes: 7 additions & 0 deletions board/safety/safety_honda.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ static void honda_rx_hook(const CANPacket_t *to_push) {
// 0x1A6 for the ILX, 0x296 for the Civic Touring
if (((addr == 0x1A6) || (addr == 0x296)) && (bus == pt_bus)) {
int button = (GET_BYTE(to_push, 0) & 0xE0U) >> 5;
bool is_main = (button == HONDA_BTN_MAIN);
main_button_press = is_main ? MADS_BUTTON_PRESSED : MADS_BUTTON_NOT_PRESSED;

int cruise_setting = (GET_BYTE(to_push, (addr == 0x296) ? 0U : 5U) & 0x0CU) >> 2U;
if (cruise_setting == 1) {
lkas_button_press = MADS_BUTTON_PRESSED;
}

// enter controls on the falling edge of set or resume
bool set = (button != HONDA_BTN_SET) && (cruise_button_prev == HONDA_BTN_SET);
Expand Down
10 changes: 10 additions & 0 deletions board/safety/safety_hyundai.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,23 @@ static void hyundai_rx_hook(const CANPacket_t *to_push) {
hyundai_common_cruise_state_check(cruise_engaged);
}

if ((addr == 0x420) && (((bus == 0) && !hyundai_camera_scc) || ((bus == 2) && hyundai_camera_scc))) {
if (!hyundai_longitudinal) {
acc_main_on = GET_BIT(to_push, 0U);
}
}

if (bus == 0) {
if (addr == 0x251) {
int torque_driver_new = (GET_BYTES(to_push, 0, 2) & 0x7ffU) - 1024U;
// update array of samples
update_sample(&torque_driver, torque_driver_new);
}

if (addr == 0x391) {
lkas_button_press = GET_BIT(to_push, 4U) ? MADS_BUTTON_PRESSED : MADS_BUTTON_NOT_PRESSED;
}

// ACC steering wheel buttons
if (addr == 0x4F1) {
int cruise_button = GET_BYTE(to_push, 0) & 0x7U;
Expand Down
2 changes: 2 additions & 0 deletions board/safety/safety_hyundai_canfd.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,11 @@ static void hyundai_canfd_rx_hook(const CANPacket_t *to_push) {
if (addr == 0x1cf) {
cruise_button = GET_BYTE(to_push, 2) & 0x7U;
main_button = GET_BIT(to_push, 19U);
lkas_button_press = GET_BIT(to_push, 23U) ? MADS_BUTTON_PRESSED : MADS_BUTTON_NOT_PRESSED;
} else {
cruise_button = (GET_BYTE(to_push, 4) >> 4) & 0x7U;
main_button = GET_BIT(to_push, 34U);
lkas_button_press = GET_BIT(to_push, 39U) ? MADS_BUTTON_PRESSED : MADS_BUTTON_NOT_PRESSED;
}
hyundai_common_cruise_buttons_check(cruise_button, main_button);
}
Expand Down
2 changes: 2 additions & 0 deletions board/safety/safety_hyundai_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ void hyundai_common_cruise_buttons_check(const int cruise_button, const bool mai
hyundai_last_button_interaction = MIN(hyundai_last_button_interaction + 1U, HYUNDAI_PREV_BUTTON_SAMPLES);
}

main_button_press = main_button ? MADS_BUTTON_PRESSED : MADS_BUTTON_NOT_PRESSED;

if (hyundai_longitudinal) {
// enter controls on falling edge of resume or set
bool set = (cruise_button != HYUNDAI_BTN_SET) && (cruise_button_prev == HYUNDAI_BTN_SET);
Expand Down
2 changes: 2 additions & 0 deletions board/safety/safety_mazda.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ static void mazda_rx_hook(const CANPacket_t *to_push) {
if (addr == MAZDA_CRZ_CTRL) {
bool cruise_engaged = GET_BYTE(to_push, 0) & 0x8U;
pcm_cruise_check(cruise_engaged);

sunnyhaibin marked this conversation as resolved.
Show resolved Hide resolved
acc_main_on = GET_BIT(to_push, 17U);
}

if (addr == MAZDA_ENGINE_DATA) {
Expand Down
11 changes: 11 additions & 0 deletions board/safety/safety_nissan.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "safety_declarations.h"

static bool nissan_alt_eps = false;
static bool nissan_leaf = false;

static void nissan_rx_hook(const CANPacket_t *to_push) {
int bus = GET_BUS(to_push);
Expand Down Expand Up @@ -53,6 +54,14 @@ static void nissan_rx_hook(const CANPacket_t *to_push) {
pcm_cruise_check(cruise_engaged);
}

if ((addr == 0x239) && (bus == 0) && nissan_leaf) {
acc_main_on = GET_BIT(to_push, 17U);
}

if ((addr == 0x1B6) && (bus == (nissan_alt_eps ? 2 : 1))) {
acc_main_on = GET_BIT(to_push, 36U);
}

generic_rx_checks((addr == 0x169) && (bus == 0));
}

Expand Down Expand Up @@ -150,8 +159,10 @@ static safety_config nissan_init(uint16_t param) {

// EPS Location. false = V-CAN, true = C-CAN
const int NISSAN_PARAM_ALT_EPS_BUS = 1;
const int NISSAN_PARAM_LEAF = 512;

nissan_alt_eps = GET_FLAG(param, NISSAN_PARAM_ALT_EPS_BUS);
nissan_leaf = GET_FLAG(param, NISSAN_PARAM_LEAF);
return BUILD_SAFETY_CFG(nissan_rx_checks, NISSAN_TX_MSGS);
}

Expand Down
9 changes: 9 additions & 0 deletions board/safety/safety_subaru.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,19 @@ static void subaru_rx_hook(const CANPacket_t *to_push) {
update_sample(&angle_meas, angle_meas_new);
}

if ((addr == MSG_SUBARU_ES_LKAS_State) && (bus == SUBARU_CAM_BUS)) {
bool lkas_hud = ((GET_BYTE(to_push, 2) & 0x0CU) >> 2U) > 0U;
if (lkas_hud) {
lkas_button_press = MADS_BUTTON_PRESSED;
}
}

sunnyhaibin marked this conversation as resolved.
Show resolved Hide resolved
// 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);

sunnyhaibin marked this conversation as resolved.
Show resolved Hide resolved
acc_main_on = GET_BIT(to_push, 40U);
}

// update vehicle moving with any non-zero wheel speed
Expand Down
2 changes: 2 additions & 0 deletions board/safety/safety_subaru_preglobal.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ static void subaru_preglobal_rx_hook(const CANPacket_t *to_push) {
if (addr == MSG_SUBARU_PG_CruiseControl) {
bool cruise_engaged = GET_BIT(to_push, 49U);
pcm_cruise_check(cruise_engaged);

sunnyhaibin marked this conversation as resolved.
Show resolved Hide resolved
acc_main_on = GET_BIT(to_push, 48U);
}

// update vehicle moving with any non-zero wheel speed
Expand Down
15 changes: 15 additions & 0 deletions board/safety/safety_toyota.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,17 @@ static bool toyota_get_quality_flag_valid(const CANPacket_t *to_push) {
static void toyota_rx_hook(const CANPacket_t *to_push) {
const int TOYOTA_LTA_MAX_ANGLE = 1657; // EPS only accepts up to 94.9461

if (GET_BUS(to_push) == 2U) {
int addr = GET_ADDR(to_push);

if (addr == 0x412) {
bool lkas_hud_visible = (GET_BYTE(to_push, 0U) & 0xC0U) > 0U;
if (lkas_hud_visible) {
lkas_button_press = MADS_BUTTON_PRESSED;
}
}
}

sunnyhaibin marked this conversation as resolved.
Show resolved Hide resolved
if (GET_BUS(to_push) == 0U) {
int addr = GET_ADDR(to_push);

Expand Down Expand Up @@ -139,6 +150,10 @@ static void toyota_rx_hook(const CANPacket_t *to_push) {
UPDATE_VEHICLE_SPEED(speed / 4.0 * 0.01 / 3.6);
}

if (addr == 0x1D3) {
acc_main_on = GET_BIT(to_push, 15U);
}

bool stock_ecu_detected = addr == 0x2E4; // STEERING_LKA
if (!toyota_stock_longitudinal && (addr == 0x343)) {
stock_ecu_detected = true; // ACC_CONTROL
Expand Down
Loading
Loading