do not run on import

This commit is contained in:
Willem Melching 2021-10-26 14:37:12 +02:00
parent e0b88dfb63
commit 59accdd814
7 changed files with 104 additions and 95 deletions

View File

@ -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)
if __name__ == "__main__":
fingerprints = _get_fingerprints()
# first check if CAN ignition specific messages are unexpectedly included in other fingerprints
check_can_ignition_conflicts(fingerprints_flat, brand_names)
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)
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("")
# first check if CAN ignition specific messages are unexpectedly included in other fingerprints
check_can_ignition_conflicts(fingerprints_flat, brand_names)
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")
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")

View File

@ -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()

View File

@ -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)

View File

@ -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)

View File

@ -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)
if time.time() - start_time > timeout:
print("Timed out!")
raise TimeoutError()
time.sleep(1)
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()
time.sleep(1)

View File

@ -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)

View File

@ -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)