summaryrefslogtreecommitdiff
path: root/libraries/OBD
diff options
context:
space:
mode:
authorStanley Huang <stanleyhuangyc@gmail.com>2015-11-28 15:16:50 +1100
committerStanley Huang <stanleyhuangyc@gmail.com>2015-11-28 15:16:50 +1100
commit6d3e3a5b5261360462d0e755c9e0967e2a0514bb (patch)
tree768422035ee90aed15a19f973aa6e3f5f3281c13 /libraries/OBD
parente12fc5e3f0bec08274794f954fa114323c874e09 (diff)
download2021-arduino-obd-6d3e3a5b5261360462d0e755c9e0967e2a0514bb.tar.gz
2021-arduino-obd-6d3e3a5b5261360462d0e755c9e0967e2a0514bb.tar.bz2
2021-arduino-obd-6d3e3a5b5261360462d0e755c9e0967e2a0514bb.zip
Update OBD library
Diffstat (limited to 'libraries/OBD')
-rw-r--r--libraries/OBD/OBD.cpp22
1 files changed, 7 insertions, 15 deletions
diff --git a/libraries/OBD/OBD.cpp b/libraries/OBD/OBD.cpp
index 5a8248e..277eaf1 100644
--- a/libraries/OBD/OBD.cpp
+++ b/libraries/OBD/OBD.cpp
@@ -224,16 +224,13 @@ bool COBD::setProtocol(OBD_PROTOCOLS h)
void COBD::sleep()
{
char buf[32];
- write("ATLP\r");
- receive(buf, sizeof(buf));
+ sendCommand("ATLP\r", buf, sizeof(buf));
}
float COBD::getVoltage()
{
char buf[32];
- write("ATRV\r");
- byte n = receive(buf, sizeof(buf));
- if (n > 0) {
+ if (sendCommand("ATRV\r", buf, sizeof(buf)) > 0) {
return atof(buf);
}
return 0;
@@ -241,8 +238,7 @@ float COBD::getVoltage()
bool COBD::getVIN(char* buffer, byte bufsize)
{
- write("0902\r");
- if (receive(buffer, bufsize, OBD_TIMEOUT_LONG)) {
+ if (sendCommand("0902\r", buffer, bufsize)) {
char *p = strstr(buffer, "0: 49 02");
if (p) {
char *q = buffer;
@@ -315,8 +311,7 @@ byte COBD::receive(char* buffer, byte bufsize, int timeout)
void COBD::recover()
{
char buf[16];
- write("AT\r");
- receive(buf, sizeof(buf));
+ sendCommand("AT\r", buf, sizeof(buf));
}
bool COBD::init(OBD_PROTOCOLS protocol)
@@ -397,22 +392,19 @@ bool COBD::setBaudRate(unsigned long baudrate)
bool COBD::initGPS(unsigned long baudrate)
{
char buf[32];
- sprintf(buf, "ATBR2 %lu\r", baudrate);
- write(buf);
- return (receive(buf, sizeof(buf)) && strstr(buf, "OK"));
+ return (sendCommand(buf, buf, sizeof(buf)) && strstr(buf, "OK"));
}
bool COBD::getGPSData(GPS_DATA* gdata)
{
char buf[128];
char *p;
- write("ATGPS\r");
- if (receive(buf, sizeof(buf)) == 0 || !(p = strstr(buf, "$GPS")))
+ if (sendCommand("ATGPS\r", buf, sizeof(buf)) == 0 || !(p = strstr(buf, "$GPS")))
return false;
byte index = 0;
char *s = buf;
- s = p + 5;
+ s = *(p + 4) == '$' ? p + 9 : p + 5;
for (p = s; *p; p++) {
char c = *p;
if (c == ',' || c == '>' || c <= 0x0d) {