dragonpilot - 基於 openpilot 的開源駕駛輔助系統
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.2 KiB

5 years ago
#!/usr/bin/env python3
import os
import subprocess
import time
import datetime
import random
from common.basedir import BASEDIR
import cereal.messaging as messaging
5 years ago
if __name__ == "__main__":
sound_dir = os.path.join(BASEDIR, "selfdrive/assets/sounds")
sound_files = [f for f in os.listdir(sound_dir) if f.endswith(".wav")]
play_sound = os.path.join(BASEDIR, "selfdrive/ui/test/play_sound")
print("disabling charging")
os.system('echo "0" > /sys/class/power_supply/battery/charging_enabled')
os.environ["LD_LIBRARY_PATH"] = ""
sm = messaging.SubMaster(["deviceState"])
5 years ago
FNULL = open(os.devnull, "w")
start_time = time.time()
while True:
volume = 15
n = random.randint(5, 10)
procs = []
for _ in range(n):
sound = random.choice(sound_files)
p = subprocess.Popen([play_sound, os.path.join(sound_dir, sound), str(volume)], stdout=FNULL, stderr=FNULL)
procs.append(p)
time.sleep(random.uniform(0, 0.75))
time.sleep(random.randint(0, 5))
for p in procs:
p.terminate()
sm.update(0)
s = time.time() - start_time
hhmmss = str(datetime.timedelta(seconds=s)).split(".")[0]
print("test duration:", hhmmss)
print("\tbattery percent", sm["deviceState"].batteryPercent)