From 62083285cdaaab054e940013bc1c20cb4959327f Mon Sep 17 00:00:00 2001 From: Arthur Guyader Date: Mon, 26 Aug 2019 15:46:08 +0200 Subject: Update function tx_send for multi frame prevision Bug-AGL : SPEC-2779 Change-Id: Ib0b04fe3648c5b83c23327431e21161b6b2489b6 Signed-off-by: Arthur Guyader --- low-can-binding/binding/low-can-subscription.cpp | 37 +++++++++++++++++++----- 1 file changed, 30 insertions(+), 7 deletions(-) (limited to 'low-can-binding') diff --git a/low-can-binding/binding/low-can-subscription.cpp b/low-can-binding/binding/low-can-subscription.cpp index d4ada3fe..edc0a0b4 100644 --- a/low-can-binding/binding/low-can-subscription.cpp +++ b/low-can-binding/binding/low-can-subscription.cpp @@ -20,6 +20,8 @@ #include "application.hpp" #include "canutil/write.h" #include "../utils/socketcan-bcm.hpp" +#include "../can/can-encoder.hpp" + #ifdef USE_FEATURE_J1939 #include "../utils/socketcan-j1939/socketcan-j1939-data.hpp" #endif @@ -535,20 +537,41 @@ int low_can_subscription_t::tx_send(low_can_subscription_t &subscription, messag { can_message_t *cm = static_cast(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 cfd_vect = cm->convert_to_canfd_frame_vector(); - for(auto cfd: cfd_vect) + + if(subscription.open_socket(subscription, bus_name,socket_type::BCM) < 0) { - subscription.add_one_bcm_frame(cfd, bcm_msg); + return -1; } - if(subscription.open_socket(subscription, bus_name,socket_type::BCM) < 0) + struct bcm_msg &bcm_cm = cm->get_bcm_msg(); + + + + if(cfd_vect.size() > 1) { + AFB_ERROR("Multi frame BCM not implemented"); + return -1; + } + else if(cfd_vect.size() == 1) // raw or fd + { + subscription.add_one_bcm_frame(cfd_vect[0], bcm_cm); + + if(subscription.socket_->write_message(*cm) < 0) + { + AFB_ERROR("Error write message id : %d",cfd_vect[0].can_id); return -1; + } + } + else // error + { + AFB_ERROR("Error no data available"); + return -1; } - cm->set_bcm_msg(bcm_msg); - subscription.socket_->write_message(*cm); if(! subscription.socket_.get()) { return -1; @@ -578,4 +601,4 @@ int low_can_subscription_t::j1939_send(low_can_subscription_t &subscription, mes return 0; } -#endif \ No newline at end of file +#endif -- cgit 1.2.3-korg