From 1e98599609d92ce1e209ccd9d872a5a3f1f2158d Mon Sep 17 00:00:00 2001 From: Stanley Huang Date: Mon, 26 Aug 2013 16:38:25 +0800 Subject: improve communication stability --- libraries/OBD/OBD.cpp | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/libraries/OBD/OBD.cpp b/libraries/OBD/OBD.cpp index 28846fd..fcb3c92 100644 --- a/libraries/OBD/OBD.cpp +++ b/libraries/OBD/OBD.cpp @@ -91,8 +91,8 @@ bool COBD::available() char COBD::read() { - char c = OBDUART.read(); - return c; + char c = OBDUART.read(); + return c; } void COBD::write(const char* s) @@ -147,7 +147,7 @@ int COBD::normalizeData(byte pid, char* data) char* COBD::getResponse(byte& pid, char* buffer) { unsigned long startTime = millis(); - static const char responseSign[3] = {'4', '1', ' '}; + static const char responseSign[3] = {'4', '1', ' '}; byte i = 0; for (;;) { @@ -180,20 +180,20 @@ char* COBD::getResponse(byte& pid, char* buffer) } buffer[i] = 0; - if (i > 6) { - char *p = buffer; - while ((p = strstr(p, responseSign))) { - p += 3; - byte curpid = hex2uint8(p); - if (pid == 0) pid = curpid; - if (curpid == pid) { - errors = 0; - p += 2; - if (*p == ' ') - return p + 1; - } - }; - } + if (i > 6) { + char *p = buffer; + while ((p = strstr(p, responseSign))) { + p += 3; + byte curpid = hex2uint8(p); + if (pid == 0) pid = curpid; + if (curpid == pid) { + errors = 0; + p += 2; + if (*p == ' ') + return p + 1; + } + }; + } return 0; } -- cgit v1.2.3