Rename class and 1:1 map to JSON description file
authorRomain Forlot <romain.forlot@iot.bzh>
Wed, 15 Mar 2017 22:16:59 +0000 (23:16 +0100)
committerRomain Forlot <romain.forlot@iot.bzh>
Thu, 16 Mar 2017 16:21:57 +0000 (17:21 +0100)
Added decoder and callback member that will be set by generator and taken
at submission to be used later, storing them into an active diagnostic
request instance, when response CAN message comes in.

Change-Id: I9ded05de3bb28ec55e4e007d72d0e1924141a6a6
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
src/configuration-generated.cpp
src/configuration.cpp
src/configuration.hpp
src/diagnostic/diagnostic-message.cpp
src/diagnostic/diagnostic-message.hpp
src/low-can-binding.cpp
src/utils/signals.cpp

index b7a3733..ccbf559 100644 (file)
@@ -7,31 +7,31 @@
 #include "can/can-decoder.hpp"
 
 // Pre-defined OBD-II PIDs to query for if supported by the vehicle.
- std::vector<obd2_signal_t> OBD2_PIDS = {
-       obd2_signal_t(0x04, "engine.load", 0, 100, POURCENT, 5, false),
-       obd2_signal_t(0x05, "engine.coolant.temperature", -40, 215, DEGREES_CELSIUS, 1, false),
-       obd2_signal_t(0x0a, "fuel.pressure", 0, 765, KPA, 1, false),
-       obd2_signal_t(0x0b, "intake.manifold.pressure", 0, 255, KPA, 1, false),
-       obd2_signal_t(0x0c, "engine.speed", 0, 16383, RPM, 5, false),
-       obd2_signal_t(0x0d, "vehicle.speed", 0, 255, KM_H, 5, false),
-       obd2_signal_t(0x0f, "intake.air.temperature", -40, 215, DEGREES_CELSIUS, 1, false),
-       obd2_signal_t(0x10, "mass.airflow", 0, 655, GRAMS_SEC, 5, false),
-       obd2_signal_t(0x11, "throttle.position", 0, 100, POURCENT, 5, false),
-       obd2_signal_t(0x1f, "running.time", 0, 65535, SECONDS, 1, false),
-       obd2_signal_t(0x2d, "EGR.error", -100, 99, POURCENT, 0, false),
-       obd2_signal_t(0x2f, "fuel.level", 0, 100, POURCENT, 1, false),
-       obd2_signal_t(0x33, "barometric.pressure", 0, 255, KPA, 1, false),
-       obd2_signal_t(0x4c, "commanded.throttle.position", 0, 100, POURCENT, 1, false),
-       obd2_signal_t(0x52, "ethanol.fuel.percentage", 0, 100, POURCENT, 1, false),
-       obd2_signal_t(0x5a, "accelerator.pedal.position", 0, 100, POURCENT, 5, false),
-       obd2_signal_t(0x5b, "hybrid.battery-pack.remaining.life", 0, 100, POURCENT, 5, false),
-       obd2_signal_t(0x5c, "engine.oil.temperature",-40, 210, DEGREES_CELSIUS, 1, false),
-       obd2_signal_t(0x63, "engine.torque", 0, 65535, NM, 1, false)
+ std::vector<diagnostic_message_t> DIAGNOSTIC_MESSAGES = {
+       diagnostic_message_t(0x04, "engine.load", 0, 100, POURCENT, 5, decoder_t::decode_obd2_response, nullptr, false),
+       diagnostic_message_t(0x05, "engine.coolant.temperature", -40, 215, DEGREES_CELSIUS, 1,  decoder_t::decode_obd2_response, nullptr, false),
+       diagnostic_message_t(0x0a, "fuel.pressure", 0, 765, KPA, 1, decoder_t::decode_obd2_response, nullptr, false),
+       diagnostic_message_t(0x0b, "intake.manifold.pressure", 0, 255, KPA, 1,  decoder_t::decode_obd2_response, nullptr, false),
+       diagnostic_message_t(0x0c, "engine.speed", 0, 16383, RPM, 5,  decoder_t::decode_obd2_response, nullptr, false),
+       diagnostic_message_t(0x0d, "vehicle.speed", 0, 255, KM_H, 5,  decoder_t::decode_obd2_response, nullptr, false),
+       diagnostic_message_t(0x0f, "intake.air.temperature", -40, 215, DEGREES_CELSIUS, 1,  decoder_t::decode_obd2_response, nullptr, false),
+       diagnostic_message_t(0x10, "mass.airflow", 0, 655, GRAMS_SEC, 5,  decoder_t::decode_obd2_response, nullptr, false),
+       diagnostic_message_t(0x11, "throttle.position", 0, 100, POURCENT, 5,  decoder_t::decode_obd2_response, nullptr, false),
+       diagnostic_message_t(0x1f, "running.time", 0, 65535, SECONDS, 1,  decoder_t::decode_obd2_response, nullptr, false),
+       diagnostic_message_t(0x2d, "EGR.error", -100, 99, POURCENT, 0,  decoder_t::decode_obd2_response, nullptr, false),
+       diagnostic_message_t(0x2f, "fuel.level", 0, 100, POURCENT, 1, decoder_t::decode_obd2_response, nullptr, false),
+       diagnostic_message_t(0x33, "barometric.pressure", 0, 255, KPA, 1, decoder_t::decode_obd2_response, nullptr, false),
+       diagnostic_message_t(0x4c, "commanded.throttle.position", 0, 100, POURCENT, 1, decoder_t::decode_obd2_response, nullptr, false),
+       diagnostic_message_t(0x52, "ethanol.fuel.percentage", 0, 100, POURCENT, 1, decoder_t::decode_obd2_response, nullptr, false),
+       diagnostic_message_t(0x5a, "accelerator.pedal.position", 0, 100, POURCENT, 5, decoder_t::decode_obd2_response, nullptr, false),
+       diagnostic_message_t(0x5b, "hybrid.battery-pack.remaining.life", 0, 100, POURCENT, 5, decoder_t::decode_obd2_response, nullptr, false),
+       diagnostic_message_t(0x5c, "engine.oil.temperature",-40, 210, DEGREES_CELSIUS, 1, decoder_t::decode_obd2_response, nullptr, false),
+       diagnostic_message_t(0x63, "engine.torque", 0, 65535, NM, 1, decoder_t::decode_obd2_response, nullptr, false)
 };
 
-std::vector<obd2_signal_t> get_predefined_obd2()
+std::vector<diagnostic_message_t> get_predefined_obd2()
 {
-       return OBD2_PIDS;
+       return DIAGNOSTIC_MESSAGES;
 }
 
 std::vector<can_message_set_t> CAN_MESSAGE_SET =
@@ -58,7 +58,7 @@ std::vector<std::vector<can_signal_t>> SIGNALS = {
 };
 
 configuration_t::configuration_t()
-       : can_message_set_{CAN_MESSAGE_SET}, can_message_definition_{CAN_MESSAGES_DEFINITION}, can_signals_{SIGNALS}, obd2_signals_{OBD2_PIDS}
+       : can_message_set_{CAN_MESSAGE_SET}, can_message_definition_{CAN_MESSAGES_DEFINITION}, can_signals_{SIGNALS}, diagnostic_messages_{DIAGNOSTIC_MESSAGES}
 {}
 
 const std::string configuration_t::get_diagnostic_bus() const
index ec12d8f..52ddde4 100644 (file)
@@ -67,9 +67,9 @@ std::vector<can_signal_t>& configuration_t::get_can_signals()
        return can_signals_[active_message_set_];
 }
 
