diff options
author | Arthur Guyader <arthur.guyader@iot.bzh> | 2019-05-24 12:16:28 +0200 |
---|---|---|
committer | Romain Forlot <romain.forlot@iot.bzh> | 2019-06-26 17:55:05 +0200 |
commit | a6fb72a70f90c35e0968f2460d324a8505410562 (patch) | |
tree | 6f975e72a72585563c2bb7c4a279db7f26626b40 /low-can-binding/utils/socketcan-raw.cpp | |
parent | 2eda264a201385f5073362207b7de84bf71f9ec1 (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-raw.cpp')
-rw-r--r-- | low-can-binding/utils/socketcan-raw.cpp | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/low-can-binding/utils/socketcan-raw.cpp b/low-can-binding/utils/socketcan-raw.cpp index ca892e70..6bd41c3b 100644 --- a/low-can-binding/utils/socketcan-raw.cpp +++ b/low-can-binding/utils/socketcan-raw.cpp @@ -62,27 +62,38 @@ namespace utils return socket_; } - socketcan_raw_t& operator>>(socketcan_raw_t& s, can_message_t& cm) + std::shared_ptr<message_t> socketcan_raw_t::read_message() { + std::shared_ptr<can_message_t> cm = std::make_shared<can_message_t>(); struct canfd_frame frame; - const struct sockaddr_can& addr = s.get_tx_address(); + const struct sockaddr_can& addr = 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); + ssize_t nbytes = ::recvfrom(socket(), &frame, sizeof(frame), 0, (struct sockaddr*)&addr, &addrlen); ifr.ifr_ifindex = addr.can_ifindex; - ioctl(s.socket(), SIOCGIFNAME, &ifr); + ioctl(socket(), SIOCGIFNAME, &ifr); AFB_DEBUG("Data available: %i bytes read", (int)nbytes); AFB_DEBUG("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]); struct timeval tv; - ioctl(s.socket(), SIOCGSTAMP, &tv); + ioctl(socket(), SIOCGSTAMP, &tv); uint64_t timestamp = 1000000 * tv.tv_sec + tv.tv_usec; cm = ::can_message_t::convert_from_frame(frame , nbytes, timestamp); - return s; + return cm; + } + + void socketcan_raw_t::write_message(std::vector<std::shared_ptr<message_t>>& vobj) + { + AFB_WARNING("Not implemented"); + } + + void socketcan_raw_t::write_message(std::shared_ptr<message_t> cm) + { + AFB_WARNING("Not implemented"); } } |