summaryrefslogtreecommitdiffstats
path: root/low-can-binding/can/can-message.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'low-can-binding/can/can-message.cpp')
-rw-r--r--low-can-binding/can/can-message.cpp121
1 files changed, 0 insertions, 121 deletions
diff --git a/low-can-binding/can/can-message.cpp b/low-can-binding/can/can-message.cpp
index 1b27d0f6..9ec35668 100644
--- a/low-can-binding/can/can-message.cpp
+++ b/low-can-binding/can/can-message.cpp
@@ -266,124 +266,3 @@ can_message_t can_message_t::convert_from_frame(const struct canfd_frame& frame,
return can_message_t(maxdlen, id, length, format, rtr_flag, flags, data, timestamp);
}
-
-/// @brief Take a can_frame struct to initialize class members
-///
-/// This is the preferred way to initialize class members.
-///
-/// @param[in] frame - can_frame to convert coming from a read of CAN socket
-/// @param[in] nbytes - bytes read from socket read operation.
-///
-/// @return A can_message_t object fully initialized with can_frame values.
-can_message_t can_message_t::convert_from_frame(const struct can_frame& frame, size_t nbytes, uint64_t timestamp)
-{
- uint8_t maxdlen = 0, length = 0, flags = 0;
- uint32_t id;
- can_message_format_t format;
- bool rtr_flag;
- std::vector<uint8_t> data;
-
- if(nbytes <= CAN_MTU)
- {
- AFB_DEBUG("Got a legacy CAN frame");
- maxdlen = CAN_MAX_DLEN;
- }
- else
- {
- AFB_ERROR("unsupported CAN frame");
- }
-
- 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<maxdlen;i++)
- {
- data.push_back(frame.data[i]);
- };
-
-// AFB_DEBUG("Found id: %X, format: %X, length: %X, data %02X%02X%02X%02X%02X%02X%02X%02X",
-// id, (uint8_t)format, length, data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7]);
- }
-
- return can_message_t(maxdlen, id, length, format, rtr_flag, flags, data, timestamp);
-}
-
-/// @brief Take all initialized class members and build a
-/// canfd_frame struct that can be use to send a CAN message over
-/// the bus.
-///
-/// @return canfd_frame struct built from class members.
-struct canfd_frame can_message_t::convert_to_canfd_frame()
-{
- canfd_frame frame;
-
- if(is_correct_to_send())
- {
- frame.can_id = get_id();
- frame.len = get_length();
- ::memcpy(frame.data, get_data(), length_);
- }
- else
- AFB_ERROR("can_message_t not correctly initialized to be sent");
-
- return frame;
-}
-
-/// @brief Take all initialized class members and build a
-/// can_frame struct that can be use to send a CAN message over
-/// the bus.
-///
-/// @return can_frame struct built from class members.
-struct can_frame can_message_t::convert_to_can_frame()
-{
- can_frame frame;
-
- if(is_correct_to_send())
- {
- frame.can_id = get_id();
- frame.can_dlc = get_length();
- ::memcpy(frame.data, get_data(), length_);
- }
- else
- AFB_ERROR("can_message_t not correctly initialized to be sent");
-
- return frame;
-}