Skip to content

Commit 6f5402d

Browse files
committed
Another bugfix for (#275)
1 parent 04c7869 commit 6f5402d

1 file changed

Lines changed: 17 additions & 26 deletions

File tree

src/ELMduino.cpp

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2404,16 +2404,27 @@ uint64_t ELM327::findResponse(const uint8_t& service,
24042404
int8_t firstHeadIndex = nextIndex(payload, header, 1);
24052405
int8_t secondHeadIndex = nextIndex(payload, header, 2);
24062406

2407+
// int8_t firstLogColonIndex = nextIndex(payload, ":", 1);
2408+
int8_t secondLogColonIndex = nextIndex(payload, ":", 2);
2409+
24072410
if (firstHeadIndex >= 0)
24082411
{
2409-
int8_t logColonIndex = 0;
2410-
int8_t logBytes = 0;
2411-
24122412
if (longQuery | isMode0x22Query)
24132413
firstDatum = firstHeadIndex + 6;
24142414
else
24152415
firstDatum = firstHeadIndex + 4;
24162416

2417+
if (secondLogColonIndex >= 0)
2418+
{
2419+
if (debugMode)
2420+
{
2421+
Serial.print(F("Log response detected at index: "));
2422+
Serial.println(secondLogColonIndex);
2423+
}
2424+
2425+
firstDatum = secondLogColonIndex + 1;
2426+
}
2427+
24172428
// Some ELM327s (such as my own) respond with two
24182429
// "responses" per query. "numPayChars" represents the
24192430
// correct number of bytes returned by the ELM327
@@ -2424,43 +2435,23 @@ uint64_t ELM327::findResponse(const uint8_t& service,
24242435
Serial.println(F("Double response detected"));
24252436

24262437
numPayChars = secondHeadIndex - firstDatum;
2427-
2428-
// Look for the first colon after the last found header - this is the colon separating the data response from the logging response
2429-
logColonIndex = nextIndex(payload + secondHeadIndex, ':', 1);
24302438
}
24312439
else
24322440
{
24332441
if (debugMode)
24342442
Serial.println(F("Single response detected"));
24352443

24362444
numPayChars = recBytes - firstDatum;
2437-
2438-
// Look for the first colon after the last found header - this is the colon separating the data response from the logging response
2439-
logColonIndex = nextIndex(payload + firstHeadIndex, ':', 1);
2440-
}
2441-
2442-
if (logColonIndex >= 0)
2443-
{
2444-
if (debugMode)
2445-
Serial.println(F("Log response detected"));
2446-
2447-
logBytes = recBytes - logColonIndex; // Number of logging bytes INCLUDING the colon
2448-
2449-
if (debugMode)
2450-
{
2451-
Serial.print(logBytes);
2452-
Serial.println(F(" log bytes found - ignoring these bytes during processing"));
2453-
}
2454-
2455-
// Do not process logging bytes
2456-
numPayChars -= logBytes;
24572445
}
24582446

24592447
response = 0;
24602448
for (uint8_t i = 0; i < numPayChars; i++)
24612449
{
24622450
uint8_t payloadIndex = firstDatum + i;
24632451
uint8_t bitsOffset = 4 * (numPayChars - i - 1);
2452+
2453+
Serial.print("\tProcessing hex nibble: ");
2454+
Serial.println(payload[payloadIndex]);
24642455

24652456
response = response | ((uint64_t)ctoi(payload[payloadIndex]) << bitsOffset);
24662457
}

0 commit comments

Comments
 (0)