diff options
-rw-r--r-- | CAN-binder/low-can-binding/utils/socketcan-bcm.cpp | 24 | ||||
-rw-r--r-- | CAN-binder/low-can-binding/utils/socketcan-bcm.hpp | 2 | ||||
-rw-r--r-- | CAN-binder/low-can-binding/utils/socketcan-raw.cpp | 21 | ||||
-rw-r--r-- | CAN-binder/low-can-binding/utils/socketcan-raw.hpp | 2 | ||||
-rw-r--r-- | CAN-binder/low-can-binding/utils/socketcan.cpp | 24 | ||||
-rw-r--r-- | CAN-binder/low-can-binding/utils/socketcan.hpp | 2 |
6 files changed, 49 insertions, 26 deletions
diff --git a/CAN-binder/low-can-binding/utils/socketcan-bcm.cpp b/CAN-binder/low-can-binding/utils/socketcan-bcm.cpp index 835f724..b0148d9 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 diff --git a/CAN-binder/low-can-binding/utils/socketcan-bcm.hpp b/CAN-binder/low-can-binding/utils/socketcan-bcm.hpp index deb30c6..d23b067 100644 --- a/CAN-binder/low-can-binding/utils/socketcan-bcm.hpp +++ b/CAN-binder/low-can-binding/utils/socketcan-bcm.hpp @@ -44,6 +44,8 @@ namespace utils private: int connect(const struct sockaddr* addr, socklen_t len); }; + + socketcan_bcm_t& operator>>(socketcan_bcm_t& s, can_message_t& cm); // socketcan_bcm_t& operator<<(socketcan_bcm_t& s, const struct simple_bcm_msg& obj); // socketcan_bcm_t& operator<<(socketcan_bcm_t& s, const struct canfd_bcm_msg& obj); } diff --git a/CAN-binder/low-can-binding/utils/socketcan-raw.cpp b/CAN-binder/low-can-binding/utils/socketcan-raw.cpp index 589f6ab..d8cd906 100644 --- a/CAN-binder/low-can-binding/utils/socketcan-raw.cpp +++ b/CAN-binder/low-can-binding/utils/socketcan-raw.cpp @@ -61,4 +61,25 @@ namespace utils } return socket_; } + + socketcan_raw_t& operator>>(socketcan_raw_t& s, can_message_t& cm) + { + struct canfd_frame frame; + + const struct sockaddr_can& addr = s.get_tx_address(); + socklen_t addrlen = sizeof(addr); + struct ifreq ifr; + + ssize_t nbytes = ::recvfrom(s.socket(), &frame, sizeof(frame), 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, frame.can_id, frame.len, + frame.data[0], frame.data[1], frame.data[2], frame.data[3], frame.data[4], frame.data[5], frame.data[6], frame.data[7]); + + cm = ::can_message_t::convert_from_frame(frame , nbytes); + + return s; + } }
\ No newline at end of file diff --git a/CAN-binder/low-can-binding/utils/socketcan-raw.hpp b/CAN-binder/low-can-binding/utils/socketcan-raw.hpp index e18ff1f..40a6e02 100644 --- a/CAN-binder/low-can-binding/utils/socketcan-raw.hpp +++ b/CAN-binder/low-can-binding/utils/socketcan-raw.hpp @@ -29,4 +29,6 @@ namespace utils private: int bind(const struct sockaddr* addr, socklen_t len); }; + + socketcan_raw_t& operator>>(socketcan_raw_t& s, can_message_t& cm); } diff --git a/CAN-binder/low-can-binding/utils/socketcan.cpp b/CAN-binder/low-can-binding/utils/socketcan.cpp index f52aaa6..d66822d 100644 --- a/CAN-binder/low-can-binding/utils/socketcan.cpp +++ b/CAN-binder/low-can-binding/utils/socketcan.cpp @@ -90,28 +90,4 @@ namespace utils { return socket_; } - - socketcan_t& operator>>(socketcan_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 diff --git a/CAN-binder/low-can-binding/utils/socketcan.hpp b/CAN-binder/low-can-binding/utils/socketcan.hpp index 76b5121..7011bf9 100644 --- a/CAN-binder/low-can-binding/utils/socketcan.hpp +++ b/CAN-binder/low-can-binding/utils/socketcan.hpp @@ -68,6 +68,4 @@ namespace utils ERROR(binder_interface, "%s: Error sending : %i %s", __FUNCTION__, errno, ::strerror(errno)); return s; } - - socketcan_t& operator>>(socketcan_t& s, can_message_t& cm); } |