summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStanley Huang <stanleyhuangyc@gmail.com>2013-08-26 16:38:25 +0800
committerStanley Huang <stanleyhuangyc@gmail.com>2013-08-26 16:38:25 +0800
commit1e98599609d92ce1e209ccd9d872a5a3f1f2158d (patch)
treee7a6c60d8cd0f9265c6adcf83fbc3365d5f73f9e
parentf1db53b2ded61c7a30004d7d68497304f1448534 (diff)
download2021-arduino-obd-1e98599609d92ce1e209ccd9d872a5a3f1f2158d.tar.gz
2021-arduino-obd-1e98599609d92ce1e209ccd9d872a5a3f1f2158d.tar.bz2
2021-arduino-obd-1e98599609d92ce1e209ccd9d872a5a3f1f2158d.zip
improve communication stability
-rw-r--r--libraries/OBD/OBD.cpp34
1 files 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;
}