Finish config parser retrieving device mapping.
authorRomain Forlot <romain.forlot@iot.bzh>
Thu, 18 May 2017 17:49:43 +0000 (19:49 +0200)
committerRomain Forlot <romain.forlot@iot.bzh>
Fri, 19 May 2017 12:48:23 +0000 (14:48 +0200)
Change-Id: Ia43f9c0edf09ff9a1c009f198bdad10a6b44b249
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
CAN-binder/low-can-binding/binding/low-can-hat.cpp
CAN-binder/low-can-binding/can/can-bus.cpp
CAN-binder/low-can-binding/can/can-bus.hpp
CAN-binder/low-can-binding/utils/config-parser.cpp
CAN-binder/low-can-binding/utils/config-parser.hpp

index 747228e..918625f 100644 (file)
@@ -68,6 +68,7 @@ extern "C"
        {
                can_bus_t& can_bus_manager = configuration_t::instance().get_can_bus_manager();
 
+               can_bus_manager.set_can_devices();
                can_bus_manager.start_threads();
 
                /// Initialize Diagnostic manager that will handle obd2 requests.
index 06338b4..bd9cde7 100644 (file)
@@ -294,9 +294,15 @@ void can_bus_t::push_new_vehicle_message(const openxc_VehicleMessage& v_msg)
 void can_bus_t::set_can_devices()
 {
        can_devices_ = conf_file_.get_devices_name();
+
+       if(can_devices_.empty())
+       {
+               ERROR(binder_interface, "%s: No mapping found in config file: '%s'. Check it that it have a CANbus-mapping section.",
+                       __FUNCTION__, conf_file_.filepath().c_str());
+       }
 }
 
-int can_bus_t::get_can_device_index(std::string bus_name) const
+int can_bus_t::get_can_device_index(const std::string& bus_name) const
 {
        int i = 0;
        for(const auto& d: can_devices_)
@@ -308,7 +314,7 @@ int can_bus_t::get_can_device_index(std::string bus_name) const
        return i;
 }
 
-std::string can_bus_t::get_can_device_name(std::string id_name) const
+const std::string can_bus_t::get_can_device_name(const std::string& id_name) const
 {
        std::string ret;
        for(const auto& d: can_devices_)
index c300c7f..1efd204 100644 (file)
@@ -75,8 +75,8 @@ public:
        can_bus_t(can_bus_t&&);
 
        void set_can_devices();
-       int get_can_device_index(std::string bus_name) const;
-       std::string get_can_device_name(std::string id_name) const;
+       int get_can_device_index(const std::string& bus_name) const;
+       const std::string get_can_device_name(const std::string& id_name) const;
 
        void start_threads();
        void stop_threads();
index 6f69916..3f33812 100644 (file)
@@ -23,11 +23,16 @@ namespace utils
 {
        /// @brief constructor using path to file
        config_parser_t::config_parser_t(std::string conf_file)
-               : config_content_{}
+               : filepath_{conf_file}, config_content_{}
        {
                config_content_.read_file(conf_file);
        }
 
+       const std::string& config_parser_t::filepath() const
+       {
+               return filepath_;
+       }
+
        /// @brief read the conf_file_ and parse it into an INIReader object
        /// to search into later.
        bool config_parser_t::check_conf()
index ce032c9..0453110 100644 (file)
@@ -29,6 +29,7 @@ namespace utils
        class config_parser_t
        {
        private:
+               const std::string filepath_; /*!< filepath_ - Path to the config file*/
                ini_config config_content_; /*!< config_content_ - Parsed content of INI file.*/
 
        public:
@@ -36,6 +37,7 @@ namespace utils
                config_parser_t(const config_parser_t&) = default;
                config_parser_t(std::string conf_file);
 
+               const std::string& filepath() const;
                bool check_conf();
                const std::vector<std::pair<std::string, std::string> > get_devices_name();
        };