From: Arthur Guyader Date: Mon, 26 Aug 2019 13:32:20 +0000 (+0200) Subject: Add function to convert vector to canfd or can frame. X-Git-Tag: 8.99.1~20 X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F44%2F22244%2F2;p=apps%2Fagl-service-can-low-level.git Add function to convert vector to canfd or can frame. This commit allows to convert the data vector to canfd or can frame. In the two cases the struct is a canfd frame, but if the type is not fd, the max size of a frame is 8. Bug-AGL : SPEC-2779 Change-Id: I60edf6a602a47572d5e5bfb508c7ca6d8761832b Signed-off-by: Arthur Guyader --- diff --git a/low-can-binding/can/message/can-message.cpp b/low-can-binding/can/message/can-message.cpp index 90bade53..deca5c72 100644 --- a/low-can-binding/can/message/can-message.cpp +++ b/low-can-binding/can/message/can-message.cpp @@ -67,7 +67,7 @@ bool can_message_t::is_correct_to_send() if (id_ != 0 && length_ != 0 && format_ != message_format_t::INVALID) { int i; - for(i=0;i can_message_t::convert_to_canfd_frame_vector() +{ + std::vector ret; + if(is_correct_to_send()) + { + if(flags_ & CAN_FD_FRAME) + { + int i=0; + do + { + canfd_frame frame; + frame.can_id = id_; + frame.len = 64; + std::vector data = get_data_vector((i*64),(i*64)+63); + if(data.size()<64) + { + ::memset(frame.data,0,sizeof(frame.data)); + ::memcpy(frame.data,data.data(),data.size()); + } + else + { + ::memcpy(frame.data,data.data(),64); + } + ret.push_back(frame); + i++; + } while (i<(length_ >> 6)); + } + else + { + int i=0; + do + { + canfd_frame frame; + frame.can_id = id_; + frame.len = 8; + std::vector data = get_data_vector(i*8,(i*8)+7); + if(data.size()<8) + { + ::memset(frame.data,0,sizeof(frame.data)); + ::memcpy(frame.data,data.data(),data.size()); + } + else + { + ::memset(frame.data,0,sizeof(frame.data)); + ::memcpy(frame.data,data.data(),8); + } + ret.push_back(frame); + i++; + } while (i<(length_ >> 3)); + } + } + else + AFB_ERROR("can_message_t not correctly initialized to be sent"); + + return ret; +} + /// @brief Take all initialized class members and build a /// can_frame struct that can be use to send a CAN message over /// the bus. diff --git a/low-can-binding/can/message/can-message.hpp b/low-can-binding/can/message/can-message.hpp index 0f8bc9b5..9e75887f 100644 --- a/low-can-binding/can/message/can-message.hpp +++ b/low-can-binding/can/message/can-message.hpp @@ -46,6 +46,7 @@ class can_message_t : public message_t { static std::shared_ptr convert_from_frame(const canfd_frame& frame, size_t nbytes, uint64_t timestamp); struct canfd_frame convert_to_canfd_frame(); + struct std::vector convert_to_canfd_frame_vector(); struct can_frame convert_to_can_frame(); bool is_correct_to_send();