From 6cbde9f3e43ff68a3c3937935a0349f9c528792a Mon Sep 17 00:00:00 2001 From: dragonpilot Date: Wed, 8 Jan 2020 15:04:49 +1000 Subject: [PATCH] add DragonBTG mode --- btg_mode.sh | 11 +++++++ common/params.py | 5 +-- selfdrive/boardd/SConscript | 6 ++++ selfdrive/boardd/boardd.cc | 14 ++++++++ selfdrive/dragonpilot/dragonconf/__init__.py | 34 +++++++++----------- selfdrive/thermald.py | 3 -- 6 files changed, 49 insertions(+), 24 deletions(-) create mode 100755 btg_mode.sh diff --git a/btg_mode.sh b/btg_mode.sh new file mode 100755 index 000000000..ecf5adc3f --- /dev/null +++ b/btg_mode.sh @@ -0,0 +1,11 @@ +#!/usr/bin/bash + +mode=$1 +if [ $1 -eq 1 ]; then + printf %s "1" > /data/params/d/DragonBTG +fi +if [ $1 -eq 0 ]; then + printf %s "0" > /data/params/d/DragonBTG +fi + +rm -rf /data/openpilot/selfdrive/boardd/boardd && reboot \ No newline at end of file diff --git a/common/params.py b/common/params.py index a987be337..6cee4b858 100755 --- a/common/params.py +++ b/common/params.py @@ -150,8 +150,8 @@ keys = { "DragonEnableSlowOnCurve": [TxType.PERSISTENT], "DragonEnableLeadCarMovingAlert": [TxType.PERSISTENT], "DragonToyotaSnGMod": [TxType.PERSISTENT], - "DragonIsEON": [TxType.PERSISTENT], - "DragonHWChecked": [TxType.PERSISTENT], + "DragonIsEON": [TxType.PERSISTENT], # deprecated + "DragonHWChecked": [TxType.PERSISTENT], # deprecated "DragonEnableSRLearner": [TxType.PERSISTENT], "DragonWazeMode": [TxType.PERSISTENT], "DragonRunWaze": [TxType.PERSISTENT], @@ -160,6 +160,7 @@ keys = { "DragonAssistedLCMinMPH": [TxType.PERSISTENT], "DragonAutoLCMinMPH": [TxType.PERSISTENT], "DragonAutoLCDelay": [TxType.PERSISTENT], + "DragonBTG": [TxType.PERSISTENT], } diff --git a/selfdrive/boardd/SConscript b/selfdrive/boardd/SConscript index 14c1ff780..bd60171c0 100644 --- a/selfdrive/boardd/SConscript +++ b/selfdrive/boardd/SConscript @@ -1,5 +1,11 @@ Import('env', 'common', 'messaging') +# dragonpilot - Add read DragonBTG value +if FindFile('DragonBTG', '/data/params/d') != None: + with open('/data/params/d/DragonBTG') as f: + if (int(f.read())) == 1: + env.Append(CCFLAGS='-DDragonBTG') + env.Program('boardd.cc', LIBS=['usb-1.0', common, messaging, 'pthread', 'zmq', 'capnp', 'kj']) env.Library('libcan_list_to_can_capnp', ['can_list_to_can_capnp.cc']) diff --git a/selfdrive/boardd/boardd.cc b/selfdrive/boardd/boardd.cc index e8a313d90..5eaa196f3 100644 --- a/selfdrive/boardd/boardd.cc +++ b/selfdrive/boardd/boardd.cc @@ -76,6 +76,7 @@ void pigeon_init(); void *pigeon_thread(void *crap); void *safety_setter_thread(void *s) { + #ifndef DragonBTG // diagnostic only is the default, needed for VIN query pthread_mutex_lock(&usb_lock); libusb_control_transfer(dev_handle, 0x40, 0xdc, (uint16_t)(cereal::CarParams::SafetyModel::ELM327), 0, NULL, 0, TIMEOUT); @@ -101,6 +102,7 @@ void *safety_setter_thread(void *s) { pthread_mutex_lock(&usb_lock); libusb_control_transfer(dev_handle, 0x40, 0xdc, (uint16_t)(cereal::CarParams::SafetyModel::NO_OUTPUT), 0, NULL, 0, TIMEOUT); pthread_mutex_unlock(&usb_lock); + #endif char *value; size_t value_sz = 0; @@ -355,12 +357,14 @@ void can_health(PubSocket *publisher) { } while(cnt != sizeof(health)); pthread_mutex_unlock(&usb_lock); + #ifndef DragonBTG // Make sure CAN buses are live: safety_setter_thread does not work if Panda CAN are silent and there is only one other CAN node if (health.safety_model == (uint8_t)(cereal::CarParams::SafetyModel::SILENT)) { pthread_mutex_lock(&usb_lock); libusb_control_transfer(dev_handle, 0x40, 0xdc, (uint16_t)(cereal::CarParams::SafetyModel::NO_OUTPUT), 0, NULL, 0, TIMEOUT); pthread_mutex_unlock(&usb_lock); } + #endif bool ignition = ((health.ignition_line != 0) || (health.ignition_can != 0)); @@ -396,12 +400,14 @@ void can_health(PubSocket *publisher) { libusb_control_transfer(dev_handle, 0xc0, 0xe7, 1, 0, NULL, 0, TIMEOUT); pthread_mutex_unlock(&usb_lock); } + #ifndef DragonBTG // set safety mode to NO_OUTPUT when car is off. ELM327 is an alternative if we want to leverage athenad/connect if (!ignition && (health.safety_model != (uint8_t)(cereal::CarParams::SafetyModel::NO_OUTPUT))) { pthread_mutex_lock(&usb_lock); libusb_control_transfer(dev_handle, 0x40, 0xdc, (uint16_t)(cereal::CarParams::SafetyModel::NO_OUTPUT), 0, NULL, 0, TIMEOUT); pthread_mutex_unlock(&usb_lock); } + #endif #endif // clear VIN, CarParams, and set new safety on car start @@ -813,6 +819,11 @@ void *pigeon_thread(void *crap) { if (pigeon_needs_init) { pigeon_needs_init = false; pigeon_init(); + #ifdef DragonBTG + pthread_mutex_lock(&usb_lock); + libusb_control_transfer(dev_handle, 0x40, 0xdc, 2, 100, NULL, 0, TIMEOUT); + pthread_mutex_unlock(&usb_lock); + #endif } int alen = 0; while (alen < 0xfc0) { @@ -855,6 +866,9 @@ int set_realtime_priority(int level) { int main() { int err; LOGW("starting boardd"); + #ifdef DragonBTG + LOGW("boardd is running in DragonBTG mode"); + #endif // set process priority err = set_realtime_priority(4); diff --git a/selfdrive/dragonpilot/dragonconf/__init__.py b/selfdrive/dragonpilot/dragonconf/__init__.py index 929535f2a..9726b6b22 100644 --- a/selfdrive/dragonpilot/dragonconf/__init__.py +++ b/selfdrive/dragonpilot/dragonconf/__init__.py @@ -54,8 +54,6 @@ default_conf = { 'DragonEnableSlowOnCurve': '1', 'DragonEnableLeadCarMovingAlert': '0', 'DragonToyotaSnGMod': '0', - 'DragonIsEON': '1', - 'DragonHWChecked': '0', 'DragonEnableSRLearner': '1', 'DragonWazeMode': '0', 'DragonRunWaze': '0', @@ -64,36 +62,34 @@ default_conf = { 'DragonAssistedLCMinMPH': 37, 'DragonAutoLCMinMPH': 60, 'DragonAutoLCDelay': 2, + 'DragonBTG': 0, } deprecated_conf = { - 'DragonDisableDriverSafetyCheck': 'DragonEnableDriverSafetyCheck', - 'DragonTempDisableSteerOnSignal': 'DragonEnableSteeringOnSignal', - 'DragonDisableLogger': 'DragonEnableLogger', - 'DragonDisableUploader': 'DragonEnableUploader', - 'DragonBBUI': 'DragonUIDev', + 'DragonIsEON': '', + 'DragonHWChecked': '', } -# deprecated_conf_invert = { +deprecated_conf_invert = { # 'DragonDisableDriverSafetyCheck': True, # 'DragonTempDisableSteerOnSignal': False, # 'DragonDisableLogger': True, # 'DragonDisableUploader': True, # 'DragonBBUI': False -# } +} def dragonpilot_set_params(params): # remove deprecated params - # for old, new in deprecated_conf.items(): - # if params.get(old) is not None: - # if new is not None: - # old_val = str(params.get(old)) - # new_val = old_val - # # invert the value if true - # if old in deprecated_conf_invert and deprecated_conf_invert[old] is True: - # new_val = "1" if old_val == "0" else "0" - # put_nonblocking(new, new_val) - # params.delete(old) + for old, new in deprecated_conf.items(): + if params.get(old) is not None: + if new is not None: + old_val = str(params.get(old)) + new_val = old_val + # invert the value if true + if old in deprecated_conf_invert and deprecated_conf_invert[old] is True: + new_val = "1" if old_val == "0" else "0" + put_nonblocking(new, new_val) + params.delete(old) # set params for key, val in default_conf.items(): diff --git a/selfdrive/thermald.py b/selfdrive/thermald.py index 100d4ef97..41de35093 100755 --- a/selfdrive/thermald.py +++ b/selfdrive/thermald.py @@ -178,9 +178,6 @@ def thermald_thread(): dragon_charging_ctrl = True if params.get('DragonChargingCtrl', encoding='utf8') == "1" else False dragon_charging_max = int(params.get('DragonCharging')) dragon_discharging_min = int(params.get('DragonDisCharging')) - charging_disabled = False - dragon_hw_checked = True if params.get('DragonHWChecked', encoding='utf8') == "1" else False - dragon_is_eon = False if params.get('DragonIsEON', encoding='utf8') == "0" else True while 1: health = messaging.recv_sock(health_sock, wait=True)