diff options
author | Stanley Huang <stanleyhuangyc@gmail.com> | 2015-05-08 23:15:54 +1000 |
---|---|---|
committer | Stanley Huang <stanleyhuangyc@gmail.com> | 2015-05-08 23:15:54 +1000 |
commit | eb4b45659858c8eee243e933aa5ae19467b57c26 (patch) | |
tree | 070fe47b2217ae9be0451ccba50a11ba2ad4f93c /libraries/OBD/OBD.cpp | |
parent | 8f7726738d17aea2c92f0e5ea27b6275ce601f68 (diff) | |
download | 2021-arduino-obd-eb4b45659858c8eee243e933aa5ae19467b57c26.tar.gz 2021-arduino-obd-eb4b45659858c8eee243e933aa5ae19467b57c26.tar.bz2 2021-arduino-obd-eb4b45659858c8eee243e933aa5ae19467b57c26.zip |
Add getVIN() for retrieving VIN as string
Diffstat (limited to 'libraries/OBD/OBD.cpp')
-rw-r--r-- | libraries/OBD/OBD.cpp | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/libraries/OBD/OBD.cpp b/libraries/OBD/OBD.cpp index 8ee5ae9..b431297 100644 --- a/libraries/OBD/OBD.cpp +++ b/libraries/OBD/OBD.cpp @@ -261,6 +261,26 @@ float COBD::getVoltage() return 0; } +bool COBD::getVIN(char* buffer) +{ + if (sendCommand("0902\r", buffer)) { + char *p = strstr(buffer, "0: 49 02"); + if (p) { + char *q = buffer; + p += 10; + do { + for (++p; *p == ' '; p += 3) { + if (*q = hex2uint8(p + 1)) q++; + } + p = strchr(p, ':'); + } while(p); + *q = 0; + return true; + } + } + return false; +} + bool COBD::isValidPID(byte pid) { if (pid >= 0x7f) @@ -380,7 +400,7 @@ bool COBD::setBaudRate(unsigned long baudrate) OBDUART.print("ATBR1 "); OBDUART.print(baudrate); OBDUART.print('\r'); - delay(100); + delay(50); OBDUART.end(); OBDUART.begin(baudrate); while (available()) read(); |