init: Fix wrong diagnostic bus name returned.
[apps/agl-service-can-low-level.git] / low-can-binding / binding / low-can-subscription.cpp
index e75bddf..3cbcb6c 100644 (file)
@@ -364,13 +364,13 @@ int low_can_subscription_t::open_socket(low_can_subscription_t &subscription, co
        int ret = -1;
        if(! subscription.socket_)
        {
-               if(flags & BCM_PROTOCOL)
+               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_name());
+                               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);
 
@@ -394,12 +394,12 @@ int low_can_subscription_t::open_socket(low_can_subscription_t &subscription, co
                                        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);
+                               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());
+                               ret = socket->open(bus_name, subscription.get_rx_id(), subscription.get_tx_id());
                                subscription.socket_ = socket;
                        }
                        subscription.index_ = (int)subscription.socket_->socket();
@@ -420,7 +420,7 @@ int low_can_subscription_t::open_socket(low_can_subscription_t &subscription, co
                else if(flags & J1939_PROTOCOL)
                {
                        pgn_t pgn = J1939_NO_PGN;
-                       if(subscription.signal_ != nullptr)
+                       if(subscription.signal_)
                        {
                                pgn = subscription.signal_->get_message()->get_id();
                                std::shared_ptr<utils::socketcan_j1939_data_t> socket = std::make_shared<utils::socketcan_j1939_data_t>();
@@ -495,7 +495,7 @@ void low_can_subscription_t::add_one_bcm_frame(struct canfd_frame& cfd, struct b
 void low_can_subscription_t::remove_last_bcm_frame(struct bcm_msg& bcm_msg)
 {
        struct canfd_frame cf;
-       memset(&cf,0,sizeof(cf));
+       memset(&cf, 0, sizeof(cf));
        bcm_msg.fd_frames[bcm_msg.msg_head.nframes] = cf;
        bcm_msg.msg_head.nframes--;
 }
@@ -648,7 +648,6 @@ int low_can_subscription_t::create_rx_filter(std::shared_ptr<diagnostic_message_
        diagnostic_message_.push_back(sig);
 
        struct timeval freq = frequency_clock_t(event_filter_.frequency).get_timeval_from_period();
-       //struct timeval timeout = frequency_clock_t(10).get_timeval_from_period();
        struct timeval timeout = {0, 0};
 
        struct bcm_msg bcm_msg =  make_bcm_head(RX_SETUP, OBD2_FUNCTIONAL_BROADCAST_ID, SETTIMER | RX_NO_AUTOTIMER | RX_FILTER_ID, timeout, freq);
@@ -666,16 +665,14 @@ int low_can_subscription_t::create_rx_filter(std::shared_ptr<diagnostic_message_
 int low_can_subscription_t::create_rx_filter_bcm(low_can_subscription_t &subscription, struct bcm_msg& bcm_msg)
 {
        // Make sure that socket is opened.
-       if(subscription.open_socket(subscription, "", BCM_PROTOCOL) < 0)
+       if(subscription.open_socket(subscription, "", CAN_PROTOCOL) < 0)
                return -1;
 
-       // If it's not an OBD2 CAN ID then just add a simple RX_SETUP job
-       // else monitor all standard 8 CAN OBD2 ID response.
-
        can_message_t msg = can_message_t();
-
        msg.set_bcm_msg(bcm_msg);
 
+       // If it's not an OBD2 CAN ID then just add a simple RX_SETUP job
+       // else monitor all standard 8 CAN OBD2 ID response.
        if(bcm_msg.msg_head.can_id != OBD2_FUNCTIONAL_BROADCAST_ID)
        {
                subscription.socket_->write_message(msg);
@@ -704,18 +701,16 @@ int low_can_subscription_t::tx_send(low_can_subscription_t &subscription, messag
 {
        can_message_t *cm = static_cast<can_message_t*>(message);
 
-       struct bcm_msg bcm_msg = subscription.make_bcm_head(TX_SEND, cm->get_id(),cm->get_flags()|TX_CP_CAN_ID); // TX_CP_CAN_ID -> copy in cfd the id of bcm
+       struct bcm_msg bcm_msg = subscription.make_bcm_head(TX_SEND, cm->get_id(), cm->get_flags()|TX_CP_CAN_ID); // TX_CP_CAN_ID -> copy in cfd the id of bcm
        cm->set_bcm_msg(bcm_msg);
 
        std::vector<canfd_frame> cfd_vect = cm->convert_to_canfd_frame_vector();
 
-       if(subscription.open_socket(subscription, bus_name, BCM_PROTOCOL) < 0)
+       if(subscription.open_socket(subscription, bus_name, CAN_PROTOCOL) < 0)
                return -1;
 
        struct bcm_msg &bcm_cm = cm->get_bcm_msg();
 
-
-
        if(cfd_vect.size() > 1)
        {
                AFB_ERROR("Multi frame BCM not implemented");
@@ -738,9 +733,7 @@ int low_can_subscription_t::tx_send(low_can_subscription_t &subscription, messag
        }
 
        if(! subscription.socket_.get())
-       {
-                       return -1;
-       }
+               return -1;
 
        return 0;
 }