From a25f2f6fc8ea9eb7c67dd3127f8f859e356a486e Mon Sep 17 00:00:00 2001 From: Willem Melching Date: Mon, 10 Jan 2022 13:57:09 +0100 Subject: [PATCH 1/4] thermald: track engaged state in param --- selfdrive/common/params.cc | 2 +- selfdrive/thermald/thermald.py | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/selfdrive/common/params.cc b/selfdrive/common/params.cc index 39cb4fcfae98b0..29dc17be90937c 100644 --- a/selfdrive/common/params.cc +++ b/selfdrive/common/params.cc @@ -86,7 +86,6 @@ std::unordered_map keys = { {"AccessToken", CLEAR_ON_MANAGER_START | DONT_LOG}, {"AthenadPid", PERSISTENT}, {"AthenadUploadQueue", PERSISTENT}, - {"BootedOnroad", CLEAR_ON_MANAGER_START | CLEAR_ON_IGNITION_OFF}, {"CalibrationParams", PERSISTENT}, {"CarBatteryCapacity", PERSISTENT}, {"CarParams", CLEAR_ON_MANAGER_START | CLEAR_ON_PANDA_DISCONNECT | CLEAR_ON_IGNITION_ON}, @@ -121,6 +120,7 @@ std::unordered_map keys = { {"IMEI", PERSISTENT}, {"InstallDate", PERSISTENT}, {"IsDriverViewEnabled", CLEAR_ON_MANAGER_START}, + {"IsEngaged", PERSISTENT}, {"IsLdwEnabled", PERSISTENT}, {"IsMetric", PERSISTENT}, {"IsOffroad", CLEAR_ON_MANAGER_START}, diff --git a/selfdrive/thermald/thermald.py b/selfdrive/thermald/thermald.py index 4ddf37f4188194..90e832276a802b 100755 --- a/selfdrive/thermald/thermald.py +++ b/selfdrive/thermald/thermald.py @@ -158,7 +158,7 @@ def thermald_thread() -> NoReturn: pandaState_timeout = int(1000 * 2.5 * DT_TRML) # 2.5x the expected pandaState frequency pandaState_sock = messaging.sub_sock('pandaStates', timeout=pandaState_timeout) - sm = messaging.SubMaster(["peripheralState", "gpsLocationExternal", "managerState"]) + sm = messaging.SubMaster(["peripheralState", "gpsLocationExternal", "managerState", "controlsState"]) fan_speed = 0 count = 0 @@ -191,6 +191,7 @@ def thermald_thread() -> NoReturn: handle_fan = None is_uno = False ui_running_prev = False + engaged_prev = False params = Params() power_monitor = PowerMonitoring() @@ -202,10 +203,6 @@ def thermald_thread() -> NoReturn: # TODO: use PI controller for UNO controller = PIController(k_p=0, k_i=2e-3, neg_limit=-80, pos_limit=0, rate=(1 / DT_TRML)) - # Leave flag for loggerd to indicate device was left onroad - if params.get_bool("IsOnroad"): - params.put_bool("BootedOnroad", True) - while True: pandaStates = messaging.recv_sock(pandaState_sock, wait=True) @@ -354,8 +351,17 @@ def thermald_thread() -> NoReturn: if should_start != should_start_prev or (count == 0): params.put_bool("IsOnroad", should_start) params.put_bool("IsOffroad", not should_start) + + params.put_bool("IsEngaged", False) + engaged_prev = False HARDWARE.set_power_save(not should_start) + if sm.updated['controlsState']: + engaged = sm['controlsState'].enabled + if engaged != engaged_prev: + params.put_bool("IsEngaged", engaged) + engaged_prev = engaged + if should_start: off_ts = None if started_ts is None: From bf5de1f30a9b2989fb82fb7be031a0bdf2a22625 Mon Sep 17 00:00:00 2001 From: Willem Melching Date: Mon, 10 Jan 2022 16:08:12 +0100 Subject: [PATCH 2/4] write in kmsg --- launch_chffrplus.sh | 3 +++ selfdrive/thermald/thermald.py | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/launch_chffrplus.sh b/launch_chffrplus.sh index 7ef671c2652e2e..6d0da524da103b 100755 --- a/launch_chffrplus.sh +++ b/launch_chffrplus.sh @@ -104,6 +104,9 @@ function tici_init { sleep 3 fi + # Allow thermald to write engagement status to kmsg + sudo chmod a+w /dev/kmsg + # setup governors sudo su -c 'echo "performance" > /sys/class/devfreq/soc:qcom,memlat-cpu0/governor' sudo su -c 'echo "performance" > /sys/class/devfreq/soc:qcom,memlat-cpu4/governor' diff --git a/selfdrive/thermald/thermald.py b/selfdrive/thermald/thermald.py index 90e832276a802b..d2ffd3bba9afdd 100755 --- a/selfdrive/thermald/thermald.py +++ b/selfdrive/thermald/thermald.py @@ -362,6 +362,12 @@ def thermald_thread() -> NoReturn: params.put_bool("IsEngaged", engaged) engaged_prev = engaged + try: + with open('/dev/kmsg', 'w') as kmsg: + kmsg.write("[thermald] engaged: {engaged}") + except Exception: + pass + if should_start: off_ts = None if started_ts is None: From 8aada2f8cb1e50d0db4ac02c480a13e0fada6c02 Mon Sep 17 00:00:00 2001 From: Willem Melching Date: Mon, 10 Jan 2022 16:14:26 +0100 Subject: [PATCH 3/4] format string --- selfdrive/thermald/thermald.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/selfdrive/thermald/thermald.py b/selfdrive/thermald/thermald.py index d2ffd3bba9afdd..11783eebd54aa3 100755 --- a/selfdrive/thermald/thermald.py +++ b/selfdrive/thermald/thermald.py @@ -364,7 +364,7 @@ def thermald_thread() -> NoReturn: try: with open('/dev/kmsg', 'w') as kmsg: - kmsg.write("[thermald] engaged: {engaged}") + kmsg.write(f"[thermald] engaged: {engaged}") except Exception: pass From 6493c2c1254d6933f758faec28fcaf26de8ebb6e Mon Sep 17 00:00:00 2001 From: Willem Melching Date: Mon, 10 Jan 2022 16:30:22 +0100 Subject: [PATCH 4/4] move to python --- launch_chffrplus.sh | 3 --- selfdrive/hardware/tici/hardware.py | 3 +++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/launch_chffrplus.sh b/launch_chffrplus.sh index 6d0da524da103b..7ef671c2652e2e 100755 --- a/launch_chffrplus.sh +++ b/launch_chffrplus.sh @@ -104,9 +104,6 @@ function tici_init { sleep 3 fi - # Allow thermald to write engagement status to kmsg - sudo chmod a+w /dev/kmsg - # setup governors sudo su -c 'echo "performance" > /sys/class/devfreq/soc:qcom,memlat-cpu0/governor' sudo su -c 'echo "performance" > /sys/class/devfreq/soc:qcom,memlat-cpu4/governor' diff --git a/selfdrive/hardware/tici/hardware.py b/selfdrive/hardware/tici/hardware.py index 855eee908efc62..31bfa736c031f7 100644 --- a/selfdrive/hardware/tici/hardware.py +++ b/selfdrive/hardware/tici/hardware.py @@ -320,6 +320,9 @@ def get_gpu_usage_percent(self): def initialize_hardware(self): self.amplifier.initialize_configuration() + # Allow thermald to write engagement status to kmsg + os.system("sudo chmod a+w /dev/kmsg") + def get_networks(self): r = {}