2019-11-27 08:18:34 +08:00
|
|
|
import time
|
2023-03-23 12:38:37 +08:00
|
|
|
import pytest
|
2022-08-03 13:28:54 +08:00
|
|
|
|
|
|
|
from panda import Panda
|
2023-05-08 19:30:23 +08:00
|
|
|
|
2019-12-06 06:19:29 +08:00
|
|
|
|
2023-04-04 11:21:10 +08:00
|
|
|
@pytest.mark.skip_panda_types((Panda.HW_TYPE_DOS, ))
|
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']
|
2023-03-15 05:49:39 +08:00
|
|
|
assert ((voltage > 11000) and (voltage < 13000))
|
2022-08-03 08:05:47 +08:00
|
|
|
time.sleep(0.1)
|
2022-08-03 13:28:54 +08:00
|
|
|
|
|
|
|
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
|
|
|
|
2023-03-23 12:38:37 +08:00
|
|
|
def test_heartbeat(p, panda_jungle):
|
|
|
|
panda_jungle.set_ignition(True)
|
2022-08-18 13:42:18 +08:00
|
|
|
# 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()
|
|
|
|
|
2023-03-23 12:38:37 +08:00
|
|
|
time.sleep(6.)
|
2022-08-18 13:42:18 +08:00
|
|
|
|
|
|
|
h = p.health()
|
|
|
|
assert h['heartbeat_lost']
|
|
|
|
assert h['safety_mode'] == Panda.SAFETY_SILENT
|
|
|
|
assert h['safety_param'] == 0
|
|
|
|
assert h['controls_allowed'] == 0
|
2023-02-14 19:16:15 +08:00
|
|
|
|
|
|
|
def test_microsecond_timer(p):
|
|
|
|
start_time = p.get_microsecond_timer()
|
|
|
|
time.sleep(1)
|
|
|
|
end_time = p.get_microsecond_timer()
|
|
|
|
|
|
|
|
# account for uint32 overflow
|
|
|
|
if end_time < start_time:
|
|
|
|
end_time += 2**32
|
|
|
|
|
|
|
|
time_diff = (end_time - start_time) / 1e6
|
|
|
|
assert 0.98 < time_diff < 1.02, f"Timer not running at the correct speed! (got {time_diff:.2f}s instead of 1.0s)"
|