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

Method get_response

src/ELMduino.cpp:2446–2591  ·  view source on GitHub ↗

obd_rx_states ELM327::get_response(void) Description: ------------ * Non Blocking (NB) receive OBD scanner response. Must be called repeatedly until the status progresses past ELM_GETTING_MSG. Inputs: ------- * void Return: ------- * int8_t - the ELM_XXX status of getting the OBD response */

Source from the content-addressed store, hash-verified

2444 * int8_t - the ELM_XXX status of getting the OBD response
2445*/
2446int8_t ELM327::get_response(void)
2447{
2448 // buffer the response of the ELM327 until either the
2449 // end marker is read or a timeout has occurred
2450 // last valid idx is PAYLOAD_LEN but want to keep one free for terminating '\0'
2451 // so limit counter to < PAYLOAD_LEN
2452 if (!elm_port->available())
2453 {
2454 nb_rx_state = ELM_GETTING_MSG;
2455 if (timeout())
2456 nb_rx_state = ELM_TIMEOUT;
2457 }
2458 else
2459 {
2460 char recChar = elm_port->read();
2461
2462 if (debugMode)
2463 {
2464 Serial.print(F("\tReceived char: "));
2465 // display each received character, make non-printables printable
2466 if (recChar == '\f')
2467 Serial.println(F("\\f"));
2468 else if (recChar == '\n')
2469 Serial.println(F("\\n"));
2470 else if (recChar == '\r')
2471 Serial.println(F("\\r"));
2472 else if (recChar == '\t')
2473 Serial.println(F("\\t"));
2474 else if (recChar == '\v')
2475 Serial.println(F("\\v"));
2476 // convert spaces to underscore, easier to see in debug output
2477 else if (recChar == ' ')
2478 Serial.println(F("_"));
2479 // display regular printable
2480 else
2481 Serial.println(recChar);
2482 }
2483
2484 // this is the end of the OBD response
2485 if (recChar == '>')
2486 {
2487 if (debugMode)
2488 Serial.println(F("Delimiter found."));
2489
2490 nb_rx_state = ELM_MSG_RXD;
2491 }
2492 else if (!isalnum(recChar) && (recChar != ':') && (recChar != '.') && (recChar != '\r'))
2493 // Keep only alphanumeric, decimal, colon, CR. These are needed for response parsing
2494 // decimal places needed to extract floating point numbers, e.g. battery voltage
2495 nb_rx_state = ELM_GETTING_MSG; // Discard this character
2496 else
2497 {
2498 if (recBytes < PAYLOAD_LEN)
2499 {
2500 payload[recBytes] = recChar;
2501 recBytes++;
2502 nb_rx_state = ELM_GETTING_MSG;
2503 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected