2 * Copyright (C) 2015, 2016 ,2017 "IoT.bzh"
3 * Copyright (C) 2021 Konsulko Group
4 * Author "Romain Forlot" <romain.forlot@iot.bzh>
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 #include "config-parser.hpp"
21 #include "../binding/low-can-hat.hpp"
25 /// @brief constructor using path to file
26 config_parser_t::config_parser_t(std::string conf_file)
27 : filepath_{conf_file}, config_content_{}
29 config_content_.read_file(conf_file);
32 const std::string& config_parser_t::filepath() const
37 /// @brief read the conf_file_ and parse it into an INIReader object
38 /// to search into later.
39 bool config_parser_t::check_conf()
41 if (config_content_.size() <= 0)
43 AFB_INFO("Cannot load INI config file: %s.", filepath_.c_str());
46 AFB_DEBUG("Configuration file parsed");
50 /// @brief Public method to access devices_name_ vector. If vector size equal 0
51 /// then it will parses the configuration file content to fill it. It could be empty even
52 /// after parsing if content file just don't have a correct "canbus" directive so you
53 /// have to test the returned value.
55 /// @return A const vector with string of linux CAN devices.
56 const std::vector<std::pair<std::string, std::string> > config_parser_t::get_devices_name()
58 std::vector<std::pair<std::string, std::string> > devices_name;
60 std::map<std::string, std::string> bus_mapping = config_content_.get_keys("CANbus-mapping");
61 for(const auto& busIt : bus_mapping )
63 devices_name.push_back(std::make_pair(busIt.first, busIt.second));