summaryrefslogtreecommitdiffstats
path: root/low-can-binding/utils
diff options
context:
space:
mode:
Diffstat (limited to 'low-can-binding/utils')
-rw-r--r--low-can-binding/utils/socketcan-bcm.cpp23
-rw-r--r--low-can-binding/utils/socketcan-bcm.hpp20
-rw-r--r--low-can-binding/utils/socketcan-j1939.cpp4
-rw-r--r--low-can-binding/utils/socketcan.hpp8
4 files changed, 17 insertions, 38 deletions
diff --git a/low-can-binding/utils/socketcan-bcm.cpp b/low-can-binding/utils/socketcan-bcm.cpp
index b9124ee3..0f6bc75c 100644
--- a/low-can-binding/utils/socketcan-bcm.cpp
+++ b/low-can-binding/utils/socketcan-bcm.cpp
@@ -70,7 +70,7 @@ namespace utils
/// Read the socket to retrieve the associated CAN message. All the hard work is do into
/// convert_from_frame method and if there isn't CAN message retrieve, only BCM head struct,
/// then CAN message will be zeroed and must be handled later.
- std::shared_ptr<can_message_t> socketcan_bcm_t::read_message()
+ std::shared_ptr<message_t> socketcan_bcm_t::read_message()
{
struct bcm_msg msg;
std::shared_ptr<can_message_t> cm = std::make_shared<can_message_t>();
@@ -98,33 +98,24 @@ namespace utils
struct timeval tv;
ioctl(socket(), SIOCGSTAMP, &tv);
uint64_t timestamp = 1000000 * tv.tv_sec + tv.tv_usec;
- *cm = can_message_t::convert_from_frame(msg.fd_frames[0] , frame_size, timestamp);
+ cm = can_message_t::convert_from_frame(msg.fd_frames[0] , frame_size, timestamp);
cm->set_sub_id((int)socket());
return cm;
}
- void socketcan_bcm_t::write_message(std::vector<std::shared_ptr<can_message_t>>& vobj)
+ void socketcan_bcm_t::write_message(std::vector<std::shared_ptr<message_t>>& vobj)
{
for(const auto& obj : vobj)
write_message(obj);
}
- void socketcan_bcm_t::write_message(std::shared_ptr<can_message_t> m)
- {
- struct can_frame obj;
- obj.can_id = m->get_id();
- obj.can_dlc = m->get_length();
- ::memcpy(obj.data, m->get_data(), CAN_MAX_DLEN);
- if (::sendto(socket(), &obj, sizeof(&obj), 0, (const struct sockaddr*)&get_tx_address(), sizeof(get_tx_address())) < 0)
- AFB_API_ERROR(afbBindingV3root, "Error sending : %i %s", errno, ::strerror(errno));
- }
-
- void socketcan_bcm_t::write_message(struct bcm_msg& obj)
+ void socketcan_bcm_t::write_message(std::shared_ptr<message_t> m)
{
+ struct bcm_msg obj = m->get_bcm_msg();
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);
+ (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(socket(), &obj, size, 0, (const struct sockaddr*)&get_tx_address(), sizeof(get_tx_address())) < 0)
AFB_API_ERROR(afbBindingV3root, "Error sending : %i %s", errno, ::strerror(errno));
}
diff --git a/low-can-binding/utils/socketcan-bcm.hpp b/low-can-binding/utils/socketcan-bcm.hpp
index 00028905..5e86aa4f 100644
--- a/low-can-binding/utils/socketcan-bcm.hpp
+++ b/low-can-binding/utils/socketcan-bcm.hpp
@@ -18,21 +18,10 @@
#pragma once
#include "socketcan.hpp"
-#include "../can/can-message.hpp"
-
-#define MAX_BCM_CAN_FRAMES 257
+#include "../can/message/can-message.hpp"
namespace utils
{
- struct bcm_msg
- {
- struct bcm_msg_head msg_head;
- union {
- struct canfd_frame fd_frames[MAX_BCM_CAN_FRAMES];
- struct can_frame frames[MAX_BCM_CAN_FRAMES];
- };
- };
-
/// @brief derivated socketcan class specialized for BCM CAN socket.make_bcm_head
class socketcan_bcm_t : public socketcan_t
{
@@ -40,10 +29,9 @@ namespace utils
using socketcan_t::socketcan_t;
virtual int open(std::string device_name);
- virtual std::shared_ptr<can_message_t> read_message();
- virtual void write_message(std::vector<std::shared_ptr<can_message_t>>& vobj);
- virtual void write_message(std::shared_ptr<can_message_t> obj);
- void write_message(struct bcm_msg& obj);
+ virtual std::shared_ptr<message_t> read_message();
+ virtual void write_message(std::vector<std::shared_ptr<message_t>>& vobj);
+ virtual void write_message(std::shared_ptr<message_t> obj);
private:
int connect(const struct sockaddr* addr, socklen_t len);
diff --git a/low-can-binding/utils/socketcan-j1939.cpp b/low-can-binding/utils/socketcan-j1939.cpp
index f914ac27..5f977f04 100644
--- a/low-can-binding/utils/socketcan-j1939.cpp
+++ b/low-can-binding/utils/socketcan-j1939.cpp
@@ -181,12 +181,12 @@ namespace utils
}
- void socketcan_j1939_t::write_message(std::vector<std::shared_ptr<can_message_t>>& vobj)
+ void socketcan_j1939_t::write_message(std::vector<std::shared_ptr<message_t>>& vobj)
{
AFB_WARNING("Not implemented");
}
- void socketcan_j1939_t::write_message(std::shared_ptr<can_message_t> cm)
+ void socketcan_j1939_t::write_message(std::shared_ptr<message_t> cm)
{
AFB_WARNING("Not implemented");
}
diff --git a/low-can-binding/utils/socketcan.hpp b/low-can-binding/utils/socketcan.hpp
index 6419175d..fdf8c949 100644
--- a/low-can-binding/utils/socketcan.hpp
+++ b/low-can-binding/utils/socketcan.hpp
@@ -24,7 +24,7 @@
#include <string.h>
#include "../binding/low-can-hat.hpp"
-#include "../can/can-message.hpp"
+#include "../can/message/can-message.hpp"
#define INVALID_SOCKET -1
@@ -47,9 +47,9 @@ namespace utils
virtual int open(std::string device_name) = 0;
int setopt(int level, int optname, const void* optval, socklen_t optlen);
virtual int close();
- virtual std::shared_ptr<can_message_t> read_message() = 0;
- virtual void write_message(std::shared_ptr<can_message_t> obj) = 0;
- virtual void write_message(std::vector<std::shared_ptr<can_message_t>>& vobj) = 0;
+ virtual std::shared_ptr<message_t> read_message() = 0;
+ virtual void write_message(std::shared_ptr<message_t> obj) = 0;
+ virtual void write_message(std::vector<std::shared_ptr<message_t>>& vobj) = 0;
protected:
int socket_;