diff --git a/selfdrive/dragonpilot/appd/appd.py b/selfdrive/dragonpilot/appd/appd.py index 76eec1b91..89042f171 100644 --- a/selfdrive/dragonpilot/appd/appd.py +++ b/selfdrive/dragonpilot/appd/appd.py @@ -30,103 +30,77 @@ def main(gctx=None): dragon_enable_mixplorer = False if params.get('DragonEnableMixplorer') == "0" else True dragon_boot_tomtom = False if params.get("DragonBootTomTom") == "0" else True dragon_boot_autonavi = False if params.get("DragonBootAutonavi") == "0" else True - tomtom_enabled = False - autonavi_enabled = False - mixplorer_enabled = False + tomtom_is_running = False + autonavi_is_running = False + mixplorer_is_running = False + allow_auto_boot = True params.put('DragonRunTomTom', '0') params.put('DragonRunAutonavi', '0') params.put('DragonRunMixplorer', '0') - # make sure packages are enabled/disabled - if dragon_enable_tomtom == "1": - system("pm enable %s" % tomtom) - else: - system("pm disable %s" % tomtom) - - if dragon_enable_autonavi == "1": - system("pm enable %s" % autonavi) - else: - system("pm disable %s" % autonavi) - - if dragon_enable_mixplorer == "1": - system("pm enable %s" % mixplorer) - else: - system("pm disable %s" % mixplorer) + # we want to disable all app when boot + system("pm disable %s" % tomtom) + system("pm disable %s" % autonavi) + system("pm disable %s" % mixplorer) thermal_sock = messaging.sub_sock(service_list['thermal'].port) while 1: msg = messaging.recv_sock(thermal_sock, wait=True) - dragon_run_tomtom = params.get('DragonRunTomTom') - dragon_run_autonavi = params.get('DragonRunAutonavi') - dragon_run_mixplorer = params.get('DragonRunMixplorer') + # allow user to manually start/stop app if dragon_enable_tomtom: - if dragon_run_tomtom == "1": - system("pm enable %s" % tomtom) - system("am start -n %s/%s" % (tomtom, tomtom_main)) - params.put('DragonRunTomTom', '0') - tomtom_enabled = True - elif dragon_run_tomtom == "-1": - system("pm disable %s" % tomtom) - system("pm enable %s" % tomtom) - params.put('DragonRunTomTom', '0') - tomtom_enabled = False + tomtom_is_running = execApp(params.get('DragonRunTomTom'), tomtom, tomtom_main, 'DragonRunTomTom') if dragon_enable_autonavi: - if dragon_run_autonavi == "1": - system("pm enable %s" % autonavi) - system("am start -n %s/%s" % (autonavi, autonavi_main)) - params.put('DragonRunAutonavi', '0') - autonavi_enabled = True - elif dragon_run_autonavi == "-1": - system("pm disable %s" % autonavi) - params.put('DragonRunAutonavi', '0') - autonavi_enabled = False + autonavi_is_running = execApp(params.get('DragonRunAutonavi'), autonavi, autonavi_main, 'DragonRunAutonavi') if dragon_enable_mixplorer: - if dragon_run_mixplorer == "1": - system("pm enable %s" % mixplorer) - system("am start -n %s/%s" % (mixplorer, mixplorer_main)) - params.put('DragonRunMixplorer', '0') - mixplorer_enabled = True - elif dragon_run_mixplorer == "-1": - system("pm disable %s" % mixplorer) - params.put('DragonRunMixplorer', '0') - mixplorer_enabled = False + mixplorer_is_running = execApp(params.get('DragonRunMixplorer'), mixplorer, mixplorer_main, 'DragonRunMixplorer') + auto_tomtom = dragon_enable_tomtom and dragon_boot_tomtom + auto_autonavi = dragon_enable_autonavi and dragon_boot_autonavi # car on if msg.thermal.started: - # dragonpilot, handle tomtom/autonavi + if msg.thermal.thermalStatus < ThermalStatus.yellow and not allow_auto_boot: + allow_auto_boot = True # do not allow tomtom / autonavi when it's hot - if msg.thermal.thermalStatus < ThermalStatus.red: - if dragon_boot_tomtom and not tomtom_enabled: - system("pm enable %s" % tomtom) - system("am start -n %s/%s" % (tomtom, tomtom_main)) - tomtom_enabled = True - if dragon_boot_autonavi and not autonavi_enabled: - system("pm enable %s" % autonavi) - system("am start -n %s/%s" % (autonavi, autonavi_main)) - autonavi_enabled = True + if allow_auto_boot: + if msg.thermal.thermalStatus < ThermalStatus.red: + if auto_tomtom and not tomtom_is_running: + tomtom_is_running = execApp('1', tomtom, tomtom_main, 'DragonRunTomTom') + if auto_autonavi and not autonavi_is_running: + autonavi_is_running = execApp('1', autonavi, autonavi_main, 'DragonRunAutonavi') + else: + allow_auto_boot = False # kill mixplorer when car started - if mixplorer_enabled: - system("pm disable %s" % mixplorer) - mixplorer_enabled = False + if mixplorer_is_running: + mixplorer_is_running = execApp('-1', mixplorer, mixplorer_main, 'DragonRunMixplorer') # car off else: - if dragon_boot_tomtom and tomtom_enabled: - system("pm disable %s" % tomtom) - tomtom_enabled = False - if dragon_boot_autonavi and autonavi_enabled: - system("pm disable %s" % autonavi) - autonavi_enabled = False + if auto_tomtom and tomtom_is_running: + tomtom_is_running = execApp('-1', tomtom, tomtom_main, 'DragonRunTomTom') + if auto_autonavi and autonavi_is_running: + autonavi_is_running = execApp('-1', autonavi, autonavi_main, 'DragonRunAutonavi') # every 3 seconds, we re-check status time.sleep(3) +def execApp(status, app, app_main, param): + 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 + + def system(cmd): try: cloudlog.info("running %s" % cmd)