aboutsummaryrefslogtreecommitdiffstats
path: root/CAN-binder
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-04-27 00:59:40 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2017-04-27 01:03:34 +0200
commit454e4f65caca85395a5ca79814d6ca333dd5ae6b (patch)
tree456e7e8a152a3202109c250a247be245e5335f67 /CAN-binder
parent512336b68da052f167bdfb8f2b9a9992ed3f1688 (diff)
Fix: write bcm message to socket.
Just allowing message with 1 frame avoiding to handle dynamic sized array... This close the door for multiplexed msg for now... Let's see later and move on Change-Id: I3626d4b6634b3f119826603e64713d63e994918e Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'CAN-binder')
-rw-r--r--CAN-binder/low-can-binding/can/can-bus-dev.cpp4
-rw-r--r--CAN-binder/low-can-binding/utils/socketcan.cpp14
-rw-r--r--CAN-binder/low-can-binding/utils/socketcan.hpp25
3 files changed, 19 insertions, 24 deletions
diff --git a/CAN-binder/low-can-binding/can/can-bus-dev.cpp b/CAN-binder/low-can-binding/can/can-bus-dev.cpp
index 7f7a7624..c0ebca11 100644
--- a/CAN-binder/low-can-binding/can/can-bus-dev.cpp
+++ b/CAN-binder/low-can-binding/can/can-bus-dev.cpp
@@ -125,7 +125,7 @@ int can_bus_dev_t::create_rx_filter(const can_signal_t& s)
{
uint32_t can_id = s.get_message().get_id();
- struct utils::basic_bcm_msg<struct can_frame> bcm_msg;
+ struct utils::simple_bcm_msg bcm_msg;
struct can_frame cfd;
memset(&cfd, 0, sizeof(cfd));
@@ -145,7 +145,7 @@ int can_bus_dev_t::create_rx_filter(const can_signal_t& s)
cfd.data,
CAN_MAX_DLEN);
- bcm_msg.frames.push_back(cfd);
+ bcm_msg.frames = cfd;
if(can_socket_ << bcm_msg)
return 0;
diff --git a/CAN-binder/low-can-binding/utils/socketcan.cpp b/CAN-binder/low-can-binding/utils/socketcan.cpp
index 486c34f6..53631e9d 100644
--- a/CAN-binder/low-can-binding/utils/socketcan.cpp
+++ b/CAN-binder/low-can-binding/utils/socketcan.cpp
@@ -161,18 +161,4 @@ namespace utils
return s;
}
-
- socketcan_t& operator<<(socketcan_t& s, const struct basic_bcm_msg<struct can_frame>& obj)
- {
- s << obj.msg_head;
- s << obj.frames;
- return s;
- }
-
- socketcan_t& operator<<(socketcan_t& s, const struct canfd_bcm_msg& obj)
- {
- s << obj.msg_head;
- s << obj.frames;
- 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 cc7326e2..a66e259a 100644
--- a/CAN-binder/low-can-binding/utils/socketcan.hpp
+++ b/CAN-binder/low-can-binding/utils/socketcan.hpp
@@ -27,20 +27,20 @@
#include "low-can-binding.hpp"
#define INVALID_SOCKET -1
-#define U64_DATA(p) (*(unsigned long long*)(p)->data)
+
namespace utils
{
-
- template <typename T>
- struct basic_bcm_msg
+ struct simple_bcm_msg
{
struct bcm_msg_head msg_head;
- std::vector<T> frames;
+ struct can_frame frames;
};
- struct canfd_bcm_msg : public basic_bcm_msg<canfd_frame>
+ struct canfd_bcm_msg
{
- canfd_bcm_msg() { msg_head.flags |= CAN_FD_FRAME; }
+ struct bcm_msg_head msg_head;
+ struct canfd_frame frames;
+ canfd_bcm_msg() { msg_head.flags |= CAN_FD_FRAME; }
};
class socketcan_t
@@ -75,7 +75,16 @@ namespace utils
s << obj;
return s;
}
- socketcan_t& operator<<(socketcan_t& s, const struct basic_bcm_msg<can_frame>& obj);
+
+ template <typename T>
+ socketcan_t& operator<<(socketcan_t& s, const T& obj)
+ {
+ if (::sendto(s.socket(), &obj, sizeof(obj), 0, (const struct sockaddr*)&s.get_tx_address(), sizeof(s.get_tx_address())) < 0)
+ ERROR(binder_interface, "%s: Error sending : %i %s", __FUNCTION__, errno, ::strerror(errno));
+ return s;
+ }
+
+ socketcan_t& operator<<(socketcan_t& s, const struct simple_bcm_msg& obj);
socketcan_t& operator<<(socketcan_t& s, const struct canfd_bcm_msg& obj);
socketcan_t& operator>>(socketcan_t& s, can_message_t& cm);