aboutsummaryrefslogtreecommitdiffstats
path: root/low-can-binding/utils/socketcan-bcm.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/utils/socketcan-bcm.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/utils/socketcan-bcm.cpp')
-rw-r--r--low-can-binding/utils/socketcan-bcm.cpp25
1 files changed, 19 insertions, 6 deletions
diff --git a/low-can-binding/utils/socketcan-bcm.cpp b/low-can-binding/utils/socketcan-bcm.cpp
index 750e772d..d1fd8e0a 100644
--- a/low-can-binding/utils/socketcan-bcm.cpp
+++ b/low-can-binding/utils/socketcan-bcm.cpp
@@ -72,7 +72,7 @@ namespace utils
/// then CAN message will be zeroed and must be handled later.
socketcan_bcm_t& operator>>(socketcan_bcm_t& s, can_message_t& cm)
{
- struct utils::simple_bcm_msg msg;
+ struct utils::bcm_msg msg;
::memset(&msg, 0, sizeof(msg));
const struct sockaddr_can& addr = s.get_tx_address();
@@ -85,17 +85,30 @@ namespace utils
long unsigned int frame_size = nbytes-sizeof(struct bcm_msg_head);
AFB_DEBUG("Data available: %li bytes read. BCM head, opcode: %i, can_id: %i, nframes: %i", frame_size, msg.msg_head.opcode, msg.msg_head.can_id, msg.msg_head.nframes);
- AFB_DEBUG("read: Found on bus %s:\n id: %X, length: %X, data %02X%02X%02X%02X%02X%02X%02X%02X", ifr.ifr_name, msg.msg_head.can_id, msg.frames.can_dlc,
- msg.frames.data[0], msg.frames.data[1], msg.frames.data[2], msg.frames.data[3], msg.frames.data[4], msg.frames.data[5], msg.frames.data[6], msg.frames.data[7]);
struct timeval tv;
ioctl(s.socket(), SIOCGSTAMP, &tv);
uint64_t timestamp = 1000000 * tv.tv_sec + tv.tv_usec;
- cm = ::can_message_t::convert_from_frame(msg.frames ,
- frame_size,
- timestamp);
+ cm = can_message_t::convert_from_frame(msg.fd_frames[0] , frame_size, timestamp);
cm.set_sub_id((int)s.socket());
return s;
}
+
+ socketcan_bcm_t& operator<<(socketcan_bcm_t& s, const std::vector<struct utils::bcm_msg>& vobj)
+ {
+ for(const auto& obj : vobj)
+ s << obj;
+ return s;
+ }
+
+ socketcan_bcm_t& operator<<(socketcan_bcm_t& s, const struct utils::bcm_msg& obj)
+ {
+ size_t size = (obj.msg_head.flags & CAN_FD_FRAME) ?
+ (size_t)((char*)&obj.fd_frames[obj.msg_head.nframes] - (char*)&obj):
+ (size_t)((char*)&obj.frames[obj.msg_head.nframes] - (char*)&obj);
+ if (::sendto(s.socket(), &obj, size, 0, (const struct sockaddr*)&s.get_tx_address(), sizeof(s.get_tx_address())) < 0)
+ AFB_API_ERROR(afbBindingV3root, "Error sending : %i %s", errno, ::strerror(errno));
+ return s;
+ }
}