Change-Id: I94cad718b516f24c5d1833e09df89f03e529f48a
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
/// @return -1 if something wrong.
int can_bus_dev_t::open(bool bcm)
{
/// @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);
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.
// Set some option on the socket : timeout, timestamp and canfd frame usage.
+void can_bus_dev_t::configure()
+{
- 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));
// 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, ×tamp_on, sizeof(timestamp_on)) < 0)
// Set timestamp for receveid frame
if (can_socket_.setopt(SOL_SOCKET, SO_TIMESTAMP, ×tamp_on, sizeof(timestamp_on)) < 0)
ERROR(binder_interface, "open_raw: socket could not be created. Error was : %s", ::strerror(errno));
ERROR(binder_interface, "open_raw: socket could not be created. Error was : %s", ::strerror(errno));
}
/// @brief Close the bus.
}
/// @brief Close the bus.
uint32_t get_address() const;
int open(bool bcm=false);
uint32_t get_address() const;
int open(bool bcm=false);
int close();
void start_reading(can_bus_t& can_bus);
int close();
void start_reading(can_bus_t& can_bus);
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] = 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);
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);