summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStanley Huang <stanleyhuangyc@live.com>2016-06-27 19:01:23 +0800
committerStanley Huang <stanleyhuangyc@live.com>2016-06-27 19:01:23 +0800
commit23ea91258a34ab568c5dd2878f2eaa8a0dec6fe7 (patch)
tree7581a7fe8aa41dd5ceb747c81f8ce77673a48c92
parent3655eb4501a8c191a01fa03c74a8f562d664a23e (diff)
download2021-arduino-obd-23ea91258a34ab568c5dd2878f2eaa8a0dec6fe7.tar.gz
2021-arduino-obd-23ea91258a34ab568c5dd2878f2eaa8a0dec6fe7.tar.bz2
2021-arduino-obd-23ea91258a34ab568c5dd2878f2eaa8a0dec6fe7.zip
Bugfix
-rw-r--r--libraries/OBD2UART/OBD2UART.cpp10
1 files changed, 6 insertions, 4 deletions
diff --git a/libraries/OBD2UART/OBD2UART.cpp b/libraries/OBD2UART/OBD2UART.cpp
index a079baa..c2a28fe 100644
--- a/libraries/OBD2UART/OBD2UART.cpp
+++ b/libraries/OBD2UART/OBD2UART.cpp
@@ -251,7 +251,7 @@ char* COBD::getResultValue(char* buf)
{
char* p = buf;
for (;;) {
- if (isdigit(*p)) {
+ if (isdigit(*p) || *p == '-') {
return p;
}
p = strchr(p, '\r');
@@ -426,7 +426,7 @@ float COBD::getTemperature()
char buf[32];
if (sendCommand("ATTEMP\r", buf, sizeof(buf)) > 0) {
char* p = getResultValue(buf);
- return (float)(atoi(p) + 12412) / 340;
+ if (p) return (float)(atoi(p) + 12412) / 340;
}
else {
return -1000;
@@ -435,9 +435,10 @@ float COBD::getTemperature()
bool COBD::readAccel(int& x, int& y, int& z)
{
- char buf[64];
+ char buf[32];
if (sendCommand("ATACL\r", buf, sizeof(buf)) > 0) do {
char* p = getResultValue(buf);
+ if (!p) break;
x = atoi(p++);
if (!(p = strchr(p, ','))) break;
y = atoi(++p);
@@ -450,9 +451,10 @@ bool COBD::readAccel(int& x, int& y, int& z)
bool COBD::readGyro(int& x, int& y, int& z)
{
- char buf[64];
+ char buf[32];
if (sendCommand("ATGYRO\r", buf, sizeof(buf)) > 0) do {
char* p = getResultValue(buf);
+ if (!p) break;
x = atoi(p++);
if (!(p = strchr(p, ','))) break;
y = atoi(++p);