Refactor Hyundai long tuning logic to use CP_SP flags.

Moved Hyundai-specific flag handling logic to utilize CP_SP flags instead of CP flags. This ensures better separation of parameters and aligns with the updated parameter structure. Updated related functions and class initializations for consistency.
This commit is contained in:
discountchubbs
2025-03-21 21:04:06 -07:00
parent a10445b148
commit 2605b99b95
4 changed files with 16 additions and 22 deletions
+1 -3
View File
@@ -26,7 +26,6 @@ from openpilot.selfdrive.car.helpers import convert_carControlSP, convert_to_cap
from openpilot.sunnypilot.mads.helpers import set_alternative_experience, set_car_specific_params
from openpilot.sunnypilot.selfdrive.car import interfaces as sunnypilot_interfaces
from openpilot.sunnypilot.selfdrive.car.hkg_specific_params import set_hyundai_long_tune_flag
REPLAY = "REPLAY" in os.environ
@@ -110,10 +109,10 @@ class Car:
self.CI = get_car(*self.can_callbacks, obd_callback(self.params), experimental_long_allowed, num_pandas, cached_params, fixed_fingerprint)
sunnypilot_interfaces.setup_car_interface_sp(self.CI.CP, self.CI.CP_SP, self.params)
sunnypilot_interfaces.set_hyundai_long_tune_flag(self.CI.CP_SP, self.params)
self.RI = interfaces[self.CI.CP.carFingerprint].RadarInterface(self.CI.CP, self.CI.CP_SP)
self.CP = self.CI.CP
self.CP_SP = self.CI.CP_SP
set_hyundai_long_tune_flag(self.CP)
# continue onto next fingerprinting step in pandad
self.params.put_bool("FirmwareQueryDone", True)
@@ -130,7 +129,6 @@ class Car:
# mads
set_alternative_experience(self.CP, self.params)
set_car_specific_params(self.CP, self.CP_SP, self.params)
set_hyundai_long_tune_flag(self.CP)
# Dynamic Experimental Control
self.dynamic_experimental_control = self.params.get_bool("DynamicExperimentalControl")
@@ -1,18 +0,0 @@
from opendbc.car import structs
from opendbc.sunnypilot.car.hyundai.values import HyundaiFlagsSP
from openpilot.common.params import Params
class HyundaiLongTuneParams:
@staticmethod
def param(params, key: str) -> bool:
val = params.get(key)
if isinstance(val, bytes):
val = val.decode("utf-8")
return val in ["1", "2"]
def set_hyundai_long_tune_flag(CP: structs.CarParams):
params = Params()
if HyundaiLongTuneParams.param(params, "HyundaiLongTune"):
CP.flags |= HyundaiFlagsSP.HKGLONGTUNING.value
if params.get_bool("HyundaiSmootherBraking"):
CP.flags |= HyundaiFlagsSP.HKGLONGTUNING_BRAKING.value
+14
View File
@@ -33,6 +33,20 @@ def setup_car_interface_sp(CP: structs.CarParams, CP_SP: structs.CarParamsSP, pa
CP.radarUnavailable = False
def set_hyundai_long_tune_flag(CP_SP: structs.CarParamsSP, params):
val = params.get("HyundaiLongTune")
if isinstance(val, bytes):
val = val.decode("utf-8")
if isinstance(val, str) and ',' in val:
val_list = [v.strip() for v in val.split(',')]
else:
val_list = [val]
if any(item in ["1", "2"] for item in val_list):
CP_SP.flags |= HyundaiFlagsSP.HKGLONGTUNING.value
if params.get_bool("HyundaiSmootherBraking"):
CP_SP.flags |= HyundaiFlagsSP.HKGLONGTUNING_BRAKING.value
def initialize_car_interface_sp(CP: structs.CarParams, CP_SP: structs.CarParamsSP, params, can_recv: CanRecvCallable,
can_send: CanSendCallable):
if CP.brand == 'hyundai':