summaryrefslogtreecommitdiff
path: root/libraries
diff options
context:
space:
mode:
authorStanley Huang <stanleyhuangyc@gmail.com>2019-06-27 17:08:05 +1000
committerStanley Huang <stanleyhuangyc@gmail.com>2019-06-27 17:08:05 +1000
commit1072457ae84fdba46e731ec71b4d6eb52154e64b (patch)
tree33258c0799d1bbde924b40270fbdb1c780580880 /libraries
parent26b42d6df6622198c2f3e6c76b6880aa3688c6a1 (diff)
download2021-arduino-obd-1072457ae84fdba46e731ec71b4d6eb52154e64b.tar.gz
2021-arduino-obd-1072457ae84fdba46e731ec71b4d6eb52154e64b.tar.bz2
2021-arduino-obd-1072457ae84fdba46e731ec71b4d6eb52154e64b.zip
Update
Diffstat (limited to 'libraries')
-rw-r--r--libraries/OBD2UART/OBD2UART.cpp38
-rw-r--r--libraries/OBD2UART/OBD2UART.h4
2 files changed, 15 insertions, 27 deletions
diff --git a/libraries/OBD2UART/OBD2UART.cpp b/libraries/OBD2UART/OBD2UART.cpp
index 76968b9..89ca2b1 100644
--- a/libraries/OBD2UART/OBD2UART.cpp
+++ b/libraries/OBD2UART/OBD2UART.cpp
@@ -1,8 +1,8 @@
/*************************************************************************
* Arduino Library for Freematics OBD-II UART Adapter
* Distributed under BSD License
-* Visit http://freematics.com for more information
-* (C)2012-2016 Stanley Huang <stanleyhuangyc@gmail.com>
+* Visit https://freematics.com for more information
+* (C)2012-2018 Stanley Huang <stanley@freematics.com.au>
*************************************************************************/
#include "OBD2UART.h"
@@ -417,7 +417,6 @@ bool COBD::init(OBD_PROTOCOLS protocol)
byte stage;
m_state = OBD_DISCONNECTED;
-
for (byte n = 0; n < 2; n++) {
stage = 0;
if (n != 0) reset();
@@ -442,38 +441,27 @@ bool COBD::init(OBD_PROTOCOLS protocol)
}
stage = 3;
// load pid map
- memset(pidmap, 0, sizeof(pidmap));
- bool success = false;
+ memset(pidmap, 0xff, sizeof(pidmap));
for (byte i = 0; i < 4; i++) {
byte pid = i * 0x20;
sprintf(buffer, "%02X%02X\r", dataMode, pid);
delay(10);
write(buffer);
- if (receive(buffer, sizeof(buffer), OBD_TIMEOUT_LONG) > 0) {
- if (checkErrorMessage(buffer)) {
- break;
- }
- char *p = buffer;
- while ((p = strstr(p, "41 "))) {
- p += 3;
- if (hex2uint8(p) == pid) {
- p += 2;
- for (byte n = 0; n < 4 && *(p + n * 3) == ' '; n++) {
- pidmap[i * 4 + n] = hex2uint8(p + n * 3 + 1);
- }
- success = true;
+ delay(10);
+ if (!receive(buffer, sizeof(buffer), OBD_TIMEOUT_LONG) || checkErrorMessage(buffer)) break;
+ for (char *p = buffer; (p = strstr(p, "41 ")); ) {
+ p += 3;
+ if (hex2uint8(p) == pid) {
+ p += 2;
+ for (byte n = 0; n < 4 && *(p + n * 3) == ' '; n++) {
+ pidmap[i * 4 + n] = hex2uint8(p + n * 3 + 1);
}
}
- } else {
- break;
}
}
- if (success) {
- stage = 0xff;
- break;
- }
+ break;
}
- if (stage == 0xff) {
+ if (stage == 3) {
m_state = OBD_CONNECTED;
errors = 0;
return true;
diff --git a/libraries/OBD2UART/OBD2UART.h b/libraries/OBD2UART/OBD2UART.h
index 2674274..38688fa 100644
--- a/libraries/OBD2UART/OBD2UART.h
+++ b/libraries/OBD2UART/OBD2UART.h
@@ -1,8 +1,8 @@
/*************************************************************************
* Arduino Library for Freematics OBD-II UART Adapter
* Distributed under BSD License
-* Visit http://freematics.com for more information
-* (C)2012-2016 Stanley Huang <stanleyhuangyc@gmail.com>
+* Visit https://freematics.com for more information
+* (C)2012-2019 Stanley Huang <stanley@freematics.com.au>
*************************************************************************/
#include <Arduino.h>