disable_ecu.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/usr/bin/env python3
  2. from openpilot.selfdrive.car.isotp_parallel_query import IsoTpParallelQuery
  3. from openpilot.common.swaglog import cloudlog
  4. EXT_DIAG_REQUEST = b'\x10\x03'
  5. EXT_DIAG_RESPONSE = b'\x50\x03'
  6. COM_CONT_RESPONSE = b''
  7. def disable_ecu(logcan, sendcan, bus=0, addr=0x7d0, sub_addr=None, com_cont_req=b'\x28\x83\x01', timeout=0.1, retry=10, debug=False):
  8. """Silence an ECU by disabling sending and receiving messages using UDS 0x28.
  9. The ECU will stay silent as long as openpilot keeps sending Tester Present.
  10. This is used to disable the radar in some cars. Openpilot will emulate the radar.
  11. WARNING: THIS DISABLES AEB!"""
  12. cloudlog.warning(f"ecu disable {hex(addr), sub_addr} ...")
  13. for i in range(retry):
  14. try:
  15. query = IsoTpParallelQuery(sendcan, logcan, bus, [(addr, sub_addr)], [EXT_DIAG_REQUEST], [EXT_DIAG_RESPONSE], debug=debug)
  16. for _, _ in query.get_data(timeout).items():
  17. cloudlog.warning("communication control disable tx/rx ...")
  18. query = IsoTpParallelQuery(sendcan, logcan, bus, [(addr, sub_addr)], [com_cont_req], [COM_CONT_RESPONSE], debug=debug)
  19. query.get_data(0)
  20. cloudlog.warning("ecu disabled")
  21. return True
  22. except Exception:
  23. cloudlog.exception("ecu disable exception")
  24. cloudlog.error(f"ecu disable retry ({i + 1}) ...")
  25. cloudlog.error("ecu disable failed")
  26. return False
  27. if __name__ == "__main__":
  28. import time
  29. import cereal.messaging as messaging
  30. sendcan = messaging.pub_sock('sendcan')
  31. logcan = messaging.sub_sock('can')
  32. time.sleep(1)
  33. # honda bosch radar disable
  34. disabled = disable_ecu(logcan, sendcan, bus=1, addr=0x18DAB0F1, com_cont_req=b'\x28\x83\x03', timeout=0.5, debug=False)
  35. print(f"disabled: {disabled}")