summaryrefslogtreecommitdiffstats
path: root/CAN-binder/low-can-binding/utils/socketcan-bcm.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'CAN-binder/low-can-binding/utils/socketcan-bcm.cpp')
-rw-r--r--CAN-binder/low-can-binding/utils/socketcan-bcm.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/CAN-binder/low-can-binding/utils/socketcan-bcm.cpp b/CAN-binder/low-can-binding/utils/socketcan-bcm.cpp
index 835f7242..b0148d91 100644
--- a/CAN-binder/low-can-binding/utils/socketcan-bcm.cpp
+++ b/CAN-binder/low-can-binding/utils/socketcan-bcm.cpp
@@ -61,4 +61,28 @@ namespace utils
}
return socket_;
}
+
+ socketcan_bcm_t& operator>>(socketcan_bcm_t& s, can_message_t& cm)
+ {
+ struct {
+ struct bcm_msg_head msg_head;
+ struct can_frame frames;
+ } msg;
+
+ const struct sockaddr_can& addr = s.get_tx_address();
+ socklen_t addrlen = sizeof(addr);
+ struct ifreq ifr;
+
+ ssize_t nbytes = ::recvfrom(s.socket(), &msg, sizeof(msg), 0, (struct sockaddr*)&addr, &addrlen);
+ ifr.ifr_ifindex = addr.can_ifindex;
+ ioctl(s.socket(), SIOCGIFNAME, &ifr);
+
+ DEBUG(binder_interface, "Data available: %i bytes read", (int)nbytes);
+ DEBUG(binder_interface, "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]);
+
+ cm = ::can_message_t::convert_from_frame(msg.frames , nbytes-sizeof(struct bcm_msg_head));
+
+ return s;
+ }
} \ No newline at end of file