summaryrefslogtreecommitdiffstats
path: root/CAN-binder/low-can-binding/can
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-04-24 19:09:28 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2017-04-24 19:09:28 +0200
commit901a27b0631909647137f49ccf12f4e9bfe38817 (patch)
tree29f6ac7b6832c53e5b8ed472c8bcf29543382e03 /CAN-binder/low-can-binding/can
parent9e72f805168ae60919117c98dc1ab6c7441873ac (diff)
Rename and handling write on socket using stream instead of specific method
Created special struct to handle bcm messages with can_frame and canfd_frame. We can now just send both of them seamlessly. Change-Id: Ia84e9cf2ab1dd0716cb09f6bb342a208e54f8e06 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'CAN-binder/low-can-binding/can')
-rw-r--r--CAN-binder/low-can-binding/can/can-bus-dev.cpp20
1 files changed, 8 insertions, 12 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 d097dc66..8470156f 100644
--- a/CAN-binder/low-can-binding/can/can-bus-dev.cpp
+++ b/CAN-binder/low-can-binding/can/can-bus-dev.cpp
@@ -151,24 +151,21 @@ void can_bus_dev_t::can_reader(can_bus_t& can_bus)
/// @return 0 if message snet, -1 if something wrong.
int can_bus_dev_t::send(can_message_t& can_msg)
{
- ssize_t nbytes;
canfd_frame f;
-
f = can_msg.convert_to_canfd_frame();
if(can_socket_)
{
- nbytes = can_socket_.send(f);
- if (nbytes == -1)
+ can_socket_ << f;
+ if(!can_socket_)
{
- ERROR(binder_interface, "send_can_message: Sending CAN frame failed.");
+ ERROR(binder_interface, "%s: Sending CAN frame failed.", __FUNCTION__);
return -1;
}
- return (int)nbytes;
}
else
{
- ERROR(binder_interface, "send_can_message: socket not initialized. Attempt to reopen can device socket.");
+ ERROR(binder_interface, "%s: socket not initialized. Attempt to reopen can device socket.", __FUNCTION__);
open();
return -1;
}
@@ -187,7 +184,6 @@ int can_bus_dev_t::send(can_message_t& can_msg)
/// @return True if message sent, false if not.
bool can_bus_dev_t::shims_send(const uint32_t arbitration_id, const uint8_t* data, const uint8_t size)
{
- ssize_t nbytes;
canfd_frame f;
f.can_id = arbitration_id;
@@ -196,18 +192,18 @@ bool can_bus_dev_t::shims_send(const uint32_t arbitration_id, const uint8_t* dat
if(can_socket_)
{
- nbytes = can_socket_.send(f);
- if (nbytes == -1)
+ can_socket_ << f;
+ if (!can_socket_)
{
ERROR(binder_interface, "send_can_message: Sending CAN frame failed.");
return false;
}
- return true;
}
else
{
ERROR(binder_interface, "send_can_message: socket not initialized. Attempt to reopen can device socket.");
open();
+ return false;
}
- return false;
+ return true;
}