Include cleaning
[apps/agl-service-can-low-level.git] / src / can / can-decoder.cpp
index ec31e36..866434e 100644 (file)
@@ -16,6 +16,7 @@
  */
 
 #include "can-decoder.hpp"
+
 #include "canutil/read.h"
 #include "../utils/openxc-utils.hpp"
 
@@ -124,7 +125,7 @@ openxc_DynamicField decoder_t::ignoreDecoder(can_signal_t& signal,
 openxc_DynamicField decoder_t::stateDecoder(can_signal_t& signal,
                const std::vector<can_signal_t>& signals, float value, bool* send)
 {
-       const std::string signal_state = signal.get_states(value);
+       const std::string signal_state = signal.get_states((uint8_t)value);
        openxc_DynamicField decoded_value = build_DynamicField(signal_state);
        if(signal_state.size() <= 0)
        {
@@ -215,3 +216,22 @@ openxc_DynamicField decoder_t::decodeSignal( can_signal_t& signal,
        float value = parseSignalBitfield(signal, message);
        return decodeSignal(signal, value, signals, send);
 }
+
+
+/**
+* @brief Decode the payload of an OBD-II PID.
+*
+* This function matches the type signature for a DiagnosticResponseDecoder, so
+* it can be used as the decoder for a DiagnosticRequest. It returns the decoded
+* value of the PID, using the standard formulas (see
+* http://en.wikipedia.org/wiki/OBD-II_PIDs#Mode_01).
+*
+* @param[in] response - the received DiagnosticResponse (the data is in response.payload,
+*  a byte array). This is most often used when the byte order is
+*  signiticant, i.e. with many OBD-II PID formulas.
+* @param[in] parsed_payload - the entire payload of the response parsed as an int.
+*/
+float decoder_t::decode_obd2_response(const DiagnosticResponse* response, float parsedPayload)
+{
+       return diagnostic_decode_obd2_pid(response);
+}
\ No newline at end of file