mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-10-30 18:44:13 +08:00
Vendor dependencies and resources for standalone builds
Keep official openpilot ancestry and dependency licenses. Store resources directly in Git, remove LFS setup requirements, and leave the downloadable big model outside the source tree.
This commit is contained in:
Executable
+58
@@ -0,0 +1,58 @@
|
||||
#!/usr/bin/env python3
|
||||
import io
|
||||
import os
|
||||
import time
|
||||
import pstats
|
||||
import cProfile
|
||||
from contextlib import contextmanager
|
||||
|
||||
from panda import Panda, PandaDFU
|
||||
from panda.tests.hitl.helpers import get_random_can_messages
|
||||
|
||||
|
||||
PROFILE = "PROFILE" in os.environ
|
||||
|
||||
@contextmanager
|
||||
def print_time(desc):
|
||||
if PROFILE:
|
||||
pr = cProfile.Profile()
|
||||
pr.enable()
|
||||
start = time.perf_counter()
|
||||
yield
|
||||
end = time.perf_counter()
|
||||
print(f"{end - start:.3f}s - {desc}")
|
||||
if PROFILE:
|
||||
pr.disable()
|
||||
s = io.StringIO()
|
||||
ps = pstats.Stats(pr, stream=s).sort_stats("cumtime")
|
||||
ps.print_stats()
|
||||
print(s.getvalue())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
with print_time("Panda()"):
|
||||
p = Panda()
|
||||
|
||||
with print_time("PandaDFU.list()"):
|
||||
PandaDFU.list()
|
||||
|
||||
fxn = [
|
||||
'reset',
|
||||
'reconnect',
|
||||
'up_to_date',
|
||||
'health',
|
||||
#'flash',
|
||||
]
|
||||
for f in fxn:
|
||||
with print_time(f"Panda.{f}()"):
|
||||
getattr(p, f)()
|
||||
|
||||
p.set_can_loopback(True)
|
||||
|
||||
for n in range(6):
|
||||
msgs = get_random_can_messages(int(10**n))
|
||||
with print_time(f"Panda.can_send_many() - {len(msgs)} msgs"):
|
||||
p.can_send_many(msgs)
|
||||
|
||||
with print_time("Panda.can_recv()"):
|
||||
m = p.can_recv()
|
||||
Executable
+29
@@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env python3
|
||||
import time
|
||||
import re
|
||||
from panda import Panda
|
||||
|
||||
RED = '\033[91m'
|
||||
GREEN = '\033[92m'
|
||||
|
||||
def colorize_errors(value):
|
||||
if isinstance(value, str):
|
||||
if re.search(r'(?i)No error', value):
|
||||
return f'{GREEN}{value}\033[0m'
|
||||
elif re.search(r'(?i)(?<!No error\s)(err|error)', value):
|
||||
return f'{RED}{value}\033[0m'
|
||||
return str(value)
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
panda = Panda()
|
||||
while True:
|
||||
print(chr(27) + "[2J") # clear screen
|
||||
print("Connected to " + ("internal panda" if panda.is_internal() else "External panda") + f" id: {panda.get_serial()[0]}: {panda.get_version()}")
|
||||
for bus in range(3):
|
||||
print(f"\nBus {bus}:")
|
||||
health = panda.can_health(bus)
|
||||
for key, value in health.items():
|
||||
print(f"{key}: {colorize_errors(value)} ", end=" ")
|
||||
print()
|
||||
time.sleep(1)
|
||||
Executable
+46
@@ -0,0 +1,46 @@
|
||||
#!/usr/bin/env python3
|
||||
import os
|
||||
import time
|
||||
from collections import defaultdict
|
||||
import binascii
|
||||
|
||||
from opendbc.car.structs import CarParams
|
||||
from panda import Panda
|
||||
|
||||
# fake
|
||||
def sec_since_boot():
|
||||
return time.time()
|
||||
|
||||
def can_printer():
|
||||
p = Panda()
|
||||
print(f"Connected to id: {p.get_serial()[0]}: {p.get_version()}")
|
||||
time.sleep(1)
|
||||
|
||||
p.can_clear(0xFFFF)
|
||||
p.set_safety_mode(CarParams.SafetyModel.allOutput)
|
||||
|
||||
start = sec_since_boot()
|
||||
lp = sec_since_boot()
|
||||
all_msgs = defaultdict(list)
|
||||
|
||||
canbus = os.getenv("CAN")
|
||||
if canbus == "3":
|
||||
p.set_obd(True)
|
||||
canbus = "1"
|
||||
|
||||
while True:
|
||||
can_recv = p.can_recv()
|
||||
for addr, dat, bus in can_recv:
|
||||
if canbus is None or str(bus) == canbus:
|
||||
all_msgs[(addr, bus)].append((dat))
|
||||
|
||||
if sec_since_boot() - lp > 0.1:
|
||||
dd = chr(27) + "[2J"
|
||||
dd += "%5.2f\n" % (sec_since_boot() - start)
|
||||
for (addr, bus), dat_log in sorted(all_msgs.items()):
|
||||
dd += "%d: %s(%6d): %s\n" % (bus, "%04X(%4d)" % (addr, addr), len(dat_log), binascii.hexlify(dat_log[-1]).decode())
|
||||
print(dd)
|
||||
lp = sec_since_boot()
|
||||
|
||||
if __name__ == "__main__":
|
||||
can_printer()
|
||||
Executable
+52
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import codecs
|
||||
|
||||
from panda import Panda
|
||||
|
||||
setcolor = ["\033[1;32;40m", "\033[1;31;40m"]
|
||||
unsetcolor = "\033[00m"
|
||||
|
||||
claim = os.getenv("CLAIM") is not None
|
||||
no_color = os.getenv("NO_COLOR") is not None
|
||||
no_reconnect = os.getenv("NO_RECONNECT") is not None
|
||||
|
||||
if __name__ == "__main__":
|
||||
while True:
|
||||
try:
|
||||
serials = Panda.list()
|
||||
if os.getenv("SERIAL"):
|
||||
serials = [x for x in serials if x == os.getenv("SERIAL")]
|
||||
|
||||
pandas = [Panda(x, claim=claim) for x in serials]
|
||||
decoders = [codecs.getincrementaldecoder('utf-8')() for _ in pandas]
|
||||
|
||||
if not len(pandas):
|
||||
print("no pandas found")
|
||||
if no_reconnect:
|
||||
sys.exit(0)
|
||||
time.sleep(1)
|
||||
continue
|
||||
|
||||
while True:
|
||||
for i, panda in enumerate(pandas):
|
||||
while True:
|
||||
ret = panda.debug_read()
|
||||
if len(ret) > 0:
|
||||
decoded = decoders[i].decode(ret)
|
||||
if no_color:
|
||||
sys.stdout.write(decoded)
|
||||
else:
|
||||
sys.stdout.write(setcolor[i] + decoded + unsetcolor)
|
||||
sys.stdout.flush()
|
||||
else:
|
||||
break
|
||||
time.sleep(0.01)
|
||||
except KeyboardInterrupt:
|
||||
break
|
||||
except Exception:
|
||||
print("panda disconnected!")
|
||||
time.sleep(0.5)
|
||||
Executable
+40
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env python3
|
||||
import time
|
||||
from panda import Panda, PandaDFU
|
||||
|
||||
class GPIO:
|
||||
STM_RST_N = 124
|
||||
STM_BOOT0 = 134
|
||||
|
||||
|
||||
def gpio_init(pin, output):
|
||||
with open(f"/sys/class/gpio/gpio{pin}/direction", 'wb') as f:
|
||||
f.write(b"out" if output else b"in")
|
||||
|
||||
def gpio_set(pin, high):
|
||||
with open(f"/sys/class/gpio/gpio{pin}/value", 'wb') as f:
|
||||
f.write(b"1" if high else b"0")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
for pin in (GPIO.STM_RST_N, GPIO.STM_BOOT0):
|
||||
gpio_init(pin, True)
|
||||
|
||||
# flash bootstub
|
||||
print("resetting into DFU")
|
||||
gpio_set(GPIO.STM_RST_N, 1)
|
||||
gpio_set(GPIO.STM_BOOT0, 1)
|
||||
time.sleep(0.2)
|
||||
gpio_set(GPIO.STM_RST_N, 0)
|
||||
gpio_set(GPIO.STM_BOOT0, 0)
|
||||
|
||||
# bootstub flash takes 2s and is limited by the 255 byte flashing chunk size
|
||||
print("flashing bootstub")
|
||||
assert Panda.wait_for_dfu(None, 5)
|
||||
PandaDFU(None).recover()
|
||||
|
||||
print("flashing app")
|
||||
assert Panda.wait_for_panda(None, 5)
|
||||
p = Panda()
|
||||
assert p.bootstub
|
||||
p.flash()
|
||||
Executable
+50
@@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env python3
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
from datetime import datetime
|
||||
from collections import defaultdict, deque
|
||||
|
||||
os.environ['NO_RETRY'] = '1' # no spi retries
|
||||
from panda import Panda, PandaSpiException
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
s = defaultdict(lambda: deque(maxlen=30))
|
||||
def avg(k):
|
||||
return sum(s[k])/len(s[k])
|
||||
|
||||
#core = 6
|
||||
#from openpilot.common.realtime import config_realtime_process
|
||||
#config_realtime_process(core, 10)
|
||||
#os.system(f"echo {core} | sudo tee /proc/irq/10/smp_affinity_list")
|
||||
#os.system("sudo chrt -f -p 1 $(pgrep -f spi0)")
|
||||
#print(f"sudo taskset -pc {core} $(pgrep -f spi0)")
|
||||
#os.system(f"sudo taskset -pc {core} $(pgrep -f spi0)")
|
||||
|
||||
p = Panda()
|
||||
p.reset()
|
||||
start = datetime.now()
|
||||
le = p.health()['spi_error_count']
|
||||
while True:
|
||||
cnt = 0
|
||||
st = time.monotonic()
|
||||
while time.monotonic() - st < 1:
|
||||
try:
|
||||
p.get_type() # get_type has no processing on panda side
|
||||
except PandaSpiException:
|
||||
print(f"ERROR after {datetime.now() - start}\n\n")
|
||||
sys.stdout.write("\033[1;32;40m" + p.debug_read().decode('utf8') + "\033[00m" + "\n")
|
||||
sys.stdout.flush()
|
||||
sys.exit()
|
||||
cnt += 1
|
||||
s['hz'].append(cnt)
|
||||
|
||||
err = p.health()['spi_error_count']
|
||||
s['err'].append((err - le) & 0xFFFFFFFF)
|
||||
le = err
|
||||
|
||||
print(
|
||||
f"{avg('hz'):04.0f}Hz {avg('err'):04.0f} errors [{cnt:04d}Hz {s['err'][-1]:04d} errors] {datetime.now() - start}"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user