From a6fb72a70f90c35e0968f2460d324a8505410562 Mon Sep 17 00:00:00 2001 From: Arthur Guyader Date: Fri, 24 May 2019 12:16:28 +0200 Subject: Implement a new socket type CAN for j1939 protocol This commit implements a new socket class for the j1939 protocol and prepares the bases classes by modifying the write and read methods. Bug-AGL: SPEC-2386 Change-Id: I16ba493418a4bb37a0262b61a2a2629be6ab5051 Signed-off-by: Arthur Guyader Signed-off-by: Stephane Desneux Signed-off-by: Romain Forlot --- low-can-binding/utils/socketcan.hpp | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) (limited to 'low-can-binding/utils/socketcan.hpp') diff --git a/low-can-binding/utils/socketcan.hpp b/low-can-binding/utils/socketcan.hpp index a1fdcb58..6419175d 100644 --- a/low-can-binding/utils/socketcan.hpp +++ b/low-can-binding/utils/socketcan.hpp @@ -24,11 +24,13 @@ #include #include "../binding/low-can-hat.hpp" +#include "../can/can-message.hpp" #define INVALID_SOCKET -1 namespace utils { + class socketcan_t { public: @@ -44,28 +46,16 @@ namespace utils int socket() const; virtual int open(std::string device_name) = 0; int setopt(int level, int optname, const void* optval, socklen_t optlen); - int close(); + virtual int close(); + virtual std::shared_ptr read_message() = 0; + virtual void write_message(std::shared_ptr obj) = 0; + virtual void write_message(std::vector>& vobj) = 0; protected: int socket_; struct sockaddr_can tx_address_; - int open(int domain, int type, int protocol); }; - template - socketcan_t& operator<<(socketcan_t& s, const std::vector& vobj) - { - for(const auto& obj : vobj) - s << obj; - return s; - } - template - 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) - AFB_API_ERROR(afbBindingV3root, "Error sending : %i %s", errno, ::strerror(errno)); - return s; - } } -- cgit 1.2.3-korg