cmake: fix lib not populated and RPATH usage
[apps/agl-service-can-low-level.git] / low-can-binding / diagnostic / diagnostic-manager.cpp
index 7c067c6..f3c513c 100644 (file)
@@ -56,16 +56,19 @@ diagnostic_manager_t::~diagnostic_manager_t()
 ///
 /// this will initialize DiagnosticShims and cancel all active requests
 ///  if there are any.
-bool diagnostic_manager_t::initialize()
+bool diagnostic_manager_t::initialize(std::string diagnostic_bus)
 {
-       // Mandatory to set the bus before intialize shims.
-       bus_ = application_t::instance().get_diagnostic_bus();
-
-       init_diagnostic_shims();
-       reset();
+       if (! diagnostic_bus.empty())
+       {
+               bus_ = diagnostic_bus;
+               init_diagnostic_shims();
+               reset();
 
-       initialized_ = true;
-       AFB_DEBUG("Diagnostic Manager initialized");
+               AFB_DEBUG("Diagnostic Manager initialized");
+               initialized_ = true;
+               return initialized_;
+       }
+       AFB_ERROR("Diagnostic Manager missing its bus name in the config");
        return initialized_;
 }
 
@@ -124,9 +127,9 @@ bool diagnostic_manager_t::shims_send(const uint32_t arbitration_id, const uint8
        bcm_msg.frames[0] = cf;
 
 
-       std::shared_ptr<message_t> msg = std::make_shared<can_message_t>();
+       can_message_t msg = can_message_t();
 
-       msg->set_bcm_msg(bcm_msg);
+       msg.set_bcm_msg(bcm_msg);
 
        tx_socket.write_message(msg);
        if(tx_socket)
@@ -256,7 +259,7 @@ active_diagnostic_request_t* diagnostic_manager_t::find_recurring_request(Diagno
                if(entry != nullptr)
                {
                        if(diagnostic_request_equals(&entry->get_handle()->request, &request))
-                               {return entry;}
+                               return entry;
                }
        }
        return nullptr;
@@ -390,7 +393,7 @@ active_diagnostic_request_t* diagnostic_manager_t::add_recurring_request(Diagnos
                }
        }
        else
-               { AFB_DEBUG("Can't add request, one already exists with same key");}
+                AFB_DEBUG("Can't add request, one already exists with same key");
        return entry;
 }
 
@@ -409,9 +412,7 @@ openxc_VehicleMessage diagnostic_manager_t::relay_diagnostic_response(active_dia
        found_signals = utils::signals_manager_t::instance().find_signals(build_DynamicField((double) adr->get_pid()));
 
        if(adr->get_decoder() != nullptr)
-       {
                value = adr->get_decoder()(&response, value);
-       }
 
        if((response.success && adr->get_name().size()) > 0)
        {
@@ -440,9 +441,7 @@ openxc_VehicleMessage diagnostic_manager_t::relay_diagnostic_response(active_dia
        }
 
        if(adr->get_callback() != nullptr)
-       {
                adr->get_callback()(adr, &response, value);
-       }
 
        // Reset the completed flag handle to make sure that it will be reprocessed the next time.
        adr->get_handle()->success = false;
@@ -473,7 +472,7 @@ openxc_VehicleMessage diagnostic_manager_t::relay_diagnostic_response(active_dia
 /// @return A pointer to a filled openxc_VehicleMessage or a nullptr if nothing has been found.
 openxc_VehicleMessage diagnostic_manager_t::relay_diagnostic_handle(active_diagnostic_request_t* entry, std::shared_ptr<message_t> m)
 {
-       DiagnosticResponse response = diagnostic_receive_can_frame(&shims_, entry->get_handle(), m->get_id(), m->get_data(), m->get_length());
+       DiagnosticResponse response = diagnostic_receive_can_frame(&shims_, entry->get_handle(), m->get_id(), m->get_data(), (uint8_t)m->get_length());
        if(response.completed && entry->get_handle()->completed)
        {
                if(entry->get_handle()->success)
@@ -526,7 +525,7 @@ openxc_VehicleMessage diagnostic_manager_t::find_and_decode_adr(std::shared_ptr<
 /// @return True if the active diagnostic request match the response.
 bool diagnostic_manager_t::is_diagnostic_response(std::shared_ptr<message_t> m)
 {
-       if(m->get_msg_format() == can_message_format_t::STANDARD || m->get_msg_format() == can_message_format_t::EXTENDED)
+       if(m->get_id() & CAN_SFF_MASK || m->get_id() & CAN_EFF_MASK)
        {
                if (m->get_id() >= 0x7e8 && m->get_id() <= 0x7ef)
                                return true;