From 79cb12807f8a092acd3323d407a4661db9c04a74 Mon Sep 17 00:00:00 2001 From: Romain Forlot Date: Thu, 9 Mar 2017 02:33:19 +0100 Subject: Move some functions to configuration class. Change-Id: I87b1b6961206ae3848cf6aca367698218fe1523e Signed-off-by: Romain Forlot --- src/can/can-signals.cpp | 24 --------------- src/can/can-signals.hpp | 1 - src/configuration.cpp | 56 +++++++++++++++++++++++++++++++++-- src/configuration.hpp | 8 +++-- src/diagnostic/diagnostic-message.cpp | 25 ++-------------- src/diagnostic/diagnostic-message.hpp | 1 - 6 files changed, 62 insertions(+), 53 deletions(-) (limited to 'src') diff --git a/src/can/can-signals.cpp b/src/can/can-signals.cpp index faecdaa..af7376b 100644 --- a/src/can/can-signals.cpp +++ b/src/can/can-signals.cpp @@ -44,30 +44,6 @@ uint8_t can_signal_t::get_bit_size() const return bit_size_; } -/** - * @fn void find_can_signals(const openxc_DynamicField& key, std::vector& found_signals) - * @brief return signals name found searching through CAN_signals and OBD2 pid - * - * @param[in] key - can contain numeric or string value in order to search against - * can signals or obd2 signals name. - * @param[out] found_signals - provided vector to fill with ponter to signals matched. - * - */ -void find_can_signals(const openxc_DynamicField& key, std::vector& found_signals) -{ - switch(key.type) - { - case openxc_DynamicField_Type::openxc_DynamicField_Type_STRING: - lookup_signals_by_name(key.string_value, get_can_signals(), found_signals); - break; - case openxc_DynamicField_Type::openxc_DynamicField_Type_NUM: - lookup_signals_by_id(key.numeric_value, get_can_signals(), found_signals); - break; - default: - ERROR(binder_interface, "find_signals: wrong openxc_DynamicField specified. Use openxc_DynamicField_Type_NUM or openxc_DynamicField_Type_STRING type only."); - break; - } - DEBUG(binder_interface, "Found %d signal(s)", (int)found_signals.size()); float can_signal_t::get_factor() const { return factor_; diff --git a/src/can/can-signals.hpp b/src/can/can-signals.hpp index a4f01eb..91403d1 100644 --- a/src/can/can-signals.hpp +++ b/src/can/can-signals.hpp @@ -127,6 +127,5 @@ public: float get_last_value() const; void set_received(bool r); -void find_can_signals(const openxc_DynamicField &key, std::vector& found_signals); void set_received(bool r); void set_last_value(float val); }; \ No newline at end of file diff --git a/src/configuration.cpp b/src/configuration.cpp index b9d78c0..2257cbf 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -77,7 +77,7 @@ const std::vector& configuration_t::get_can_message_set() con return can_message_set_; } -const std::vector& configuration_t::get_can_signals() const +std::vector& configuration_t::get_can_signals() const { return can_signals_[active_message_set_]; } @@ -87,7 +87,7 @@ const std::vector& configuration_t::get_can_message_de return can_message_definition_[active_message_set_]; } -const std::vector& configuration_t::get_obd2_signals() const +std::vector& configuration_t::get_obd2_signals() const { return obd2_signals_; } @@ -105,4 +105,56 @@ uint32_t configuration_t::get_signal_id(can_signal_t& sig) const void configuration_t::set_active_message_set(uint8_t id) { active_message_set_ = id; +} + +/** + * @fn std::vector find_signals(const openxc_DynamicField &key) + * @brief return signals name found searching through CAN_signals and OBD2 pid + * + * @param[in] key - can contain numeric or string value in order to search against + * can signals or obd2 signals name. + * + * @return Vector of signals name found. + */ +void configuration_t::find_obd2_signals(const openxc_DynamicField &key, std::vector& found_signals) +{ + switch(key.type) + { + case openxc_DynamicField_Type::openxc_DynamicField_Type_STRING: + lookup_signals_by_name(key.string_value, obd2_signals_, found_signals); + break; + case openxc_DynamicField_Type::openxc_DynamicField_Type_NUM: + lookup_signals_by_id(key.numeric_value, obd2_signals_, found_signals); + break; + default: + ERROR(binder_interface, "find_signals: wrong openxc_DynamicField specified. Use openxc_DynamicField_Type_NUM or openxc_DynamicField_Type_STRING type only."); + break; + } + DEBUG(binder_interface, "Found %d signal(s)", (int)found_signals.size()); +} + +/** + * @fn void find_can_signals(const openxc_DynamicField& key, std::vector& found_signals) + * @brief return signals name found searching through CAN_signals and OBD2 pid + * + * @param[in] key - can contain numeric or string value in order to search against + * can signals or obd2 signals name. + * @param[out] found_signals - provided vector to fill with ponter to signals matched. + * + */ +void configuration_t::find_can_signals(const openxc_DynamicField& key, std::vector& found_signals) +{ + switch(key.type) + { + case openxc_DynamicField_Type::openxc_DynamicField_Type_STRING: + lookup_signals_by_name(std::string(key.string_value), can_signals_, found_signals); + break; + case openxc_DynamicField_Type::openxc_DynamicField_Type_NUM: + lookup_signals_by_id(key.numeric_value, can_signals_ found_signals); + break; + default: + ERROR(binder_interface, "find_signals: wrong openxc_DynamicField specified. Use openxc_DynamicField_Type_NUM or openxc_DynamicField_Type_STRING type only."); + break; + } + DEBUG(binder_interface, "Found %d signal(s)", (int)found_signals.size()); } \ No newline at end of file diff --git a/src/configuration.hpp b/src/configuration.hpp index 77f452f..9c49da0 100644 --- a/src/configuration.hpp +++ b/src/configuration.hpp @@ -63,11 +63,11 @@ class configuration_t const std::vector& get_can_message_set() const; - const std::vector& get_can_signals() const; + std::vector& get_can_signals() const; const std::vector& get_can_message_definition() const; - const std::vector& get_obd2_signals() const; + std::vector& get_obd2_signals() const; uint32_t get_signal_id(obd2_signal_t& sig) const; @@ -75,6 +75,10 @@ class configuration_t void set_active_message_set(uint8_t id); + void find_obd2_signals(const openxc_DynamicField &key, std::vector& found_signals); + + void find_can_signals(const openxc_DynamicField &key, std::vector& found_signals); + /* /// TODO: implement this function as method into can_bus class /// @brief Pre initialize actions made before CAN bus initialization diff --git a/src/diagnostic/diagnostic-message.cpp b/src/diagnostic/diagnostic-message.cpp index 76b9799..247917b 100644 --- a/src/diagnostic/diagnostic-message.cpp +++ b/src/diagnostic/diagnostic-message.cpp @@ -42,30 +42,9 @@ uint32_t obd2_signal_t::get_pid() return (uint32_t)pid_; } -/** - * @fn std::vector find_signals(const openxc_DynamicField &key) - * @brief return signals name found searching through CAN_signals and OBD2 pid - * - * @param[in] key - can contain numeric or string value in order to search against - * can signals or obd2 signals name. - * - * @return Vector of signals name found. - */ -void obd2_signal_t::find_obd2_signals(const openxc_DynamicField &key, std::vector& found_signals) +std::string& obd2_signal_t::get_generic_name() { - switch(key.type) - { - case openxc_DynamicField_Type::openxc_DynamicField_Type_STRING: - lookup_signals_by_name(key.string_value, get_obd2_signals(), found_signals); - break; - case openxc_DynamicField_Type::openxc_DynamicField_Type_NUM: - lookup_signals_by_id(key.numeric_value, get_obd2_signals(), found_signals); - break; - default: - ERROR(binder_interface, "find_signals: wrong openxc_DynamicField specified. Use openxc_DynamicField_Type_NUM or openxc_DynamicField_Type_STRING type only."); - break; - } - DEBUG(binder_interface, "Found %d signal(s)", (int)found_signals.size()); + return generic_name_; } bool obd2_signal_t::is_obd2_response(can_message_t can_message) diff --git a/src/diagnostic/diagnostic-message.hpp b/src/diagnostic/diagnostic-message.hpp index 33035ff..9dca770 100644 --- a/src/diagnostic/diagnostic-message.hpp +++ b/src/diagnostic/diagnostic-message.hpp @@ -83,7 +83,6 @@ class obd2_signal_t { void add_request(int pid); - void find_obd2_signals(const openxc_DynamicField &key, std::vector& found_signals); bool is_obd2_response(can_message_t can_message); bool is_obd2_request(DiagnosticRequest *request); -- cgit 1.2.3-korg