From de178ea79ccb66f0ed15f0ea98e93068b2e41ca6 Mon Sep 17 00:00:00 2001 From: Greg Hogan Date: Tue, 22 Feb 2022 16:14:59 -0800 Subject: [PATCH] script to clear DTCs --- selfdrive/debug/clear_dtc.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100755 selfdrive/debug/clear_dtc.py diff --git a/selfdrive/debug/clear_dtc.py b/selfdrive/debug/clear_dtc.py new file mode 100755 index 000000000..f4d38367b --- /dev/null +++ b/selfdrive/debug/clear_dtc.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 +import sys +from subprocess import check_output, CalledProcessError +from panda import Panda +from panda.python.uds import UdsClient, MessageTimeoutError, SESSION_TYPE, DTC_GROUP_TYPE + +try: + check_output(["pidof", "boardd"]) + print("boardd is running, please kill openpilot before running this script! (aborted)") + sys.exit(1) +except CalledProcessError as e: + if e.returncode != 1: # 1 == no process found (boardd not running) + raise e + +panda = Panda() +panda.set_safety_mode(Panda.SAFETY_ELM327) +address = 0x7DF # functional (broadcast) address +uds_client = UdsClient(panda, address, bus=0, debug=False) +print("extended diagnostic session ...") +try: + uds_client.diagnostic_session_control(SESSION_TYPE.EXTENDED_DIAGNOSTIC) +except MessageTimeoutError: + pass # functional address isn't properly handled so a timeout occurs +print("clear diagnostic info ...") +try: + uds_client.clear_diagnostic_information(DTC_GROUP_TYPE.ALL) +except MessageTimeoutError: + pass # functional address isn't properly handled so a timeout occurs +print("") +print("you may need to power cycle your vehicle now")