-std::vector<obd2_signal_t>& configuration_t::get_obd2_signals()
+std::vector<diagnostic_message_t>& configuration_t::get_diagnostic_messages()
 {
-       return obd2_signals_[active_message_set_];
+       return diagnostic_messages_[active_message_set_];
 }
 
 const std::vector<std::string>& configuration_t::get_signals_prefix() const
@@ -82,7 +82,7 @@ const std::vector<can_message_definition_t>& configuration_t::get_can_message_de
        return can_message_definition_[active_message_set_];
 }
 
-uint32_t configuration_t::get_signal_id(obd2_signal_t& sig) const
+uint32_t configuration_t::get_signal_id(diagnostic_message_t& sig) const
 {
        return sig.get_pid();
 }
@@ -106,21 +106,21 @@ void configuration_t::set_active_message_set(uint8_t id)
  *
  * @return Vector of signals name found.
  */
-void configuration_t::find_obd2_signals(const openxc_DynamicField &key, std::vector<obd2_signal_t*>& found_signals)
+void configuration_t::find_diagnostic_messages(const openxc_DynamicField &key, std::vector<diagnostic_message_t*>& found_signals)
 {
        switch(key.type)
        {
                case openxc_DynamicField_Type::openxc_DynamicField_Type_STRING:
-                               lookup_signals_by_name(key.string_value, obd2_signals_[active_message_set_], found_signals);
+                               lookup_signals_by_name(key.string_value, diagnostic_messages_[active_message_set_], found_signals);
                        break;
                case openxc_DynamicField_Type::openxc_DynamicField_Type_NUM:
-                               lookup_signals_by_id(key.numeric_value, obd2_signals_[active_message_set_], found_signals);
+                               lookup_signals_by_id(key.numeric_value, diagnostic_messages_[active_message_set_], found_signals);
                        break;
                default:
-                       ERROR(binder_interface, "find_obd2_signals: wrong openxc_DynamicField specified. Use openxc_DynamicField_Type_NUM or openxc_DynamicField_Type_STRING type only.");
+                       ERROR(binder_interface, "find_diagnostic_messages: wrong openxc_DynamicField specified. Use openxc_DynamicField_Type_NUM or openxc_DynamicField_Type_STRING type only.");
                        break;
        }
-       DEBUG(binder_interface, "find_obd2_signals: Found %d signal(s)", (int)found_signals.size());
+       DEBUG(binder_interface, "find_diagnostic_messages: Found %d signal(s)", (int)found_signals.size());
 }
 
 /**
index 224672e..266f219 100644 (file)
@@ -49,7 +49,7 @@ class configuration_t
                std::vector<can_message_set_t> can_message_set_;
                std::vector<std::vector<can_message_definition_t>> can_message_definition_;
                std::vector<std::vector<can_signal_t>> can_signals_;
-               std::vector<std::vector<obd2_signal_t>> obd2_signals_;
+               std::vector<std::vector<diagnostic_message_t>> diagnostic_messages_;
 
                /// Private constructor with implementation generated by the AGL generator.
                configuration_t();
@@ -73,19 +73,19 @@ class configuration_t
 
                std::vector<can_signal_t>& get_can_signals();
 
-               std::vector<obd2_signal_t>& get_obd2_signals();
+               std::vector<diagnostic_message_t>& get_diagnostic_messages();
 
                const std::vector<std::string>& get_signals_prefix() const;
 
                const std::vector<can_message_definition_t>& get_can_message_definition();
 
-               uint32_t get_signal_id(obd2_signal_t& sig) const;
+               uint32_t get_signal_id(diagnostic_message_t& sig) const;
 
                uint32_t get_signal_id(can_signal_t& sig) const;
 
                void set_active_message_set(uint8_t id);
 
-               void find_obd2_signals(const openxc_DynamicField &key, std::vector<obd2_signal_t*>& found_signals);
+               void find_diagnostic_messages(const openxc_DynamicField &key, std::vector<diagnostic_message_t*>& found_signals);
 
                void find_can_signals(const openxc_DynamicField &key, std::vector<can_signal_t*>& found_signals);
 
@@ -114,4 +114,4 @@ class configuration_t
 };
 
 // TEMP Function to access OBD2_PIDS vector
-std::vector<obd2_signal_t> get_predefined_obd2();
+std::vector<diagnostic_message_t> get_predefined_obd2();
index a460ac5..b7c5d45 100644 (file)
@@ -33,36 +33,45 @@ const char *UNIT_NAMES[10] = {
        "NM"
 };
 
-obd2_signal_t::obd2_signal_t(uint8_t pid, const char* generic_name, const int min, const int max, enum UNIT unit, int frequency, bool supported)
-       :       pid_{pid}, generic_name_{generic_name}, min_{min}, max_{max}, unit_{unit}, frequency_{frequency}, supported_{supported}
-{
-}
+diagnostic_message_t::diagnostic_message_t(uint8_t pid, const std::string generic_name, const int min, const int max, enum UNIT unit, float frequency,
+                                                                                       DiagnosticResponseDecoder decoder, DiagnosticResponseCallback callback, bool supported)
+       : pid_{pid}, generic_name_{generic_name}, min_{min}, max_{max}, unit_{unit}, frequency_{frequency}, decoder_{decoder}, callback_{callback}, supported_{supported}
+{}
 
-uint32_t obd2_signal_t::get_pid()
+uint32_t diagnostic_message_t::get_pid()
 {
        return (uint32_t)pid_;
 }
 
-const std::string& obd2_signal_t::get_generic_name() const
+const std::string& diagnostic_message_t::get_generic_name() const
 {
        return generic_name_;
 }
 
-const std::string obd2_signal_t::get_name() const
+const std::string diagnostic_message_t::get_name() const
 {
        return active_diagnostic_request_t::get_prefix() + "." + generic_name_;
 }
 
-int obd2_signal_t::get_frequency() const
+float diagnostic_message_t::get_frequency() const
 {
        return frequency_;
 }
 
+DiagnosticResponseDecoder diagnostic_message_t::get_decoder() const
+{
+       return decoder_;
+}
+DiagnosticResponseCallback diagnostic_message_t::get_callback() const
+{
+       return callback_;
+}
+
 /**
  * @brief Build a DiagnosticRequest struct to be passed
  *  to diagnostic manager instance.
  */
