Make and use a single function to read incoming CAN messages
[apps/low-level-can-service.git] / CAN-binder / low-can-binding / diagnostic / diagnostic-manager.cpp
index 7539634..4b25426 100644 (file)
@@ -57,16 +57,6 @@ bool diagnostic_manager_t::initialize()
        return initialized_;
 }
 
-void diagnostic_manager_t::read_socket()
-{
-       can_message_t msg;
-       can_bus_t& cbm = configuration_t::instance().get_can_bus_manager();
-       socket_ >> msg;
-       std::lock_guard<std::mutex> can_message_lock(cbm.get_can_message_mutex());
-       { cbm.push_new_can_message(msg); }
-       cbm.get_new_can_message_cv().notify_one();
-}
-
 utils::socketcan_bcm_t& diagnostic_manager_t::get_socket()
 {
        return socket_;
@@ -168,6 +158,7 @@ bool diagnostic_manager_t::shims_send(const uint32_t arbitration_id, const uint8
        bcm_msg.msg_head.ival2.tv_sec = freq.tv_sec;
        bcm_msg.msg_head.ival2.tv_usec = freq.tv_usec;
        bcm_msg.msg_head.nframes = 1;
+       cfd.can_dlc = size;
        ::memcpy(cfd.data, data, size);
 
        bcm_msg.frames = cfd;
@@ -244,10 +235,8 @@ void diagnostic_manager_t::cancel_request(active_diagnostic_request_t* entry)
 /// @param[in] force - Force the cleaning or not ?
 void diagnostic_manager_t::cleanup_request(active_diagnostic_request_t* entry, bool force)
 {
-       if((force || (entry != nullptr && entry->get_in_flight() && entry->request_completed())))
+       if((force || (entry != nullptr && entry->response_received())))
        {
-               entry->set_in_flight(false);
-
                char request_string[128] = {0};
                diagnostic_request_to_string(&entry->get_handle()->request,
                        request_string, sizeof(request_string));
@@ -455,7 +444,7 @@ active_diagnostic_request_t* diagnostic_manager_t::add_recurring_request(Diagnos
                                                &event_source_,
                                                socket_.socket(),
                                                EPOLLIN,
-                                               read_diagnostic_message,
+                                               read_message,
                                                nullptr) < 0)
                                        {
                                                cleanup_request(entry, true);
@@ -475,41 +464,6 @@ active_diagnostic_request_t* diagnostic_manager_t::add_recurring_request(Diagnos
        return entry;
 }
 
-/// @brief Returns true if there are two active requests running for the same arbitration ID.
-bool diagnostic_manager_t::conflicting(active_diagnostic_request_t* request, active_diagnostic_request_t* candidate) const
-{
-       return (candidate->get_in_flight() && candidate != request &&
-                       candidate->get_can_bus_dev() == request->get_can_bus_dev() &&
-                       candidate->get_id() == request->get_id());
-}
-
-
-/// @brief Returns true if there are no other active requests to the same arbitration ID
-/// and if there aren't more than 8 requests in flight at the same time.
-bool diagnostic_manager_t::clear_to_send(active_diagnostic_request_t* request) const
-{
-       int total_in_flight = 0;
-       for ( auto entry : non_recurring_requests_)
-       {
-               if(conflicting(request, entry))
-                       return false;
-               if(entry->get_in_flight())
-                       total_in_flight++;
-       }
-
-       for ( auto entry : recurring_requests_)
-       {
-               if(conflicting(request, entry))
-                       return false;
-               if(entry->get_in_flight())
-                       total_in_flight++;
-       }
-
-       if(total_in_flight > MAX_SIMULTANEOUS_IN_FLIGHT_REQUESTS)
-               return false;
-       return true;
-}
-
 /// @brief Will decode the diagnostic response and build the final openxc_VehicleMessage to return.
 ///
 /// @param[in] adr - A pointer to an active diagnostic request holding a valid diagnostic handle
@@ -557,7 +511,7 @@ openxc_VehicleMessage diagnostic_manager_t::relay_diagnostic_response(active_dia
        }
 
        // Reset the completed flag handle to make sure that it will be reprocessed the next time.
-       adr->get_handle()->completed = false;
+       adr->get_handle()->success = false;
        return message;
 }