X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=CAN-binder%2Flow-can-binding%2Fcan%2Fcan-message.cpp;h=abfbfdb064971464187f4d57ebc98910e9e70246;hb=7747851ca010a3dfe9ffee808376dd5a7af68b91;hp=f27dce3f80c5b329e800deccd47c28e3444fbc79;hpb=f0973849c4df5740ffb241a21fc08398fa741a7e;p=apps%2Flow-level-can-service.git diff --git a/CAN-binder/low-can-binding/can/can-message.cpp b/CAN-binder/low-can-binding/can/can-message.cpp index f27dce3..abfbfdb 100644 --- a/CAN-binder/low-can-binding/can/can-message.cpp +++ b/CAN-binder/low-can-binding/can/can-message.cpp @@ -19,7 +19,7 @@ #include -#include "../low-can-binding.hpp" +#include "../binding/low-can-hat.hpp" /// /// @brief Class constructor @@ -27,7 +27,7 @@ /// Constructor about can_message_t class. /// can_message_t::can_message_t() - : maxdlen_{0}, id_{0}, length_{0}, format_{can_message_format_t::ERROR}, rtr_flag_{false}, flags_{0} + : maxdlen_{0}, id_{0}, length_{0}, format_{can_message_format_t::INVALID}, rtr_flag_{false}, flags_{0}, timestamp_{0} {} can_message_t::can_message_t(uint8_t maxdlen, @@ -36,14 +36,16 @@ can_message_t::can_message_t(uint8_t maxdlen, can_message_format_t format, bool rtr_flag, uint8_t flags, - std::vector data) + std::vector& data, + uint64_t timestamp) : maxdlen_{maxdlen}, id_{id}, length_{length}, format_{format}, rtr_flag_{rtr_flag}, flags_{flags}, - data_{data} + data_{data}, + timestamp_{timestamp} {} /// @@ -74,7 +76,7 @@ bool can_message_t::get_rtr_flag_() const can_message_format_t can_message_t::get_format() const { if (format_ != can_message_format_t::STANDARD || format_ != can_message_format_t::EXTENDED) - return can_message_format_t::ERROR; + return can_message_format_t::INVALID; return format_; } @@ -99,6 +101,16 @@ const uint8_t* can_message_t::get_data() const return data_.data(); } +/// +/// @brief Retrieve data_ member whole vector +/// +/// @return the vector as is +/// +const std::vector can_message_t::get_data_vector() const +{ + return data_; +} + /// /// @brief Retrieve length_ member value. /// @@ -109,6 +121,16 @@ uint8_t can_message_t::get_length() const return length_; } +uint64_t can_message_t::get_timestamp() const +{ + return timestamp_; +} + +void can_message_t::set_timestamp(uint64_t timestamp) +{ + timestamp_ = timestamp; +} + /// /// @brief Control whether the object is correctly initialized /// to be sent over the CAN bus @@ -117,7 +139,7 @@ uint8_t can_message_t::get_length() const /// bool can_message_t::is_correct_to_send() { - if (id_ != 0 && length_ != 0 && format_ != can_message_format_t::ERROR) + if (id_ != 0 && length_ != 0 && format_ != can_message_format_t::INVALID) { int i; for(i=0;i data; + + if(nbytes <= CAN_MTU) + { + DEBUG(binder_interface, "%s: Got a legacy CAN frame", __FUNCTION__); + maxdlen = CAN_MAX_DLEN; + } + else + { + ERROR(binder_interface, "%s: unsupported CAN frame", __FUNCTION__); + } + + if (frame.can_id & CAN_ERR_FLAG) + { + format = can_message_format_t::INVALID; + id = frame.can_id & (CAN_ERR_MASK|CAN_ERR_FLAG); + } + else if (frame.can_id & CAN_EFF_FLAG) + { + format = can_message_format_t::EXTENDED; + id = frame.can_id & CAN_EFF_MASK; + } + else + { + format = can_message_format_t::STANDARD; + id = frame.can_id & CAN_SFF_MASK; + } + + /* Overwrite length_ if RTR flags is detected. + * standard CAN frames may have RTR enabled. There are no ERR frames with RTR */ + if (frame.can_id & CAN_RTR_FLAG) + { + rtr_flag = true; + if(frame.can_dlc && frame.can_dlc <= CAN_MAX_DLC) + { + if(rtr_flag) + length = frame.can_dlc& 0xF; + else + { + length = (frame.can_dlc > maxdlen) ? maxdlen : frame.can_dlc; + } + } + } + else + { + length = (frame.can_dlc > maxdlen) ? maxdlen : frame.can_dlc; + + if (data.capacity() < maxdlen) + data.reserve(maxdlen); + int i; + + data.clear(); + /* maxdlen_ is now set at CAN_MAX_DLEN or CANFD_MAX_DLEN, respectively 8 and 64 bytes*/ + for(i=0;i