2023-09-06 07:33:26 +08:00
|
|
|
#!/usr/bin/env python3
|
2023-08-21 11:49:55 +08:00
|
|
|
from openpilot.selfdrive.car.isotp_parallel_query import IsoTpParallelQuery
|
2023-12-07 09:27:51 +08:00
|
|
|
from openpilot.common.swaglog import cloudlog
|
2021-09-14 13:03:08 +08:00
|
|
|
|
|
|
|
EXT_DIAG_REQUEST = b'\x10\x03'
|
|
|
|
EXT_DIAG_RESPONSE = b'\x50\x03'
|
|
|
|
|
|
|
|
COM_CONT_RESPONSE = b''
|
|
|
|
|
2022-07-14 03:43:36 +08:00
|
|
|
|
2023-07-24 09:34:35 +08:00
|
|
|
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):
|
2021-09-14 13:03:08 +08:00
|
|
|
"""Silence an ECU by disabling sending and receiving messages using UDS 0x28.
|
|
|
|
The ECU will stay silent as long as openpilot keeps sending Tester Present.
|
|
|
|
|
|
|
|
This is used to disable the radar in some cars. Openpilot will emulate the radar.
|
|
|
|
WARNING: THIS DISABLES AEB!"""
|
2023-07-24 09:34:35 +08:00
|
|
|
cloudlog.warning(f"ecu disable {hex(addr), sub_addr} ...")
|
2021-09-14 13:03:08 +08:00
|
|
|
|
|
|
|
for i in range(retry):
|
|
|
|
try:
|
2023-07-24 09:34:35 +08:00
|
|
|
query = IsoTpParallelQuery(sendcan, logcan, bus, [(addr, sub_addr)], [EXT_DIAG_REQUEST], [EXT_DIAG_RESPONSE], debug=debug)
|
2021-09-14 13:03:08 +08:00
|
|
|
|
|
|
|
for _, _ in query.get_data(timeout).items():
|
|
|
|
cloudlog.warning("communication control disable tx/rx ...")
|
|
|
|
|
2023-07-24 09:34:35 +08:00
|
|
|
query = IsoTpParallelQuery(sendcan, logcan, bus, [(addr, sub_addr)], [com_cont_req], [COM_CONT_RESPONSE], debug=debug)
|
2021-09-14 13:03:08 +08:00
|
|
|
query.get_data(0)
|
|
|
|
|
|
|
|
cloudlog.warning("ecu disabled")
|
|
|
|
return True
|
2022-07-14 03:43:36 +08:00
|
|
|
|
2021-09-14 13:03:08 +08:00
|
|
|
except Exception:
|
|
|
|
cloudlog.exception("ecu disable exception")
|
|
|
|
|
2023-05-18 13:19:49 +08:00
|
|
|
cloudlog.error(f"ecu disable retry ({i + 1}) ...")
|
|
|
|
cloudlog.error("ecu disable failed")
|
2021-09-14 13:03:08 +08:00
|
|
|
return False
|
2022-07-14 03:43:36 +08:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
import time
|
|
|
|
import cereal.messaging as messaging
|
|
|
|
sendcan = messaging.pub_sock('sendcan')
|
|
|
|
logcan = messaging.sub_sock('can')
|
|
|
|
time.sleep(1)
|
|
|
|
|
|
|
|
# honda bosch radar disable
|
|
|
|
disabled = disable_ecu(logcan, sendcan, bus=1, addr=0x18DAB0F1, com_cont_req=b'\x28\x83\x03', timeout=0.5, debug=False)
|
|
|
|
print(f"disabled: {disabled}")
|