diff options
author | Stanley Huang <stanleyhuangyc@gmail.com> | 2017-01-30 23:42:15 +1100 |
---|---|---|
committer | Stanley Huang <stanleyhuangyc@gmail.com> | 2017-01-30 23:42:15 +1100 |
commit | 8ce5b2fdea4f8321f3bdee8e43c4ac21b2826bbb (patch) | |
tree | 538f1ebd3fdf0af83c97a9950aa608a5b82d8e07 /libraries/OBD/OBD.cpp | |
parent | fb398f95a37434015e770991cdda6b821a97c84d (diff) | |
download | 2021-arduino-obd-8ce5b2fdea4f8321f3bdee8e43c4ac21b2826bbb.tar.gz 2021-arduino-obd-8ce5b2fdea4f8321f3bdee8e43c4ac21b2826bbb.tar.bz2 2021-arduino-obd-8ce5b2fdea4f8321f3bdee8e43c4ac21b2826bbb.zip |
Fixed manual setting protocol issue
Diffstat (limited to 'libraries/OBD/OBD.cpp')
-rw-r--r-- | libraries/OBD/OBD.cpp | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/libraries/OBD/OBD.cpp b/libraries/OBD/OBD.cpp index 88ed733..5dc22a2 100644 --- a/libraries/OBD/OBD.cpp +++ b/libraries/OBD/OBD.cpp @@ -388,16 +388,19 @@ void COBD::recover() bool COBD::init(OBD_PROTOCOLS protocol) { - const char PROGMEM *initcmd[] = {PSTR("ATZ\r"),PSTR("ATE0\r"),PSTR("ATL1\r"),PSTR("ATSP%02u\r")}; + const char *initcmd[] = {"ATZ\r", "ATE0\r", "ATL1\r"}; char buffer[64]; for (unsigned char i = 0; i < sizeof(initcmd) / sizeof(initcmd[0]); i++) { - sprintf_P(buffer, initcmd[i], protocol); -#ifdef DEBUG - debugOutput(buffer); -#endif - write(buffer); - if (receive(buffer, sizeof(buffer), OBD_TIMEOUT_LONG) == 0 || (i > 0 && !strstr(buffer, "OK"))) { + write(initcmd[i]); + if (receive(buffer, sizeof(buffer), OBD_TIMEOUT_LONG) == 0) { + m_state = OBD_DISCONNECTED; + return false; + } + } + if (protocol != PROTO_AUTO) { + sprintf_P(buffer, PSTR("ATSP%u\r"), protocol); + if (receive(buffer, sizeof(buffer), OBD_TIMEOUT_LONG) == 0 && !strstr(buffer, "OK")) { m_state = OBD_DISCONNECTED; return false; } |