Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
stanleyhuangyc committed Jun 27, 2019
1 parent 26b42d6 commit 1072457
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 30 deletions.
38 changes: 13 additions & 25 deletions libraries/OBD2UART/OBD2UART.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*************************************************************************
* Arduino Library for Freematics OBD-II UART Adapter
* Distributed under BSD License
* Visit http://freematics.com for more information
* (C)2012-2016 Stanley Huang <stanleyhuangyc@gmail.com>
* Visit https://freematics.com for more information
* (C)2012-2018 Stanley Huang <stanley@freematics.com.au>
*************************************************************************/

#include "OBD2UART.h"
Expand Down Expand Up @@ -417,7 +417,6 @@ bool COBD::init(OBD_PROTOCOLS protocol)
byte stage;

m_state = OBD_DISCONNECTED;

for (byte n = 0; n < 2; n++) {
stage = 0;
if (n != 0) reset();
Expand All @@ -442,38 +441,27 @@ bool COBD::init(OBD_PROTOCOLS protocol)
}
stage = 3;
// load pid map
memset(pidmap, 0, sizeof(pidmap));
bool success = false;
memset(pidmap, 0xff, sizeof(pidmap));
for (byte i = 0; i < 4; i++) {
byte pid = i * 0x20;
sprintf(buffer, "%02X%02X\r", dataMode, pid);
delay(10);
write(buffer);
if (receive(buffer, sizeof(buffer), OBD_TIMEOUT_LONG) > 0) {
if (checkErrorMessage(buffer)) {
break;
}
char *p = buffer;
while ((p = strstr(p, "41 "))) {
p += 3;
if (hex2uint8(p) == pid) {
p += 2;
for (byte n = 0; n < 4 && *(p + n * 3) == ' '; n++) {
pidmap[i * 4 + n] = hex2uint8(p + n * 3 + 1);
}
success = true;
delay(10);
if (!receive(buffer, sizeof(buffer), OBD_TIMEOUT_LONG) || checkErrorMessage(buffer)) break;
for (char *p = buffer; (p = strstr(p, "41 ")); ) {
p += 3;
if (hex2uint8(p) == pid) {
p += 2;
for (byte n = 0; n < 4 && *(p + n * 3) == ' '; n++) {
pidmap[i * 4 + n] = hex2uint8(p + n * 3 + 1);
}
}
} else {
break;
}
}
if (success) {
stage = 0xff;
break;
}
break;
}
if (stage == 0xff) {
if (stage == 3) {
m_state = OBD_CONNECTED;
errors = 0;
return true;
Expand Down
4 changes: 2 additions & 2 deletions libraries/OBD2UART/OBD2UART.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*************************************************************************
* Arduino Library for Freematics OBD-II UART Adapter
* Distributed under BSD License
* Visit http://freematics.com for more information
* (C)2012-2016 Stanley Huang <stanleyhuangyc@gmail.com>
* Visit https://freematics.com for more information
* (C)2012-2019 Stanley Huang <stanley@freematics.com.au>
*************************************************************************/

#include <Arduino.h>
Expand Down
3 changes: 1 addition & 2 deletions nanologger/nanologger.ino
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <OBD.h>
#include <OBD2UART.h>
#include <MicroLCD.h>
#include "images.h"
#include "config.h"
Expand Down Expand Up @@ -239,7 +239,6 @@ private:
}
state &= ~STATE_SLEEPING;
fileIndex++;
recover();
setup();
}
byte state;
Expand Down
2 changes: 1 addition & 1 deletion nanotimer/nanotimer.ino
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <SPI.h>
#include <SD.h>
#include <MicroLCD.h>
#include <OBD.h>
#include <OBD2UART.h>
#include "config.h"
#if USE_SOFTSERIAL
#include <SoftwareSerial.h>
Expand Down

0 comments on commit 1072457

Please sign in to comment.