From eb4b45659858c8eee243e933aa5ae19467b57c26 Mon Sep 17 00:00:00 2001 From: Stanley Huang Date: Fri, 8 May 2015 23:15:54 +1000 Subject: Add getVIN() for retrieving VIN as string --- libraries/OBD/OBD.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'libraries/OBD/OBD.cpp') 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(); -- cgit v1.2.3