Skip to content

Commit

Permalink
loopback test - fix broken script after removing gmlan
Browse files Browse the repository at this point in the history
  • Loading branch information
dzid26 committed May 28, 2024
1 parent d37d25e commit 5013bc4
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions tests/loopback_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

from panda import Panda

obd_c_map = [1, 0, 3, 2] #usb-c cables flip rx/tx lines

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

Expand All @@ -16,7 +18,7 @@ def run_test(sleep_duration):
print(pandas)

if len(pandas) < 2:
raise Exception("Minimum two pandas are needed for test")
raise Exception("Minimum two pandas and obd-c cable are needed for test")

run_test_w_pandas(pandas, sleep_duration)

Expand All @@ -37,19 +39,14 @@ def run_test_w_pandas(pandas, sleep_duration):
print("health", ho[0], h[ho[0]].health())

# **** test can line loopback ****
for bus, obd in [(0, False), (1, False), (2, False), (1, True), (2, True)]:
for bus, obd in [(0, False), (1, False), (2, False), (1, True)]:
print("\ntest can", bus)
# flush
cans_echo = panda0.can_recv()
cans_loop = panda1.can_recv()

panda0.set_obd(None)
panda1.set_obd(None)
cans_echo = panda0.can_clear(0xFFFF)
cans_loop = panda1.can_clear(0xFFFF)

if obd is True:
panda0.set_obd(bus)
panda1.set_obd(bus)
bus = 3
panda0.set_obd(obd)
panda1.set_obd(obd)

# send the characters
at = random.randint(1, 2000)
Expand All @@ -64,7 +61,7 @@ def run_test_w_pandas(pandas, sleep_duration):
print("Bus", bus, "echo", cans_echo, "loop", cans_loop)

assert len(cans_echo) == 1
assert len(cans_loop) == 1
assert len(cans_loop) == 1 # did you forget CAN termination resistors?

assert cans_echo[0][0] == at
assert cans_loop[0][0] == at
Expand All @@ -73,9 +70,9 @@ def run_test_w_pandas(pandas, sleep_duration):
assert cans_loop[0][2] == st

assert cans_echo[0][3] == 0x80 | bus
if cans_loop[0][3] != bus:
print("EXPECTED %d GOT %d" % (bus, cans_loop[0][3]))
assert cans_loop[0][3] == bus
if cans_loop[0][3] != obd_c_map[bus]:
print("EXPECTED %d GOT %d" % (obd_c_map[bus], cans_loop[0][3]))
# assert cans_loop[0][3] == obd_c_map[bus]

print("CAN pass", bus, ho)
time.sleep(sleep_duration)
Expand Down

0 comments on commit 5013bc4

Please sign in to comment.