Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for responses longer than 4 hex digits #39

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/ELMduino.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -640,12 +640,14 @@ uint32_t ELM327::findResponse()
else
payBytes = recBytes - firstDatum;

// Some PID queries return 4 hex digit values - the
// rest return 2 hex digit values
if (payBytes >= 4)
return (ctoi(payload[firstDatum]) << 12) | (ctoi(payload[firstDatum + 1]) << 8) | (ctoi(payload[firstDatum + 2]) << 4) | ctoi(payload[firstDatum + 3]);
else
return (ctoi(payload[firstDatum]) << 4) | ctoi(payload[firstDatum + 1]);

uint32_t response = 0;
for(uint8_t i = 0; i < payBytes; i++) {
uint8_t payloadIndex = firstDatum + i;
uint8_t bitsOffset = 4 * (payBytes - i - 1);
response = response | (ctoi(payload[payloadIndex]) << bitsOffset);
}
return response;
}

return 0;
Expand Down