@@ -117,7 +117,7 @@ bool ELM327::initializeELM(const char &protocol, const byte &dataTimeout)
117
117
// the timeout value to 30 seconds, then restore the previous value.
118
118
uint16_t prevTimeout = timeout_ms;
119
119
timeout_ms = 30000 ;
120
-
120
+
121
121
int8_t state = sendCommand_Blocking (" 0100" );
122
122
123
123
if (state == ELM_SUCCESS)
@@ -203,6 +203,8 @@ void ELM327::formatQueryArray(uint8_t service, uint16_t pid, uint8_t num_respons
203
203
Serial.println (pid);
204
204
}
205
205
206
+ isMode0x22Query = (service == 0x22 && pid <= 0xFF ); // mode 0x22 responses always zero-pad the pid to 4 chars, even for a 2-char pid
207
+
206
208
query[0 ] = ((service >> 4 ) & 0xF ) + ' 0' ;
207
209
query[1 ] = (service & 0xF ) + ' 0' ;
208
210
@@ -616,7 +618,7 @@ double ELM327::processPID(const uint8_t &service, const uint16_t &pid, const uin
616
618
{
617
619
nb_query_state = SEND_COMMAND; // Reset the query state machine for next command
618
620
619
- findResponse ();
621
+ findResponse (service, pid );
620
622
621
623
return conditionResponse (numExpectedBytes, scaleFactor, bias);
622
624
}
@@ -2312,7 +2314,7 @@ int8_t ELM327::get_response(void)
2312
2314
}
2313
2315
2314
2316
/*
2315
- uint64_t ELM327::findResponse()
2317
+ uint64_t ELM327::findResponse(uint8_t &service )
2316
2318
2317
2319
Description:
2318
2320
------------
@@ -2326,7 +2328,7 @@ int8_t ELM327::get_response(void)
2326
2328
-------
2327
2329
* uint64_t - Query response value
2328
2330
*/
2329
- uint64_t ELM327::findResponse ()
2331
+ uint64_t ELM327::findResponse (const uint8_t &service, const uint8_t &pid )
2330
2332
{
2331
2333
uint8_t firstDatum = 0 ;
2332
2334
char header[7 ] = {' \0 ' };
@@ -2344,8 +2346,18 @@ uint64_t ELM327::findResponse()
2344
2346
{
2345
2347
header[0 ] = query[0 ] + 4 ;
2346
2348
header[1 ] = query[1 ];
2347
- header[2 ] = query[2 ];
2348
- header[3 ] = query[3 ];
2349
+ if (isMode0x22Query) // mode 0x22 responses always zero-pad the pid to 4 chars, even for a 2-char pid
2350
+ {
2351
+ header[2 ] = ' 0' ;
2352
+ header[3 ] = ' 0' ;
2353
+ header[4 ] = query[2 ];
2354
+ header[5 ] = query[3 ];
2355
+ }
2356
+ else
2357
+ {
2358
+ header[2 ] = query[2 ];
2359
+ header[3 ] = query[3 ];
2360
+ }
2349
2361
}
2350
2362
2351
2363
if (debugMode)
@@ -2359,7 +2371,7 @@ uint64_t ELM327::findResponse()
2359
2371
2360
2372
if (firstHeadIndex >= 0 )
2361
2373
{
2362
- if (longQuery)
2374
+ if (longQuery | isMode0x22Query )
2363
2375
firstDatum = firstHeadIndex + 6 ;
2364
2376
else
2365
2377
firstDatum = firstHeadIndex + 4 ;
0 commit comments