openpilot is an open source driver assistance system. openpilot performs the functions of Automated Lane Centering and Adaptive Cruise Control for over 200 supported car makes and models.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.9 KiB

#!/usr/bin/env python3
import unittest
from cereal import car
from selfdrive.car.fingerprints import FW_VERSIONS
from selfdrive.car.fw_versions import match_fw_to_car
from selfdrive.car.toyota.values import CAR as TOYOTA
CarFw = car.CarParams.CarFw
Ecu = car.CarParams.Ecu
ECU_NAME = {v: k for k, v in Ecu.schema.enumerants.items()}
class TestFwFingerprint(unittest.TestCase):
def assertFingerprints(self, candidates, expected):
candidates = list(candidates)
self.assertEqual(len(candidates), 1)
self.assertEqual(candidates[0], TOYOTA.RAV4_TSS2)
def test_rav4_tss2(self):
CP = car.CarParams.new_message()
CP.carFw = [
{"ecu": Ecu.esp,
"fwVersion": b"\x01F15260R210\x00\x00\x00\x00\x00\x00",
"address": 1968,
"subAddress": 0},
{"ecu": Ecu.engine,
"fwVersion": b"\x028966342Y8000\x00\x00\x00\x00897CF1201001\x00\x00\x00\x00",
"address": 1792,
"subAddress": 0},
{"ecu": Ecu.eps,
"fwVersion": b"\x028965B0R01200\x00\x00\x00\x008965B0R02200\x00\x00\x00\x00",
"address": 1953,
"subAddress": 0},
{"ecu": Ecu.fwdRadar,
"fwVersion": b"\x018821F3301200\x00\x00\x00\x00",
"address": 1872,
"subAddress": 15},
{"ecu": Ecu.fwdCamera,
"fwVersion": b"\x028646F4203300\x00\x00\x00\x008646G26011A0\x00\x00\x00\x00",
"address": 1872,
"subAddress": 109}
]
self.assertFingerprints(match_fw_to_car(CP.carFw), TOYOTA.RAV4_TSS2)
def test_no_duplicate_fw_versions(self):
passed = True
for car_name, ecus in FW_VERSIONS.items():
for ecu, ecu_fw in ecus.items():
duplicates = set([fw for fw in ecu_fw if ecu_fw.count(fw) > 1])
if len(duplicates):
print(car_name, ECU_NAME[ecu[0]], duplicates)
passed = False
self.assertTrue(passed, "Duplicate FW versions found")
if __name__ == "__main__":
unittest.main()