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/diagnostic | |
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/diagnostic')
-rw-r--r-- | CAN-binder/low-can-binding/diagnostic/diagnostic-manager.cpp | 22 | ||||
-rw-r--r-- | CAN-binder/low-can-binding/diagnostic/diagnostic-manager.hpp | 3 |
2 files changed, 21 insertions, 4 deletions
diff --git a/CAN-binder/low-can-binding/diagnostic/diagnostic-manager.cpp b/CAN-binder/low-can-binding/diagnostic/diagnostic-manager.cpp index 8a55365e..935767a8 100644 --- a/CAN-binder/low-can-binding/diagnostic/diagnostic-manager.cpp +++ b/CAN-binder/low-can-binding/diagnostic/diagnostic-manager.cpp @@ -49,6 +49,7 @@ bool diagnostic_manager_t::initialize() bus_ = configuration_t::instance().get_diagnostic_bus(); init_diagnostic_shims(); + event_source_ = nullptr; reset(); initialized_ = true; @@ -456,15 +457,28 @@ active_diagnostic_request_t* diagnostic_manager_t::add_recurring_request(Diagnos { // TODO: implement Acceptance Filter //if(updateRequiredAcceptanceFilters(bus, request)) { - active_diagnostic_request_t* entry = new active_diagnostic_request_t(bus_, request, name, + entry = new active_diagnostic_request_t(bus_, request, name, wait_for_multiple_responses, decoder, callback, frequencyHz); recurring_requests_.push_back(entry); entry->set_handle(shims_, request); if(add_rx_filter(OBD2_FUNCTIONAL_BROADCAST_ID) < 0) - { recurring_requests_.pop_back(); } + { recurring_requests_.pop_back(); } else - { start_diagnostic_request(&shims_, entry->get_handle()); } + { + start_diagnostic_request(&shims_, entry->get_handle()); + if(event_source_ == nullptr && sd_event_add_io(afb_daemon_get_event_loop(binder_interface->daemon), + &event_source_, + socket_.socket(), + EPOLLIN, + read_diagnostic_message, + nullptr) < 0) + { + cleanup_request(entry, true); + WARNING(binder_interface, "%s: signal: %s isn't supported. Canceling operation.", __FUNCTION__, entry->get_name().c_str()); + return entry; + } + } } else { @@ -473,7 +487,7 @@ active_diagnostic_request_t* diagnostic_manager_t::add_recurring_request(Diagnos } } else - { DEBUG(binder_interface, "%s: Can't add request, one already exists with same key", __FUNCTION__);} + { DEBUG(binder_interface, "%s: Can't add request, one already exists with same key", __FUNCTION__);} return entry; } diff --git a/CAN-binder/low-can-binding/diagnostic/diagnostic-manager.hpp b/CAN-binder/low-can-binding/diagnostic/diagnostic-manager.hpp index 65ff0cb5..66a4d73f 100644 --- a/CAN-binder/low-can-binding/diagnostic/diagnostic-manager.hpp +++ b/CAN-binder/low-can-binding/diagnostic/diagnostic-manager.hpp @@ -57,6 +57,7 @@ private: * response is received for a non-recurring request or it times out, it is removed*/ bool initialized_; /*!< * initialized - True if the DiagnosticsManager has been initialized with shims. It will interface with the uds-c lib*/ utils::socketcan_bcm_t socket_; ///< rx_socket_ - a BCM socket with 8 RX_SETUP jobs for the 8 CAN ID on which ECU could respond. + struct sd_event_source* event_source_; void init_diagnostic_shims(); void reset(); @@ -66,6 +67,8 @@ public: bool initialize(); + void read_socket(); + utils::socketcan_bcm_t& get_socket(); std::string get_can_bus(); active_diagnostic_request_t* get_last_recurring_requests() const; DiagnosticShims& get_shims(); |