summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStanley Huang <stanleyhuangyc@gmail.com>2014-03-09 12:26:36 +0800
committerStanley Huang <stanleyhuangyc@gmail.com>2014-03-09 12:26:36 +0800
commit2a4d5373475f57247c547c5224477a85f1219a23 (patch)
tree903c97d7fc0e871b4bdc58df79cec4d758c3b968
parentc2aa5159fac7169cf3b6067f15ed8e1cb2c56288 (diff)
download2021-arduino-obd-2a4d5373475f57247c547c5224477a85f1219a23.tar.gz
2021-arduino-obd-2a4d5373475f57247c547c5224477a85f1219a23.tar.bz2
2021-arduino-obd-2a4d5373475f57247c547c5224477a85f1219a23.zip
Improve timeout processing
-rw-r--r--libraries/OBD/OBD.cpp32
1 files changed, 16 insertions, 16 deletions
diff --git a/libraries/OBD/OBD.cpp b/libraries/OBD/OBD.cpp
index c7c6024..a3186ea 100644
--- a/libraries/OBD/OBD.cpp
+++ b/libraries/OBD/OBD.cpp
@@ -169,22 +169,22 @@ int COBD::normalizeData(byte pid, char* data)
char* COBD::getResponse(byte& pid, char* buffer)
{
- receive(buffer);
- char *p = buffer;
- while ((p = strstr(p, "41 "))) {
- p += 3;
- byte curpid = hex2uint8(p);
- if (pid == 0) pid = curpid;
- if (curpid == pid) {
- errors = 0;
- p += 2;
- if (*p == ' ')
- return p + 1;
- } else {
- receive(buffer);
- p = buffer;
- }
- }
+ int timeout = OBD_TIMEOUT_SHORT;
+ while (receive(buffer, timeout) > 0) {
+ char *p = buffer;
+ while ((p = strstr(p, "41 "))) {
+ p += 3;
+ byte curpid = hex2uint8(p);
+ if (pid == 0) pid = curpid;
+ if (curpid == pid) {
+ errors = 0;
+ p += 2;
+ if (*p == ' ')
+ return p + 1;
+ }
+ }
+ timeout = 0;
+ }
return 0;
}