summaryrefslogtreecommitdiffstats
path: root/low-can-binding/utils/socketcan.hpp
diff options
context:
space:
mode:
authorArthur Guyader <arthur.guyader@iot.bzh>2019-05-24 12:16:28 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2019-06-26 17:55:05 +0200
commita6fb72a70f90c35e0968f2460d324a8505410562 (patch)
tree6f975e72a72585563c2bb7c4a279db7f26626b40 /low-can-binding/utils/socketcan.hpp
parent2eda264a201385f5073362207b7de84bf71f9ec1 (diff)
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 <arthur.guyader@iot.bzh> Signed-off-by: Stephane Desneux <stephane.desneux@iot.bzh> Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'low-can-binding/utils/socketcan.hpp')
-rw-r--r--low-can-binding/utils/socketcan.hpp22
1 files changed, 6 insertions, 16 deletions
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 <string.h>
#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<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;
protected:
int socket_;
struct sockaddr_can tx_address_;
-
int open(int domain, int type, int protocol);
};
- template <typename T>
- socketcan_t& operator<<(socketcan_t& s, const std::vector<T>& vobj)
- {
- for(const auto& obj : vobj)
- s << obj;
- return s;
- }
- 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)
- AFB_API_ERROR(afbBindingV3root, "Error sending : %i %s", errno, ::strerror(errno));
- return s;
- }
}