diff --git a/selfdrive/test/test_fingerprints.py b/selfdrive/test/test_fingerprints.py index 178e113768..07e4774827 100755 --- a/selfdrive/test/test_fingerprints.py +++ b/selfdrive/test/test_fingerprints.py @@ -58,36 +58,38 @@ def check_can_ignition_conflicts(fingerprints, brands): sys.exit(1) -fingerprints = _get_fingerprints() - -fingerprints_flat = [] -car_names = [] -brand_names = [] -for brand in fingerprints: - for car in fingerprints[brand]: - fingerprints_flat += fingerprints[brand][car] - for i in range(len(fingerprints[brand][car])): - car_names.append(car) - brand_names.append(brand) - -# first check if CAN ignition specific messages are unexpectedly included in other fingerprints -check_can_ignition_conflicts(fingerprints_flat, brand_names) - -valid = True -for idx1, f1 in enumerate(fingerprints_flat): - for idx2, f2 in enumerate(fingerprints_flat): - if idx1 < idx2 and not check_fingerprint_consistency(f1, f2): - valid = False - print("Those two fingerprints are inconsistent {0} {1}".format(car_names[idx1], car_names[idx2])) - print("") - print(', '.join("%d: %d" % v for v in sorted(f1.items()))) - print("") - print(', '.join("%d: %d" % v for v in sorted(f2.items()))) - print("") - -print("Found {0} individual fingerprints".format(len(fingerprints_flat))) -if not valid or len(fingerprints_flat) == 0: - print("TEST FAILED") - sys.exit(1) -else: - print("TEST SUCESSFUL") + +if __name__ == "__main__": + fingerprints = _get_fingerprints() + + fingerprints_flat = [] + car_names = [] + brand_names = [] + for brand in fingerprints: + for car in fingerprints[brand]: + fingerprints_flat += fingerprints[brand][car] + for i in range(len(fingerprints[brand][car])): + car_names.append(car) + brand_names.append(brand) + + # first check if CAN ignition specific messages are unexpectedly included in other fingerprints + check_can_ignition_conflicts(fingerprints_flat, brand_names) + + valid = True + for idx1, f1 in enumerate(fingerprints_flat): + for idx2, f2 in enumerate(fingerprints_flat): + if idx1 < idx2 and not check_fingerprint_consistency(f1, f2): + valid = False + print("Those two fingerprints are inconsistent {0} {1}".format(car_names[idx1], car_names[idx2])) + print("") + print(', '.join("%d: %d" % v for v in sorted(f1.items()))) + print("") + print(', '.join("%d: %d" % v for v in sorted(f2.items()))) + print("") + + print("Found {0} individual fingerprints".format(len(fingerprints_flat))) + if not valid or len(fingerprints_flat) == 0: + print("TEST FAILED") + sys.exit(1) + else: + print("TEST SUCESSFUL") diff --git a/tools/replay/can_replay.py b/tools/replay/can_replay.py index 5221054262..dd16493abf 100755 --- a/tools/replay/can_replay.py +++ b/tools/replay/can_replay.py @@ -16,24 +16,6 @@ except Exception: PandaJungle = None # type: ignore -print("Loading log...") -ROUTE = "77611a1fac303767/2020-03-24--09-50-38" -REPLAY_SEGS = list(range(10, 16)) # route has 82 segments available -CAN_MSGS = [] -for i in tqdm(REPLAY_SEGS): - log_url = f"https://commadataci.blob.core.windows.net/openpilotci/{ROUTE}/{i}/rlog.bz2" - lr = LogReader(log_url) - CAN_MSGS += [can_capnp_to_can_list(m.can) for m in lr if m.which() == 'can'] - - -# set both to cycle ignition -IGN_ON = int(os.getenv("ON", "0")) -IGN_OFF = int(os.getenv("OFF", "0")) -ENABLE_IGN = IGN_ON > 0 and IGN_OFF > 0 -if ENABLE_IGN: - print(f"Cycling ignition: on for {IGN_ON}s, off for {IGN_OFF}s") - - def send_thread(s, flock): if "Jungle" in str(type(s)): if "FLASH" in os.environ: @@ -99,4 +81,21 @@ def connect(): if __name__ == "__main__": + print("Loading log...") + ROUTE = "77611a1fac303767/2020-03-24--09-50-38" + REPLAY_SEGS = list(range(10, 16)) # route has 82 segments available + CAN_MSGS = [] + for i in tqdm(REPLAY_SEGS): + log_url = f"https://commadataci.blob.core.windows.net/openpilotci/{ROUTE}/{i}/rlog.bz2" + lr = LogReader(log_url) + CAN_MSGS += [can_capnp_to_can_list(m.can) for m in lr if m.which() == 'can'] + + + # set both to cycle ignition + IGN_ON = int(os.getenv("ON", "0")) + IGN_OFF = int(os.getenv("OFF", "0")) + ENABLE_IGN = IGN_ON > 0 and IGN_OFF > 0 + if ENABLE_IGN: + print(f"Cycling ignition: on for {IGN_ON}s, off for {IGN_OFF}s") + connect() diff --git a/tools/zookeeper/check_consumption.py b/tools/zookeeper/check_consumption.py index 608e0bfe4c..1345b90571 100755 --- a/tools/zookeeper/check_consumption.py +++ b/tools/zookeeper/check_consumption.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import sys import time @@ -8,19 +8,20 @@ from tools.zookeeper import Zookeeper # Exit code: 0 -> passed # 1 -> failed -z = Zookeeper() +if __name__ == "__main__": + z = Zookeeper() -averaging_time_s = int(sys.argv[1]) -max_average_power = float(sys.argv[2]) + averaging_time_s = int(sys.argv[1]) + max_average_power = float(sys.argv[2]) -start_time = time.time() -measurements = [] -while time.time() - start_time < averaging_time_s: - measurements.append(z.read_power()) - time.sleep(0.1) + start_time = time.time() + measurements = [] + while time.time() - start_time < averaging_time_s: + measurements.append(z.read_power()) + time.sleep(0.1) -average_power = sum(measurements)/len(measurements) -print(f"Average power: {round(average_power, 4)}W") + average_power = sum(measurements)/len(measurements) + print(f"Average power: {round(average_power, 4)}W") -if average_power > max_average_power: - exit(1) + if average_power > max_average_power: + exit(1) diff --git a/tools/zookeeper/disable.py b/tools/zookeeper/disable.py index 1e510dbcc3..6c1eecc18b 100755 --- a/tools/zookeeper/disable.py +++ b/tools/zookeeper/disable.py @@ -1,7 +1,8 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 from tools.zookeeper import Zookeeper -z = Zookeeper() -z.set_device_power(False) +if __name__ == "__main__": + z = Zookeeper() + z.set_device_power(False) diff --git a/tools/zookeeper/enable_and_wait.py b/tools/zookeeper/enable_and_wait.py index b8cbf620ad..398ef412b1 100755 --- a/tools/zookeeper/enable_and_wait.py +++ b/tools/zookeeper/enable_and_wait.py @@ -1,25 +1,27 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import os import sys import time from tools.zookeeper import Zookeeper -z = Zookeeper() -z.set_device_power(True) - def is_online(ip): return (os.system(f"ping -c 1 {ip} > /dev/null") == 0) -ip = str(sys.argv[1]) -timeout = int(sys.argv[2]) -start_time = time.time() -while not is_online(ip): - print(f"{ip} not online yet!") +if __name__ == "__main__": + z = Zookeeper() + z.set_device_power(True) + + + ip = str(sys.argv[1]) + timeout = int(sys.argv[2]) + start_time = time.time() + while not is_online(ip): + print(f"{ip} not online yet!") - if time.time() - start_time > timeout: - print("Timed out!") - raise TimeoutError() + if time.time() - start_time > timeout: + print("Timed out!") + raise TimeoutError() - time.sleep(1) + time.sleep(1) diff --git a/tools/zookeeper/ignition.py b/tools/zookeeper/ignition.py index ad093c6936..5c85be203d 100755 --- a/tools/zookeeper/ignition.py +++ b/tools/zookeeper/ignition.py @@ -1,8 +1,10 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import sys from tools.zookeeper import Zookeeper -z = Zookeeper() -z.set_device_ignition(1 if int(sys.argv[1]) > 0 else 0) + +if __name__ == "__main__": + z = Zookeeper() + z.set_device_ignition(1 if int(sys.argv[1]) > 0 else 0) diff --git a/tools/zookeeper/test_zookeeper.py b/tools/zookeeper/test_zookeeper.py index d1f99ac9dc..ba395ad7ba 100755 --- a/tools/zookeeper/test_zookeeper.py +++ b/tools/zookeeper/test_zookeeper.py @@ -3,21 +3,23 @@ import time from tools.zookeeper import Zookeeper -z = Zookeeper() -z.set_device_power(True) -i = 0 -ign = False -while 1: - voltage = round(z.read_voltage(), 2) - current = round(z.read_current(), 3) - power = round(z.read_power(), 2) - z.set_device_ignition(ign) - print(f"Voltage: {voltage}V, Current: {current}A, Power: {power}W, Ignition: {ign}") +if __name__ == "__main__": + z = Zookeeper() + z.set_device_power(True) - if i > 200: - ign = not ign - i = 0 - - i += 1 - time.sleep(0.1) + i = 0 + ign = False + while 1: + voltage = round(z.read_voltage(), 2) + current = round(z.read_current(), 3) + power = round(z.read_power(), 2) + z.set_device_ignition(ign) + print(f"Voltage: {voltage}V, Current: {current}A, Power: {power}W, Ignition: {ign}") + + if i > 200: + ign = not ign + i = 0 + + i += 1 + time.sleep(0.1)