MCPcopy Create free account
hub / github.com/PowerBroker2/ELMduino / findResponse

Method findResponse

src/ELMduino.cpp:2713–2837  ·  view source on GitHub ↗

uint64_t ELM327::findResponse(const uint8_t& service, const uint8_t& pid) Description: ------------ * Parses the buffered ELM327's response and returns the queried data Inputs: ------- * const uint8_t& service - The diagnostic service ID. 01 is "Show current data" * const uint8_t& pid - The Parameter ID (PID) from the service Return: ------- * void */

Source from the content-addressed store, hash-verified

2711 * void
2712*/
2713uint64_t ELM327::findResponse()
2714{
2715 uint8_t firstDatum = 0;
2716 char header[7] = {'\0'};
2717
2718 if (longQuery)
2719 {
2720 header[0] = query[0] + 4;
2721 header[1] = query[1];
2722 header[2] = query[2];
2723 header[3] = query[3];
2724 header[4] = query[4];
2725 header[5] = query[5];
2726 }
2727 else
2728 {
2729 header[0] = query[0] + 4;
2730 header[1] = query[1];
2731
2732 if (isMode0x22Query) // mode 0x22 responses always zero-pad the pid to 4 chars, even for a 2-char pid
2733 {
2734 header[2] = '0';
2735 header[3] = '0';
2736 header[4] = query[2];
2737 header[5] = query[3];
2738 }
2739 else
2740 {
2741 header[2] = query[2];
2742 header[3] = query[3];
2743 }
2744 }
2745
2746 if (debugMode)
2747 {
2748 Serial.print(F("Expected response header: "));
2749 Serial.println(header);
2750 }
2751
2752 int8_t firstHeadIndex = nextIndex(payload, header, 1);
2753 int8_t secondHeadIndex = nextIndex(payload, header, 2);
2754
2755 if (firstHeadIndex >= 0)
2756 {
2757 if (longQuery | isMode0x22Query)
2758 firstDatum = firstHeadIndex + 6;
2759 else
2760 firstDatum = firstHeadIndex + 4;
2761
2762 // Some ELM327s (such as my own) respond with two
2763 // "responses" per query. "numPayChars" represents the
2764 // correct number of bytes returned by the ELM327
2765 // regardless of how many "responses" were returned
2766 if (secondHeadIndex >= 0)
2767 {
2768 if (debugMode)
2769 Serial.println(F("Double response detected"));
2770

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected