summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStanley Huang <stanleyhuangyc@gmail.com>2015-05-08 23:15:54 +1000
committerStanley Huang <stanleyhuangyc@gmail.com>2015-05-08 23:15:54 +1000
commiteb4b45659858c8eee243e933aa5ae19467b57c26 (patch)
tree070fe47b2217ae9be0451ccba50a11ba2ad4f93c
parent8f7726738d17aea2c92f0e5ea27b6275ce601f68 (diff)
download2021-arduino-obd-eb4b45659858c8eee243e933aa5ae19467b57c26.tar.gz
2021-arduino-obd-eb4b45659858c8eee243e933aa5ae19467b57c26.tar.bz2
2021-arduino-obd-eb4b45659858c8eee243e933aa5ae19467b57c26.zip
Add getVIN() for retrieving VIN as string
-rw-r--r--libraries/OBD/OBD.cpp22
-rw-r--r--libraries/OBD/OBD.h2
2 files changed, 23 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();
diff --git a/libraries/OBD/OBD.h b/libraries/OBD/OBD.h
index 362c1bb..dcd30fb 100644
--- a/libraries/OBD/OBD.h
+++ b/libraries/OBD/OBD.h
@@ -138,6 +138,8 @@ public:
virtual void clearDTC();
// get battery voltage (in 0.1V, e.g. 125 for 12.5V, works without ECU)
virtual float getVoltage();
+ // get VIN as a string, buffer length should be >= OBD_RECV_BUF_SIZE
+ virtual bool getVIN(char* buffer);
// send query for specified PID
virtual void sendQuery(byte pid);
// retrive and parse the response of specifie PID