diff options
author | Romain Forlot <romain.forlot@iot.bzh> | 2017-05-16 12:37:46 +0200 |
---|---|---|
committer | Romain Forlot <romain.forlot@iot.bzh> | 2017-05-19 11:36:42 +0200 |
commit | 4f1b1d088afe8eb9a5b75287429104e4175e97e7 (patch) | |
tree | f3d0ba62b108f1f9ad022800929022f575c70b45 /CAN-binder/low-can-binding/binding/low-can-cb.cpp | |
parent | c59a57338a488cc451482f1180fe672e7d5c9179 (diff) |
Adding also diagnostic request to systemd event loop
As for CAN signal, monitoring diagnostic request messages is now handled by
systemD io event loop. Socket reading is common for all OBD2 signals and handled
by the diagnostic manager.
systemd callback function lies in binding callback which in turns call read_socket
method of diagnostic manager. Processing is little bit different from classic CAN
messages so it is a separate callback function.
Lot of cleaning to do now...
Change-Id: I4d2ada0beb5d3348736dfdf3c56a7cb875a1c6c7
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'CAN-binder/low-can-binding/binding/low-can-cb.cpp')
-rw-r--r-- | CAN-binder/low-can-binding/binding/low-can-cb.cpp | 31 |
1 files changed, 24 insertions, 7 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 55d9bdd4..b3c9e2e0 100644 --- a/CAN-binder/low-can-binding/binding/low-can-cb.cpp +++ b/CAN-binder/low-can-binding/binding/low-can-cb.cpp @@ -52,7 +52,7 @@ void on_no_clients(std::string message) } } -int read(sd_event_source *s, int fd, uint32_t revents, void *userdata) +int read_can_signal(sd_event_source *s, int fd, uint32_t revents, void *userdata) { can_signal_t* sig= (can_signal_t*)userdata; sig->read_socket(); @@ -67,6 +67,25 @@ int read(sd_event_source *s, int fd, uint32_t revents, void *userdata) return 0; } +int read_diagnostic_message(sd_event_source *s, int fd, uint32_t revents, void *userdata) +{ + diagnostic_manager_t& diag_m = configuration_t::instance().get_diagnostic_manager(); + diag_m.read_socket(); + + /* 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__); + return -1; + } + + return 0; +} + + ///****************************************************************************** /// /// Subscription and unsubscription @@ -161,10 +180,9 @@ static int subscribe_unsubscribe_signals(struct afb_req request, bool subscribe, // poll a PID for nothing. if(sig->get_supported() && subscribe) { - float frequency = sig->get_frequency(); - subscribe = diag_m.add_recurring_request( - diag_req, sig->get_name().c_str(), false, sig->get_decoder(), sig->get_callback(), (float)frequency); - //TODO: Adding callback requesting ignition status: diag_req, sig.c_str(), false, diagnostic_message_t::decode_obd2_response, diagnostic_message_t::check_ignition_status, frequency); + float frequency = sig->get_frequency(); + diag_m.add_recurring_request(diag_req, sig->get_name().c_str(), false, sig->get_decoder(), sig->get_callback(), (float)frequency); + //TODO: Adding callback requesting ignition status: diag_req, sig.c_str(), false, diagnostic_message_t::decode_obd2_response, diagnostic_message_t::check_ignition_status, frequency); } else { @@ -188,8 +206,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, sig.get()); + sd_event_add_io(afb_daemon_get_event_loop(binder_interface->daemon), &e_source, sig->get_socket().socket(), EPOLLIN, read_can_signal, sig.get()); rets++; DEBUG(binder_interface, "%s: signal: %s subscribed", __FUNCTION__, sig->get_name().c_str()); } |