diff --git a/cereal/log.capnp b/cereal/log.capnp index 479e5ec64..e81cbcf8e 100644 --- a/cereal/log.capnp +++ b/cereal/log.capnp @@ -284,6 +284,7 @@ struct ThermalData { thermalStatus @14 :ThermalStatus; chargingError @17 :Bool; chargingDisabled @18 :Bool; + ipAddr @19 :Text; enum ThermalStatus { green @0; # all processes run diff --git a/selfdrive/dragonpilot/appd/appd.py b/selfdrive/dragonpilot/appd/appd.py index 263574038..f3f2d4cc6 100644 --- a/selfdrive/dragonpilot/appd/appd.py +++ b/selfdrive/dragonpilot/appd/appd.py @@ -1,7 +1,6 @@ #!/usr/bin/env python2.7 import time -import zmq import selfdrive.messaging as messaging from selfdrive.services import service_list import subprocess @@ -45,10 +44,7 @@ def main(gctx=None): # we want to disable all app when boot system("pm disable %s ; pm disable %s ; pm disable %s" % (tomtom, autonavi, mixplorer)) - poller = zmq.Poller() - sock = messaging.sub_sock(service_list['thermal'].port, poller) - poller.poll(timeout=1000) - + thermal_sock = messaging.sub_sock(service_list['thermal'].port) while dragon_enable_tomtom or dragon_enable_autonavi or dragon_enable_mixplorer: @@ -77,7 +73,7 @@ def main(gctx=None): 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 - msg = messaging.recv_sock(sock, wait=True) + msg = messaging.recv_sock(thermal_sock, wait=True) started = msg.thermal.started # car on if started: diff --git a/selfdrive/dragonpilot/dashcamd/dashcamd.py b/selfdrive/dragonpilot/dashcamd/dashcamd.py index 2f9f083e7..a476d5ded 100644 --- a/selfdrive/dragonpilot/dashcamd/dashcamd.py +++ b/selfdrive/dragonpilot/dashcamd/dashcamd.py @@ -10,7 +10,6 @@ import os import time import datetime -import zmq import selfdrive.messaging as messaging from selfdrive.services import service_list import subprocess @@ -29,9 +28,7 @@ def main(gctx=None): if not os.path.exists(dashcam_videos): os.makedirs(dashcam_videos) - poller = zmq.Poller() - sock = messaging.sub_sock(service_list['thermal'].port, poller) - poller.poll(timeout=1000) + thermal_sock = messaging.sub_sock(service_list['thermal'].port) while 1: if params.get("DragonEnableDashcam") == "1": now = datetime.datetime.now() @@ -47,12 +44,12 @@ def main(gctx=None): # get health of board, log this in "thermal" start_time = time.time() - msg = messaging.recv_sock(sock, wait=True) + msg = messaging.recv_sock(thermal_sock, wait=True) if used_spaces >= max_storage or (msg is not None and msg.thermal.freeSpace < freespace_limit): # get all the files in the dashcam_videos path files = [f for f in sorted(os.listdir(dashcam_videos)) if os.path.isfile(dashcam_videos + f)] for file in files: - msg = messaging.recv_sock(sock, wait=True) + msg = messaging.recv_sock(thermal_sock, wait=True) # delete file one by one and once it has enough space for 1 video, we stop deleting if used_spaces - last_used_spaces < max_size_per_file or msg.thermal.freeSpace < freespace_limit: system("rm -fr %s" % (dashcam_videos + file)) diff --git a/selfdrive/thermald.py b/selfdrive/thermald.py index a087d670f..1b8b38f2f 100755 --- a/selfdrive/thermald.py +++ b/selfdrive/thermald.py @@ -13,6 +13,9 @@ from common.numpy_fast import clip from common.filter_simple import FirstOrderFilter params = Params() +import subprocess +import re + ThermalStatus = log.ThermalData.ThermalStatus CURRENT_TAU = 15. # 15s time constant @@ -149,6 +152,9 @@ def thermald_thread(): # Make sure charging is enabled charging_disabled = False os.system('echo "1" > /sys/class/power_supply/battery/charging_enabled') + ts_last_ip = 0. + last_ip_addr = '255.255.255.255' + ip_addr = '255.255.255.255' while 1: health = messaging.recv_sock(health_sock, wait=True) @@ -176,6 +182,26 @@ def thermald_thread(): msg.thermal.batteryVoltage = int(f.read()) with open("/sys/class/power_supply/usb/present") as f: msg.thermal.usbOnline = bool(int(f.read())) + # update ip every 5 seconds + ts = sec_since_boot() + if ts - ts_last_ip > 5.: + try: + result = subprocess.check_output(["service", "call", "connectivity", "2"]).strip().split("\n") + except subprocess.CalledProcessError: + return False + + data = ''.join(''.join(w.decode("hex")[::-1] for w in l[14:49].split()) for l in result[1:]) + + if "\x00".join("WIFI") in data: + result = subprocess.check_output(["ifconfig", "wlan0"]) + ip_addr = re.findall(r"inet addr:((\d+\.){3}\d+)", result)[0][0] + ts_last_ip = ts + else: + ip_addr = '' + else: + ip_addr = last_ip_addr + msg.thermal.ipAddr = ip_addr + last_ip_addr = ip_addr current_filter.update(msg.thermal.batteryCurrent / 1e6)