From a483f245eb1aae07917c9074568c8cda82855ff6 Mon Sep 17 00:00:00 2001 From: Romain Forlot Date: Fri, 14 Jul 2017 17:30:43 +0200 Subject: Handle object without signal, only a bus To be able to send or receive message on bus without depending upon on a signals, this is adds opening socket just with a bus_name if provided. Also handle send a frame on bus depending on a signal or not. Change-Id: I3a60a03a2d36db4db14b9ae90eefc4bbc8f21e32 Signed-off-by: Romain Forlot --- low-can-binding/binding/low-can-socket.cpp | 26 +++++++++++++++++++++++++- low-can-binding/binding/low-can-socket.hpp | 5 +++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/low-can-binding/binding/low-can-socket.cpp b/low-can-binding/binding/low-can-socket.cpp index 716b75b9..fdd506b3 100644 --- a/low-can-binding/binding/low-can-socket.cpp +++ b/low-can-binding/binding/low-can-socket.cpp @@ -160,7 +160,7 @@ void low_can_socket_t::set_max(float max) /// this will open the socket with the required CAN bus device name. /// /// @return INVALID_SOCKET on failure else positive integer -int low_can_socket_t::open_socket() +int low_can_socket_t::open_socket(const std::string& bus_name) { int ret = 0; if(! socket_) @@ -169,6 +169,8 @@ int low_can_socket_t::open_socket() {ret = socket_.open(can_signal_->get_message()->get_bus_device_name());} else if (! diagnostic_message_ .empty()) {ret = socket_.open(application_t::instance().get_diagnostic_manager().get_bus_device_name());} + else if ( ! bus_name.empty()) + { ret = socket_.open(bus_name);} index_ = (int)socket_.socket(); } return ret; @@ -181,6 +183,7 @@ int low_can_socket_t::open_socket() struct utils::simple_bcm_msg low_can_socket_t::make_bcm_head(uint32_t opcode, uint32_t can_id, uint32_t flags, const struct timeval& timeout, const struct timeval& frequency_thinning) const { struct utils::simple_bcm_msg bcm_msg; + ::memset(&bcm_msg, 0, sizeof(bcm_msg)); bcm_msg.msg_head.opcode = opcode; bcm_msg.msg_head.can_id = can_id; @@ -312,3 +315,24 @@ int low_can_socket_t::tx_send(const struct can_frame& cf, std::shared_ptr sig); int create_rx_filter(std::shared_ptr sig); int create_rx_filter(utils::simple_bcm_msg& bcm_msg); - int tx_send(const struct can_frame& cf, std::shared_ptr sig = nullptr); + int tx_send(const struct can_frame& cf, std::shared_ptr sig); + int tx_send(const struct can_frame& cf, const std::string& bus_name); }; -- cgit 1.2.3-korg