summaryrefslogtreecommitdiffstats
path: root/low-can-binding
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-07-14 17:30:43 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2017-07-21 12:02:11 +0200
commita483f245eb1aae07917c9074568c8cda82855ff6 (patch)
tree55ed7a58911fd615ce9a6ae4d2e1c52c09723b54 /low-can-binding
parent2408a177e8260dcda266df9993e6acd528bebbbc (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')
-rw-r--r--low-can-binding/binding/low-can-socket.cpp26
-rw-r--r--low-can-binding/binding/low-can-socket.hpp5
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<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;
+}
diff --git a/low-can-binding/binding/low-can-socket.hpp b/low-can-binding/binding/low-can-socket.hpp
index 3621a3d6..018b3076 100644
--- a/low-can-binding/binding/low-can-socket.hpp
+++ b/low-can-binding/binding/low-can-socket.hpp
@@ -80,11 +80,12 @@ public:
struct utils::simple_bcm_msg make_bcm_head(uint32_t opcode, uint32_t can_id = 0, uint32_t flags = 0, const struct timeval& timeout = {0,0}, const struct timeval& frequency_thinning = {0,0}) const;
void add_bcm_frame(const struct can_frame& cfd, struct utils::simple_bcm_msg& bcm_msg) const;
- int open_socket();
+ int open_socket(const std::string& bus_name = "");
int create_rx_filter(std::shared_ptr<can_signal_t> sig);
int create_rx_filter(std::shared_ptr<diagnostic_message_t> sig);
int create_rx_filter(utils::simple_bcm_msg& bcm_msg);
- int tx_send(const struct can_frame& cf, std::shared_ptr<can_signal_t> sig = nullptr);
+ int tx_send(const struct can_frame& cf, std::shared_ptr<can_signal_t> sig);
+ int tx_send(const struct can_frame& cf, const std::string& bus_name);
};