From 6eeb9120c5dd32b5d515a656421db4b405639447 Mon Sep 17 00:00:00 2001 From: Stanley Huang Date: Sat, 19 Sep 2015 16:18:01 +1000 Subject: Minor update --- libraries/OBD/OBD.cpp | 19 ++++++++++--------- libraries/OBD/OBD.h | 9 +++++---- 2 files changed, 15 insertions(+), 13 deletions(-) (limited to 'libraries') diff --git a/libraries/OBD/OBD.cpp b/libraries/OBD/OBD.cpp index c28c1f2..4242cf3 100644 --- a/libraries/OBD/OBD.cpp +++ b/libraries/OBD/OBD.cpp @@ -426,37 +426,38 @@ bool COBD::getGPSData(GPS_DATA* gdata) for (p = s; *p; p++) { char c = *p; if (c == ',' || c == '>' || c <= 0x0d) { + long value = atol(s); switch (index) { case 0: - gdata->date = (uint32_t)atol(s); + gdata->date = (uint32_t)value; break; case 1: - gdata->time = (uint32_t)atol(s); + gdata->time = (uint32_t)value; break; case 2: - gdata->lat = atol(s); + gdata->lat = value; break; case 3: - gdata->lon = atol(s); + gdata->lon = value; break; case 4: - gdata->alt = atoi(s); + gdata->alt = value; break; case 5: - gdata->speed = atof(s); + gdata->speed = value; break; case 6: - gdata->heading = atoi(s); + gdata->heading = value; break; case 7: - gdata->sat = atoi(s); + gdata->sat = value; break; } index++; s = p + 1; } } - return index > 7; + return index >= 4; } #ifdef DEBUG diff --git a/libraries/OBD/OBD.h b/libraries/OBD/OBD.h index 74e4225..90944e9 100644 --- a/libraries/OBD/OBD.h +++ b/libraries/OBD/OBD.h @@ -12,6 +12,7 @@ #define OBD_TIMEOUT_SHORT 2000 /* ms */ #define OBD_TIMEOUT_LONG 7000 /* ms */ +#define OBD_TIMEOUT_GPS 200 /* ms */ #define OBD_SERIAL_BAUDRATE 38400 #define OBD_RECV_BUF_SIZE 128 @@ -98,10 +99,10 @@ typedef struct { uint32_t time; int32_t lat; int32_t lon; - int alt; - float speed; - int heading; - int sat; + int16_t alt; + uint8_t speed; + uint8_t sat; + int16_t heading; } GPS_DATA; uint16_t hex2uint16(const char *p); -- cgit v1.2.3