Skip to content

Commit

Permalink
Merge branch 'master' into honda_bosch_check
Browse files Browse the repository at this point in the history
  • Loading branch information
maxime-desroches committed Oct 3, 2024
2 parents 22af923 + fab8d0b commit 9e1e361
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ repos:
additional_dependencies: ['numpy', 'types-requests', 'types-atomicwrites',
'types-pycurl']
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.3
rev: v0.6.8
hooks:
- id: ruff
20 changes: 18 additions & 2 deletions board/jungle/scripts/can_health.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
#!/usr/bin/env python3

import time
import re
from panda import PandaJungle

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__":
jungle = PandaJungle()

while True:
print(chr(27) + "[2J") # clear screen
print("Connected to " + ("internal panda" if jungle.is_internal() else "External panda") + f" id: {jungle.get_serial()[0]}: {jungle.get_version()}")
for bus in range(3):
print(bus, jungle.can_health(bus))
print(f"\nBus {bus}:")
health = jungle.can_health(bus)
for key, value in health.items():
print(f"{key}: {colorize_errors(value)} ", end=" ")
print()
time.sleep(1)
17 changes: 11 additions & 6 deletions board/jungle/scripts/can_printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,27 @@ def sec_since_boot():

def can_printer():
p = PandaJungle()
print(f"Connected to: {p._serial}: {p.get_version()}")
time.sleep(1)

p.can_clear(0xFFFF)

start = sec_since_boot()
lp = sec_since_boot()
msgs = defaultdict(list)
canbus = int(os.getenv("CAN", "0"))
canbus = os.getenv("CAN")
while True:
can_recv = p.can_recv()
for address, dat, src in can_recv:
if src == canbus:
msgs[address].append(dat)
for address,dat, src in can_recv:
if canbus is None or str(src) == canbus:
msgs[address].append((dat, src))

if sec_since_boot() - lp > 0.1:
dd = chr(27) + "[2J"
dd += "%5.2f\n" % (sec_since_boot() - start)
for k,v in sorted(zip(list(msgs.keys()), [binascii.hexlify(x[-1]) for x in list(msgs.values())], strict=True)):
dd += "%s(%6d) %s\n" % ("%04X(%4d)" % (k,k),len(msgs[k]), v)
for k, v in sorted(msgs.items()):
last_msg, last_src = v[-1]
dd += "%d: %s(%6d): %s\n" % (last_src, "%04X(%4d)" % (k, k), len(v), binascii.hexlify(last_msg).decode())
print(dd)
lp = sec_since_boot()

Expand Down
20 changes: 20 additions & 0 deletions board/jungle/scripts/spam_can.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env python3
import os
import random
from panda import PandaJungle

def get_test_string():
return b"test" + os.urandom(10)

if __name__ == "__main__":
p = PandaJungle()

p.set_safety_mode(PandaJungle.SAFETY_ALLOUTPUT)

print("Spamming all buses...")
while True:
at = random.randint(1, 2000)
st = get_test_string()[0:8]
bus = random.randint(0, 2)
p.can_send(at, st, bus)
# print("Sent message on bus: ", bus)
29 changes: 29 additions & 0 deletions tests/can_health.py
Original file line number Diff line number Diff line change
@@ -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)
20 changes: 10 additions & 10 deletions tests/can_printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,28 @@ def sec_since_boot():

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(Panda.SAFETY_ALLOUTPUT)

start = sec_since_boot()
lp = sec_since_boot()
msgs = defaultdict(list)

canbus = int(os.getenv("CAN", "0"))
if canbus == 3:
canbus = 1
p.set_obd(True)

canbus = os.getenv("CAN")
while True:
can_recv = p.can_recv()
for address, dat, src in can_recv:
if src == canbus:
msgs[address].append(dat)
if canbus is None or str(src) == canbus:
msgs[address].append((dat, src))

if sec_since_boot() - lp > 0.1:
dd = chr(27) + "[2J"
dd += "%5.2f\n" % (sec_since_boot() - start)
for k, v in sorted(zip(list(msgs.keys()), [binascii.hexlify(x[-1]) for x in list(msgs.values())], strict=True)):
dd += "%s(%6d) %s\n" % ("%04X(%4d)" % (k, k), len(msgs[k]), v)
for k, v in sorted(msgs.items()):
last_msg, last_src = v[-1]
dd += "%d: %s(%6d): %s\n" % (last_src, "%04X(%4d)" % (k, k), len(v), binascii.hexlify(last_msg).decode())
print(dd)
lp = sec_since_boot()

Expand Down
3 changes: 2 additions & 1 deletion tests/safety/mutation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ $DIR/install_mull.sh

GIT_REF="${GIT_REF:-origin/master}"
GIT_ROOT=$(git rev-parse --show-toplevel)
echo -e "mutators:\n - cxx_all" > $GIT_ROOT/mull.yml
MULL_OPS="mutators: [cxx_increment, cxx_decrement, cxx_comparison, cxx_boundary, cxx_bitwise_assignment, cxx_bitwise, cxx_arithmetic_assignment, cxx_arithmetic]"
echo -e "$MULL_OPS" > $GIT_ROOT/mull.yml
scons --mutation -j$(nproc) -D
echo -e "timeout: 10000\ngitDiffRef: $GIT_REF\ngitProjectRoot: $GIT_ROOT" >> $GIT_ROOT/mull.yml

Expand Down

0 comments on commit 9e1e361

Please sign in to comment.