Code: Select all
bool COBD::readPidWithHeader(byte pid, byte header, byte dataMode, int& result)
{
char buffer[64];
char* data = 0;
sprintf(buffer, "%02X#%02X%02X\r", header, dataMode, pid);
write(buffer);
Serial.println(buffer);
idleTasks();
if (receive(buffer, sizeof(buffer)) > 0) {
char *p = buffer;
while ((p = strstr(p, "41 "))) {
p += 3;
byte curpid = hex2uint8(p);
if (curpid == pid) {
errors = 0;
while (*p && *p != ' ') p++;
while (*p == ' ') p++;
if (*p) {
data = p;
break;
}
}
}
}
if (!data) {
errors++;
result = -9999;
return false; //was return false
//checkErrorMessage(buffer); // This didn't used to be here. Trying to get the error message
}
result = normalizeData(pid, data);
return true;
}