From 32d963c5f7377a80e347b11d8da19c95bee676c7 Mon Sep 17 00:00:00 2001 From: Jason Joyner Date: Wed, 13 Jan 2021 23:24:31 -0500 Subject: [PATCH 1/7] Added function to clear diagnostic trouble codes (DTC) using Service 04 functionality. --- src/OBD2.cpp | 30 ++++++++++++++++++++++++++++++ src/OBD2.h | 2 ++ 2 files changed, 32 insertions(+) diff --git a/src/OBD2.cpp b/src/OBD2.cpp index bece249..83dc740 100644 --- a/src/OBD2.cpp +++ b/src/OBD2.cpp @@ -695,6 +695,36 @@ int OBD2Class::supportedPidsRead() return 1; } +int OBD2Class::clearAllStoredDTC() { + //Function clears stored Diagnostic Trouble Codes (DTC) + + // make sure at least 60 ms have passed since the last response + unsigned long lastResponseDelta = millis() - _lastPidResponseMillis; + if (lastResponseDelta < 60) { + delay(60 - lastResponseDelta); + } + + for (int retries = 10; retries > 0; retries--) { + if (_useExtendedAddressing) { + CAN.beginExtendedPacket(0x18db33f1, 8); + } + else { + CAN.beginPacket(0x7df, 8); + } + CAN.write(0x00); // number of additional bytes + CAN.write(0x04); // Mode / Service 4, for clearing DTC + if (CAN.endPacket()) { + // send success + break; + } + else if (retries <= 1) { + return 0; + } + } + + return 0; +} + int OBD2Class::pidRead(uint8_t mode, uint8_t pid, void* data, int length) { // make sure at least 60 ms have passed since the last response diff --git a/src/OBD2.h b/src/OBD2.h index 52312e0..0605763 100644 --- a/src/OBD2.h +++ b/src/OBD2.h @@ -131,6 +131,8 @@ class OBD2Class { void setTimeout(unsigned long timeout); + int clearAllStoredDTC(); + private: int supportedPidsRead(); From d258961c2085b0c8111306e5add44f15c5aa0b72 Mon Sep 17 00:00:00 2001 From: Jason Joyner Date: Wed, 13 Jan 2021 23:24:31 -0500 Subject: [PATCH 2/7] Added function to clear diagnostic trouble codes (DTC) using Service 04 functionality. Added clearAllStoredDTC function to keywords.txt file Corrected return value of clearAllStoredDTC function to return 1 upon success --- keywords.txt | 1 + src/OBD2.cpp | 30 ++++++++++++++++++++++++++++++ src/OBD2.h | 2 ++ 3 files changed, 33 insertions(+) diff --git a/keywords.txt b/keywords.txt index 3a3ec6d..235d70d 100644 --- a/keywords.txt +++ b/keywords.txt @@ -24,6 +24,7 @@ pidReadRaw KEYWORD2 vinRead KEYWORD2 ecuNameRead KEYWORD2 setTimeout KEYWORD2 +clearAllStoredDTC KEYWORD2 ####################################### # Constants (LITERAL1) diff --git a/src/OBD2.cpp b/src/OBD2.cpp index bece249..83dc740 100644 --- a/src/OBD2.cpp +++ b/src/OBD2.cpp @@ -695,6 +695,36 @@ int OBD2Class::supportedPidsRead() return 1; } +int OBD2Class::clearAllStoredDTC() { + //Function clears stored Diagnostic Trouble Codes (DTC) + + // make sure at least 60 ms have passed since the last response + unsigned long lastResponseDelta = millis() - _lastPidResponseMillis; + if (lastResponseDelta < 60) { + delay(60 - lastResponseDelta); + } + + for (int retries = 10; retries > 0; retries--) { + if (_useExtendedAddressing) { + CAN.beginExtendedPacket(0x18db33f1, 8); + } + else { + CAN.beginPacket(0x7df, 8); + } + CAN.write(0x00); // number of additional bytes + CAN.write(0x04); // Mode / Service 4, for clearing DTC + if (CAN.endPacket()) { + // send success + break; + } + else if (retries <= 1) { + return 0; + } + } + + return 0; +} + int OBD2Class::pidRead(uint8_t mode, uint8_t pid, void* data, int length) { // make sure at least 60 ms have passed since the last response diff --git a/src/OBD2.h b/src/OBD2.h index 52312e0..0605763 100644 --- a/src/OBD2.h +++ b/src/OBD2.h @@ -131,6 +131,8 @@ class OBD2Class { void setTimeout(unsigned long timeout); + int clearAllStoredDTC(); + private: int supportedPidsRead(); From 5552f83957a9bffca6b394f1ee4918b4c59aeac2 Mon Sep 17 00:00:00 2001 From: Sandeep Mistry Date: Sat, 23 Jan 2021 10:49:40 -0500 Subject: [PATCH 3/7] Update src/OBD2.cpp --- src/OBD2.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/OBD2.cpp b/src/OBD2.cpp index 7654002..040d61d 100644 --- a/src/OBD2.cpp +++ b/src/OBD2.cpp @@ -707,8 +707,7 @@ int OBD2Class::clearAllStoredDTC() { for (int retries = 10; retries > 0; retries--) { if (_useExtendedAddressing) { CAN.beginExtendedPacket(0x18db33f1, 8); - } - else { +} else { CAN.beginPacket(0x7df, 8); } CAN.write(0x00); // number of additional bytes From 3db9dcb3615cecd31c198c78d48f8fa10fc300ff Mon Sep 17 00:00:00 2001 From: Sandeep Mistry Date: Sat, 23 Jan 2021 10:49:46 -0500 Subject: [PATCH 4/7] Update src/OBD2.cpp --- src/OBD2.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/OBD2.cpp b/src/OBD2.cpp index 040d61d..f00f00d 100644 --- a/src/OBD2.cpp +++ b/src/OBD2.cpp @@ -715,8 +715,7 @@ int OBD2Class::clearAllStoredDTC() { if (CAN.endPacket()) { // send success break; - } - else if (retries <= 1) { +} else if (retries <= 1) { return 0; } } From 2bd1ee2c537acabaffa86dc1e36476e786af6c12 Mon Sep 17 00:00:00 2001 From: Sandeep Mistry Date: Sat, 23 Jan 2021 10:51:50 -0500 Subject: [PATCH 5/7] Update src/OBD2.cpp --- src/OBD2.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/OBD2.cpp b/src/OBD2.cpp index f00f00d..254c782 100644 --- a/src/OBD2.cpp +++ b/src/OBD2.cpp @@ -695,7 +695,8 @@ int OBD2Class::supportedPidsRead() return 1; } -int OBD2Class::clearAllStoredDTC() { +int OBD2Class::clearAllStoredDTC() +{ //Function clears stored Diagnostic Trouble Codes (DTC) // make sure at least 60 ms have passed since the last response From 063daf7fb74d23a50be4340a84cbcaebfa5faaf6 Mon Sep 17 00:00:00 2001 From: Sandeep Mistry Date: Sat, 23 Jan 2021 10:51:59 -0500 Subject: [PATCH 6/7] Update src/OBD2.cpp --- src/OBD2.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OBD2.cpp b/src/OBD2.cpp index 254c782..eb55a3e 100644 --- a/src/OBD2.cpp +++ b/src/OBD2.cpp @@ -708,7 +708,7 @@ int OBD2Class::clearAllStoredDTC() for (int retries = 10; retries > 0; retries--) { if (_useExtendedAddressing) { CAN.beginExtendedPacket(0x18db33f1, 8); -} else { + } else { CAN.beginPacket(0x7df, 8); } CAN.write(0x00); // number of additional bytes From a9681e2b6455c4f16cfb8ed78b9144ca32de831b Mon Sep 17 00:00:00 2001 From: Sandeep Mistry Date: Sat, 23 Jan 2021 10:52:06 -0500 Subject: [PATCH 7/7] Update src/OBD2.cpp --- src/OBD2.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OBD2.cpp b/src/OBD2.cpp index eb55a3e..8fd329c 100644 --- a/src/OBD2.cpp +++ b/src/OBD2.cpp @@ -716,7 +716,7 @@ int OBD2Class::clearAllStoredDTC() if (CAN.endPacket()) { // send success break; -} else if (retries <= 1) { + } else if (retries <= 1) { return 0; } }