-const DiagnosticRequest obd2_signal_t::build_diagnostic_request()
+const DiagnosticRequest diagnostic_message_t::build_diagnostic_request()
 {
        return {/*arbitration_id: */OBD2_FUNCTIONAL_BROADCAST_ID,
                        /*mode: */0x1,
@@ -80,7 +89,7 @@ const DiagnosticRequest obd2_signal_t::build_diagnostic_request()
 *
 * @return true if the request is a mode 1 request and it has a 1 byte PID.
 */
-bool obd2_signal_t::is_obd2_request(const DiagnosticRequest* request)
+bool diagnostic_message_t::is_obd2_request(const DiagnosticRequest* request)
 {
        return request->mode == 0x1 && request->has_pid && request->pid < 0xff;
 }
index e806257..83c4dcc 100644 (file)
@@ -42,7 +42,7 @@ enum UNIT {
 /**
  * @brief - A representation of an OBD-II PID.
  */
-class obd2_signal_t {
+class diagnostic_message_t {
        private:
                uint8_t pid_; /*!< pid - The 1 byte PID.*/
                std::string generic_name_; /*!< generic_name_ - A human readable name to use for this PID when published.*/
@@ -50,16 +50,25 @@ class obd2_signal_t {
                int max_; /*!< max_ - Maximum value that can take this pid */
                enum UNIT unit_; /*!< unit_ : Which unit system is used by that pid. See enum UNIT above.*/
                int frequency_; /*!< frequency - The frequency to request this PID if supported by the vehicle when automatic, recurring OBD-II requests are enabled.*/
+               DiagnosticResponseDecoder decoder_; /*!< decoder_ - An optional DiagnosticResponseDecoder to parse the payload of responses
+                                                                                        * to this request. If the decoder is NULL, the output will include the raw payload
+                                                                                        * instead of a parsed value.*/
+               DiagnosticResponseCallback callback_; /*!< callback_ - An optional DiagnosticResponseCallback to be notified whenever a
+                                                                                          * response is received for this request.*/
+               
                bool supported_; /*!< supported_ - boolean indicating whether this pid is supported by the vehicle or not.*/
 
        public:
                const char* generic_name = generic_name_.c_str();
-               obd2_signal_t(uint8_t pid, const char* generic_name, const int min_, const int max_, enum UNIT unit, int frequency, bool supported);
+               diagnostic_message_t(uint8_t pid, const std::string generic_name, const int min, const int max, enum UNIT unit, float frequency,
+                                                                                       DiagnosticResponseDecoder decoder, DiagnosticResponseCallback callback, bool supported);
 
                uint32_t get_pid();
                const std::string& get_generic_name() const;
                const std::string get_name() const;
                int get_frequency() const;
+               DiagnosticResponseDecoder get_decoder() const;
+               DiagnosticResponseCallback get_callback() const;
 
                const DiagnosticRequest build_diagnostic_request();
 
index 074e95c..53d34c7 100644 (file)
@@ -130,13 +130,13 @@ static int subscribe_unsubscribe_signals(struct afb_req request, bool subscribe,
                int ret;
                if (active_diagnostic_request_t::is_diagnostic_signal(sig) && subscribe)
                {
-                       std::vector<obd2_signal_t*> found;
-                       configuration_t::instance().find_obd2_signals(build_DynamicField(sig), found);
-                       int frequency = found.front()->get_frequency();
+                       std::vector<diagnostic_message_t*> found;
+                       configuration_t::instance().find_diagnostic_messages(build_DynamicField(sig), found);
+                       float frequency = found.front()->get_frequency();
                        DiagnosticRequest* diag_req = new DiagnosticRequest(found.front()->build_diagnostic_request());
                        configuration_t::instance().get_diagnostic_manager().add_recurring_request(
-                               diag_req, sig.c_str(), false, obd2_signal_t::decode_obd2_response, nullptr, (float)frequency);
-                               //TODO: Adding callback requesting ignition status:     diag_req, sig.c_str(), false, obd2_signal_t::decode_obd2_response, obd2_signal_t::check_ignition_status, frequency);
+                               diag_req, sig.c_str(), false, found.front()->get_decoder(), found.front()->get_callback(), (float)frequency);
+                               //TODO: Adding callback requesting ignition status:     diag_req, sig.c_str(), false, diagnostic_message_t::decode_obd2_response, diagnostic_message_t::check_ignition_status, frequency);
                }
 
                ret = subscribe_unsubscribe_signal(request, subscribe, sig);
index 1ce932d..41e13c0 100644 (file)
@@ -61,11 +61,11 @@ std::vector<std::string> find_signals(const openxc_DynamicField &key)
        {
                case openxc_DynamicField_Type::openxc_DynamicField_Type_STRING:
                                lookup_signals_by_name(key.string_value, configuration_t::instance().get_can_signals(), found_signals_name);
-                               lookup_signals_by_name(key.string_value, configuration_t::instance().get_obd2_signals(), found_signals_name);
+                               lookup_signals_by_name(key.string_value, configuration_t::instance().get_diagnostic_messages(), found_signals_name);
                        break;
                case openxc_DynamicField_Type::openxc_DynamicField_Type_NUM:
                                lookup_signals_by_id(key.numeric_value, configuration_t::instance().get_can_signals(), found_signals_name);
-                               lookup_signals_by_id(key.numeric_value, configuration_t::instance().get_obd2_signals(), found_signals_name);
+                               lookup_signals_by_id(key.numeric_value, configuration_t::instance().get_diagnostic_messages(), found_signals_name);
                        break;
                default:
                        ERROR(binder_interface, "find_signals: wrong openxc_DynamicField specified. Use openxc_DynamicField_Type_NUM or openxc_DynamicField_Type_STRING type only.");