From 858c992bda6ac9a8e7ecc0e98354c5c6f79fc3e4 Mon Sep 17 00:00:00 2001 From: George Hotz Date: Tue, 18 Feb 2020 11:48:04 -0800 Subject: [PATCH] Disable Power Down option for desk devices (#1117) * './params.py DisablePowerDown 1' to use * fix issues --- common/params.py | 7 +++++-- selfdrive/boardd/boardd.cc | 18 ++++++++++++------ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/common/params.py b/common/params.py index c623e3dc31..22ee0aa55b 100755 --- a/common/params.py +++ b/common/params.py @@ -22,6 +22,8 @@ file in place without messing with /d. """ import time import os +import string +import binascii import errno import sys import shutil @@ -59,6 +61,7 @@ keys = { "CommunityFeaturesToggle": [TxType.PERSISTENT], "CompletedTrainingVersion": [TxType.PERSISTENT], "ControlsParams": [TxType.PERSISTENT], + "DisablePowerDown": [TxType.PERSISTENT], "DoUninstall": [TxType.CLEAR_ON_MANAGER_START], "DongleId": [TxType.PERSISTENT], "GitBranch": [TxType.PERSISTENT], @@ -407,10 +410,10 @@ if __name__ == "__main__": pp = params.get(k) if pp is None: print("%s is None" % k) - elif all(ord(c) < 128 and ord(c) >= 32 for c in pp): + elif all(chr(c) in string.printable for c in pp): print("%s = %s" % (k, pp)) else: - print("%s = %s" % (k, pp.encode("hex"))) + print("%s = %s" % (k, binascii.hexlify(pp))) # Test multiprocess: # seq 0 100000 | xargs -P20 -I{} python common/params.py DongleId {} && sleep 0.05 diff --git a/selfdrive/boardd/boardd.cc b/selfdrive/boardd/boardd.cc index ef5faeb36c..0955be1012 100644 --- a/selfdrive/boardd/boardd.cc +++ b/selfdrive/boardd/boardd.cc @@ -392,12 +392,18 @@ void can_health(PubSocket *publisher) { bool cdp_mode = health.usb_power_mode == (uint8_t)(cereal::HealthData::UsbPowerMode::CDP); bool no_ignition_exp = no_ignition_cnt > NO_IGNITION_CNT_MAX; if ((no_ignition_exp || (voltage_f < VBATT_PAUSE_CHARGING)) && cdp_mode && !ignition) { - printf("TURN OFF CHARGING!\n"); - pthread_mutex_lock(&usb_lock); - libusb_control_transfer(dev_handle, 0xc0, 0xe6, (uint16_t)(cereal::HealthData::UsbPowerMode::CLIENT), 0, NULL, 0, TIMEOUT); - pthread_mutex_unlock(&usb_lock); - printf("POWER DOWN DEVICE\n"); - system("service call power 17 i32 0 i32 1"); + char *disable_power_down = NULL; + size_t disable_power_down_sz = 0; + const int result = read_db_value(NULL, "DisablePowerDown", &disable_power_down, &disable_power_down_sz); + if (disable_power_down_sz != 1 || disable_power_down[0] != '1') { + printf("TURN OFF CHARGING!\n"); + pthread_mutex_lock(&usb_lock); + libusb_control_transfer(dev_handle, 0xc0, 0xe6, (uint16_t)(cereal::HealthData::UsbPowerMode::CLIENT), 0, NULL, 0, TIMEOUT); + pthread_mutex_unlock(&usb_lock); + printf("POWER DOWN DEVICE\n"); + system("service call power 17 i32 0 i32 1"); + } + if (disable_power_down) free(disable_power_down); } if (!no_ignition_exp && (voltage_f > VBATT_START_CHARGING) && !cdp_mode) { printf("TURN ON CHARGING!\n");