Merge branch 'devel-en' into devel-zhs

This commit is contained in:
dragonpilot
2019-08-22 00:11:59 +10:00
+74 -67
View File
@@ -30,103 +30,110 @@ 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
manual_tomtom = False
manual_autonavi = False
last_started = False
started = False
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))
status = params.get('DragonRunTomTom')
if not status == "0":
tomtom_is_running = execApp(status, 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
manual_tomtom = status != "0"
if dragon_enable_autonavi:
if dragon_run_autonavi == "1":
system("pm enable %s" % autonavi)
system("am start -n %s/%s" % (autonavi, autonavi_main))
status = params.get('DragonRunAutonavi')
if not status == "0":
autonavi_is_running = execApp(status, 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
manual_autonavi = status != "0"
if dragon_enable_mixplorer:
if dragon_run_mixplorer == "1":
system("pm enable %s" % mixplorer)
system("am start -n %s/%s" % (mixplorer, mixplorer_main))
status = params.get('DragonRunMixplorer')
if not status == "0":
mixplorer_is_running = execApp(status, 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
# 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:
# dragonpilot, handle tomtom/autonavi
# 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 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
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)
if auto_autonavi and not autonavi_is_running:
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_enabled:
system("pm disable %s" % mixplorer)
mixplorer_enabled = False
if mixplorer_is_running:
mixplorer_is_running = execApp('-1', mixplorer, mixplorer_main)
# 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)
if auto_autonavi and autonavi_is_running:
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):
if status == "1":
system("pm enable %s" % app)
system("am start -n %s/%s" % (app, app_main))
return True
if status == "-1":
system("pm disable %s" % app)
return False
def system(cmd):
try:
cloudlog.info("running %s" % cmd)