summaryrefslogtreecommitdiffstats
path: root/low-can-binding/can/can-message.cpp
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2018-09-28 17:12:18 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2018-12-14 08:58:56 +0000
commitea35eabeadce57e4f5015797fea530c5bb219fff (patch)
tree69fbb0f4e4d5528500873d122bc35b3423d7ca96 /low-can-binding/can/can-message.cpp
parentb049485873e1692cc9e7857e91e017f86dd91218 (diff)
CAN FD implementation
Add a flag to CAN message definitions which set the message as using FD protocol if true. Use a new generated file with the new FD flag field on the message definitions. Change BCM socket "struct" using an union to store the CAN frames either using the FD struct or the classic non FD struct. A BCM socket can only one frame type once configured. Use as much as possible the "struct canfd_frame" in the binding and only make a difference before writing or reading the socket. From a memory point of view both struct are identical and only the last member differ and could hold more data with messages of 64 bytes long. So the canfd_frame is compatible with the can_frame and can be differentiated by a flag set in the can_id member. Remove now unused code processing can_frame. Keep the diagnostic manager using the classic CAN frame. Set the maximum number of frames that a BCM socket can handle to 257. Bug-AGL: SPEC-1980 Change-Id: Ifcc041281ea6745fc25cbd384743761f4446f489 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
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;
-}