diff options
-rw-r--r-- | src/can/can-bus.cpp | 2 | ||||
-rw-r--r-- | src/diagnostic/diagnostic-manager.cpp | 38 | ||||
-rw-r--r-- | src/diagnostic/diagnostic-manager.hpp | 3 |
3 files changed, 17 insertions, 26 deletions
diff --git a/src/can/can-bus.cpp b/src/can/can-bus.cpp index 7c6ae429..18417f9c 100644 --- a/src/can/can-bus.cpp +++ b/src/can/can-bus.cpp @@ -179,7 +179,7 @@ void can_bus_t::can_decode_message() new_can_message_cv_.wait(can_message_lock); can_message = next_can_message(); - active_diagnostic_request_t* adr = configuration_t::instance().get_diagnostic_manager().is_diagnostic_response(can_message); + if(configuration_t::instance().get_diagnostic_manager().is_diagnostic_response(can_message)) if(adr != nullptr) process_diagnostic_signals(adr, can_message); else diff --git a/src/diagnostic/diagnostic-manager.cpp b/src/diagnostic/diagnostic-manager.cpp index 1477b2b9..31eed0e2 100644 --- a/src/diagnostic/diagnostic-manager.cpp +++ b/src/diagnostic/diagnostic-manager.cpp @@ -254,29 +254,6 @@ bool diagnostic_manager_t::add_recurring_request(DiagnosticRequest* request, con return added; } -bool diagnostic_manager_t::is_diagnostic_response(const active_diagnostic_request_t& adr, const can_message_t& cm) const -{ - if(cm.get_id() == adr.get_id() + DIAGNOSTIC_RESPONSE_ARBITRATION_ID_OFFSET) - return true; - DEBUG(binder_interface, "Doesn't find an active diagnostic request that matches."); - return false; -} - -active_diagnostic_request_t* diagnostic_manager_t::is_diagnostic_response(const can_message_t& can_message) -{ - for (auto& entry : non_recurring_requests_) - { - if(is_diagnostic_response(*entry, can_message)) - return entry; - } - - for (auto& entry : recurring_requests_) - { - if(is_diagnostic_response(*entry, can_message)) - return entry; - } - return nullptr; -} openxc_VehicleMessage diagnostic_manager_t::relay_diagnostic_response(active_diagnostic_request_t* adr, const DiagnosticResponse& response) const { @@ -369,6 +346,21 @@ int diagnostic_manager_t::send_request(sd_event_source *s, uint64_t usec, void * return -1; } + +/// @brief Tell if the CAN message received is a diagnostic response. +/// Request broadcast ID use 0x7DF and assigned ID goes from 0x7E0 to Ox7E7. That allows up to 8 ECU to respond +/// at the same time. The response is the assigned ID + 0x8, so response ID can goes from 0x7E8 to 0x7EF. +/// +/// @param[in] cm - CAN message received from the socket. +/// +/// @return True if the active diagnostic request match the response. +bool diagnostic_manager_t::is_diagnostic_response(const can_message_t& cm) +{ + if (cm.get_id() >= 0x7e8 && cm.get_id() <= 0x7ef) + return true; + return false; +} + DiagnosticShims& diagnostic_manager_t::get_shims() { return shims_; diff --git a/src/diagnostic/diagnostic-manager.hpp b/src/diagnostic/diagnostic-manager.hpp index ff055d54..1db83636 100644 --- a/src/diagnostic/diagnostic-manager.hpp +++ b/src/diagnostic/diagnostic-manager.hpp @@ -88,12 +88,11 @@ public: bool waitForMultipleResponses, const DiagnosticResponseDecoder decoder, const DiagnosticResponseCallback callback, float frequencyHz); - bool is_diagnostic_response(const active_diagnostic_request_t& adr, const can_message_t& cm) const; - active_diagnostic_request_t* is_diagnostic_response(const can_message_t& can_message); openxc_VehicleMessage relay_diagnostic_response(active_diagnostic_request_t* adr, const DiagnosticResponse& response) const; bool conflicting(active_diagnostic_request_t* request, active_diagnostic_request_t* candidate) const; bool clear_to_send(active_diagnostic_request_t* request) const; static int send_request(sd_event_source *s, uint64_t usec, void *userdata); + bool is_diagnostic_response(const can_message_t& cm); }; |