+ utils::config_parser_t conf_file("/etc/dev-mapping.conf");
+ if(conf_file.check_conf())
+ {
+ // If a mapping file in /etc exists, use it
+ AFB_INFO("Using /etc/dev-mapping.conf");
+ application->get_can_bus_manager().set_can_devices(conf_file.get_devices_name());
+ } else {
+ // Use whatever configuration is in the controller JSON
+ if(wrap_json_unpack(json_obj, "{so}",
+ "dev-mapping", &dev_mapping)) {
+ AFB_ERROR("No device mapping in controller JSON");
+ return -1;
+ }
+
+ application->get_can_bus_manager().set_can_devices(dev_mapping);
+ }
+
+ // Find all required buses
+ std::set<std::string> buses;
+ std::set<std::string> j1939_buses;
+ vect_ptr_msg_def_t msg_defs = application->get_messages_definition();
+ for(std::shared_ptr<message_definition_t> &msg_def : msg_defs) {
+ if(!msg_def->is_j1939())
+ buses.insert(msg_def->get_bus_name());
+ else
+ j1939_buses.insert(msg_def->get_bus_name());
+ }
+#ifdef USE_FEATURE_J1939
+ // NOTE: With C++17 just: buses.merge(j1939_buses)
+ for(auto it = begin(j1939_buses); it != end(j1939_buses); ++it)
+ buses.insert(*it);
+#endif
+
+ // Check that required buses have device mappings
+ for(auto it = begin(buses); it != end(buses); ++it) {
+ std::string dev = application->get_can_bus_manager().get_can_device_name(*it);
+ if(dev == "") {
+ AFB_ERROR("No CAN device defined for bus \"%s\"", it->c_str());
+ return -1;
+ }
+ AFB_INFO("Using CAN device %s for bus \"%s\"", dev.c_str(), it->c_str());
+ }
+
+ // Check that diagnostic bus is one of the configured buses
+ if(diagnostic_bus && buses.count(diagnostic_bus) == 0) {
+ AFB_ERROR("No CAN device mapping defined for diagnostic bus \"%s\"", diagnostic_bus);