diff --git a/selfdrive/dragonpilot/appd/appd.py b/selfdrive/dragonpilot/appd/appd.py index 89042f171..929e93699 100644 --- a/selfdrive/dragonpilot/appd/appd.py +++ b/selfdrive/dragonpilot/appd/appd.py @@ -34,6 +34,10 @@ def main(gctx=None): autonavi_is_running = False mixplorer_is_running = False allow_auto_boot = True + manual_tomtom = False + manual_autonavi = False + last_started = False + started = False params.put('DragonRunTomTom', '0') params.put('DragonRunAutonavi', '0') @@ -51,53 +55,82 @@ def main(gctx=None): # allow user to manually start/stop app if dragon_enable_tomtom: - tomtom_is_running = execApp(params.get('DragonRunTomTom'), tomtom, tomtom_main, 'DragonRunTomTom') + status = params.get('DragonRunTomTom') + if not status == "0": + tomtom_is_running = execApp(status, tomtom, tomtom_main) + params.put('DragonRunTomTom', '0') + manual_tomtom = status != "0" if dragon_enable_autonavi: - autonavi_is_running = execApp(params.get('DragonRunAutonavi'), autonavi, autonavi_main, 'DragonRunAutonavi') + status = params.get('DragonRunAutonavi') + if not status == "0": + autonavi_is_running = execApp(status, autonavi, autonavi_main) + params.put('DragonRunAutonavi', '0') + manual_autonavi = status != "0" if dragon_enable_mixplorer: - mixplorer_is_running = execApp(params.get('DragonRunMixplorer'), mixplorer, mixplorer_main, 'DragonRunMixplorer') + status = params.get('DragonRunMixplorer') + if not status == "0": + mixplorer_is_running = execApp(status, mixplorer, mixplorer_main) + params.put('DragonRunMixplorer', '0') - auto_tomtom = dragon_enable_tomtom and dragon_boot_tomtom - auto_autonavi = dragon_enable_autonavi and dragon_boot_autonavi + # if manual control is set, we do not allow any of the auto actions + auto_tomtom = not manual_tomtom and dragon_enable_tomtom and dragon_boot_tomtom + auto_autonavi = not manual_autonavi and dragon_enable_autonavi and dragon_boot_autonavi + + started = msg.thermal.started # car on - if msg.thermal.started: - if msg.thermal.thermalStatus < ThermalStatus.yellow and not allow_auto_boot: + if started: + # + # Logic: + # if temp reach red, we disable all 3rd party apps. + # once the temp drop below yellow, we then re-enable them + # + # set allow_auto_boot back to True once the thermal status is < yellow + if not allow_auto_boot and msg.thermal.thermalStatus < ThermalStatus.yellow: allow_auto_boot = True - # do not allow tomtom / autonavi when it's hot if allow_auto_boot: + # only allow auto boot when thermal status is < red if msg.thermal.thermalStatus < ThermalStatus.red: if auto_tomtom and not tomtom_is_running: - tomtom_is_running = execApp('1', tomtom, tomtom_main, 'DragonRunTomTom') + tomtom_is_running = execApp('1', tomtom, tomtom_main) if auto_autonavi and not autonavi_is_running: - autonavi_is_running = execApp('1', autonavi, autonavi_main, 'DragonRunAutonavi') + autonavi_is_running = execApp('1', autonavi, autonavi_main) else: + if auto_tomtom and tomtom_is_running: + tomtom_is_running = execApp('-1', tomtom, tomtom_main) + if auto_autonavi and autonavi_is_running: + autonavi_is_running = execApp('-1', autonavi, autonavi_main) + # set allow_auto_boot to False once the thermal status is >= red allow_auto_boot = False # kill mixplorer when car started if mixplorer_is_running: - mixplorer_is_running = execApp('-1', mixplorer, mixplorer_main, 'DragonRunMixplorer') + mixplorer_is_running = execApp('-1', mixplorer, mixplorer_main) # car off else: if auto_tomtom and tomtom_is_running: - tomtom_is_running = execApp('-1', tomtom, tomtom_main, 'DragonRunTomTom') + tomtom_is_running = execApp('-1', tomtom, tomtom_main) if auto_autonavi and autonavi_is_running: - autonavi_is_running = execApp('-1', autonavi, autonavi_main, 'DragonRunAutonavi') + autonavi_is_running = execApp('-1', autonavi, autonavi_main) + # if car stats changed, we remove manual control state + if not last_started == started: + manual_tomtom = False + manual_autonavi = False + + last_started = started # every 3 seconds, we re-check status time.sleep(3) -def execApp(status, app, app_main, param): +def execApp(status, app, app_main): if status == "1": system("pm enable %s" % app) system("am start -n %s/%s" % (app, app_main)) - params.put(param, '0') return True if status == "-1": system("pm disable %s" % app) - params.put(param, '0') return False