-/// @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() >= 0)
- {
- can_bus_t::can_devices_[device]->configure();
- DEBUG(binder_interface, "%s: Start reading thread", __FUNCTION__);
- NOTICE(binder_interface, "%s: %s device opened and reading", __FUNCTION__, device.c_str());
- //can_bus_t::can_devices_[device]->start_reading(*this);
- i++;
- }
- else
- {
- ERROR(binder_interface, "%s: Can't open device %s", __FUNCTION__, device.c_str());
- return 1;
- }
- }
- NOTICE(binder_interface, "%s: Initialized %d/%d can bus device(s)", __FUNCTION__, i, (int)t);
- return 0;
- }
- ERROR(binder_interface, "%s: Error at CAN device initialization. No devices read from configuration file", __FUNCTION__);
- return 1;
- }
- ERROR(binder_interface, "%s: Can't read INI configuration file", __FUNCTION__);
- return 2;
-}
-