Simplification of checking Diagnostic response.
authorRomain Forlot <romain.forlot@iot.bzh>
Wed, 15 Mar 2017 22:07:34 +0000 (23:07 +0100)
committerRomain Forlot <romain.forlot@iot.bzh>
Thu, 16 Mar 2017 16:21:57 +0000 (17:21 +0100)
A CAN message will be considered as a Diagnostic response when its
arbitration ID is between standardized 0x7E8 and 0x7EF.
Checking which request belong to that response will done in later methods

Change-Id: I7a093edf44b62a4552b90fe3d8935f94dc677cf4
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
src/can/can-bus.cpp
src/diagnostic/diagnostic-manager.cpp
src/diagnostic/diagnostic-manager.hpp

index 7c6ae42..18417f9 100644 (file)
@@ -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
index 1477b2b..31eed0e 100644 (file)
@@ -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_;
index ff055d5..1db8363 100644 (file)
@@ -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);
 };