From 3bb4af65ae7208bc0623de71681dc6776690dfa4 Mon Sep 17 00:00:00 2001 From: dragonpilot Date: Wed, 21 Aug 2019 23:30:53 +1000 Subject: [PATCH 1/2] =?UTF-8?q?=E8=AA=BF=E6=95=B4appd=20logic?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- selfdrive/dragonpilot/appd/appd.py | 110 +++++++++++------------------ 1 file changed, 42 insertions(+), 68 deletions(-) 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) From 5c8114ef731ebdc01ce6e6bb3774dd6af46c25d5 Mon Sep 17 00:00:00 2001 From: dragonpilot Date: Wed, 21 Aug 2019 23:57:29 +1000 Subject: [PATCH 2/2] =?UTF-8?q?=E8=AA=BF=E6=95=B4appd=20logic?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- selfdrive/dragonpilot/appd/appd.py | 65 ++++++++++++++++++++++-------- 1 file changed, 49 insertions(+), 16 deletions(-) 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