summaryrefslogtreecommitdiffstats
path: root/CAN-binder/low-can-binding/can
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-04-20 17:40:06 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2017-04-20 17:40:06 +0200
commitabf974815dc03c17a8ad7c6c749d53698cdd8dc1 (patch)
treef86d4aef7dd785fc0e2b97ec50877b290ffd9300 /CAN-binder/low-can-binding/can
parent0a27582743cb7b4ad191adea4eefeda01d179896 (diff)
Separate socket configuration and opening
Change-Id: I94cad718b516f24c5d1833e09df89f03e529f48a 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.cpp14
-rw-r--r--CAN-binder/low-can-binding/can/can-bus-dev.hpp1
-rw-r--r--CAN-binder/low-can-binding/can/can-bus.cpp1
3 files changed, 10 insertions, 6 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 a1c6fcda..81e8f30d 100644
--- a/CAN-binder/low-can-binding/can/can-bus-dev.cpp
+++ b/CAN-binder/low-can-binding/can/can-bus-dev.cpp
@@ -53,20 +53,21 @@ uint32_t can_bus_dev_t::get_address() const
/// @return -1 if something wrong.
int can_bus_dev_t::open(bool bcm)
{
- const int canfd_on = 1;
- const int timestamp_on = 1;
- struct timeval timeout;
-
DEBUG(binder_interface, "open_raw: CAN Handler socket : %d", can_socket_.socket());
return can_socket_.open(device_name_, bcm);
+}
// Set some option on the socket : timeout, timestamp and canfd frame usage.
+void can_bus_dev_t::configure()
+{
if (can_socket_)
{
- DEBUG(binder_interface, "open_raw: CAN Handler socket correctly initialized : %d", can_socket_.socket());
+ const int timestamp_on = 1;
+ const int canfd_on = 1;
// Set timeout for read
can_socket_.setopt(SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout, sizeof(timeout));
+ DEBUG(binder_interface, "open_raw: CAN Handler socket correctly initialized : %d", can_socket_.socket());
// Set timestamp for receveid frame
if (can_socket_.setopt(SOL_SOCKET, SO_TIMESTAMP, &timestamp_on, sizeof(timestamp_on)) < 0)
@@ -86,8 +87,9 @@ int can_bus_dev_t::open(bool bcm)
}
}
else
+ {
ERROR(binder_interface, "open_raw: socket could not be created. Error was : %s", ::strerror(errno));
- return -1;
+ }
}
/// @brief Close the bus.
diff --git a/CAN-binder/low-can-binding/can/can-bus-dev.hpp b/CAN-binder/low-can-binding/can/can-bus-dev.hpp
index 8cafaf83..96aa373e 100644
--- a/CAN-binder/low-can-binding/can/can-bus-dev.hpp
+++ b/CAN-binder/low-can-binding/can/can-bus-dev.hpp
@@ -51,6 +51,7 @@ public:
uint32_t get_address() const;
int open(bool bcm=false);
+ void configure();
int close();
void start_reading(can_bus_t& can_bus);
diff --git a/CAN-binder/low-can-binding/can/can-bus.cpp b/CAN-binder/low-can-binding/can/can-bus.cpp
index 4775b4fe..5d8221c0 100644
--- a/CAN-binder/low-can-binding/can/can-bus.cpp
+++ b/CAN-binder/low-can-binding/can/can-bus.cpp
@@ -239,6 +239,7 @@ int can_bus_t::init_can_dev()
can_bus_t::can_devices_[device] = std::make_shared<can_bus_dev_t>(device, i);
if (can_bus_t::can_devices_[device]->open(true) >= 0)
{
+ can_bus_t::can_devices_[device]->configure();
DEBUG(binder_interface, "Start reading thread");
NOTICE(binder_interface, "%s device opened and reading", device.c_str());
can_bus_t::can_devices_[device]->start_reading(*this);