diff options
author | Stanley Huang <stanleyhuangyc@gmail.com> | 2014-03-08 12:49:39 +0800 |
---|---|---|
committer | Stanley Huang <stanleyhuangyc@gmail.com> | 2014-03-08 12:49:39 +0800 |
commit | 61c4955f807004623e1daeb2ad5aadba99ef0ed6 (patch) | |
tree | 42af7d624122a2a51035829d6e6c65c2449b38c5 /libraries/OBD/OBD.cpp | |
parent | 2b1e91b1ccd6130a303a17463c7fe75cf0859273 (diff) | |
download | 2021-arduino-obd-61c4955f807004623e1daeb2ad5aadba99ef0ed6.tar.gz 2021-arduino-obd-61c4955f807004623e1daeb2ad5aadba99ef0ed6.tar.bz2 2021-arduino-obd-61c4955f807004623e1daeb2ad5aadba99ef0ed6.zip |
Update OBD library
Diffstat (limited to 'libraries/OBD/OBD.cpp')
-rw-r--r-- | libraries/OBD/OBD.cpp | 55 |
1 files changed, 22 insertions, 33 deletions
diff --git a/libraries/OBD/OBD.cpp b/libraries/OBD/OBD.cpp index b02cea9..c7c6024 100644 --- a/libraries/OBD/OBD.cpp +++ b/libraries/OBD/OBD.cpp @@ -14,9 +14,8 @@ #define MAX_CMD_LEN 6
-const char PROGMEM s_initcmd[][MAX_CMD_LEN] = {"ATZ\r","ATE0\r","ATL1\r","0902\r"};
-const char PROGMEM s_cmd_fmt[] = "%02X%02X 1\r";
-const char PROGMEM s_cmd_sleep[] = "atlp\r";
+const char PROGMEM s_initcmd[][MAX_CMD_LEN] = {"ATZ\r","ATE0\r","ATL1\r"};
+#define STR_CMD_FMT "%02X%02X 1\r"
#define STR_SEARCHING "SEARCHING..."
unsigned int hex2uint16(const char *p)
@@ -65,10 +64,10 @@ unsigned char hex2uint8(const char *p) *************************************************************************/
#include <Wire.h>
-void COBD::sendQuery(unsigned char pid)
+void COBD::sendQuery(byte pid)
{
char cmd[8];
- sprintf_P(cmd, s_cmd_fmt, dataMode, pid);
+ sprintf(cmd, STR_CMD_FMT, dataMode, pid);
#ifdef DEBUG
debugOutput(cmd);
#endif
@@ -201,15 +200,25 @@ bool COBD::getResult(byte& pid, int& result) return true;
}
-void COBD::sleep(int seconds)
+void COBD::setProtocol(byte h)
{
- char cmd[MAX_CMD_LEN];
- strcpy_P(cmd, s_cmd_sleep);
- write(cmd);
- if (seconds) {
- delay((unsigned long)seconds << 10);
- write('\r');
- }
+ if (h == -1) {
+ write("ATSP00\r");
+ } else {
+ char cmd[8];
+ sprintf(cmd, "ATSP%d\r", h);
+ write(cmd);
+ }
+}
+
+void COBD::sleep()
+{
+ write("ATLP\r");
+}
+
+void COBD::wakeup()
+{
+ write('\r');
}
bool COBD::isValidPID(byte pid)
@@ -409,26 +418,6 @@ byte COBDI2C::receive(char* buffer, int timeout) return 0;
}
-bool COBDI2C::btInit(uint16_t baudrate)
-{
- return sendCommand(CMD_UART_BEGIN, baudrate / 1200);
-}
-
-bool COBDI2C::btSend(byte* data, byte length)
-{
- return sendCommand(CMD_UART_SEND, 0, data, length);
-}
-
-bool COBDI2C::btReceive(byte* buffer, byte bufsize)
-{
- if (!sendCommand(CMD_UART_RECV, bufsize)) return false;
- memset(buffer, 0, MAX_PAYLOAD_SIZE);
- delay(10);
- Wire.requestFrom((byte)m_addr, (byte)MAX_PAYLOAD_SIZE, (byte)1);
- Wire.readBytes((char*)buffer, MAX_PAYLOAD_SIZE);
- return true;
-}
-
bool COBDI2C::gpsQuery(GPS_DATA* gpsdata)
{
if (!sendCommand(CMD_GPS_QUERY, 0)) return false;
|