Skip to content

Commit

Permalink
ri testing with more switchable params
Browse files Browse the repository at this point in the history
  • Loading branch information
MoreTore committed Nov 19, 2023
1 parent b05b188 commit ecdeb00
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
45 changes: 30 additions & 15 deletions board/safety/safety_mazda.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
#define MAZDA_AUX 1
#define MAZDA_CAM 2

const uint16_t MAZDA_RADAR_INTERCEPT_MODE = 1;
const uint16_t MAZDA_RI_USE_CRZ_EVENTS = 2;
bool radar_intercept = false;
bool use_crz_events = false;

const SteeringLimits MAZDA_STEERING_LIMITS = {
.max_steer = 800,
.max_rate_up = 10,
Expand Down Expand Up @@ -82,11 +87,16 @@ static int mazda_rx_hook(CANPacket_t *to_push) {
update_sample(&torque_driver, torque_driver_new);
}

// // enter controls on rising edge of ACC, exit controls on ACC off
// if (addr == MAZDA_CRZ_CTRL) {
// bool cruise_engaged = GET_BYTE(to_push, 0) & 0x8U;
// pcm_cruise_check(cruise_engaged);
// }
// enter controls on rising edge of ACC, exit controls on ACC off
if (addr == MAZDA_CRZ_CTRL && !radar_intercept && !use_crz_events) {
bool cruise_engaged = GET_BYTE(to_push, 0) & 0x8U;
pcm_cruise_check(cruise_engaged);
}

if (addr == MAZDA_CRZ_EVENTS && use_crz_events && radar_intercept) {
bool cruise_engaged = GET_BYTE(to_push, 2) & 0x1U;
pcm_cruise_check(cruise_engaged);
}

if (addr == MAZDA_ENGINE_DATA) {
gas_pressed = (GET_BYTE(to_push, 4) || (GET_BYTE(to_push, 5) & 0xF0U));
Expand All @@ -107,7 +117,7 @@ static int mazda_rx_hook(CANPacket_t *to_push) {
}
}

if (valid && (GET_BUS(to_push) == MAZDA_CAM)) { // Use radar for cruise state
if (valid && (GET_BUS(to_push) == MAZDA_CAM && radar_intercept && !use_crz_events)) { // Use radar for cruise state
int addr = GET_ADDR(to_push);
// enter controls on rising edge of ACC, exit controls on ACC off
if (addr == MAZDA_CRZ_CTRL) {
Expand Down Expand Up @@ -164,14 +174,16 @@ static int mazda_fwd_hook(int bus, int addr) {
} else if (bus == MAZDA_CAM) {
block |= (addr == MAZDA_LKAS);
block |= (addr == MAZDA_LKAS_HUD);
block |= (addr == MAZDA_CRZ_INFO);
block |= (addr == MAZDA_CRZ_CTRL);
block |= (addr == MAZDA_RADAR_361);
block |= (addr == MAZDA_RADAR_362);
block |= (addr == MAZDA_RADAR_363);
block |= (addr == MAZDA_RADAR_364);
block |= (addr == MAZDA_RADAR_365);
block |= (addr == MAZDA_RADAR_366);
if (radar_intercept){
block |= (addr == MAZDA_CRZ_INFO);
block |= (addr == MAZDA_CRZ_CTRL);
block |= (addr == MAZDA_RADAR_361);
block |= (addr == MAZDA_RADAR_362);
block |= (addr == MAZDA_RADAR_363);
block |= (addr == MAZDA_RADAR_364);
block |= (addr == MAZDA_RADAR_365);
block |= (addr == MAZDA_RADAR_366);
}
if (!block) {
bus_fwd = MAZDA_MAIN;
}
Expand All @@ -183,8 +195,9 @@ static int mazda_fwd_hook(int bus, int addr) {
}

static const addr_checks* mazda_init(uint16_t param) {
UNUSED(param);
return &mazda_rx_checks;
radar_intercept = GET_FLAG(param, MAZDA_RADAR_INTERCEPT_MODE);
use_crz_events = GET_FLAG(param, MAZDA_RI_USE_CRZ_EVENTS);
}

const safety_hooks mazda_hooks = {
Expand All @@ -195,6 +208,8 @@ const safety_hooks mazda_hooks = {
.fwd = mazda_fwd_hook,
};



/*
Mazda Gen 4 2019+
Mazda 3 2019+
Expand Down
3 changes: 3 additions & 0 deletions python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ class Panda:
FLAG_FORD_LONG_CONTROL = 1
FLAG_FORD_CANFD = 2

FLAG_MAZDA_RADAR_INTERCEPT_MODE = 1
FLAG_MAZDA_RI_USE_CRZ_EVENTS = 2

def __init__(self, serial: Optional[str] = None, claim: bool = True, disable_checks: bool = True):
self._connect_serial = serial
self._disable_checks = disable_checks
Expand Down

0 comments on commit ecdeb00

Please sign in to comment.