|
|
|
@ -163,10 +163,11 @@ def thermald_thread(): |
|
|
|
|
fan_speed = 0 |
|
|
|
|
count = 0 |
|
|
|
|
|
|
|
|
|
startup_conditions = { |
|
|
|
|
onroad_conditions = { |
|
|
|
|
"ignition": False, |
|
|
|
|
} |
|
|
|
|
startup_conditions_prev = startup_conditions.copy() |
|
|
|
|
startup_conditions = {} |
|
|
|
|
startup_conditions_prev = {} |
|
|
|
|
|
|
|
|
|
off_ts = None |
|
|
|
|
started_ts = None |
|
|
|
@ -220,12 +221,12 @@ def thermald_thread(): |
|
|
|
|
if pandaState.pandaType == log.PandaState.PandaType.unknown: |
|
|
|
|
no_panda_cnt += 1 |
|
|
|
|
if no_panda_cnt > DISCONNECT_TIMEOUT / DT_TRML: |
|
|
|
|
if startup_conditions["ignition"]: |
|
|
|
|
if onroad_conditions["ignition"]: |
|
|
|
|
cloudlog.error("Lost panda connection while onroad") |
|
|
|
|
startup_conditions["ignition"] = False |
|
|
|
|
onroad_conditions["ignition"] = False |
|
|
|
|
else: |
|
|
|
|
no_panda_cnt = 0 |
|
|
|
|
startup_conditions["ignition"] = pandaState.ignitionLine or pandaState.ignitionCan |
|
|
|
|
onroad_conditions["ignition"] = pandaState.ignitionLine or pandaState.ignitionCan |
|
|
|
|
|
|
|
|
|
in_car = pandaState.harnessStatus != log.PandaState.HarnessStatus.notConnected |
|
|
|
|
usb_power = peripheralState.usbPowerMode != log.PeripheralState.UsbPowerMode.client |
|
|
|
@ -304,7 +305,7 @@ def thermald_thread(): |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
if handle_fan is not None: |
|
|
|
|
fan_speed = handle_fan(controller, max_comp_temp, fan_speed, startup_conditions["ignition"]) |
|
|
|
|
fan_speed = handle_fan(controller, max_comp_temp, fan_speed, onroad_conditions["ignition"]) |
|
|
|
|
msg.deviceState.fanSpeedPercentDesired = fan_speed |
|
|
|
|
|
|
|
|
|
is_offroad_for_5_min = (started_ts is None) and ((not started_seen) or (off_ts is None) or (sec_since_boot() - off_ts > 60 * 5)) |
|
|
|
@ -339,14 +340,17 @@ def thermald_thread(): |
|
|
|
|
startup_conditions["not_taking_snapshot"] = not params.get_bool("IsTakingSnapshot") |
|
|
|
|
# if any CPU gets above 107 or the battery gets above 63, kill all processes |
|
|
|
|
# controls will warn with CPU above 95 or battery above 60 |
|
|
|
|
startup_conditions["device_temp_good"] = thermal_status < ThermalStatus.danger |
|
|
|
|
set_offroad_alert_if_changed("Offroad_TemperatureTooHigh", (not startup_conditions["device_temp_good"])) |
|
|
|
|
onroad_conditions["device_temp_good"] = thermal_status < ThermalStatus.danger |
|
|
|
|
set_offroad_alert_if_changed("Offroad_TemperatureTooHigh", (not onroad_conditions["device_temp_good"])) |
|
|
|
|
|
|
|
|
|
if TICI: |
|
|
|
|
set_offroad_alert_if_changed("Offroad_StorageMissing", (not Path("/data/media").is_mount())) |
|
|
|
|
|
|
|
|
|
# Handle offroad/onroad transition |
|
|
|
|
should_start = all(startup_conditions.values()) |
|
|
|
|
should_start = all(onroad_conditions.values()) |
|
|
|
|
if started_ts is None: |
|
|
|
|
should_start = should_start and all(startup_conditions.values()) |
|
|
|
|
|
|
|
|
|
if should_start != should_start_prev or (count == 0): |
|
|
|
|
params.put_bool("IsOnroad", should_start) |
|
|
|
|
params.put_bool("IsOffroad", not should_start) |
|
|
|
@ -358,25 +362,25 @@ def thermald_thread(): |
|
|
|
|
started_ts = sec_since_boot() |
|
|
|
|
started_seen = True |
|
|
|
|
else: |
|
|
|
|
if startup_conditions["ignition"] and (startup_conditions != startup_conditions_prev): |
|
|
|
|
cloudlog.event("Startup blocked", startup_conditions=startup_conditions) |
|
|
|
|
if onroad_conditions["ignition"] and (startup_conditions != startup_conditions_prev): |
|
|
|
|
cloudlog.event("Startup blocked", startup_conditions=startup_conditions, onroad_conditions=onroad_conditions) |
|
|
|
|
|
|
|
|
|
started_ts = None |
|
|
|
|
if off_ts is None: |
|
|
|
|
off_ts = sec_since_boot() |
|
|
|
|
|
|
|
|
|
# Offroad power monitoring |
|
|
|
|
power_monitor.calculate(peripheralState, startup_conditions["ignition"]) |
|
|
|
|
power_monitor.calculate(peripheralState, onroad_conditions["ignition"]) |
|
|
|
|
msg.deviceState.offroadPowerUsageUwh = power_monitor.get_power_used() |
|
|
|
|
msg.deviceState.carBatteryCapacityUwh = max(0, power_monitor.get_car_battery_capacity()) |
|
|
|
|
current_power_draw = HARDWARE.get_current_power_draw() # pylint: disable=assignment-from-none |
|
|
|
|
msg.deviceState.powerDrawW = current_power_draw if current_power_draw is not None else 0 |
|
|
|
|
|
|
|
|
|
# Check if we need to disable charging (handled by boardd) |
|
|
|
|
msg.deviceState.chargingDisabled = power_monitor.should_disable_charging(startup_conditions["ignition"], in_car, off_ts) |
|
|
|
|
msg.deviceState.chargingDisabled = power_monitor.should_disable_charging(onroad_conditions["ignition"], in_car, off_ts) |
|
|
|
|
|
|
|
|
|
# Check if we need to shut down |
|
|
|
|
if power_monitor.should_shutdown(peripheralState, startup_conditions["ignition"], in_car, off_ts, started_seen): |
|
|
|
|
if power_monitor.should_shutdown(peripheralState, onroad_conditions["ignition"], in_car, off_ts, started_seen): |
|
|
|
|
cloudlog.info(f"shutting device down, offroad since {off_ts}") |
|
|
|
|
# TODO: add function for blocking cloudlog instead of sleep |
|
|
|
|
time.sleep(10) |
|
|
|
|