float ELM327::batteryVoltage() Description: ------------ * Get the current vehicle battery voltage in Volts DC Inputs: ------- * void Return: ------- * float - vehicle battery voltage in VDC */
| 2896 | * float - vehicle battery voltage in VDC |
| 2897 | */ |
| 2898 | float ELM327::batteryVoltage() |
| 2899 | { |
| 2900 | if (nb_query_state == SEND_COMMAND) |
| 2901 | { |
| 2902 | sendCommand(READ_VOLTAGE); |
| 2903 | nb_query_state = WAITING_RESP; |
| 2904 | } |
| 2905 | else if (nb_query_state == WAITING_RESP) |
| 2906 | { |
| 2907 | get_response(); |
| 2908 | if (nb_rx_state == ELM_SUCCESS) |
| 2909 | { |
| 2910 | nb_query_state = SEND_COMMAND; // Reset the query state machine for next command |
| 2911 | payload[strlen(payload) - 1] = '\0'; // Remove the last char ("V") from the payload value |
| 2912 | |
| 2913 | if (strncmp(payload, "ATRV", 4) == 0) |
| 2914 | return (float)strtod(payload + 4, NULL); |
| 2915 | else |
| 2916 | return (float)strtod(payload, NULL); |
| 2917 | } |
| 2918 | else if (nb_rx_state != ELM_GETTING_MSG) |
| 2919 | nb_query_state = SEND_COMMAND; // Error or timeout, so reset the query state machine for next command |
| 2920 | } |
| 2921 | return 0.0; |
| 2922 | } |
| 2923 | |
| 2924 | /* |
| 2925 | int8_t ELM327::get_vin_blocking(char *vin) |
nothing calls this directly
no outgoing calls
no test coverage detected