fingerprints.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. from selfdrive.car.interfaces import get_interface_attr
  2. FW_VERSIONS = get_interface_attr('FW_VERSIONS', combine_brands=True, ignore_none=True)
  3. _FINGERPRINTS = get_interface_attr('FINGERPRINTS', combine_brands=True, ignore_none=True)
  4. _DEBUG_ADDRESS = {1880: 8} # reserved for debug purposes
  5. def is_valid_for_fingerprint(msg, car_fingerprint):
  6. adr = msg.address
  7. # ignore addresses that are more than 11 bits
  8. return (adr in car_fingerprint and car_fingerprint[adr] == len(msg.dat)) or adr >= 0x800
  9. def eliminate_incompatible_cars(msg, candidate_cars):
  10. """Removes cars that could not have sent msg.
  11. Inputs:
  12. msg: A cereal/log CanData message from the car.
  13. candidate_cars: A list of cars to consider.
  14. Returns:
  15. A list containing the subset of candidate_cars that could have sent msg.
  16. """
  17. compatible_cars = []
  18. for car_name in candidate_cars:
  19. car_fingerprints = _FINGERPRINTS[car_name]
  20. for fingerprint in car_fingerprints:
  21. fingerprint.update(_DEBUG_ADDRESS) # add alien debug address
  22. if is_valid_for_fingerprint(msg, fingerprint):
  23. compatible_cars.append(car_name)
  24. break
  25. return compatible_cars
  26. def all_known_cars():
  27. """Returns a list of all known car strings."""
  28. return list({*FW_VERSIONS.keys(), *_FINGERPRINTS.keys()})
  29. def all_legacy_fingerprint_cars():
  30. """Returns a list of all known car strings, FPv1 only."""
  31. return list(_FINGERPRINTS.keys())