+ if(flags & CAN_PROTOCOL)
+ {
+ subscription.socket_ = std::make_shared<utils::socketcan_bcm_t>();
+ if( subscription.signal_ )
+ ret = subscription.socket_->open(subscription.signal_->get_message()->get_bus_device_name());
+ else if(! subscription.diagnostic_message_.empty())
+ ret = subscription.socket_->open(application_t::instance().get_diagnostic_manager().get_bus_device_name());
+ else if(! bus_name.empty())
+ ret = subscription.socket_->open(bus_name);
+
+ subscription.index_ = (int)subscription.socket_->socket();
+ }
+#ifdef USE_FEATURE_ISOTP
+ else if(flags & ISOTP_PROTOCOL)
+ {
+ std::shared_ptr<utils::socketcan_isotp_t> socket = std::make_shared<utils::socketcan_isotp_t>();
+ if(subscription.signal_ )
+ {
+ canid_t rx = NO_CAN_ID;
+ canid_t tx = NO_CAN_ID;
+ if(flags & ISOTP_SEND)
+ {
+ rx = subscription.get_rx_id();
+ tx = subscription.signal_->get_message()->get_id();
+ }
+ else if(flags & ISOTP_RECEIVE)
+ {
+ rx = subscription.signal_->get_message()->get_id();
+ tx = subscription.get_tx_id();
+ }
+ ret = socket->open(subscription.signal_->get_message()->get_bus_device_name(), rx, tx);
+ subscription.socket_ = socket;
+ }
+ else if(! bus_name.empty())
+ {
+ ret = socket->open(bus_name, subscription.get_rx_id(), subscription.get_tx_id());
+ subscription.socket_ = socket;
+ }
+ subscription.index_ = (int)subscription.socket_->socket();
+ }
+#endif
+#ifdef USE_FEATURE_J1939
+ else if(flags & J1939_ADDR_CLAIM_PROTOCOL)
+ {
+ pgn_t pgn = J1939_NO_PGN;
+ std::shared_ptr<utils::socketcan_j1939_addressclaiming_t> socket = std::make_shared<utils::socketcan_j1939_addressclaiming_t>();
+ if(!bus_name.empty())
+ {
+ ret = socket->open(bus_name, pgn);
+ }
+ subscription.socket_ = socket;
+ subscription.index_ = (int)subscription.socket_->socket();
+ }
+ else if(flags & J1939_PROTOCOL)
+ {
+ pgn_t pgn = J1939_NO_PGN;
+ std::shared_ptr<utils::socketcan_j1939_data_t> socket = std::make_shared<utils::socketcan_j1939_data_t>();
+ if(subscription.signal_)
+ {
+ pgn = subscription.signal_->get_message()->get_id();
+ ret = socket->open(subscription.signal_->get_message()->get_bus_device_name(), pgn);
+ }
+ else if(!bus_name.empty())
+ {
+ ret = socket->open(bus_name, pgn);
+ }
+
+ if(ret)
+ socket->define_opt(!j1939_pgn_is_pdu1(pgn),subscription.event_filter_.promisc);
+
+ subscription.socket_ = socket;
+ subscription.index_ = (int)subscription.socket_->socket();
+ }
+#endif
+ else
+ {
+ AFB_ERROR("Socket format not supported");
+ return INVALID_SOCKET;
+ }
+ }
+ else{
+ ret = subscription.socket_->socket();