diff options
author | Romain Forlot <romain.forlot@iot.bzh> | 2019-12-19 11:29:07 +0100 |
---|---|---|
committer | Romain Forlot <romain.forlot@iot.bzh> | 2020-01-09 16:25:36 +0100 |
commit | 2dcfd4d0faa9699a4a32af1c39be674dc2856f41 (patch) | |
tree | b45f6ace6d4a14cbaeaa7859a5ada10c1e0ac0e0 | |
parent | b6bc89e63ee24c4e5ec1559d7390da90201ff9cd (diff) |
message: Fix copying all bytes but the last one
Change-Id: I8c2fce0f8080f213fda26a054f691ba3ed457bda
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
-rw-r--r-- | low-can-binding/can/message/can-message.cpp | 59 | ||||
-rw-r--r-- | low-can-binding/can/message/message.cpp | 22 | ||||
-rw-r--r-- | low-can-binding/can/message/message.hpp | 1 |
3 files changed, 18 insertions, 64 deletions
diff --git a/low-can-binding/can/message/can-message.cpp b/low-can-binding/can/message/can-message.cpp index a8843b9f..2d530f53 100644 --- a/low-can-binding/can/message/can-message.cpp +++ b/low-can-binding/can/message/can-message.cpp @@ -191,56 +191,33 @@ struct canfd_frame can_message_t::convert_to_canfd_frame() struct std::vector<canfd_frame> can_message_t::convert_to_canfd_frame_vector() { std::vector<canfd_frame> ret; + int i = 0; + if(is_correct_to_send()) { - if(flags_ & CAN_FD_FRAME) + while (i < length_) { - int i=0; - do + canfd_frame frame; + frame.can_id = id_; + if(flags_ & CAN_FD_FRAME) { - canfd_frame frame; - frame.can_id = id_; - frame.len = 64; - std::vector<uint8_t> 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 + frame.len = (length_ - (i * CANFD_MAX_DLC)) > CANFD_MAX_DLC - 1 ? CANFD_MAX_DLC : (uint8_t)(length_ - (i * CANFD_MAX_DLC)); + ::memcpy(frame.data, &data_.data()[i*CANFD_MAX_DLC], frame.len); + i += CANFD_MAX_DLC; + } + else { - canfd_frame frame; - frame.can_id = id_; - frame.len = 8; - std::vector<uint8_t> 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)); + frame.len = (length_ - (i * CAN_MAX_DLC)) > CAN_MAX_DLC - 1 ? CAN_MAX_DLC : (uint8_t)(length_ - (i * CAN_MAX_DLC)); + ::memcpy(frame.data, &data_.data()[i*CAN_MAX_DLEN], frame.len); + i += CAN_MAX_DLC; + } + ret.push_back(frame); } } else + { AFB_ERROR("can_message_t not correctly initialized to be sent"); + } return ret; } diff --git a/low-can-binding/can/message/message.cpp b/low-can-binding/can/message/message.cpp index 56e9379f..c714f506 100644 --- a/low-can-binding/can/message/message.cpp +++ b/low-can-binding/can/message/message.cpp @@ -76,28 +76,6 @@ const uint8_t* message_t::get_data() const return data_.data(); } - -/// -/// @brief Retrieve data_ member value. -/// -/// @return pointer to the first element -/// of class member data_ -/// -const std::vector<uint8_t> message_t::get_data_vector(int start, int end) const -{ - if ( start > length_ || end > length_ ) - { - AFB_ERROR("Error index to get data vector, [%d-%d] - for length %d", start, end, length_); - return data_; - } - - std::vector<uint8_t>::const_iterator first = data_.begin() + start; - std::vector<uint8_t>::const_iterator last = data_.begin() + end; - std::vector<uint8_t> ret(first, last); - - return ret; -} - /// /// @brief Retrieve data_ member whole vector /// diff --git a/low-can-binding/can/message/message.hpp b/low-can-binding/can/message/message.hpp index ce488c06..b77ce8bd 100644 --- a/low-can-binding/can/message/message.hpp +++ b/low-can-binding/can/message/message.hpp @@ -68,7 +68,6 @@ public: int get_sub_id() const; const uint8_t* get_data() const; const std::vector<uint8_t> get_data_vector() const; - const std::vector<uint8_t> get_data_vector(int start, int end) const; uint32_t get_length() const; uint64_t get_timestamp() const; |