summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStanley Huang <stanleyhuangyc@gmail.com>2015-04-27 22:52:52 +1000
committerStanley Huang <stanleyhuangyc@gmail.com>2015-04-27 22:52:52 +1000
commit38f00a77bd293fc98771c86b251f45accadbc582 (patch)
treeaecc1a8ac68e4d26619c125af3a91e557246b7e1
parent431cc8f156fe852ffd6fbfcc200a11b44d25bee7 (diff)
download2021-arduino-obd-38f00a77bd293fc98771c86b251f45accadbc582.tar.gz
2021-arduino-obd-38f00a77bd293fc98771c86b251f45accadbc582.tar.bz2
2021-arduino-obd-38f00a77bd293fc98771c86b251f45accadbc582.zip
Minor cleanup
-rw-r--r--libraries/OBD/OBD.cpp45
-rw-r--r--libraries/OBD/OBD.h14
2 files changed, 6 insertions, 53 deletions
diff --git a/libraries/OBD/OBD.cpp b/libraries/OBD/OBD.cpp
index 431d910..f20d459 100644
--- a/libraries/OBD/OBD.cpp
+++ b/libraries/OBD/OBD.cpp
@@ -420,36 +420,6 @@ void COBDI2C::end()
m_state = OBD_DISCONNECTED;
}
-bool COBDI2C::init(OBD_PROTOCOLS protocol)
-{
- bool success = false;
- m_state = OBD_CONNECTING;
- sendCommand(CMD_QUERY_STATUS);
-
- char recvbuf[MAX_PAYLOAD_SIZE];
- for (byte n = 0; n < 3; n++) {
- memset(recvbuf, 0, sizeof(recvbuf));
- receive(recvbuf);
- if (!memcmp(recvbuf, "OBD ", 4))
- break;
- }
- if (recvbuf[4] == 'Y') {
- memcpy(pidmap, recvbuf + 16, sizeof(pidmap));
- if (protocol != PROTO_AUTO) {
- setProtocol(protocol);
- }
- int value;
- success = read(PID_RPM, value);
- }
- if (success) {
- return true;
- m_state = OBD_CONNECTED;
- } else {
- m_state = OBD_DISCONNECTED;
- return false;
- }
-}
-
bool COBDI2C::read(byte pid, int& result)
{
sendQuery(pid);
@@ -503,23 +473,10 @@ byte COBDI2C::receive(char* buffer, int timeout)
}
return offset;
- } while(millis() - start < OBD_TIMEOUT_LONG);
+ } while(millis() - start < timeout);
return 0;
}
-bool COBDI2C::gpsQuery(GPS_DATA* gpsdata)
-{
- if (!sendCommand(CMD_GPS_QUERY, 0)) return false;
- Wire.requestFrom((byte)I2C_ADDR, (byte)MAX_PAYLOAD_SIZE, (byte)1);
- Wire.readBytes((char*)gpsdata, MAX_PAYLOAD_SIZE);
- return true;
-}
-
-void COBDI2C::gpsSetup(uint32_t baudrate, const char* cmds)
-{
- sendCommand(CMD_GPS_SETUP, baudrate / 1200, (byte*)cmds, cmds ? strlen(cmds) : 0);
-}
-
void COBDI2C::setPID(byte pid)
{
byte n = 0;
diff --git a/libraries/OBD/OBD.h b/libraries/OBD/OBD.h
index e53d243..acf64e9 100644
--- a/libraries/OBD/OBD.h
+++ b/libraries/OBD/OBD.h
@@ -140,16 +140,16 @@ public:
protected:
virtual char* getResponse(byte& pid, char* buffer);
virtual byte receive(char* buffer = 0, int timeout = OBD_TIMEOUT_SHORT);
+ virtual bool available();
+ virtual char read();
+ virtual void write(const char* s);
+ virtual void write(char c);
virtual void dataIdleLoop() {}
void recover();
void debugOutput(const char* s);
int normalizeData(byte pid, char* data);
OBD_STATES m_state;
private:
- virtual bool available();
- virtual char read();
- virtual void write(const char* s);
- virtual void write(char c);
virtual uint8_t getPercentageValue(char* data)
{
return (uint16_t)hex2uint8(data) * 100 / 255;
@@ -208,7 +208,6 @@ class COBDI2C : public COBD {
public:
void begin();
void end();
- bool init(OBD_PROTOCOLS protocol = PROTO_AUTO);
bool read(byte pid, int& result);
void write(const char* s);
// Asynchronized access API
@@ -216,12 +215,9 @@ public:
void applyPIDs();
void loadData();
uint16_t getData(byte pid, int& result);
- // GPS API
- bool gpsQuery(GPS_DATA* gpsdata);
- void gpsSetup(uint32_t baudrate, const char* cmds = 0);
protected:
bool sendCommand(byte cmd, uint8_t data = 0, byte* payload = 0, byte payloadBytes = 0);
- byte receive(char* buffer, int timeout = OBD_TIMEOUT_SHORT);
+ byte receive(char* buffer, int timeout = OBD_TIMEOUT_LONG);
byte m_addr;
PID_INFO obdInfo[MAX_PIDS];
byte obdPid[MAX_PIDS];