interface: handle None parameters gracefully in interface initializations (#335)

* check None params_list

* update parameter handling

---------

Co-authored-by: Jason Wen <haibin.wen3@gmail.com>
This commit is contained in:
dzid26
2025-12-22 20:05:30 +00:00
committed by GitHub
parent 20383025ec
commit e03fbf9be8

View File

@@ -75,7 +75,10 @@ class NanoFFModel:
def setup_interfaces(CI, CP: structs.CarParams, CP_SP: structs.CarParamsSP,
params_list: list[dict[str, str]], can_recv: CanRecvCallable = None, can_send: CanSendCallable = None) -> None:
params_list: list[dict[str, str]] | None = None, can_recv: CanRecvCallable = None, can_send: CanSendCallable = None) -> None:
if params_list is None:
params_list = []
params_dict = {k: v for param in params_list for k, v in param.items()}
_initialize_custom_longitudinal_tuning(CI, CP, CP_SP, params_dict)
@@ -90,7 +93,7 @@ def _initialize_custom_longitudinal_tuning(CI, CP: structs.CarParams, CP_SP: str
# Hyundai Custom Longitudinal Tuning
if CP.brand == 'hyundai':
hyundai_longitudinal_tuning = int(params_dict["HyundaiLongitudinalTuning"])
hyundai_longitudinal_tuning = int(params_dict.get("HyundaiLongitudinalTuning", 0))
if hyundai_longitudinal_tuning == LongitudinalTuningType.DYNAMIC:
CP_SP.flags |= HyundaiFlagsSP.LONG_TUNING_DYNAMIC.value
if hyundai_longitudinal_tuning == LongitudinalTuningType.PREDICTIVE:
@@ -116,8 +119,8 @@ def _initialize_radar_tracks(CP: structs.CarParams, CP_SP: structs.CarParamsSP,
def _initialize_stop_and_go(CP: structs.CarParams, CP_SP: structs.CarParamsSP, params_dict: dict[str, str]) -> None:
if CP.brand == 'subaru' and not CP.flags & (SubaruFlags.GLOBAL_GEN2 | SubaruFlags.HYBRID):
stop_and_go = int(params_dict["SubaruStopAndGo"]) == 1
stop_and_go_manual_parking_brake = int(params_dict["SubaruStopAndGoManualParkingBrake"]) == 1
stop_and_go = int(params_dict.get("SubaruStopAndGo", 0)) == 1
stop_and_go_manual_parking_brake = int(params_dict.get("SubaruStopAndGoManualParkingBrake", 0)) == 1
if stop_and_go:
CP_SP.flags |= SubaruFlagsSP.STOP_AND_GO.value
@@ -129,7 +132,7 @@ def _initialize_stop_and_go(CP: structs.CarParams, CP_SP: structs.CarParamsSP, p
def _initialize_toyota(CP: structs.CarParams, CP_SP: structs.CarParamsSP, params_dict: dict[str, str]) -> None:
if CP.brand == 'toyota':
toyota_stock_long = int(params_dict["ToyotaEnforceStockLongitudinal"]) == 1
toyota_stock_long = int(params_dict.get("ToyotaEnforceStockLongitudinal", 0)) == 1
if toyota_stock_long:
CP_SP.flags |= ToyotaFlagsSP.STOCK_LONGITUDINAL.value