diff options
author | Stanley Huang <stanleyhuangyc@gmail.com> | 2014-03-17 14:51:24 +0800 |
---|---|---|
committer | Stanley Huang <stanleyhuangyc@gmail.com> | 2014-03-17 14:51:24 +0800 |
commit | 49882cea4e2cb134c990963110cd5c9714462460 (patch) | |
tree | c042935ed70530eca7c3863265617ee1ec647de3 /libraries/OBD/OBD.cpp | |
parent | 3e44e8f47c9f8cbbca19d05e2ff0d53565bc1a82 (diff) | |
parent | d4f3d7e28e1694f805ec8d010f67ee8fefa376d7 (diff) | |
download | 2021-arduino-obd-49882cea4e2cb134c990963110cd5c9714462460.tar.gz 2021-arduino-obd-49882cea4e2cb134c990963110cd5c9714462460.tar.bz2 2021-arduino-obd-49882cea4e2cb134c990963110cd5c9714462460.zip |
Merge branch 'master' of https://github.com/stanleyhuangyc/ArduinoOBD
Diffstat (limited to 'libraries/OBD/OBD.cpp')
-rw-r--r-- | libraries/OBD/OBD.cpp | 100 |
1 files changed, 50 insertions, 50 deletions
diff --git a/libraries/OBD/OBD.cpp b/libraries/OBD/OBD.cpp index 8bcdb9c..3dba269 100644 --- a/libraries/OBD/OBD.cpp +++ b/libraries/OBD/OBD.cpp @@ -153,20 +153,20 @@ int COBD::normalizeData(byte pid, char* data) char* COBD::getResponse(byte& pid, char* buffer)
{
- while (receive(buffer, OBD_TIMEOUT_SHORT) > 0) {
- char *p = buffer;
- while ((p = strstr(p, "41 "))) {
- p += 3;
- byte curpid = hex2uint8(p);
- if (pid == 0) pid = curpid;
- if (curpid == pid) {
- errors = 0;
- p += 2;
- if (*p == ' ')
- return p + 1;
- }
- }
- }
+ while (receive(buffer, OBD_TIMEOUT_SHORT) > 0) {
+ char *p = buffer;
+ while ((p = strstr(p, "41 "))) {
+ p += 3;
+ byte curpid = hex2uint8(p);
+ if (pid == 0) pid = curpid;
+ if (curpid == pid) {
+ errors = 0;
+ p += 2;
+ if (*p == ' ')
+ return p + 1;
+ }
+ }
+ }
return 0;
}
@@ -185,13 +185,13 @@ bool COBD::getResult(byte& pid, int& result) void COBD::setProtocol(byte h)
{
- if (h == -1) {
- write("ATSP00\r");
- } else {
- char cmd[8];
- sprintf(cmd, "ATSP%d\r", h);
- write(cmd);
- }
+ if (h == -1) {
+ write("ATSP00\r");
+ } else {
+ char cmd[8];
+ sprintf(cmd, "ATSP%d\r", h);
+ write(cmd);
+ }
}
void COBD::sleep()
@@ -201,7 +201,7 @@ void COBD::sleep() void COBD::wakeup()
{
- write('\r');
+ write('\r');
}
bool COBD::isValidPID(byte pid)
@@ -262,7 +262,7 @@ void COBD::recover() bool COBD::init(byte protocol)
{
- const char *initcmd[] = {"ATZ\r","ATE0\r","ATL1\r"};
+ const char *initcmd[] = {"ATZ\r","ATE0\r","ATL1\r"};
char buffer[OBD_RECV_BUF_SIZE];
m_state = OBD_CONNECTING;
@@ -279,30 +279,30 @@ bool COBD::init(byte protocol) delay(50);
}
if (protocol) {
- write("ATSP");
- write('0' + protocol);
- write('\r');
- receive(buffer);
- delay(50);
+ write("ATSP");
+ write('0' + protocol);
+ write('\r');
+ receive(buffer);
+ delay(50);
}
while (available()) read();
- // load pid map
- memset(pidmap, 0, sizeof(pidmap));
- for (byte i = 0; i < 4; i++) {
- byte pid = i * 0x20;
- sendQuery(pid);
- char* data = getResponse(pid, buffer);
- if (!data) break;
- data--;
- for (byte n = 0; n < 4; n++) {
- if (data[n * 3] != ' ')
- break;
- pidmap[i * 4 + n] = hex2uint8(data + n * 3 + 1);
- }
- delay(100);
- }
- while (available()) read();
+ // load pid map
+ memset(pidmap, 0, sizeof(pidmap));
+ for (byte i = 0; i < 4; i++) {
+ byte pid = i * 0x20;
+ sendQuery(pid);
+ char* data = getResponse(pid, buffer);
+ if (!data) break;
+ data--;
+ for (byte n = 0; n < 4; n++) {
+ if (data[n * 3] != ' ')
+ break;
+ pidmap[i * 4 + n] = hex2uint8(data + n * 3 + 1);
+ }
+ delay(100);
+ }
+ while (available()) read();
m_state = OBD_CONNECTED;
errors = 0;
@@ -451,12 +451,12 @@ void COBDI2C::loadData() uint16_t COBDI2C::getData(byte pid, int& result)
{
- byte n;
- for (n = 0; n < MAX_PIDS && obdPid[n] != pid; n++);
- if (n == MAX_PIDS)
- return -1;
-
- PID_INFO* pi = obdInfo + n;
+ byte n;
+ for (n = 0; n < MAX_PIDS && obdPid[n] != pid; n++);
+ if (n == MAX_PIDS)
+ return -1;
+
+ PID_INFO* pi = obdInfo + n;
switch (pid) {
case PID_RPM:
result = pi->value >> 2;
|