summaryrefslogtreecommitdiffstats
path: root/CAN-binder/low-can-binding/binding
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-05-16 16:36:51 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2017-05-19 11:36:43 +0200
commitfd3978709abbb3ed46caaf48c1d2f45b2c74fa89 (patch)
tree9df7ea79f378ee6e91276d1bf110e2f723e70315 /CAN-binder/low-can-binding/binding
parent1a8c681528f9f1ff45d111b0c8cdfed7a697bae6 (diff)
Make and use a single function to read incoming CAN messages
Change-Id: I5d3f2a8628ace464ad25989346cc76682c591bd8 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'CAN-binder/low-can-binding/binding')
-rw-r--r--CAN-binder/low-can-binding/binding/low-can-cb.cpp53
-rw-r--r--CAN-binder/low-can-binding/binding/low-can-hat.hpp3
2 files changed, 36 insertions, 20 deletions
diff --git a/CAN-binder/low-can-binding/binding/low-can-cb.cpp b/CAN-binder/low-can-binding/binding/low-can-cb.cpp
index d298779..4faae85 100644
--- a/CAN-binder/low-can-binding/binding/low-can-cb.cpp
+++ b/CAN-binder/low-can-binding/binding/low-can-cb.cpp
@@ -52,33 +52,50 @@ void on_no_clients(std::string message)
}
}
-int read_can_signal(sd_event_source *s, int fd, uint32_t revents, void *userdata)
+static void push_n_notify(const can_message_t cm)
{
- can_signal_t* sig= (can_signal_t*)userdata;
- sig->read_socket();
-
- /* check if error or hangup */
- if ((revents & (EPOLLERR|EPOLLRDHUP|EPOLLHUP)) != 0)
- {
- sd_event_source_unref(s);
- sig->get_socket().close();
- sig->create_rx_filter();
- }
- return 0;
+ can_bus_t& cbm = configuration_t::instance().get_can_bus_manager();
+ std::lock_guard<std::mutex> can_message_lock(cbm.get_can_message_mutex());
+ { cbm.push_new_can_message(cm); }
+ cbm.get_new_can_message_cv().notify_one();
}
-int read_diagnostic_message(sd_event_source *s, int fd, uint32_t revents, void *userdata)
+int read_message(sd_event_source *s, int fd, uint32_t revents, void *userdata)
{
+ can_message_t cm;
+ can_signal_t* sig;
diagnostic_manager_t& diag_m = configuration_t::instance().get_diagnostic_manager();
- diag_m.read_socket();
+
+ if(userdata != nullptr)
+ {
+ sig = (can_signal_t*)userdata;
+ utils::socketcan_bcm_t s = sig->get_socket();
+ s >> cm;
+ }
+ else
+ {
+ utils::socketcan_bcm_t s = diag_m.get_socket();
+ s >> cm;
+ }
+
+ push_n_notify(cm);
/* check if error or hangup */
if ((revents & (EPOLLERR|EPOLLRDHUP|EPOLLHUP)) != 0)
{
sd_event_source_unref(s);
- diag_m.get_socket().close();
- diag_m.cleanup_active_requests(true);
- ERROR(binder_interface, "%s: Error on diagnostic manager socket, cancelling active requests.", __FUNCTION__);
+ if(userdata != nullptr)
+ {
+ sig->get_socket().close();
+ sig->create_rx_filter();
+ NOTICE(binder_interface, "%s: Recreated RX_SETUP BCM job for signal: %s", __FUNCTION__, sig->get_name().c_str());
+ }
+ else
+ {
+ diag_m.get_socket().close();
+ diag_m.cleanup_active_requests(true);
+ ERROR(binder_interface, "%s: Error on diagnostic manager socket, cancelling active requests.", __FUNCTION__);
+ }
return -1;
}
@@ -207,7 +224,7 @@ static int subscribe_unsubscribe_signals(struct afb_req request, bool subscribe,
return -1;
}
struct sd_event_source* e_source;
- sd_event_add_io(afb_daemon_get_event_loop(binder_interface->daemon), &e_source, sig->get_socket().socket(), EPOLLIN, read_can_signal, sig.get());
+ sd_event_add_io(afb_daemon_get_event_loop(binder_interface->daemon), &e_source, sig->get_socket().socket(), EPOLLIN, read_message, sig.get());
rets++;
DEBUG(binder_interface, "%s: signal: %s subscribed", __FUNCTION__, sig->get_name().c_str());
}
diff --git a/CAN-binder/low-can-binding/binding/low-can-hat.hpp b/CAN-binder/low-can-binding/binding/low-can-hat.hpp
index 57c0a53..b3384d7 100644
--- a/CAN-binder/low-can-binding/binding/low-can-hat.hpp
+++ b/CAN-binder/low-can-binding/binding/low-can-hat.hpp
@@ -32,8 +32,7 @@ extern "C" struct afb_binding_interface;
extern const struct afb_binding_interface *binder_interface;
void on_no_clients(std::string message);
-int read_can_signal(sd_event_source *s, int fd, uint32_t revents, void *userdata);
-int read_diagnostic_message(sd_event_source *s, int fd, uint32_t revents, void *userdata);
+int read_message(sd_event_source *s, int fd, uint32_t revents, void *userdata);
void subscribe(struct afb_req request);
void unsubscribe(struct afb_req request); \ No newline at end of file