X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=low-can-binding%2Fbinding%2Flow-can-subscription.cpp;h=edc0a0b4f6530c268fcfb636f53ae8655f4e20c6;hb=a8d5f5d3018da0b051dad4c143c6257b2fba9fac;hp=a1187edde387d5ba7ad0adf4a4cac2d1a8eec306;hpb=5174772b69e56b671fb149e8acdc4f2a35e354d9;p=apps%2Fagl-service-can-low-level.git diff --git a/low-can-binding/binding/low-can-subscription.cpp b/low-can-binding/binding/low-can-subscription.cpp index a1187edd..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 @@ -331,6 +333,7 @@ struct bcm_msg low_can_subscription_t::make_bcm_head(uint32_t opcode, uint32_t c bcm_msg.msg_head.ival2.tv_sec = frequency_thinning.tv_sec ; bcm_msg.msg_head.ival2.tv_usec = frequency_thinning.tv_usec; + return bcm_msg; } @@ -353,6 +356,17 @@ void low_can_subscription_t::add_one_bcm_frame(struct canfd_frame& cfd, struct b bcm_msg.msg_head.nframes++; } +/// @brief Take an existing bcm_msg struct and add a can_frame. +/// Currently only 1 uniq can_frame can be added, it's not possible to build +/// a multiplexed message with several can_frame. +void low_can_subscription_t::remove_last_bcm_frame(struct bcm_msg& bcm_msg) +{ + struct canfd_frame cf; + memset(&cf,0,sizeof(cf)); + bcm_msg.fd_frames[bcm_msg.msg_head.nframes] = cf; + bcm_msg.msg_head.nframes--; +} + #ifdef USE_FEATURE_J1939 int low_can_subscription_t::create_rx_filter_j1939(low_can_subscription_t &subscription, std::shared_ptr sig) { @@ -378,32 +392,65 @@ int low_can_subscription_t::create_rx_filter_can(low_can_subscription_t &subscri struct timeval freq, timeout = {0, 0}; struct canfd_frame cfd; subscription.signal_= sig; + bool is_fd = sig->get_message()->is_fd(); + + std::vector data; + uint32_t length_msg = sig->get_message()->get_length(); - if (sig->get_message()->is_fd()) + if(length_msg == 0) + { + AFB_ERROR("Error in the length of message with id %d",sig->get_message()->get_id()); + return -1; + } + + for(int i = 0; iget_message()->get_id(),length_msg,sig->get_message()->get_format(),false,CAN_FD_FRAME,data,0); } else { flags = SETTIMER|RX_NO_AUTOTIMER; cfd.len = CAN_MAX_DLEN; + cm = can_message_t(CAN_MAX_DLEN,sig->get_message()->get_id(),length_msg,sig->get_message()->get_format(),false,0,data,0); } - val = (float)(1 << subscription.signal_->get_bit_size()) - 1; - if(! bitfield_encode_float(val, - subscription.signal_->get_bit_position(), - subscription.signal_->get_bit_size(), - 1, - subscription.signal_->get_offset(), - cfd.data, - cfd.len)) - return -1; frequency_clock_t f = subscription.event_filter_.frequency == 0 ? subscription.signal_->get_frequency() : frequency_clock_t(subscription.event_filter_.frequency); freq = f.get_timeval_from_period(); struct bcm_msg bcm_msg = subscription.make_bcm_head(RX_SETUP, subscription.signal_->get_message()->get_id(), flags, timeout, freq); - subscription.add_one_bcm_frame(cfd, bcm_msg); + + std::vector cfd_vect = cm.convert_to_canfd_frame_vector(); + + if(cfd_vect.size() > 1) //multi + { + AFB_ERROR("Not implemented yet"); + return -1; + } + else if(cfd_vect.size() == 1) + { + canfd_frame cf = cfd_vect[0]; + for(int i=0;i(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; @@ -533,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