mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-12-04 00:03:41 +08:00
Qualify Panda safety checks and restore fresh-install defaults
This commit is contained in:
@@ -392,6 +392,16 @@ class TestHyundaiFingerprint(unittest.TestCase):
|
||||
continue
|
||||
assert bool(CP.flags & HyundaiFlags.ALT_LIMITS) == bool(CP.safetyConfigs[-1].safetyParam & HyundaiSafetyFlags.ALT_LIMITS)
|
||||
|
||||
def test_i30_2026_remains_dashcam_only(self):
|
||||
for alpha in (False, True):
|
||||
for release in (False, True):
|
||||
with self.subTest(alpha=alpha, release=release):
|
||||
cp = CarInterface.get_params(CAR.HYUNDAI_I30_2026, gen_empty_fingerprint(), [], alpha, release, False)
|
||||
assert cp.dashcamOnly and not cp.openpilotLongitudinalControl
|
||||
assert len(cp.safetyConfigs) == 1 and cp.safetyConfigs[0].safetyModel == CarParams.SafetyModel.noOutput
|
||||
assert cp.lateralTuning.pid.kf == 0
|
||||
assert list(cp.lateralTuning.pid.kpV) == list(cp.lateralTuning.pid.kiV) == [0.0]
|
||||
|
||||
def test_can_features(self):
|
||||
for car_model in CAR:
|
||||
flags = car_model.config.flags
|
||||
|
||||
@@ -21,8 +21,9 @@ from opendbc.car.psa.values import CAR as PSA
|
||||
from opendbc.car.mg.values import CAR as MG
|
||||
from opendbc.car.leapmotor.values import CAR as LEAPMOTOR
|
||||
|
||||
# Configurations with source tests but no matching recorded route.
|
||||
# Configurations with source tests but no matching CI recording.
|
||||
unrecorded_route_gaps = {
|
||||
HYUNDAI.HYUNDAI_I30_2026: "hyundai/tests/test_hyundai.py",
|
||||
SUBARU.SUBARU_CROSSTREK_2018: "subaru/tests/test_supported_firmware.py",
|
||||
GM.CHEVROLET_VOLT_CC: "gm/tests/test_volt_cc_gas.py",
|
||||
GM.CHEVROLET_MALIBU_HYBRID_CC: "gm/tests/test_ordinary_cc.py",
|
||||
@@ -156,7 +157,6 @@ class CarTestRoute(NamedTuple):
|
||||
|
||||
routes = [
|
||||
CarTestRoute("efdf9af95e71cd84/2022-05-13--19-03-31", COMMA.COMMA_BODY),
|
||||
CarTestRoute("8b2271c96337f00d/00000002--e6c1c373c3", HYUNDAI.HYUNDAI_I30_2026, segment=2),
|
||||
|
||||
CarTestRoute("c5e3aa51055c8f47/2023-12-06--20-01-44", CHRYSLER.JEEP_CHEROKEE_5TH_GEN),
|
||||
CarTestRoute("0c94aa1e1296d7c6/2021-05-05--19-48-37", CHRYSLER.JEEP_GRAND_CHEROKEE),
|
||||
|
||||
@@ -4,6 +4,7 @@ from pathlib import Path
|
||||
from opendbc.car.values import PLATFORMS
|
||||
from opendbc.car.tests.routes import non_tested_cars, routes, unrecorded_route_gaps
|
||||
from opendbc.car.gm.values import CAR as GM
|
||||
from opendbc.car.hyundai.values import CAR as HYUNDAI
|
||||
from opendbc.car.subaru.values import CAR as SUBARU
|
||||
from opendbc.car.tesla.values import CAR as TESLA
|
||||
from opendbc.car.toyota.values import CAR as TOYOTA
|
||||
@@ -20,6 +21,7 @@ class TestRoutes(unittest.TestCase):
|
||||
|
||||
def test_explicit_unrecorded_configuration_gaps(self):
|
||||
self.assertEqual(set(unrecorded_route_gaps), {
|
||||
HYUNDAI.HYUNDAI_I30_2026,
|
||||
GM.CHEVROLET_VOLT_CC, GM.CHEVROLET_MALIBU_HYBRID_CC, TOYOTA.TOYOTA_PRIUS_RETROFIT, TESLA.TESLA_MODEL_S_HW1,
|
||||
SUBARU.SUBARU_CROSSTREK_2018, VOLVO.VOLVO_XC40_RECHARGE, VOLVO.VOLVO_S60_RECHARGE, VOLVO.POLESTAR_2, VOLVO.VOLVO_V60,
|
||||
})
|
||||
|
||||
@@ -233,7 +233,7 @@ typedef bool (*tx_hook)(const CANPacket_t *msg); // returns true if the message
|
||||
typedef bool (*fwd_hook)(int bus_num, int addr); // returns true if the message should be blocked from forwarding
|
||||
|
||||
typedef bool (*fwd_packet_hook)(const CANPacket_t *msg);
|
||||
typedef bool (*fwd_output_hook)(const CANPacket_t *msg, CANPacket_t *output, bool *replaced);
|
||||
typedef void (*fwd_output_hook)(const CANPacket_t *msg, CANPacket_t *output, bool *replaced);
|
||||
|
||||
typedef struct {
|
||||
safety_hook_init init;
|
||||
|
||||
@@ -338,7 +338,7 @@ static void hyundai_rx_hook(const CANPacket_t *msg) {
|
||||
}
|
||||
cruise_button_prev = cruise_button;
|
||||
} else if (hyundai_kona_ev_label_cruise) {
|
||||
hyundai_common_cruise_buttons_check(cruise_button == HYUNDAI_BTN_CANCEL ? HYUNDAI_BTN_NONE : cruise_button,
|
||||
hyundai_common_cruise_buttons_check((cruise_button == HYUNDAI_BTN_CANCEL) ? HYUNDAI_BTN_NONE : cruise_button,
|
||||
false, false, hyundai_long_main_policy);
|
||||
if ((cruise_button == HYUNDAI_BTN_CANCEL) || main_button) {
|
||||
controls_allowed = false;
|
||||
|
||||
@@ -170,12 +170,12 @@ static void blended_aol_rx(const CANPacket_t *msg) {
|
||||
const uint32_t now = microsecond_timer_get();
|
||||
const bool stock_hda2 = blended_aol_hda2 && !blended_aol_long;
|
||||
if (stock_hda2 && msg_matches(msg, 0x421U, pt, 8U)) {
|
||||
const bool main = GET_BIT(msg, 27U);
|
||||
if (blended_aol_main && !main) {
|
||||
const bool cruise_main = GET_BIT(msg, 27U);
|
||||
if (blended_aol_main && !cruise_main) {
|
||||
blended_aol_clear();
|
||||
}
|
||||
blended_aol_main_seen = true;
|
||||
blended_aol_main = main;
|
||||
blended_aol_main = cruise_main;
|
||||
blended_aol_main_ts = now;
|
||||
}
|
||||
if (stock_hda2 && msg_matches(msg, 0x394U, pt, 8U)) {
|
||||
|
||||
@@ -529,12 +529,14 @@ static void hyundai_canfd_ioniq6_optional_rx_hook(const CANPacket_t *msg) {
|
||||
|
||||
#if defined(ALLOW_DEBUG) && !defined(STM32F4)
|
||||
static bool hyundai_kona_ccnc_feedback = false;
|
||||
static bool hyundai_kona_camera_seen = false;
|
||||
static uint8_t hyundai_kona_camera_counter = 0U;
|
||||
static uint32_t hyundai_kona_camera_ts = 0U;
|
||||
static bool hyundai_kona_host_seen = false;
|
||||
static uint8_t hyundai_kona_host_counter = 0U;
|
||||
static uint32_t hyundai_kona_host_ts = 0U;
|
||||
typedef struct {
|
||||
bool seen;
|
||||
uint8_t counter;
|
||||
uint32_t ts;
|
||||
} HyundaiKonaLfaState;
|
||||
|
||||
static HyundaiKonaLfaState hyundai_kona_camera;
|
||||
static HyundaiKonaLfaState hyundai_kona_host;
|
||||
|
||||
static bool hyundai_kona_lfa_valid(const CANPacket_t *msg) {
|
||||
return !msg->extended && (GET_LEN(msg) == 16U) &&
|
||||
@@ -545,17 +547,17 @@ static void hyundai_kona_camera_rx(const CANPacket_t *msg) {
|
||||
if (hyundai_kona_ccnc_feedback && (msg->addr == 0x12AU) && (msg->bus == 2U) &&
|
||||
msg->fd && hyundai_kona_lfa_valid(msg)) {
|
||||
const uint32_t now = microsecond_timer_get();
|
||||
const uint8_t delta = (uint8_t)(msg->data[2] - hyundai_kona_camera_counter);
|
||||
if (!hyundai_kona_camera_seen || (safety_get_ts_elapsed(now, hyundai_kona_camera_ts) > 50000U) ||
|
||||
const uint8_t delta = (uint8_t)(msg->data[2] - hyundai_kona_camera.counter);
|
||||
if (!hyundai_kona_camera.seen || (safety_get_ts_elapsed(now, hyundai_kona_camera.ts) > 50000U) ||
|
||||
((delta > 0U) && (delta <= 127U))) {
|
||||
hyundai_kona_camera_seen = true;
|
||||
hyundai_kona_camera_counter = msg->data[2];
|
||||
hyundai_kona_camera_ts = now;
|
||||
hyundai_kona_camera.seen = true;
|
||||
hyundai_kona_camera.counter = msg->data[2];
|
||||
hyundai_kona_camera.ts = now;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static bool hyundai_kona_mdps_output(const CANPacket_t *msg, CANPacket_t *output, bool *replaced) {
|
||||
static void hyundai_kona_mdps_output(const CANPacket_t *msg, CANPacket_t *output, bool *replaced) {
|
||||
if (hyundai_kona_ccnc_feedback && (msg->addr == 0xEAU) && (msg->bus == 0U) &&
|
||||
msg->fd && !msg->extended && (GET_LEN(msg) == 24U) &&
|
||||
((msg->data[3] & 7U) == 0U) && ((msg->data[6] & 0xFCU) == 0U) &&
|
||||
@@ -568,7 +570,6 @@ static bool hyundai_kona_mdps_output(const CANPacket_t *msg, CANPacket_t *output
|
||||
output->data[1] = (uint8_t)(checksum >> 8U);
|
||||
*replaced = true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1353,29 +1354,32 @@ static bool hyundai_canfd_tx_hook_checked(const CANPacket_t *msg) {
|
||||
}
|
||||
|
||||
static bool hyundai_canfd_tx_hook(const CANPacket_t *msg) {
|
||||
bool allowed;
|
||||
#if defined(ALLOW_DEBUG) && !defined(STM32F4)
|
||||
if (hyundai_kona_ccnc_feedback && (msg->addr == 0x12AU)) {
|
||||
const uint32_t now = microsecond_timer_get();
|
||||
const uint8_t delta = (uint8_t)(msg->data[2] - hyundai_kona_host_counter);
|
||||
const bool advancing = !hyundai_kona_host_seen ||
|
||||
(safety_get_ts_elapsed(now, hyundai_kona_host_ts) > 50000U) ||
|
||||
const uint8_t delta = (uint8_t)(msg->data[2] - hyundai_kona_host.counter);
|
||||
const bool advancing = !hyundai_kona_host.seen ||
|
||||
(safety_get_ts_elapsed(now, hyundai_kona_host.ts) > 50000U) ||
|
||||
((delta > 0U) && (delta <= 127U));
|
||||
const bool active = ((msg->data[5] & 0xFEU) != 0U) || ((msg->data[6] & 0x3FU) != 8U);
|
||||
const bool camera_current = hyundai_kona_camera_seen &&
|
||||
(safety_get_ts_elapsed(now, hyundai_kona_camera_ts) <= 50000U);
|
||||
const bool allowed = !relay_malfunction && advancing && hyundai_kona_lfa_valid(msg) &&
|
||||
(!active || (!safety_rx_checks_invalid && aol_rx_healthy() &&
|
||||
lateral_controls_allowed() && camera_current)) &&
|
||||
hyundai_canfd_tx_hook_checked(msg);
|
||||
const bool camera_current = hyundai_kona_camera.seen &&
|
||||
(safety_get_ts_elapsed(now, hyundai_kona_camera.ts) <= 50000U);
|
||||
allowed = !relay_malfunction && advancing && hyundai_kona_lfa_valid(msg) &&
|
||||
(!active || (!safety_rx_checks_invalid && aol_rx_healthy() &&
|
||||
lateral_controls_allowed() && camera_current)) &&
|
||||
hyundai_canfd_tx_hook_checked(msg);
|
||||
if (allowed) {
|
||||
hyundai_kona_host_seen = true;
|
||||
hyundai_kona_host_counter = msg->data[2];
|
||||
hyundai_kona_host_ts = now;
|
||||
hyundai_kona_host.seen = true;
|
||||
hyundai_kona_host.counter = msg->data[2];
|
||||
hyundai_kona_host.ts = now;
|
||||
}
|
||||
return allowed;
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
return hyundai_canfd_tx_hook_checked(msg);
|
||||
{
|
||||
allowed = hyundai_canfd_tx_hook_checked(msg);
|
||||
}
|
||||
return allowed;
|
||||
}
|
||||
|
||||
static void hyundai_canfd_reset_ioniq6_state(void) {
|
||||
@@ -2331,8 +2335,8 @@ static safety_config hyundai_canfd_init(uint16_t raw_param) {
|
||||
hyundai_ordinary_angle_reset();
|
||||
#if defined(ALLOW_DEBUG) && !defined(STM32F4) && !defined(PANDA_BODY)
|
||||
hyundai_kona_ccnc_feedback = (raw_param == 0x1C0CU) && (alternative_experience == 32);
|
||||
hyundai_kona_camera_seen = false;
|
||||
hyundai_kona_host_seen = false;
|
||||
hyundai_kona_camera.seen = false;
|
||||
hyundai_kona_host.seen = false;
|
||||
const bool kona_profile_valid = (raw_param != 0x1C0CU) || hyundai_kona_ccnc_feedback;
|
||||
const uint16_t param = hyundai_kona_ccnc_feedback ? 0x0C0CU : raw_param;
|
||||
const bool valid = !GET_FLAG(param, 32768U) || (param == 0x8015U) || (param == 0x8095U) ||
|
||||
|
||||
@@ -382,8 +382,8 @@ int safety_fwd_output_hook(const CANPacket_t *msg, CANPacket_t *output, bool *re
|
||||
int destination;
|
||||
if (current_hooks->fwd_output != NULL) {
|
||||
destination = safety_fwd_hook(msg->bus, msg->addr);
|
||||
if ((destination >= 0) && current_hooks->fwd_output(msg, output, replaced)) {
|
||||
destination = -1;
|
||||
if (destination >= 0) {
|
||||
current_hooks->fwd_output(msg, output, replaced);
|
||||
}
|
||||
} else {
|
||||
destination = safety_fwd_packet_hook(msg);
|
||||
|
||||
@@ -48,6 +48,13 @@ class TestHyundaiKonaCcncFeedback(unittest.TestCase):
|
||||
self.assertFalse(release.safety_uses_forward_transform(feedback))
|
||||
self.assertEqual(release.safety_fwd_packet_hook(feedback), -1)
|
||||
|
||||
def test_output_hook_without_transform_keeps_normal_forwarding_decision(self):
|
||||
self.assertEqual(self.safety.set_safety_hooks(structs.CarParams.SafetyModel.toyota, 0), 0)
|
||||
packet = self.packet(0xEA, 0, bytes(24))
|
||||
self.assertEqual(self.forward(packet)[:2], (2, False))
|
||||
self.safety.set_relay_malfunction(True)
|
||||
self.assertEqual(self.forward(packet)[:2], (-1, False))
|
||||
|
||||
def test_eps_feedback_preserves_faults_and_never_changes_vehicle_side_input(self):
|
||||
self.debug_mode()
|
||||
for warning_byte, toi_byte, modify in ((0, 0, True), (0, 1, True), (0, 3, False),
|
||||
@@ -99,14 +106,15 @@ class TestHyundaiKonaCcncFeedback(unittest.TestCase):
|
||||
self.assertTrue(self.safety.safety_tx_hook(lfa(0, 254, 5, True)))
|
||||
for stamp, count, torque in ((1_010_000, 255, 10), (1_020_000, 0, 15)):
|
||||
self.safety.set_timer(stamp)
|
||||
self.safety.safety_rx_hook(lfa(2, 82, 0, False))
|
||||
self.assertTrue(self.safety.safety_tx_hook(lfa(0, count, torque, True)))
|
||||
self.assertFalse(self.safety.safety_tx_hook(lfa(0, count, torque, True)))
|
||||
corrupt = lfa(0, 1, 20, True)
|
||||
corrupt[0].data[0] ^= 1
|
||||
self.assertFalse(self.safety.safety_tx_hook(corrupt))
|
||||
self.assertFalse(self.safety.safety_tx_hook(lfa(0, 1, 500, True)))
|
||||
self.safety.set_timer(1_050_001)
|
||||
self.assertFalse(self.safety.safety_tx_hook(lfa(0, 1, 5, True)))
|
||||
self.safety.set_timer(1_060_001)
|
||||
self.assertFalse(self.safety.safety_tx_hook(lfa(0, 1, 15, True)))
|
||||
self.safety.safety_rx_hook(lfa(2, 150, 0, False))
|
||||
self.safety.set_controls_allowed(False)
|
||||
self.safety.aol_set_host_request(0)
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
import base64
|
||||
import json
|
||||
import hashlib
|
||||
import os
|
||||
|
||||
from openpilot.starpilot.saved_source import read_saved
|
||||
from openpilot.starpilot.longitudinal.profile_document import (
|
||||
@@ -96,8 +97,11 @@ def retire_settings(params):
|
||||
if not readable or master not in (None, b"0", b"1"):
|
||||
archive("QOLLongitudinal", master, "Invalid cruise switch; inactive cruise features restored to defaults", readable)
|
||||
if master != b"1":
|
||||
for key in ("ForceStops", "ReverseCruise"):
|
||||
params.put_bool(key, False, block=True)
|
||||
fresh_install = (readable and master is None and not os.path.lexists(params.get_param_path("Version")) and
|
||||
not os.path.lexists(params.get_param_path("ForceStops")))
|
||||
if not fresh_install:
|
||||
params.put_bool("ForceStops", False, block=True)
|
||||
params.put_bool("ReverseCruise", False, block=True)
|
||||
for key, value in (("CustomCruise", 1.0), ("CustomCruiseLong", 5.0)):
|
||||
params.put(key, value, block=True)
|
||||
params.remove("QOLLongitudinal")
|
||||
|
||||
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-93e8d9be-Pf38f504f-DEBUG";
|
||||
const uint8_t gitversion[29] = "DEV-8d489bdd-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-93e8d9be-Pf38f504f-DEBUG
|
||||
DEV-8d489bdd-Pf38f504f-DEBUG
|
||||
Binary file not shown.
+1
-1
@@ -1 +1 @@
|
||||
{"protected_inventory_sha256": "05fbf0756a87b25f33116434e85dfa742203b6884f049ce59ff2733a02ce5021", "schema_version": 1}
|
||||
{"protected_inventory_sha256": "156df70c4921d45d5bf7ae581a81207f0a287cc68d47bcf9fc192d5ecff87de2", "schema_version": 1}
|
||||
|
||||
Reference in New Issue
Block a user