-/// @brief Will initialize can_bus_dev_t objects after reading
-/// the configuration file passed in the constructor. All CAN buses
-/// Initialized here will be added to a vector holding them for
-/// inventory and later access.
-///
-/// That will initialize CAN socket reading too using a new thread.
-///
-/// @return 0 if ok, other if not.
-int can_bus_t::init_can_dev()
-{
- std::vector<std::string> devices_name;
- int i = 0;
- size_t t;
-
- if(conf_file_.check_conf())
- {
- devices_name = conf_file_.get_devices_name();
- if (! devices_name.empty())
- {
- t = devices_name.size();
-
- for(const auto& device : devices_name)
- {
- can_bus_t::can_devices_[device] = std::make_shared<can_bus_dev_t>(device, i);
- if (can_bus_t::can_devices_[device]->open_raw() == 0)
- {
- DEBUG(binder_interface, "Start reading thread");
- NOTICE(binder_interface, "%s device opened and reading", device.c_str());
- can_bus_t::can_devices_[device]->start_reading(*this);
- i++;
- }
- else
- {
- ERROR(binder_interface, "Can't open device %s", device.c_str());
- return 1;
- }
- }
- NOTICE(binder_interface, "Initialized %d/%d can bus device(s)", i, (int)t);
- return 0;
- }
- ERROR(binder_interface, "init_can_dev: Error at CAN device initialization. No devices read from configuration file");
- return 1;
- }
- ERROR(binder_interface, "init_can_dev: Can't read INI configuration file");
- return 2;
-}
-