mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-12-03 00:13:41 +08:00
Restore Sharan PQ AOL with matching Panda firmware
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
"""Checked automatic gateway Sharan profile; unverified EPS modifications grant no capability."""
|
||||
|
||||
from opendbc.car import structs
|
||||
from opendbc.car.volkswagen.values import CAR, VolkswagenFlags
|
||||
from opendbc.car.volkswagen.stock_aol import safety_config
|
||||
|
||||
WORDS = frozenset((8, 9))
|
||||
|
||||
|
||||
def qualified(cp, *, marked_only=False):
|
||||
try:
|
||||
safety = safety_config(cp)
|
||||
base = int(cp.openpilotLongitudinalControl)
|
||||
return bool(
|
||||
cp.brand == 'volkswagen'
|
||||
and cp.carFingerprint == CAR.VOLKSWAGEN_SHARAN_MK2
|
||||
and cp.flags & int(VolkswagenFlags.PQ)
|
||||
and not cp.flags & ~int(VolkswagenFlags.PQ | VolkswagenFlags.HAS_BSM)
|
||||
and not cp.passive
|
||||
and not cp.notCar
|
||||
and not cp.dashcamOnly
|
||||
and cp.minSteerSpeed >= 50 / 3.6
|
||||
and cp.steerControlType == structs.CarParams.SteerControlType.torque
|
||||
and cp.transmissionType == structs.CarParams.TransmissionType.automatic
|
||||
and cp.networkLocation == structs.CarParams.NetworkLocation.gateway
|
||||
and bool(cp.pcmCruise) != bool(cp.openpilotLongitudinalControl)
|
||||
and cp.alphaLongitudinalAvailable
|
||||
and safety is not None
|
||||
and safety.safetyModel == structs.CarParams.SafetyModel.volkswagenPq
|
||||
and (
|
||||
cp.alternativeExperience == 32 and safety.safetyParam == (8 | base) or not marked_only and cp.alternativeExperience == 0 and safety.safetyParam == base
|
||||
)
|
||||
)
|
||||
except (AttributeError, TypeError, ValueError, OverflowError, IndexError):
|
||||
return False
|
||||
@@ -14,6 +14,8 @@
|
||||
#define MSG_ACC_GRA_ANZEIGE 0x56AU // TX by OP, ACC HUD
|
||||
#define MSG_LDW_1 0x5BEU // TX by OP, Lane line recognition and text alerts
|
||||
|
||||
#include "opendbc/safety/modes/volkswagen_pq_aol.h"
|
||||
|
||||
static uint32_t volkswagen_pq_get_checksum(const CANPacket_t *msg) {
|
||||
return (uint32_t)msg->data[(msg->addr == MSG_MOTOR_5) ? 7 : 0];
|
||||
}
|
||||
@@ -48,14 +50,14 @@ static uint32_t volkswagen_pq_compute_checksum(const CANPacket_t *msg) {
|
||||
|
||||
static safety_config volkswagen_pq_init(uint16_t param) {
|
||||
// Transmit of GRA_Neu is allowed on bus 0 and 2 to keep compatibility with gateway and camera integration
|
||||
static const CanMsg VOLKSWAGEN_PQ_STOCK_TX_MSGS[] = {
|
||||
static CanMsg VOLKSWAGEN_PQ_STOCK_TX_MSGS[] = {
|
||||
{MSG_HCA_1, 0, 5, .check_relay = true},
|
||||
{MSG_LDW_1, 0, 8, .check_relay = true},
|
||||
{MSG_GRA_NEU, 0, 4, .check_relay = false},
|
||||
{MSG_GRA_NEU, 2, 4, .check_relay = false},
|
||||
};
|
||||
|
||||
static const CanMsg VOLKSWAGEN_PQ_LONG_TX_MSGS[] = {
|
||||
static CanMsg VOLKSWAGEN_PQ_LONG_TX_MSGS[] = {
|
||||
{MSG_HCA_1, 0, 5, .check_relay = true},
|
||||
{MSG_LDW_1, 0, 8, .check_relay = true},
|
||||
{MSG_ACC_SYSTEM, 0, 8, .check_relay = true},
|
||||
@@ -72,14 +74,38 @@ static safety_config volkswagen_pq_init(uint16_t param) {
|
||||
};
|
||||
|
||||
volkswagen_common_init();
|
||||
pq_aol_reset();
|
||||
#ifdef ALLOW_DEBUG
|
||||
pq_aol_enabled = ((unsigned int)alternative_experience == 32U) && ((param == 8U) || (param == 9U));
|
||||
#endif
|
||||
VOLKSWAGEN_PQ_STOCK_TX_MSGS[0].disable_static_blocking = pq_aol_enabled;
|
||||
VOLKSWAGEN_PQ_STOCK_TX_MSGS[1].disable_static_blocking = pq_aol_enabled;
|
||||
VOLKSWAGEN_PQ_LONG_TX_MSGS[0].disable_static_blocking = pq_aol_enabled;
|
||||
VOLKSWAGEN_PQ_LONG_TX_MSGS[1].disable_static_blocking = pq_aol_enabled;
|
||||
if (pq_aol_enabled) {
|
||||
static const AolSafetyPolicy policy = {
|
||||
.reset = pq_aol_reset,
|
||||
.host_request = pq_aol_request,
|
||||
.request_mask = pq_aol_request_mask,
|
||||
.permission_mask = pq_aol_permission,
|
||||
.rx_invalid = pq_aol_clear,
|
||||
};
|
||||
aol_policy = &policy;
|
||||
}
|
||||
|
||||
|
||||
#ifdef ALLOW_DEBUG
|
||||
volkswagen_longitudinal = GET_FLAG(param, FLAG_VOLKSWAGEN_LONG_CONTROL);
|
||||
#else
|
||||
SAFETY_UNUSED(param);
|
||||
#endif
|
||||
return volkswagen_longitudinal ? BUILD_SAFETY_CFG(volkswagen_pq_rx_checks, VOLKSWAGEN_PQ_LONG_TX_MSGS) : \
|
||||
safety_config ret = volkswagen_longitudinal ? BUILD_SAFETY_CFG(volkswagen_pq_rx_checks, VOLKSWAGEN_PQ_LONG_TX_MSGS) : \
|
||||
BUILD_SAFETY_CFG(volkswagen_pq_rx_checks, VOLKSWAGEN_PQ_STOCK_TX_MSGS);
|
||||
if ((((unsigned int)alternative_experience == 32U) || ((param & 8U) != 0U)) && !pq_aol_enabled) {
|
||||
ret.tx_msgs = NULL;
|
||||
ret.tx_msgs_len = 0;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void volkswagen_pq_rx_hook(const CANPacket_t *msg) {
|
||||
@@ -148,6 +174,7 @@ static void volkswagen_pq_rx_hook(const CANPacket_t *msg) {
|
||||
if (msg_matches(msg, MSG_MOTOR_2, 0U)) {
|
||||
brake_pressed = (msg->data[2] & 0x1U);
|
||||
}
|
||||
pq_aol_rx(msg);
|
||||
}
|
||||
|
||||
static bool volkswagen_pq_tx_hook(const CANPacket_t *msg) {
|
||||
@@ -212,12 +239,15 @@ static bool volkswagen_pq_tx_hook(const CANPacket_t *msg) {
|
||||
}
|
||||
}
|
||||
|
||||
pq_aol_tx_commit(msg, tx && !relay_malfunction);
|
||||
return tx;
|
||||
}
|
||||
|
||||
const safety_hooks volkswagen_pq_hooks = {
|
||||
.init = volkswagen_pq_init,
|
||||
.rx = volkswagen_pq_rx_hook,
|
||||
.optional_rx = pq_aol_optional_rx,
|
||||
.fwd = pq_aol_fwd,
|
||||
.tx = volkswagen_pq_tx_hook,
|
||||
.get_counter = volkswagen_pq_get_counter,
|
||||
.get_checksum = volkswagen_pq_get_checksum,
|
||||
|
||||
@@ -0,0 +1,271 @@
|
||||
#pragma once
|
||||
|
||||
static bool pq_aol_enabled = false;
|
||||
static bool pq_aol_token = false;
|
||||
static bool pq_aol_pending = false;
|
||||
static bool pq_aol_session = false;
|
||||
static uint32_t pq_aol_grant_ts = 0U;
|
||||
static bool pq_aol_long_armed = false;
|
||||
static uint8_t pq_aol_buttons = 0U;
|
||||
static bool pq_aol_cruise = false;
|
||||
static uint32_t pq_aol_neutral_ts = 0U;
|
||||
static bool pq_aol_startup = true;
|
||||
static bool pq_aol_main_neutral = false;
|
||||
static bool pq_aol_requested = false;
|
||||
static bool pq_aol_gear_drive = false;
|
||||
static bool pq_aol_eps_ready = false;
|
||||
static bool pq_aol_speed_ready = false;
|
||||
static bool pq_aol_pair_seen[2] = {false, false};
|
||||
static uint8_t pq_aol_counter[2] = {0U, 0U};
|
||||
static uint8_t pq_aol_seen = 0U;
|
||||
static uint32_t pq_aol_source_ts[4] = {0U, 0U, 0U, 0U};
|
||||
static bool pq_aol_accepted[2] = {false, false};
|
||||
static uint32_t pq_aol_accepted_ts[2] = {0U, 0U};
|
||||
|
||||
static void pq_aol_clear(void) {
|
||||
pq_aol_token = false;
|
||||
pq_aol_pending = false;
|
||||
pq_aol_session = false;
|
||||
pq_aol_long_armed = false;
|
||||
pq_aol_buttons = 0U;
|
||||
pq_aol_main_neutral = false;
|
||||
for (unsigned int i = 0U; i < 2U; i++) {
|
||||
pq_aol_accepted[i] = false;
|
||||
}
|
||||
}
|
||||
|
||||
static void pq_aol_reset(void) {
|
||||
pq_aol_clear();
|
||||
pq_aol_enabled = false;
|
||||
pq_aol_startup = true;
|
||||
pq_aol_requested = false;
|
||||
pq_aol_cruise = false;
|
||||
pq_aol_neutral_ts = 0U;
|
||||
pq_aol_grant_ts = 0U;
|
||||
pq_aol_gear_drive = false;
|
||||
pq_aol_eps_ready = false;
|
||||
pq_aol_speed_ready = false;
|
||||
pq_aol_seen = 0U;
|
||||
for (unsigned int i = 0U; i < 4U; i++) {
|
||||
pq_aol_source_ts[i] = 0U;
|
||||
}
|
||||
for (unsigned int i = 0U; i < 2U; i++) {
|
||||
pq_aol_pair_seen[i] = false;
|
||||
pq_aol_counter[i] = 0U;
|
||||
pq_aol_accepted_ts[i] = 0U;
|
||||
}
|
||||
}
|
||||
|
||||
static bool pq_aol_current(void) {
|
||||
bool current = pq_aol_seen == 15U;
|
||||
for (unsigned int i = 0U; i < 4U; i++) {
|
||||
current = current && (safety_get_ts_elapsed(microsecond_timer_get(), pq_aol_source_ts[i]) <= 300000U);
|
||||
}
|
||||
return current;
|
||||
}
|
||||
|
||||
static void pq_aol_request(uint8_t mask) {
|
||||
pq_aol_requested |= mask != 0U;
|
||||
if (mask == 0U) {
|
||||
pq_aol_accepted[0] = false;
|
||||
pq_aol_accepted[1] = false;
|
||||
}
|
||||
}
|
||||
|
||||
static uint8_t pq_aol_request_mask(void) {
|
||||
uint8_t request = 0U;
|
||||
const bool expired = pq_aol_requested &&
|
||||
(safety_get_ts_elapsed(microsecond_timer_get(), aol_host_request_ts) > AOL_HOST_REQUEST_TIMEOUT_US);
|
||||
const uint32_t grant_age = safety_get_ts_elapsed(microsecond_timer_get(), pq_aol_grant_ts);
|
||||
const bool pending_expired = pq_aol_pending && (grant_age > AOL_HOST_REQUEST_TIMEOUT_US);
|
||||
if (!pq_aol_enabled || relay_malfunction || expired || pending_expired || safety_rx_checks_invalid ||
|
||||
!aol_rx_healthy() || !pq_aol_current()) {
|
||||
pq_aol_clear();
|
||||
} else if (pq_aol_pending) {
|
||||
if (heartbeat_engaged && ((aol_host_axis_mask & 2U) != 0U) &&
|
||||
(safety_get_ts_elapsed(microsecond_timer_get(), aol_host_request_ts) < grant_age)) {
|
||||
pq_aol_pending = false;
|
||||
pq_aol_session = true;
|
||||
request = aol_host_axis_mask;
|
||||
}
|
||||
} else if (!heartbeat_engaged) {
|
||||
if (pq_aol_session) {
|
||||
pq_aol_clear();
|
||||
} else if (pq_aol_main_neutral &&
|
||||
(safety_get_ts_elapsed(microsecond_timer_get(), pq_aol_neutral_ts) > AOL_HOST_REQUEST_TIMEOUT_US)) {
|
||||
pq_aol_main_neutral = false;
|
||||
} else {
|
||||
}
|
||||
} else {
|
||||
pq_aol_session = true;
|
||||
request = aol_host_axis_mask;
|
||||
}
|
||||
return request;
|
||||
}
|
||||
|
||||
static uint8_t pq_aol_permission(void) {
|
||||
const uint8_t request = pq_aol_request_mask();
|
||||
uint8_t permission = 0U;
|
||||
if (acc_main_on && pq_aol_gear_drive && pq_aol_eps_ready) {
|
||||
if (pq_aol_token && pq_aol_speed_ready) {
|
||||
permission = request & 1U;
|
||||
}
|
||||
if (volkswagen_longitudinal && pq_aol_long_armed && controls_allowed && !brake_pressed) {
|
||||
permission |= request & 2U;
|
||||
}
|
||||
}
|
||||
return permission;
|
||||
}
|
||||
|
||||
static void pq_aol_optional_rx(const CANPacket_t *msg) {
|
||||
if (pq_aol_enabled && (msg_matches(msg, 0x440U, 0U, 8U) || msg_matches(msg, 0x3D2U, 0U, 7U))) {
|
||||
const bool gear = msg->addr == 0x440U;
|
||||
const unsigned int index = gear ? 0U : 1U;
|
||||
const unsigned int source = gear ? 1U : 2U;
|
||||
const uint8_t counter = gear ? ((msg->data[6] >> 3) & 15U) : (msg->data[1] & 15U);
|
||||
uint8_t checksum = 0U;
|
||||
for (unsigned int i = 1U; i < 7U; i++) {
|
||||
checksum ^= msg->data[i];
|
||||
}
|
||||
const bool valid = gear || (checksum == msg->data[0]);
|
||||
const bool pair = valid && pq_aol_pair_seen[index] &&
|
||||
(counter == ((pq_aol_counter[index] + 1U) & 15U)) &&
|
||||
(safety_get_ts_elapsed(microsecond_timer_get(), pq_aol_source_ts[source]) <= 300000U);
|
||||
pq_aol_pair_seen[index] = valid;
|
||||
pq_aol_counter[index] = counter;
|
||||
if (valid) {
|
||||
pq_aol_source_ts[source] = microsecond_timer_get();
|
||||
}
|
||||
if (pair) {
|
||||
pq_aol_seen |= (uint8_t)(1U << source);
|
||||
} else {
|
||||
pq_aol_seen &= (uint8_t)~(1U << source);
|
||||
}
|
||||
if (gear) {
|
||||
const unsigned int position = msg->data[1] >> 4;
|
||||
pq_aol_gear_drive = pair && ((position == 5U) || (position == 12U) ||
|
||||
(position == 10U) || (position == 11U) || (position == 14U));
|
||||
} else {
|
||||
const unsigned int eps = msg->data[2] & 15U;
|
||||
pq_aol_eps_ready = pair && ((eps == 3U) || (eps == 5U) || (eps == 7U));
|
||||
}
|
||||
if (!pair) {
|
||||
pq_aol_clear();
|
||||
} else if (gear && !pq_aol_gear_drive) {
|
||||
pq_aol_long_armed = false;
|
||||
} else if (!gear && !pq_aol_eps_ready) {
|
||||
const unsigned int eps = msg->data[2] & 15U;
|
||||
pq_aol_long_armed = false;
|
||||
if ((eps != 1U) && (eps != 4U)) {
|
||||
pq_aol_clear();
|
||||
}
|
||||
} else {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void pq_aol_rx(const CANPacket_t *msg) {
|
||||
if (pq_aol_enabled) {
|
||||
if (brake_pressed && (!brake_pressed_prev || vehicle_moving)) {
|
||||
pq_aol_long_armed = false;
|
||||
}
|
||||
if (msg_matches(msg, MSG_BREMSE_1, 0U, 8U)) {
|
||||
const unsigned int speed = ((msg->data[2] & 0xFEU) >> 1) | (msg->data[3] << 7);
|
||||
pq_aol_speed_ready = speed >= 5000U;
|
||||
pq_aol_seen |= 8U;
|
||||
pq_aol_source_ts[3] = microsecond_timer_get();
|
||||
} else if (msg_matches(msg, MSG_MOTOR_5, 0U, 8U)) {
|
||||
acc_main_on = GET_BIT(msg, 50U);
|
||||
pq_aol_seen |= 1U;
|
||||
pq_aol_source_ts[0] = microsecond_timer_get();
|
||||
if (!acc_main_on) {
|
||||
pq_aol_startup = false;
|
||||
pq_aol_clear();
|
||||
pq_aol_main_neutral = true;
|
||||
pq_aol_neutral_ts = microsecond_timer_get();
|
||||
controls_allowed = false;
|
||||
} else if ((pq_aol_startup || pq_aol_main_neutral) && heartbeat_engaged && aol_rx_healthy() &&
|
||||
!safety_rx_checks_invalid && pq_aol_current() && pq_aol_gear_drive && pq_aol_eps_ready &&
|
||||
pq_aol_speed_ready && !brake_pressed) {
|
||||
pq_aol_token = true;
|
||||
pq_aol_startup = false;
|
||||
pq_aol_main_neutral = false;
|
||||
} else {
|
||||
}
|
||||
} else if (msg_matches(msg, MSG_MOTOR_2, 0U, 8U)) {
|
||||
const unsigned int status = (msg->data[2] >> 6) & 3U;
|
||||
const bool cruise = (status == 1U) || (status == 2U);
|
||||
if (!volkswagen_longitudinal && cruise && !pq_aol_cruise && controls_allowed && acc_main_on &&
|
||||
heartbeat_engaged && aol_rx_healthy() && !safety_rx_checks_invalid && pq_aol_current() &&
|
||||
pq_aol_gear_drive && pq_aol_eps_ready && pq_aol_speed_ready && !brake_pressed) {
|
||||
pq_aol_token = true;
|
||||
pq_aol_startup = false;
|
||||
}
|
||||
pq_aol_cruise = cruise;
|
||||
} else if (msg_matches(msg, MSG_GRA_NEU, 0U, 4U)) {
|
||||
if (GET_BIT(msg, 9U)) {
|
||||
if (!pq_aol_session || pq_aol_pending) {
|
||||
pq_aol_token = false;
|
||||
}
|
||||
pq_aol_pending = false;
|
||||
pq_aol_long_armed = false;
|
||||
pq_aol_buttons = 0U;
|
||||
pq_aol_main_neutral = false;
|
||||
} else if (volkswagen_longitudinal) {
|
||||
const uint8_t buttons = (GET_BIT(msg, 16U) ? 1U : 0U) | (GET_BIT(msg, 17U) ? 2U : 0U);
|
||||
if ((!heartbeat_engaged && pq_aol_session) || relay_malfunction ||
|
||||
!aol_rx_healthy() || safety_rx_checks_invalid || !pq_aol_current()) {
|
||||
pq_aol_buttons = 0U;
|
||||
} else if (buttons == 0U) {
|
||||
if (((pq_aol_buttons & 3U) != 0U) && controls_allowed && acc_main_on &&
|
||||
pq_aol_gear_drive && pq_aol_eps_ready && (!brake_pressed || !vehicle_moving)) {
|
||||
pq_aol_token = true;
|
||||
pq_aol_long_armed = true;
|
||||
pq_aol_pending = !heartbeat_engaged;
|
||||
pq_aol_session = heartbeat_engaged;
|
||||
pq_aol_grant_ts = microsecond_timer_get();
|
||||
pq_aol_startup = false;
|
||||
}
|
||||
pq_aol_buttons = 4U;
|
||||
} else if ((pq_aol_buttons & 4U) != 0U) {
|
||||
pq_aol_buttons = 4U | buttons;
|
||||
} else {
|
||||
}
|
||||
} else {
|
||||
}
|
||||
} else {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void pq_aol_tx_commit(const CANPacket_t *msg, bool accepted) {
|
||||
if (pq_aol_enabled) {
|
||||
if (msg_matches(msg, MSG_HCA_1, 0U, 5U)) {
|
||||
const unsigned int status = msg->data[1] >> 4;
|
||||
const unsigned int torque = (msg->data[2] | ((msg->data[3] & 0x7FU) << 8)) / 32U;
|
||||
pq_aol_accepted[0] = accepted && ((status == 5U) || (status == 7U)) && (torque != 0U) &&
|
||||
((pq_aol_permission() & 1U) != 0U);
|
||||
pq_aol_accepted_ts[0] = microsecond_timer_get();
|
||||
} else if (msg_matches(msg, MSG_LDW_1, 0U, 8U)) {
|
||||
pq_aol_accepted[1] = accepted;
|
||||
pq_aol_accepted_ts[1] = microsecond_timer_get();
|
||||
} else {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static bool pq_aol_fwd(int bus, int addr) {
|
||||
bool blocked = false;
|
||||
const uint32_t now = microsecond_timer_get();
|
||||
if (pq_aol_enabled && (bus == 2) && pq_aol_accepted[0] && ((pq_aol_permission() & 1U) != 0U) &&
|
||||
(safety_get_ts_elapsed(now, pq_aol_accepted_ts[0]) <= AOL_HOST_REQUEST_TIMEOUT_US)) {
|
||||
if (addr == (int)MSG_HCA_1) {
|
||||
blocked = true;
|
||||
} else if (addr == (int)MSG_LDW_1) {
|
||||
blocked = pq_aol_accepted[1] &&
|
||||
(safety_get_ts_elapsed(now, pq_aol_accepted_ts[1]) <= AOL_HOST_REQUEST_TIMEOUT_US);
|
||||
} else {
|
||||
}
|
||||
}
|
||||
return blocked;
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -469,7 +469,7 @@ void pandad_run(std::vector<Panda *> &pandas) {
|
||||
Panda *previous_aol_owner = nullptr;
|
||||
bool engaged = false;
|
||||
bool is_onroad = false;
|
||||
constexpr AolSafetyProfile aol_profiles[] = {HONDA_AOL_PROFILE, HONDA_STOCK_AOL_PROFILE, HONDA_NIDEC_AOL_PROFILE, HYUNDAI_AOL_PROFILE, HYUNDAI_CLASSIC_AOL_PROFILE, HYUNDAI_LEGACY_AOL_PROFILE, GM_AOL_PROFILE, FORD_AOL_PROFILE, MAZDA_AOL_PROFILE, RIVIAN_AOL_PROFILE, CHRYSLER_AOL_PROFILE, TESLA_PREAP_AOL_PROFILE, TESLA_SCREEN_AOL_PROFILE, TOYOTA_AOL_PROFILE, NISSAN_AOL_PROFILE, VOLKSWAGEN_STOCK_AOL_PROFILE, VOLKSWAGEN_LONG_AOL_PROFILE, VOLKSWAGEN_MEB_AOL_PROFILE, SUBARU_AOL_PROFILE};
|
||||
constexpr AolSafetyProfile aol_profiles[] = {HONDA_AOL_PROFILE, HONDA_STOCK_AOL_PROFILE, HONDA_NIDEC_AOL_PROFILE, HYUNDAI_AOL_PROFILE, HYUNDAI_CLASSIC_AOL_PROFILE, HYUNDAI_LEGACY_AOL_PROFILE, GM_AOL_PROFILE, FORD_AOL_PROFILE, MAZDA_AOL_PROFILE, RIVIAN_AOL_PROFILE, CHRYSLER_AOL_PROFILE, TESLA_PREAP_AOL_PROFILE, TESLA_SCREEN_AOL_PROFILE, TOYOTA_AOL_PROFILE, NISSAN_AOL_PROFILE, VOLKSWAGEN_STOCK_AOL_PROFILE, VOLKSWAGEN_LONG_AOL_PROFILE, VOLKSWAGEN_MEB_AOL_PROFILE, VOLKSWAGEN_PQ_AOL_PROFILE, SUBARU_AOL_PROFILE};
|
||||
const AolProfileRegistry aol_registry{aol_profiles, std::size(aol_profiles)};
|
||||
AolAxisNegotiator aol_negotiator(aol_registry);
|
||||
// Main loop: receive CAN first, then process lower priority panda and peripheral state.
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -1933,11 +1933,13 @@ class SelfdriveD:
|
||||
ford_native_accepts_cp(self.CP, int(car.CarParams.SafetyModel.ford), self.CP.safetyConfigs[-1].safetyParam))
|
||||
# Driver steering does not invalidate a still-current native LAT grant.
|
||||
from opendbc.car.volkswagen.long_aol import qualified as volkswagen_long_qualified
|
||||
from opendbc.car.volkswagen.pq_aol import qualified as volkswagen_pq_qualified
|
||||
from openpilot.starpilot.car.toyota.aol import qualified as toyota_aol_qualified
|
||||
toyota_longitudinal = bool(self.CP.brand == 'toyota' and self.CP.openpilotLongitudinalControl and
|
||||
toyota_aol_qualified(self.CP, marked_only=True))
|
||||
steering_override_allowed = (ordinary_ford or toyota_longitudinal or self.CP.brand == 'hyundai' or
|
||||
volkswagen_long_qualified(self.CP, marked_only=True))
|
||||
volkswagen_long_qualified(self.CP, marked_only=True) or
|
||||
self.CP.openpilotLongitudinalControl and volkswagen_pq_qualified(self.CP, marked_only=True))
|
||||
# Paused Ford steering has no LAT grant to retain. The same ordinary
|
||||
# mismatch owner can observe denied LONG with both outputs inactive.
|
||||
ford_long_only = bool(ordinary_ford and not previous.lateral_active and
|
||||
|
||||
@@ -32,7 +32,9 @@ from openpilot.starpilot.aol.tests.stock_lateral_test_helpers import authority_c
|
||||
def test_mqb_full_engagement_brake_reverse_drive_actual_callers(gearbox, alpha, offset, fixed, engage_on_set,
|
||||
stop_and_resume=False, candidate=CAR.VOLKSWAGEN_GOLF_MK7,
|
||||
brake_held_engagement=False, creep_start=False, early_brake=False,
|
||||
parked_boot=False, cruise_cancel=False, main_cycle=False):
|
||||
parked_boot=False, cruise_cancel=False, main_cycle=False,
|
||||
pq_eps_pause=False, pq_real_fault=False):
|
||||
pq = candidate == CAR.VOLKSWAGEN_SHARAN_MK2
|
||||
with ExitStack() as cleanup:
|
||||
cleanup.enter_context(OpenpilotPrefix())
|
||||
cleanup.enter_context(mock.patch.dict('os.environ', {'SIMULATION': '0', 'AOL_REPLAY_RUNTIME': '1'}))
|
||||
@@ -43,8 +45,8 @@ def test_mqb_full_engagement_brake_reverse_drive_actual_callers(gearbox, alpha,
|
||||
params.put_bool('AlphaLongitudinalEnabled', alpha, block=True)
|
||||
fp = {bus: {} for bus in range(8)}
|
||||
if gearbox != 'manual':
|
||||
fp[offset][0xAD if gearbox == 'automatic' else 0x187] = 8
|
||||
fp[offset + 1][0xFD] = 8
|
||||
fp[offset][0x440 if pq else 0xAD if gearbox == 'automatic' else 0x187] = 8
|
||||
fp[offset + 1][0x1A0 if pq else 0xFD] = 8
|
||||
if stop_and_resume or brake_held_engagement:
|
||||
fp[offset + 2][0x126] = 8
|
||||
fp[offset][0x6B8] = 8
|
||||
@@ -148,11 +150,11 @@ def test_mqb_full_engagement_brake_reverse_drive_actual_callers(gearbox, alpha,
|
||||
cleanup.callback(native.init_tests)
|
||||
native.init_tests()
|
||||
native.set_alternative_experience(32)
|
||||
native.set_safety_hooks(15, (24 if gearbox == 'manual' else 40 if gearbox == 'direct' else 8) | int(alpha))
|
||||
native.set_safety_hooks(21 if pq else 15, (24 if gearbox == 'manual' else 40 if gearbox == 'direct' else 8) | int(alpha))
|
||||
native.set_aol_test_heartbeat(not parked_boot)
|
||||
card.CI.update([])
|
||||
dbc = ParsedDBC('vw_mqb')
|
||||
packer = CANPacker('vw_mqb')
|
||||
dbc = ParsedDBC('vw_pq' if pq else 'vw_mqb')
|
||||
packer = CANPacker('vw_pq' if pq else 'vw_mqb')
|
||||
emitted, lat_commands, long_commands = [], [], []
|
||||
request = 0
|
||||
for tick in range(120):
|
||||
@@ -188,11 +190,25 @@ def test_mqb_full_engagement_brake_reverse_drive_actual_callers(gearbox, alpha,
|
||||
'GRA_Tip_Setzen': int(engage_on_set and (tick in (20, 50) if creep_start else tick == 20))},
|
||||
'ACC_02': {'ACC_Gesetzte_Zeitluecke': 1},
|
||||
}
|
||||
if pq:
|
||||
overrides = {
|
||||
'Motor_2': {'MO2_Sta_GRA': int(ordinary and not alpha), 'MO2_BLS': int(brake)},
|
||||
'Motor_3': {'MO3_Pedalwert': 0},
|
||||
'Motor_5': {'MO5_GRA_Hauptsch': int(not main_cycle or not 45 <= tick < 50)},
|
||||
'Lenkhilfe_2': {'LH2_Sta_HCA': 2 if pq_real_fault and tick == 60 else 4 if pq_eps_pause and 45 <= tick < 50 else 3},
|
||||
'Lenkhilfe_3': {'LH3_LM': 100 if early_brake and 52 <= tick <= 61 else 0},
|
||||
'Getriebe_1': {'GE1_Wahl_Pos': 7 if reverse else 5},
|
||||
'Bremse_1': {'BR1_Rad_kmh': 0 if (parked_boot or brake_held_engagement) and tick < 30 else 72},
|
||||
'Airbag_1': {'Gurtschalter_Fahrer': int(not 105 <= tick < 111)},
|
||||
'GRA_Neu': {'GRA_Abbrechen': int(cruise_cancel and tick == 55),
|
||||
'GRA_Hauptschalt': int(not main_cycle or not 45 <= tick < 50),
|
||||
'GRA_Neu_Setzen': int(engage_on_set and tick == 20)},
|
||||
}
|
||||
incoming = []
|
||||
for parser in card.CI.can_parsers.values():
|
||||
for name in tuple(parser.vl):
|
||||
if isinstance(name, str) and name in dbc.name_to_msg:
|
||||
if tick < 3 and name in ('TSK_06', 'LH_EPS_03'):
|
||||
if tick < 3 and name in (('Motor_5', 'Lenkhilfe_2') if pq else ('TSK_06', 'LH_EPS_03')):
|
||||
continue # Real startup may receive other CAN sources before cruise and EPS.
|
||||
fields: dict[str, float] = dict(overrides.get(name, {}))
|
||||
if 'COUNTER' in dbc.name_to_msg[name].sigs:
|
||||
@@ -204,7 +220,9 @@ def test_mqb_full_engagement_brake_reverse_drive_actual_callers(gearbox, alpha,
|
||||
native.aol_set_host_request(request)
|
||||
permission = native.aol_get_permission_mask()
|
||||
if early_brake and tick == 60:
|
||||
incoming = [(address, data, bus) for address, data, bus in incoming if address not in (0x106, 0x3BE)]
|
||||
incoming = [(address, data, bus) for address, data, bus in incoming if address not in ((0x288,) if pq else (0x106, 0x3BE))]
|
||||
if pq_real_fault:
|
||||
incoming = [(address, data, bus) for address, data, bus in incoming if address != 0x3D2]
|
||||
assert not native.get_controls_allowed() and not permission & 2
|
||||
original_message = messaging.new_message
|
||||
def clocked_card_message(*args, original_message=original_message, now=now, **kwargs):
|
||||
@@ -232,6 +250,10 @@ def test_mqb_full_engagement_brake_reverse_drive_actual_callers(gearbox, alpha,
|
||||
panda_controls_allowed=native.get_controls_allowed())
|
||||
if early_brake and tick == 60:
|
||||
assert not state.brakePressed and state.steeringPressed
|
||||
if pq_real_fault:
|
||||
assert permission == 0 and log.OnroadEvent.EventName.controlsMismatch in sd.events.names
|
||||
assert not command.latActive and not command.longActive
|
||||
return
|
||||
assert log.OnroadEvent.EventName.controlsMismatch not in sd.events.names, 'VW_EARLY_BRAKE_STEERING_MISMATCH'
|
||||
assert not command.longActive
|
||||
assert card.aol_card_intent.allowed_latch
|
||||
@@ -252,6 +274,15 @@ def test_mqb_full_engagement_brake_reverse_drive_actual_callers(gearbox, alpha,
|
||||
assert card.aol_card_intent.allowed_latch
|
||||
assert command.latActive, 'VW_MAIN_ON_REQUIRES_SET_AFTER_HEARTBEAT_WITHDRAWAL'
|
||||
assert not command.longActive
|
||||
if pq_eps_pause and 46 <= tick < 50:
|
||||
assert state.steerFaultTemporary and not command.latActive
|
||||
assert card.aol_card_intent.allowed_latch
|
||||
if pq_eps_pause and 51 <= tick < 60:
|
||||
assert not command.latActive # Await the next genuine 10 Hz native acknowledgment.
|
||||
if pq_eps_pause and 62 <= tick < 65:
|
||||
assert command.latActive and permission & 1, (tick, permission, request, state.to_dict(), axis.to_dict(),
|
||||
list(sd.events.names), card.aol_card_intent.allowed_latch, card.aol_card_intent._fault_inhibit)
|
||||
assert log.OnroadEvent.EventName.controlsMismatch not in sd.events.names
|
||||
if tick >= 112:
|
||||
assert command.driverMonitoringEscalation
|
||||
if stop_and_resume and 45 <= tick < 56:
|
||||
@@ -283,7 +314,12 @@ def test_mqb_full_engagement_brake_reverse_drive_actual_callers(gearbox, alpha,
|
||||
card.controls_update(state, card.sm['carControl'])
|
||||
for addr, data, bus in sent:
|
||||
assert offset <= bus < offset + 4
|
||||
assert native.safety_tx_hook(make_msg(bus - offset, addr, dat=data)), (tick, hex(addr), data.hex(), bus)
|
||||
accepted = native.safety_tx_hook(make_msg(bus - offset, addr, dat=data))
|
||||
if pq and main_cycle and alpha and 45 <= tick < 50 and addr == 0x368:
|
||||
# Physical MAIN withdrawal precedes the next 10 Hz host acknowledgment.
|
||||
assert not accepted and not native.get_controls_allowed() and not permission & 2
|
||||
else:
|
||||
assert accepted, (tick, hex(addr), data.hex(), bus)
|
||||
if quiet is not None:
|
||||
for addr, data, bus in sent:
|
||||
assert not quiet.safety_tx_hook(make_msg(bus - offset, addr, dat=data))
|
||||
@@ -383,3 +419,38 @@ def test_mqb_default_cancel_withdraws_only_cruise_actual_callers(gearbox, alpha)
|
||||
@pytest.mark.parametrize('alpha', (False, True))
|
||||
def test_mqb_main_cycle_without_set_recovers_only_lateral_actual_callers(gearbox, alpha):
|
||||
test_mqb_full_engagement_brake_reverse_drive_actual_callers(gearbox, alpha, 0, False, False, main_cycle=True)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('alpha', (False, True))
|
||||
@pytest.mark.parametrize('offset,fixed', ((0,False), (4,True)))
|
||||
def test_pq_factory_parser_card_control_native_actual_callers(alpha, offset, fixed):
|
||||
test_mqb_full_engagement_brake_reverse_drive_actual_callers(
|
||||
'automatic', alpha, offset, fixed, True, candidate=CAR.VOLKSWAGEN_SHARAN_MK2)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('alpha', (False, True))
|
||||
@pytest.mark.parametrize('scenario', ('parked_boot', 'cruise_cancel', 'main_cycle'))
|
||||
def test_pq_main_and_cancel_actual_callers(alpha, scenario):
|
||||
test_mqb_full_engagement_brake_reverse_drive_actual_callers(
|
||||
'automatic', alpha, 0, False, scenario != 'parked_boot', candidate=CAR.VOLKSWAGEN_SHARAN_MK2, **{scenario: True})
|
||||
|
||||
|
||||
@pytest.mark.parametrize('alpha', (False, True))
|
||||
def test_pq_aol_eps_pause_and_recovery_actual_callers(alpha):
|
||||
test_mqb_full_engagement_brake_reverse_drive_actual_callers(
|
||||
'automatic', alpha, 0, False, False, candidate=CAR.VOLKSWAGEN_SHARAN_MK2, pq_eps_pause=True)
|
||||
|
||||
|
||||
def test_pq_early_native_brake_with_driver_steering_actual_callers():
|
||||
test_mqb_full_engagement_brake_reverse_drive_actual_callers(
|
||||
'automatic', True, 0, False, True, candidate=CAR.VOLKSWAGEN_SHARAN_MK2, early_brake=True)
|
||||
|
||||
|
||||
def test_pq_real_native_eps_fault_is_not_ordinary_long_withdrawal():
|
||||
test_mqb_full_engagement_brake_reverse_drive_actual_callers(
|
||||
'automatic', True, 0, False, True, candidate=CAR.VOLKSWAGEN_SHARAN_MK2, early_brake=True, pq_real_fault=True)
|
||||
|
||||
|
||||
def test_pq_brake_held_standstill_engagement_actual_callers():
|
||||
test_mqb_full_engagement_brake_reverse_drive_actual_callers(
|
||||
'automatic', True, 0, False, True, candidate=CAR.VOLKSWAGEN_SHARAN_MK2, brake_held_engagement=True)
|
||||
|
||||
@@ -0,0 +1,253 @@
|
||||
import pytest
|
||||
from opendbc.car import structs, gen_empty_fingerprint
|
||||
from opendbc.car.volkswagen.interface import CarInterface
|
||||
from opendbc.car.volkswagen.values import CAR
|
||||
from opendbc.car.volkswagen.pq_aol import qualified
|
||||
from openpilot.starpilot.car.volkswagen.aol import policy_for, VolkswagenStockCardIntent, native_accepts_cp
|
||||
from openpilot.starpilot.aol.intent import AolSettings
|
||||
from openpilot.starpilot.aol.vehicle import native_matches_cp
|
||||
from opendbc.safety.tests.libsafety import libsafety_py
|
||||
from opendbc.can import CANPacker
|
||||
from opendbc.safety.tests.common import make_msg
|
||||
|
||||
|
||||
|
||||
def cp_for(alpha=False, release=False, offset=0):
|
||||
fp = gen_empty_fingerprint()
|
||||
for b in range(8):
|
||||
fp.setdefault(b, {})
|
||||
fp[offset][0x440] = 8
|
||||
fp[offset + 1][0x1A0] = 8
|
||||
return CarInterface.get_params(CAR.VOLKSWAGEN_SHARAN_MK2, fp, [], alpha, release, False)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('alpha', (False, True))
|
||||
@pytest.mark.parametrize('offset', (0, 4))
|
||||
def test_real_factory_and_marked_admission(alpha, offset):
|
||||
cp = cp_for(alpha, offset=offset)
|
||||
assert qualified(cp)
|
||||
p = policy_for(cp)
|
||||
assert p.intent_supported and p.runtime_supported
|
||||
cp.alternativeExperience |= p.alternative_experience_addition
|
||||
cp.safetyConfigs[-1].safetyParam |= p.safety_param_addition
|
||||
assert cp.safetyConfigs[-1].safetyParam == 8 | int(alpha)
|
||||
assert qualified(cp, marked_only=True)
|
||||
assert native_matches_cp(cp, 21, 8 | int(alpha))
|
||||
assert not native_matches_cp(cp, 15, 8 | int(alpha))
|
||||
assert cp.openpilotLongitudinalControl == alpha
|
||||
assert cp.pcmCruise != alpha
|
||||
assert not qualified(cp_for(alpha, release=True))
|
||||
for field, value in [
|
||||
('minSteerSpeed', 0),
|
||||
('dashcamOnly', True),
|
||||
('passive', True),
|
||||
('notCar', True),
|
||||
('networkLocation', structs.CarParams.NetworkLocation.fwdCamera),
|
||||
('transmissionType', structs.CarParams.TransmissionType.manual),
|
||||
('flags', 1 << 20),
|
||||
('alternativeExperience', 33),
|
||||
('carFingerprint', CAR.VOLKSWAGEN_GOLF_MK7),
|
||||
]:
|
||||
bad = structs.CarParams(**cp.to_dict())
|
||||
setattr(bad, field, value)
|
||||
assert not qualified(bad), (field, value)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('enabled', (False, True))
|
||||
def test_host_default_main_waits_for_floor_and_respects_off(enabled):
|
||||
cp = cp_for()
|
||||
cp.alternativeExperience = 32
|
||||
cp.safetyConfigs[-1].safetyParam = 8
|
||||
settings = AolSettings(enabled, 5.0, 0, 0, (0, 0, 0), (0, 0, 0))
|
||||
owner = VolkswagenStockCardIntent(cp, settings)
|
||||
cs = structs.CarState(canValid=True, gearShifter=structs.CarState.GearShifter.drive)
|
||||
cs.cruiseState.available = True
|
||||
for t in range(30):
|
||||
owner.update(cs, now_ns=1_000_000_000 + t * 10_000_000, fault_active=False)
|
||||
assert not owner.allowed_latch
|
||||
cs.vEgo = 20.0
|
||||
cs.standstill = False
|
||||
owner.update(cs, now_ns=1_400_000_000, fault_active=False)
|
||||
assert owner.allowed_latch == enabled
|
||||
|
||||
|
||||
class Native:
|
||||
def __init__(self, alpha=False, experience=32, param=None):
|
||||
self.s = libsafety_py.libsafety
|
||||
self.packer = CANPacker('vw_pq')
|
||||
self.tick = 0
|
||||
self.alpha = alpha
|
||||
self.s.init_tests()
|
||||
self.s.set_alternative_experience(experience)
|
||||
assert self.s.set_safety_hooks(21, 8 | int(alpha) if param is None else param) == 0
|
||||
self.s.set_aol_test_heartbeat(True)
|
||||
|
||||
def msg(self, name, fields=None, bus=0):
|
||||
a, d, b = self.packer.make_can_msg(name, bus, fields or {})
|
||||
return make_msg(b, a, dat=d)
|
||||
|
||||
def feed(self, *, speed=72, gear=5, eps=3, main=True, brake=False, set_button=False, cancel=False, cruise=False, skip=(), request=3):
|
||||
self.tick += 1
|
||||
self.s.set_timer(1_000_000 + self.tick * 10_000)
|
||||
rows = [
|
||||
('Getriebe_1', {'GE1_Wahl_Pos': gear, 'COUNTER': self.tick % 16}),
|
||||
('Lenkhilfe_2', {'LH2_Sta_HCA': eps, 'COUNTER': self.tick % 16}),
|
||||
('Lenkhilfe_3', {'COUNTER': self.tick % 16}),
|
||||
('Bremse_1', {'BR1_Rad_kmh': speed}),
|
||||
('Motor_2', {'MO2_Sta_GRA': int(cruise), 'MO2_BLS': int(brake)}),
|
||||
('Motor_3', {}),
|
||||
('Motor_5', {'MO5_GRA_Hauptsch': int(main)}),
|
||||
('GRA_Neu', {'GRA_Hauptschalt': int(main), 'GRA_Neu_Setzen': int(set_button), 'GRA_Abbrechen': int(cancel), 'COUNTER': self.tick % 16}),
|
||||
]
|
||||
for n, f in rows:
|
||||
if n not in skip:
|
||||
assert self.s.safety_rx_hook(self.msg(n, f)), n
|
||||
self.s.safety_tick()
|
||||
self.s.aol_set_host_request(request)
|
||||
return self.s.aol_get_permission_mask()
|
||||
|
||||
def prime(self, **kw):
|
||||
for _ in range(15):
|
||||
p = self.feed(**kw)
|
||||
return p
|
||||
|
||||
def steer(self, torque=4, active=True):
|
||||
return self.msg('HCA_1', {'HCA_Status': 7 if active else 3, 'LM_Offset': abs(torque), 'LM_OffSign': int(torque < 0), 'Vib_Freq': 16})
|
||||
|
||||
|
||||
@pytest.mark.parametrize('alpha', (False, True))
|
||||
def test_native_permission_limits_brake_cancel_and_expiry(alpha):
|
||||
n = Native(alpha)
|
||||
s = n.s
|
||||
assert n.prime() == 1
|
||||
assert not s.get_controls_allowed()
|
||||
assert s.safety_tx_hook(n.steer())
|
||||
assert not s.safety_tx_hook(n.steer(301))
|
||||
# A denied command must release ownership; only accepted current nonzero output may block stock.
|
||||
assert s.safety_fwd_hook(2, 0xD2) == 0
|
||||
n.feed()
|
||||
assert s.safety_tx_hook(n.steer())
|
||||
assert s.safety_fwd_hook(2, 0xD2) == -1
|
||||
assert s.safety_fwd_hook(2, 0x5BE) == 0
|
||||
assert s.safety_tx_hook(n.msg('LDW_Status'))
|
||||
assert s.safety_fwd_hook(2, 0x5BE) == -1
|
||||
assert n.feed(speed=49.99) == 0
|
||||
assert s.safety_fwd_hook(2, 0xD2) == 0
|
||||
assert n.feed(speed=50) == 1
|
||||
if alpha:
|
||||
n.feed(set_button=True)
|
||||
assert n.feed() == 3
|
||||
assert n.feed(cancel=True) == 1
|
||||
assert not s.get_controls_allowed()
|
||||
assert n.feed() == 1
|
||||
n.feed(set_button=True)
|
||||
assert n.feed() == 3
|
||||
assert n.feed(brake=True) == 1
|
||||
assert n.feed() == 1
|
||||
assert n.feed(gear=7) == 0
|
||||
assert n.feed() == 1
|
||||
assert n.feed(eps=4) == 0
|
||||
assert n.feed() == 1
|
||||
assert n.feed(main=False) == 0
|
||||
assert n.feed() == 1
|
||||
s.set_timer(1_000_000 + n.tick * 10_000 + 200_001)
|
||||
assert s.aol_get_permission_mask() == 0
|
||||
assert s.safety_fwd_hook(2, 0xD2) == 0
|
||||
assert n.feed() == 0 # expired intent cannot silently re-arm
|
||||
|
||||
|
||||
@pytest.mark.parametrize('source', ('Getriebe_1', 'Lenkhilfe_2', 'Motor_5', 'Bremse_1'))
|
||||
def test_native_stale_physical_source_revokes(source):
|
||||
n = Native()
|
||||
assert n.prime() == 1
|
||||
for _ in range(32):
|
||||
p = n.feed(skip=(source,))
|
||||
assert p == 0
|
||||
|
||||
|
||||
@pytest.mark.parametrize('param,experience', [(8, 0), (9, 0), (10, 32), (24, 32), (0, 32), (1, 32)])
|
||||
def test_unknown_profile_cannot_transmit(param, experience):
|
||||
n = Native(experience=experience, param=param)
|
||||
n.prime()
|
||||
assert n.s.aol_get_permission_mask() == 0
|
||||
assert not n.s.safety_tx_hook(n.steer())
|
||||
|
||||
|
||||
@pytest.mark.parametrize('source', ('Lenkhilfe_2', 'Getriebe_1'))
|
||||
def test_duplicate_optional_counter_revokes(source):
|
||||
n = Native()
|
||||
assert n.prime() == 1
|
||||
fields = {'COUNTER': n.tick % 16}
|
||||
fields.update({'LH2_Sta_HCA': 3} if source == 'Lenkhilfe_2' else {'GE1_Wahl_Pos': 5})
|
||||
n.s.safety_rx_hook(n.msg(source, fields))
|
||||
assert n.s.aol_get_permission_mask() == 0
|
||||
|
||||
|
||||
def test_native_eps_checksum_and_hardware_denial():
|
||||
n = Native()
|
||||
n.prime()
|
||||
m = n.msg('Lenkhilfe_2', {'LH2_Sta_HCA': 3, 'COUNTER': (n.tick + 1) % 16})
|
||||
m[0].data[0] ^= 1
|
||||
n.s.safety_rx_hook(m)
|
||||
assert n.s.aol_get_permission_mask() == 0
|
||||
n = Native()
|
||||
n.prime()
|
||||
n.s.set_aol_test_heartbeat(False)
|
||||
assert n.s.aol_get_permission_mask() == 0
|
||||
n = Native()
|
||||
n.prime()
|
||||
n.s.set_relay_malfunction(True)
|
||||
assert n.s.aol_get_permission_mask() == 0
|
||||
|
||||
|
||||
@pytest.mark.parametrize('cancel,expire', ((False, False), (True, False), (False, True)))
|
||||
def test_pending_set_requires_new_request_and_cancel_or_expiry_revokes(cancel, expire):
|
||||
n = Native(True)
|
||||
n.s.set_aol_test_heartbeat(False)
|
||||
assert n.prime() == 0
|
||||
n.feed(set_button=True)
|
||||
assert n.feed() == 0
|
||||
if cancel:
|
||||
assert n.feed(cancel=True) == 0
|
||||
if expire:
|
||||
for _ in range(31):
|
||||
assert n.feed() == 0
|
||||
n.s.set_aol_test_heartbeat(True)
|
||||
assert n.feed() == (0 if cancel or expire else 3)
|
||||
|
||||
|
||||
def test_shared_marker_word_cannot_cross_native_models():
|
||||
fp = gen_empty_fingerprint()
|
||||
fp[0][0xAD] = 8
|
||||
fp[1][0xFD] = 8
|
||||
cp = CarInterface.get_params(CAR.VOLKSWAGEN_GOLF_MK7, fp, [], False, False, False)
|
||||
cp.alternativeExperience = 32
|
||||
cp.safetyConfigs[-1].safetyParam = 8
|
||||
assert native_accepts_cp(cp, 15, 8)
|
||||
assert not native_accepts_cp(cp, 21, 8)
|
||||
assert not native_accepts_cp(cp, 34, 8)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('cancel', (False, True))
|
||||
def test_set_below_steering_floor_needs_no_second_set_when_speed_rises(cancel):
|
||||
n = Native(True)
|
||||
assert n.prime(speed=0) == 0
|
||||
n.feed(speed=0, set_button=True)
|
||||
assert n.feed(speed=0) == 2
|
||||
assert not n.s.safety_tx_hook(n.steer())
|
||||
if cancel:
|
||||
assert n.feed(speed=0, cancel=True) == 0
|
||||
# Cancel withdraws LONG from the joined session; eligible AOL retains its intent.
|
||||
assert n.feed(speed=72) == (1 if cancel else 3)
|
||||
|
||||
|
||||
def test_brake_held_standstill_set_waits_for_release_and_new_brake_withdraws_long():
|
||||
n = Native(True)
|
||||
assert n.prime(speed=0, brake=True) == 0
|
||||
n.feed(speed=0, brake=True, set_button=True)
|
||||
assert n.feed(speed=0, brake=True) == 0
|
||||
for _ in range(5):
|
||||
assert n.feed(speed=0, brake=True) == 0
|
||||
assert n.feed(speed=0) == 2
|
||||
assert n.feed(speed=0, brake=True) == 0
|
||||
assert n.feed(speed=0) == 0
|
||||
@@ -0,0 +1,59 @@
|
||||
from pathlib import Path
|
||||
from tempfile import TemporaryDirectory
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import patch
|
||||
import pytest
|
||||
from openpilot.common.params import Params
|
||||
from openpilot.selfdrive.ui.layouts.settings import developer as large
|
||||
from openpilot.selfdrive.ui.mici.layouts.settings import developer as compact
|
||||
from openpilot.starpilot.ui.tests.test_ioniq6_alpha_request import Toggle
|
||||
from openpilot.starpilot.state_migration import prepare_manager_start, load_snapshot
|
||||
from openpilot.starpilot.aol.tests.test_pq_aol import cp_for
|
||||
|
||||
|
||||
@pytest.mark.parametrize('module,layout', ((large, large.DeveloperLayout), (compact, compact.DeveloperLayoutMici)))
|
||||
@pytest.mark.parametrize('raw', (None, b'0', b'1'))
|
||||
def test_sharan_alpha_available_without_rewriting_choice(module, layout, raw):
|
||||
with TemporaryDirectory() as folder:
|
||||
params = Params(folder)
|
||||
path = Path(params.get_param_path('AlphaLongitudinalEnabled'))
|
||||
if raw is not None:
|
||||
path.write_bytes(raw)
|
||||
ui = SimpleNamespace(
|
||||
CP=cp_for(), params=params, is_release=False, engaged=False, has_longitudinal_control=False, is_offroad=lambda: True, update_params=lambda: None
|
||||
)
|
||||
panel = layout.__new__(layout)
|
||||
panel._alpha_long_toggle = Toggle()
|
||||
panel._long_maneuver_toggle = Toggle()
|
||||
panel._lat_maneuver_toggle = Toggle()
|
||||
if layout is large.DeveloperLayout:
|
||||
panel._params = params
|
||||
panel._is_release = False
|
||||
for key in ('_joystick_toggle', '_adb_toggle', '_ssh_toggle', '_ui_debug_toggle', '_cellular_disabled_toggle'):
|
||||
setattr(panel, key, Toggle())
|
||||
else:
|
||||
panel._refresh_toggles = (('AlphaLongitudinalEnabled', panel._alpha_long_toggle),)
|
||||
with patch.object(module, 'ui_state', ui):
|
||||
panel._update_toggles()
|
||||
assert panel._alpha_long_toggle.visible
|
||||
assert panel._alpha_long_toggle.state == (raw == b'1')
|
||||
assert (path.read_bytes() if path.exists() else None) == raw
|
||||
|
||||
|
||||
@pytest.mark.parametrize('raw', (b'0', b'1'))
|
||||
def test_first_start_archives_prior_alpha_without_enabling_speed_control(raw):
|
||||
with TemporaryDirectory() as folder:
|
||||
root = Path(folder)
|
||||
params = Params(str(root / 'params'))
|
||||
params.put_bool('AlphaLongitudinalEnabled', raw == b'1', block=True)
|
||||
prepare_manager_start(params, root / 'recovery', auto_migrate=True)
|
||||
assert params.get('AlphaLongitudinalEnabled') is None
|
||||
assert not params.get_bool('AlphaLongitudinalEnabled')
|
||||
snapshots = list((root / 'recovery/snapshots').iterdir())
|
||||
assert len(snapshots) == 1
|
||||
assert load_snapshot(snapshots[0])['AlphaLongitudinalEnabled'] == raw
|
||||
# Later explicit choices in the initialized namespace survive ordinary startup.
|
||||
params.put_bool('AlphaLongitudinalEnabled', raw == b'1', block=True)
|
||||
prepare_manager_start(params, root / 'recovery', auto_migrate=True)
|
||||
assert Path(params.get_param_path('AlphaLongitudinalEnabled')).read_bytes() == raw
|
||||
assert params.get_bool('AlphaLongitudinalEnabled') == (raw == b'1')
|
||||
@@ -2,12 +2,14 @@ from opendbc.car import structs
|
||||
from opendbc.car.volkswagen.stock_aol import qualified as stock_qualified, safety_config as aol_safety_config, AOL_WORD, MANUAL_WORD, DIRECT_WORD, AOL_WORDS
|
||||
from opendbc.car.volkswagen.long_aol import qualified as long_qualified, WORDS as LONG_WORDS
|
||||
from opendbc.car.volkswagen.meb_modes import qualified as meb_qualified, profile_word as meb_word, base_word as meb_base_word, AOL_WORDS as MEB_WORDS
|
||||
from opendbc.car.volkswagen.pq_aol import qualified as pq_qualified, WORDS as PQ_WORDS
|
||||
from openpilot.starpilot.aol.intent import AolCardIntent, AOL_TOGGLE, ButtonType
|
||||
from openpilot.starpilot.aol.policy import AolVehiclePolicy
|
||||
|
||||
|
||||
def qualified(cp, *, marked_only=False):
|
||||
return stock_qualified(cp, marked_only=marked_only) or long_qualified(cp, marked_only=marked_only) or meb_qualified(cp, marked_only=marked_only)
|
||||
return (stock_qualified(cp, marked_only=marked_only) or long_qualified(cp, marked_only=marked_only) or
|
||||
meb_qualified(cp, marked_only=marked_only) or pq_qualified(cp, marked_only=marked_only))
|
||||
|
||||
|
||||
|
||||
@@ -50,11 +52,14 @@ def policy_for(cp):
|
||||
|
||||
def native_profile_supported(model, param):
|
||||
return (model == int(structs.CarParams.SafetyModel.volkswagen) and param in AOL_WORDS | LONG_WORDS or
|
||||
model == int(structs.CarParams.SafetyModel.volkswagenMeb) and param in MEB_WORDS)
|
||||
model == int(structs.CarParams.SafetyModel.volkswagenMeb) and param in MEB_WORDS or
|
||||
model == int(structs.CarParams.SafetyModel.volkswagenPq) and param in PQ_WORDS)
|
||||
|
||||
|
||||
def native_accepts_cp(cp, model, param):
|
||||
return qualified(cp, marked_only=True) and native_profile_supported(model, param) and param == aol_safety_config(cp).safetyParam
|
||||
config = aol_safety_config(cp)
|
||||
return (qualified(cp, marked_only=True) and config is not None and native_profile_supported(model, param) and
|
||||
model == int(config.safetyModel.raw) and param == config.safetyParam)
|
||||
|
||||
|
||||
def native_latch_rejected(cp, native):
|
||||
@@ -74,7 +79,7 @@ class VolkswagenStockCardIntent(AolCardIntent):
|
||||
|
||||
def __init__(self, cp, settings):
|
||||
self.cp = cp
|
||||
self.mqb = stock_qualified(cp) or long_qualified(cp)
|
||||
self.cruise_lateral = stock_qualified(cp) or long_qualified(cp) or pq_qualified(cp)
|
||||
self.physical_eps_pause = False
|
||||
self.eps_recovery_ns = 0
|
||||
self.main_seen = False
|
||||
@@ -83,7 +88,7 @@ class VolkswagenStockCardIntent(AolCardIntent):
|
||||
self.main_neutral = False
|
||||
self.main_pulse = False
|
||||
super().__init__(settings, explicit_latch=True, lkas_button_supported=False,
|
||||
preserve_unassigned_cancel=self.mqb)
|
||||
preserve_unassigned_cancel=self.cruise_lateral)
|
||||
|
||||
def update(self, CS, **kwargs):
|
||||
from openpilot.starpilot.aol.runtime import SAFETY_MAX_AGE_NS
|
||||
@@ -113,9 +118,9 @@ class VolkswagenStockCardIntent(AolCardIntent):
|
||||
if (not self.settings.enabled or self.settings.main_action == AOL_TOGGLE or self.settings.lkas_action == AOL_TOGGLE or
|
||||
(state.canValid and not state.canTimeout and (state.steerFaultPermanent or state.accFaulted)) or
|
||||
any(event.type == ButtonType.cancel and event.pressed for event in CS.buttonEvents) and
|
||||
(not self.mqb or any(self.settings.cancel_actions))):
|
||||
(not self.cruise_lateral or any(self.settings.cancel_actions))):
|
||||
self.main_startup_pending = False
|
||||
if (self.mqb and self.settings.enabled and state.canValid and not state.canTimeout and
|
||||
if (self.cruise_lateral and self.settings.enabled and state.canValid and not state.canTimeout and
|
||||
not state.steerFaultPermanent and not state.accFaulted and available and self.main_neutral and
|
||||
not self.main_available and self.settings.main_action != AOL_TOGGLE and self.settings.lkas_action != AOL_TOGGLE):
|
||||
self.main_startup_pending = True
|
||||
@@ -140,7 +145,7 @@ class VolkswagenStockCardIntent(AolCardIntent):
|
||||
super().update(state.as_reader(), **kwargs)
|
||||
if (default_main_edge and state.canValid and not state.canTimeout and self.settings.enabled and
|
||||
not state.steerFaultPermanent and not state.accFaulted and not self._fault_inhibit and
|
||||
(not self.mqb or not lateral_output_inhibited(self.cp, state))):
|
||||
(not self.cruise_lateral or not lateral_output_inhibited(self.cp, state))):
|
||||
self.allowed_latch = True
|
||||
self.main_startup_pending = False
|
||||
self.main_neutral = False
|
||||
@@ -218,7 +223,7 @@ def physical_cancel_lateral_allowed(cp, cs, intent, native, *, settings, previou
|
||||
from openpilot.starpilot.aol.runtime import (AXIS_MAX_AGE_NS, INTENT_MAX_AGE_NS, SAFETY_MAX_AGE_NS,
|
||||
native_inventory_matches_cp)
|
||||
try:
|
||||
return bool((stock_qualified(cp, marked_only=True) or long_qualified(cp, marked_only=True)) and
|
||||
return bool((stock_qualified(cp, marked_only=True) or long_qualified(cp, marked_only=True) or pq_qualified(cp, marked_only=True)) and
|
||||
settings is not None and settings.enabled and not any(settings.cancel_actions) and
|
||||
previous is not None and previous.lateral_active and previous.native_acknowledged and
|
||||
intent is not None and intent.settingsQualified and intent.allowedLatch and intent.lateralArmed and
|
||||
|
||||
@@ -14,3 +14,8 @@ inline bool volkswagen_meb_aol_param(uint16_t param) {
|
||||
(param == 24U) || (param == 26U) || (param == 28U) || (param == 30U);
|
||||
}
|
||||
inline constexpr AolSafetyProfile VOLKSWAGEN_MEB_AOL_PROFILE{34U, volkswagen_meb_aol_param, true};
|
||||
|
||||
inline bool volkswagen_pq_aol_param(uint16_t param) {
|
||||
return (param == 8U) || (param == 9U);
|
||||
}
|
||||
inline constexpr AolSafetyProfile VOLKSWAGEN_PQ_AOL_PROFILE{21U, volkswagen_pq_aol_param, true};
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,4 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
extern const uint8_t gitversion[29];
|
||||
const uint8_t gitversion[29] = "DEV-768a7c47-Pf38f504f-DEBUG";
|
||||
const uint8_t gitversion[29] = "DEV-7fe19d9c-Pf38f504f-DEBUG";
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1 +1 @@
|
||||
DEV-768a7c47-Pf38f504f-DEBUG
|
||||
DEV-7fe19d9c-Pf38f504f-DEBUG
|
||||
Binary file not shown.
+1
-1
@@ -1 +1 @@
|
||||
{"protected_inventory_sha256": "c44b25c9810279ef0928cdc7dca7cd28a38db3e422679b9966a0abda85ed02bf", "schema_version": 1}
|
||||
{"protected_inventory_sha256": "cd323096762ecce1992eff7643310a22f3fee8eaec57e902f09b91b7ae43a0f1", "schema_version": 1}
|
||||
|
||||
Reference in New Issue
Block a user