2019-11-27 08:18:34 +08:00
|
|
|
import time
|
2022-08-03 13:28:54 +08:00
|
|
|
|
|
|
|
from panda import Panda
|
2019-11-27 08:18:34 +08:00
|
|
|
from panda_jungle import PandaJungle # pylint: disable=import-error
|
2022-08-03 08:05:47 +08:00
|
|
|
from .helpers import panda_jungle, test_all_pandas, test_all_gen2_pandas, panda_connect_and_init
|
2019-11-27 08:18:34 +08:00
|
|
|
|
2022-08-03 13:28:54 +08:00
|
|
|
|
2019-11-27 08:18:34 +08:00
|
|
|
@test_all_pandas
|
|
|
|
@panda_connect_and_init
|
|
|
|
def test_ignition(p):
|
2022-08-03 08:05:47 +08:00
|
|
|
# Set harness orientation to #2, since the ignition line is on the wrong SBU bus :/
|
|
|
|
panda_jungle.set_harness_orientation(PandaJungle.HARNESS_ORIENTATION_2)
|
|
|
|
p.reset()
|
|
|
|
|
|
|
|
for ign in (True, False):
|
|
|
|
panda_jungle.set_ignition(ign)
|
2019-11-27 08:18:34 +08:00
|
|
|
time.sleep(2)
|
2022-08-03 08:05:47 +08:00
|
|
|
assert p.health()['ignition_line'] == ign
|
|
|
|
|
2019-11-27 08:18:34 +08:00
|
|
|
|
|
|
|
@test_all_gen2_pandas
|
|
|
|
@panda_connect_and_init
|
|
|
|
def test_orientation_detection(p):
|
|
|
|
seen_orientations = []
|
|
|
|
for i in range(3):
|
|
|
|
panda_jungle.set_harness_orientation(i)
|
2022-08-03 08:05:47 +08:00
|
|
|
time.sleep(0.25)
|
|
|
|
p.reset()
|
|
|
|
time.sleep(0.25)
|
|
|
|
|
2019-11-27 08:18:34 +08:00
|
|
|
detected_harness_orientation = p.health()['car_harness_status']
|
2020-05-27 06:35:51 +08:00
|
|
|
print(f"Detected orientation: {detected_harness_orientation}")
|
2019-11-27 08:18:34 +08:00
|
|
|
if (i == 0 and detected_harness_orientation != 0) or detected_harness_orientation in seen_orientations:
|
|
|
|
assert False
|
|
|
|
seen_orientations.append(detected_harness_orientation)
|
2019-12-06 06:19:29 +08:00
|
|
|
|
|
|
|
@test_all_pandas
|
2023-01-24 07:05:16 +08:00
|
|
|
@panda_connect_and_init
|
2019-12-06 06:19:29 +08:00
|
|
|
def test_voltage(p):
|
2022-08-03 08:05:47 +08:00
|
|
|
for _ in range(10):
|
|
|
|
voltage = p.health()['voltage']
|
|
|
|
assert ((voltage > 10000) and (voltage < 14000))
|
|
|
|
time.sleep(0.1)
|
2022-08-03 13:28:54 +08:00
|
|
|
|
|
|
|
@test_all_pandas
|
|
|
|
@panda_connect_and_init
|
|
|
|
def test_hw_type(p):
|
|
|
|
"""
|
|
|
|
hw type should be same in bootstub as application
|
|
|
|
"""
|
|
|
|
|
|
|
|
hw_type = p.get_type()
|
|
|
|
mcu_type = p.get_mcu_type()
|
|
|
|
assert mcu_type is not None
|
|
|
|
|
2023-01-16 12:13:26 +08:00
|
|
|
app_uid = p.get_uid()
|
|
|
|
usb_serial = p.get_usb_serial()
|
|
|
|
assert app_uid == usb_serial
|
|
|
|
|
2022-08-03 13:28:54 +08:00
|
|
|
p.reset(enter_bootstub=True, reconnect=True)
|
|
|
|
p.close()
|
|
|
|
time.sleep(3)
|
2023-01-14 08:17:20 +08:00
|
|
|
with Panda(p.get_usb_serial()) as pp:
|
|
|
|
assert pp.bootstub
|
|
|
|
assert pp.get_type() == hw_type, "Bootstub and app hw type mismatch"
|
|
|
|
assert pp.get_mcu_type() == mcu_type, "Bootstub and app MCU type mismatch"
|
2023-01-16 12:13:26 +08:00
|
|
|
assert pp.get_uid() == app_uid
|
2022-08-18 13:42:18 +08:00
|
|
|
|
|
|
|
|
|
|
|
@test_all_pandas
|
|
|
|
@panda_connect_and_init
|
|
|
|
def test_heartbeat(p):
|
|
|
|
# TODO: add more cases here once the tests aren't super slow
|
|
|
|
p.set_safety_mode(mode=Panda.SAFETY_HYUNDAI, param=Panda.FLAG_HYUNDAI_LONG)
|
|
|
|
p.send_heartbeat()
|
|
|
|
assert p.health()['safety_mode'] == Panda.SAFETY_HYUNDAI
|
|
|
|
assert p.health()['safety_param'] == Panda.FLAG_HYUNDAI_LONG
|
|
|
|
|
|
|
|
# shouldn't do anything once we're in a car safety mode
|
|
|
|
p.set_heartbeat_disabled()
|
|
|
|
|
|
|
|
time.sleep(6)
|
|
|
|
|
|
|
|
h = p.health()
|
|
|
|
assert h['heartbeat_lost']
|
|
|
|
assert h['safety_mode'] == Panda.SAFETY_SILENT
|
|
|
|
assert h['safety_param'] == 0
|
|
|
|
assert h['controls_allowed'] == 0
|