diff options
author | Romain Forlot <romain.forlot@iot.bzh> | 2017-07-14 17:30:43 +0200 |
---|---|---|
committer | Romain Forlot <romain.forlot@iot.bzh> | 2017-07-21 12:02:11 +0200 |
commit | a483f245eb1aae07917c9074568c8cda82855ff6 (patch) | |
tree | 55ed7a58911fd615ce9a6ae4d2e1c52c09723b54 /low-can-binding/binding/low-can-socket.cpp | |
parent | 2408a177e8260dcda266df9993e6acd528bebbbc (diff) |
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 <romain.forlot@iot.bzh>
Diffstat (limited to 'low-can-binding/binding/low-can-socket.cpp')
-rw-r--r-- | low-can-binding/binding/low-can-socket.cpp | 26 |
1 files changed, 25 insertions, 1 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<can_si return 0; } + +/// @brief Create a TX_SEND job used by the BCM socket to +/// simply send message +/// +/// @return 0 if ok else -1 +int low_can_socket_t::tx_send(const struct can_frame& cf, const std::string& bus_name) +{ + can_signal_ = nullptr; + + utils::simple_bcm_msg bcm_msg = make_bcm_head(TX_SEND); + add_bcm_frame(cf, bcm_msg); + + if(open_socket(bus_name) < 0) + {return -1;} + + socket_ << bcm_msg; + if(! socket_) + return -1; + + return 0; +} |