From 88434dc9e48bcb10b4e4afd9c77cc8e917844f06 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Tue, 4 May 2021 11:32:40 -0700 Subject: [PATCH] add CLEAR_ON_IGNITION param type (#20810) old-commit-hash: b4447993c10b36628cb72b58dba8104c9060bb7f --- common/params_pxd.pxd | 1 + common/params_pyx.pyx | 7 +------ common/tests/test_params.py | 6 +++--- selfdrive/boardd/boardd.cc | 7 +------ selfdrive/common/params.cc | 6 +++--- selfdrive/common/params.h | 3 ++- selfdrive/manager/manager.py | 4 ++-- selfdrive/test/process_replay/process_replay.py | 1 - selfdrive/thermald/thermald.py | 4 ++-- 9 files changed, 15 insertions(+), 24 deletions(-) diff --git a/common/params_pxd.pxd b/common/params_pxd.pxd index 979805d230..b31a5ab70f 100644 --- a/common/params_pxd.pxd +++ b/common/params_pxd.pxd @@ -12,6 +12,7 @@ cdef extern from "selfdrive/common/params.h": PERSISTENT CLEAR_ON_MANAGER_START CLEAR_ON_PANDA_DISCONNECT + CLEAR_ON_IGNITION ALL cdef cppclass Params: diff --git a/common/params_pyx.pyx b/common/params_pyx.pyx index 78187fb619..dab8d20fac 100755 --- a/common/params_pyx.pyx +++ b/common/params_pyx.pyx @@ -13,6 +13,7 @@ cdef class ParamKeyType: PERSISTENT = c_ParamKeyType.PERSISTENT CLEAR_ON_MANAGER_START = c_ParamKeyType.CLEAR_ON_MANAGER_START CLEAR_ON_PANDA_DISCONNECT = c_ParamKeyType.CLEAR_ON_PANDA_DISCONNECT + CLEAR_ON_IGNITION = c_ParamKeyType.CLEAR_ON_IGNITION ALL = c_ParamKeyType.ALL def ensure_bytes(v): @@ -43,12 +44,6 @@ cdef class Params: self.p.clearAll(tx_type) - def manager_start(self): - self.clear_all(ParamKeyType.CLEAR_ON_MANAGER_START) - - def panda_disconnect(self): - self.clear_all(ParamKeyType.CLEAR_ON_PANDA_DISCONNECT) - def check_key(self, key): key = ensure_bytes(key) diff --git a/common/tests/test_params.py b/common/tests/test_params.py index 1fac4dbc7e..ca91369309 100644 --- a/common/tests/test_params.py +++ b/common/tests/test_params.py @@ -6,7 +6,7 @@ import shutil import stat import unittest -from common.params import Params, UnknownKeyName, put_nonblocking +from common.params import Params, ParamKeyType, UnknownKeyName, put_nonblocking class TestParams(unittest.TestCase): def setUp(self): @@ -35,7 +35,7 @@ class TestParams(unittest.TestCase): self.params.put("CarParams", "test") self.params.put("DongleId", "cb38263377b873ee") assert self.params.get("CarParams") == b"test" - self.params.panda_disconnect() + self.params.clear_all(ParamKeyType.CLEAR_ON_PANDA_DISCONNECT) assert self.params.get("CarParams") is None assert self.params.get("DongleId") is not None @@ -43,7 +43,7 @@ class TestParams(unittest.TestCase): self.params.put("CarParams", "test") self.params.put("DongleId", "cb38263377b873ee") assert self.params.get("CarParams") == b"test" - self.params.manager_start() + self.params.clear_all(ParamKeyType.CLEAR_ON_MANAGER_START) assert self.params.get("CarParams") is None assert self.params.get("DongleId") is not None diff --git a/selfdrive/boardd/boardd.cc b/selfdrive/boardd/boardd.cc index f43071e857..e53e08a38d 100644 --- a/selfdrive/boardd/boardd.cc +++ b/selfdrive/boardd/boardd.cc @@ -320,12 +320,7 @@ void panda_state_thread(bool spoofing_started) { // clear VIN, CarParams, and set new safety on car start if (ignition && !ignition_last) { - int result = params.remove("CarVin"); - assert((result == 0) || (result == ERR_NO_VALUE)); - result = params.remove("CarParams"); - assert((result == 0) || (result == ERR_NO_VALUE)); - result = params.remove("ControlsReady"); - assert((result == 0) || (result == ERR_NO_VALUE)); + params.clearAll(CLEAR_ON_IGNITION); if (!safety_setter_thread_running) { safety_setter_thread_running = true; diff --git a/selfdrive/common/params.cc b/selfdrive/common/params.cc index 670e29367e..ebf3aeed1e 100644 --- a/selfdrive/common/params.cc +++ b/selfdrive/common/params.cc @@ -149,11 +149,11 @@ std::unordered_map keys = { {"AthenadPid", PERSISTENT}, {"CalibrationParams", PERSISTENT}, {"CarBatteryCapacity", PERSISTENT}, - {"CarParams", CLEAR_ON_MANAGER_START | CLEAR_ON_PANDA_DISCONNECT}, + {"CarParams", CLEAR_ON_MANAGER_START | CLEAR_ON_PANDA_DISCONNECT | CLEAR_ON_IGNITION}, {"CarParamsCache", CLEAR_ON_MANAGER_START | CLEAR_ON_PANDA_DISCONNECT}, - {"CarVin", CLEAR_ON_MANAGER_START | CLEAR_ON_PANDA_DISCONNECT}, + {"CarVin", CLEAR_ON_MANAGER_START | CLEAR_ON_PANDA_DISCONNECT | CLEAR_ON_IGNITION}, {"CommunityFeaturesToggle", PERSISTENT}, - {"ControlsReady", CLEAR_ON_MANAGER_START | CLEAR_ON_PANDA_DISCONNECT}, + {"ControlsReady", CLEAR_ON_MANAGER_START | CLEAR_ON_PANDA_DISCONNECT | CLEAR_ON_IGNITION}, {"EnableLteOnroad", PERSISTENT}, {"EndToEndToggle", PERSISTENT}, {"CompletedTrainingVersion", PERSISTENT}, diff --git a/selfdrive/common/params.h b/selfdrive/common/params.h index 7ee1e2602d..279ea41931 100644 --- a/selfdrive/common/params.h +++ b/selfdrive/common/params.h @@ -11,7 +11,8 @@ enum ParamKeyType { PERSISTENT = 0x02, CLEAR_ON_MANAGER_START = 0x04, CLEAR_ON_PANDA_DISCONNECT = 0x08, - ALL = 0x02 | 0x04 | 0x08 + CLEAR_ON_IGNITION = 0x10, + ALL = 0x02 | 0x04 | 0x08 | 0x10 }; class Params { diff --git a/selfdrive/manager/manager.py b/selfdrive/manager/manager.py index b9faec3f43..c7df568cd7 100755 --- a/selfdrive/manager/manager.py +++ b/selfdrive/manager/manager.py @@ -9,7 +9,7 @@ import traceback import cereal.messaging as messaging import selfdrive.crash as crash from common.basedir import BASEDIR -from common.params import Params +from common.params import Params, ParamKeyType from common.text_window import TextWindow from selfdrive.boardd.set_time import set_time from selfdrive.hardware import HARDWARE, PC, TICI @@ -28,7 +28,7 @@ def manager_init(): set_time(cloudlog) params = Params() - params.manager_start() + params.clear_all(ParamKeyType.CLEAR_ON_MANAGER_START) default_params = [ ("CompletedTrainingVersion", "0"), diff --git a/selfdrive/test/process_replay/process_replay.py b/selfdrive/test/process_replay/process_replay.py index 5ae4265840..183b997616 100755 --- a/selfdrive/test/process_replay/process_replay.py +++ b/selfdrive/test/process_replay/process_replay.py @@ -351,7 +351,6 @@ def python_replay_process(cfg, lr): params = Params() params.clear_all() - params.manager_start() params.put_bool("OpenpilotEnabledToggle", True) params.put_bool("Passive", False) params.put_bool("CommunityFeaturesToggle", True) diff --git a/selfdrive/thermald/thermald.py b/selfdrive/thermald/thermald.py index 43e6962a39..6bd36b55b2 100755 --- a/selfdrive/thermald/thermald.py +++ b/selfdrive/thermald/thermald.py @@ -12,7 +12,7 @@ import cereal.messaging as messaging from cereal import log from common.filter_simple import FirstOrderFilter from common.numpy_fast import clip, interp -from common.params import Params +from common.params import Params, ParamKeyType from common.realtime import DT_TRML, sec_since_boot from common.dict_helpers import strip_deprecated_keys from selfdrive.controls.lib.alertmanager import set_offroad_alert @@ -222,7 +222,7 @@ def thermald_thread(): if pandaState_prev is not None: if pandaState.pandaState.pandaType == log.PandaState.PandaType.unknown and \ pandaState_prev.pandaState.pandaType != log.PandaState.PandaType.unknown: - params.panda_disconnect() + params.clear_all(ParamKeyType.CLEAR_ON_PANDA_DISCONNECT) pandaState_prev = pandaState # get_network_type is an expensive call. update every 10s