aboutsummaryrefslogtreecommitdiffstats
path: root/CAN-binder/low-can-binding/utils/socketcan.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'CAN-binder/low-can-binding/utils/socketcan.cpp')
-rw-r--r--CAN-binder/low-can-binding/utils/socketcan.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/CAN-binder/low-can-binding/utils/socketcan.cpp b/CAN-binder/low-can-binding/utils/socketcan.cpp
index 17ce6ce7..c462f76a 100644
--- a/CAN-binder/low-can-binding/utils/socketcan.cpp
+++ b/CAN-binder/low-can-binding/utils/socketcan.cpp
@@ -24,6 +24,7 @@
#include "socketcan.hpp"
#include "low-can-binding.hpp"
+#include "can-message.hpp"
namespace utils
{
@@ -139,6 +140,27 @@ namespace utils
return socket_;
}
+ socketcan_t& operator>>(socketcan_t& s, const can_message_t& cm)
+ {
+ struct {
+ struct bcm_msg_head msg_head;
+ struct canfd_frame frames;
+ } msg;
+
+ 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);
+
+ printf("Data available: %i bytes read\n", (int)nbytes);
+ printf("read: Found on bus %s:\n id: %X, length: %X, data %02X%02X%02X%02X%02X%02X%02X%02X\n", ifr.ifr_name, msg.msg_head.can_id, msg.frames.len,
+ 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]);
+ return s;
+ }
+
socketcan_t& operator<<(socketcan_t& s, const struct bcm_msg_head& obj)
{
struct sockaddr_can addr = s.get_tx_address();