Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cereal
13 changes: 7 additions & 6 deletions selfdrive/thermald/thermald.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,12 +348,13 @@ def thermald_thread(end_event, hw_queue):
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
if current_power_draw is not None:
statlog.sample("power_draw", current_power_draw)
msg.deviceState.powerDrawW = current_power_draw
else:
msg.deviceState.powerDrawW = 0
current_power_draw = HARDWARE.get_current_power_draw()
statlog.sample("power_draw", current_power_draw)
msg.deviceState.powerDrawW = current_power_draw

som_power_draw = HARDWARE.get_som_power_draw()
statlog.sample("som_power_draw", som_power_draw)
msg.deviceState.somPowerDrawW = som_power_draw

# Check if we need to disable charging (handled by boardd)
msg.deviceState.chargingDisabled = power_monitor.should_disable_charging(onroad_conditions["ignition"], in_car, off_ts)
Expand Down
4 changes: 4 additions & 0 deletions system/hardware/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ def get_usb_present(self):
def get_current_power_draw(self):
pass

@abstractmethod
def get_som_power_draw(self):
pass

@abstractmethod
def shutdown(self):
pass
Expand Down
3 changes: 3 additions & 0 deletions system/hardware/pc/hardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ def get_usb_present(self):

def get_current_power_draw(self):
return 0

def get_som_power_draw(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just let the base implementation return 0. No need to define twice. We need to clean up some of the other ones too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will clean this up in a separate PR

return 0

def shutdown(self):
print("SHUTDOWN!")
Expand Down
3 changes: 3 additions & 0 deletions system/hardware/tici/hardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,9 @@ def get_usb_present(self):
def get_current_power_draw(self):
return (self.read_param_file("/sys/class/hwmon/hwmon1/power1_input", int) / 1e6)

def get_som_power_draw(self):
return (self.read_param_file("/sys/class/power_supply/bms/voltage_now", int) * self.read_param_file("/sys/class/power_supply/bms/current_now", int) / 1e12)

def shutdown(self):
# Note that for this to work and have the device stay powered off, the panda needs to be in UsbPowerMode::CLIENT!
os.system("sudo poweroff")
Expand Down