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

Method currentDTCCodes

src/ELMduino.cpp:3064–3222  ·  view source on GitHub ↗

void ELM327::currentDTCCodes(const bool& isBlocking) Description: ------------ * Get the list of current DTC codes. This method is blocking by default, but can be run in non-blocking mode if desired with optional boolean argument. Typical use involves calling the monitorStatus() function first to get the number of DTC current codes stored, then calling this function to retr

Source from the content-addressed store, hash-verified

3062 * void
3063*/
3064void ELM327::currentDTCCodes(const bool& isBlocking)
3065{
3066 char *idx;
3067 char codeType = '\0';
3068 char codeNumber[5] = {0};
3069 char temp[6] = {0};
3070
3071 if (isBlocking) // In blocking mode, we loop here until get_response() is past ELM_GETTING_MSG state
3072 {
3073 sendCommand("03"); // Check DTC is always Service 03 with no PID
3074 while (get_response() == ELM_GETTING_MSG)
3075 ;
3076 }
3077 else
3078 {
3079 if (nb_query_state == SEND_COMMAND)
3080 {
3081 sendCommand("03");
3082 nb_query_state = WAITING_RESP;
3083 }
3084
3085 else if (nb_query_state == WAITING_RESP)
3086 get_response();
3087 }
3088
3089 if (nb_rx_state == ELM_SUCCESS)
3090 {
3091 nb_query_state = SEND_COMMAND; // Reset the query state machine for next command
3092 memset(DTC_Response.codes, 0, DTC_CODE_LEN * DTC_MAX_CODES);
3093
3094 if (strstr(payload, "43") != NULL) // Successful response to Mode 03 request
3095 {
3096 // OBD scanner will provide a response that contains one or more lines indicating the codes present.
3097 // Each response line will start with "43" indicating it is a response to a Mode 03 request.
3098 // See p. 31 of ELM327 datasheet for details and lookup table of code types.
3099
3100 uint8_t codesFound = strlen(payload) / 8; // Each code found returns 8 chars starting with "43"
3101 idx = strstr(payload, "43") + 4; // Pointer to first DTC code digit (third char in the response)
3102
3103 if (codesFound > DTC_MAX_CODES) // I don't think the ELM is capable of returning
3104 { // more than 0xF (16) codes, but just in case...
3105 codesFound = DTC_MAX_CODES;
3106 Serial.print(F("DTC response truncated at "));
3107 Serial.print(DTC_MAX_CODES);
3108 Serial.println(F(" codes."));
3109 }
3110
3111 DTC_Response.codesFound = codesFound;
3112
3113 for (int i = 0; i < codesFound; i++)
3114 {
3115 memset(temp, 0, sizeof(temp));
3116 memset(codeNumber, 0, sizeof(codeNumber));
3117
3118 codeType = *idx; // Get first digit of second byte
3119 codeNumber[0] = *(idx + 1); // Get second digit of second byte
3120 codeNumber[1] = *(idx + 2); // Get first digit of third byte
3121 codeNumber[2] = *(idx + 3); // Get second digit of third byte

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected