Skip to content
Permalink
Browse files

Add number of expected responses parameter to speed up Arduino <> Car…

… communications
  • Loading branch information
Thom wijtenburg
Thom wijtenburg committed Mar 20, 2018
1 parent db7fdf2 commit 4f3e11b706cded2746118b5c128423245acdab6f
Showing with 10 additions and 10 deletions.
  1. +7 −7 libraries/OBD/OBD.cpp
  2. +3 −3 libraries/OBD/OBD.h
@@ -63,29 +63,29 @@ byte COBD::sendCommand(const char* cmd, char* buf, byte bufsize, int timeout)
return receive(buf, bufsize, timeout);
}

void COBD::sendQuery(byte pid)
void COBD::sendQuery(byte pid, byte num_results)
{
char cmd[8];
sprintf(cmd, "%02X%02X\r", dataMode, pid);
sprintf(cmd, "%02X%02X%01X\r", dataMode, pid, num_results);
#ifdef DEBUG
debugOutput(cmd);
#endif
write(cmd);
}

bool COBD::readPID(byte pid, int& result)
bool COBD::readPID(byte pid, int& result, byte num_results)
{
// send a query command
sendQuery(pid);
sendQuery(pid, num_results);
// receive and parse the response
return getResult(pid, result);
}

byte COBD::readPID(const byte pid[], byte count, int result[])
byte COBD::readPID(const byte pid[], byte count, int result[], byte num_results)
{
byte results = 0;
for (byte n = 0; n < count; n++) {
if (readPID(pid[n], result[n])) {
if (readPID(pid[n], result[n], num_results)) {
results++;
}
}
@@ -430,7 +430,7 @@ bool COBD::init(OBD_PROTOCOLS protocol)
bool success = false;
for (byte i = 0; i < 4; i++) {
byte pid = i * 0x20;
sendQuery(pid);
sendQuery(pid, 1);
if (receive(buffer, sizeof(buffer), OBD_TIMEOUT_LONG) > 0) {
char *p = buffer;
while ((p = strstr(p, "41"))) {
@@ -130,9 +130,9 @@ class COBD
// get connection state
virtual OBD_STATES getState() { return m_state; }
// read specified OBD-II PID value
virtual bool readPID(byte pid, int& result);
virtual bool readPID(byte pid, int& result, byte num_results);
// read multiple (up to 8) OBD-II PID values, return number of values obtained
virtual byte readPID(const byte pid[], byte count, int result[]);
virtual byte readPID(const byte pid[], byte count, int result[], byte num_results);
// set device into low power mode
virtual void enterLowPowerMode();
// wake up device from low power mode
@@ -152,7 +152,7 @@ class COBD
// read out MEMS data (acc for accelerometer, gyr for gyroscope, temp in 0.1 celcius degree)
virtual bool memsRead(int16_t* acc, int16_t* gyr = 0, int16_t* mag = 0, int16_t* temp = 0);
// send query for specified PID
virtual void sendQuery(byte pid);
virtual void sendQuery(byte pid, byte num_results);
// retrive and parse the response of specifie PID
virtual bool getResult(byte& pid, int& result);
// determine if the PID is supported

0 comments on commit 4f3e11b

Please sign in to comment.
You can’t perform that action at this time.