From 1d464d2a7380248b04c3e734ed5c6e84bbf53ddf Mon Sep 17 00:00:00 2001 From: Romain Forlot Date: Wed, 15 Mar 2017 13:04:42 +0100 Subject: Revert accessing CAN device with a map indexing on dev name Main reason for that behavior revert is because of generator that rely on CAN device name and so we have point on these object by specify the device name. Instead of shared pointer between objects, instead binding is based on device name. With a device name you can get the shared pointer on it using new static method from can_bus_t object. Change-Id: I331e0ad8d03c88a15c697d12a9fce3699b0cd962 Signed-off-by: Romain Forlot --- src/diagnostic/active-diagnostic-request.cpp | 12 +++++++----- src/diagnostic/active-diagnostic-request.hpp | 7 ++++--- src/diagnostic/diagnostic-manager.cpp | 14 +++++++------- src/diagnostic/diagnostic-manager.hpp | 11 ++++++----- 4 files changed, 24 insertions(+), 20 deletions(-) (limited to 'src/diagnostic') diff --git a/src/diagnostic/active-diagnostic-request.cpp b/src/diagnostic/active-diagnostic-request.cpp index 9d0f6aa..fcdbc97 100644 --- a/src/diagnostic/active-diagnostic-request.cpp +++ b/src/diagnostic/active-diagnostic-request.cpp @@ -16,9 +16,12 @@ */ #include +#include #include "active-diagnostic-request.hpp" +#include "../configuration.hpp" + std::string active_diagnostic_request_t::prefix_ = "diagnostic_messages"; bool active_diagnostic_request_t::operator==(const active_diagnostic_request_t& b) @@ -52,9 +55,8 @@ active_diagnostic_request_t::active_diagnostic_request_t() in_flight_{false}, frequency_clock_{frequency_clock_t()}, timeout_clock_{frequency_clock_t()} {} -active_diagnostic_request_t::active_diagnostic_request_t(std::shared_ptr bus, DiagnosticRequest* request, - const std::string& name, bool wait_for_multiple_responses, - const DiagnosticResponseDecoder decoder, +active_diagnostic_request_t::active_diagnostic_request_t(const std::string& bus, DiagnosticRequest* request, + const std::string& name, bool wait_for_multiple_responses, const DiagnosticResponseDecoder decoder, const DiagnosticResponseCallback callback, float frequencyHz) : bus_{bus}, id_{request->arbitration_id}, handle_{nullptr}, name_{name}, decoder_{decoder}, callback_{callback}, recurring_{frequencyHz ? true : false}, wait_for_multiple_responses_{wait_for_multiple_responses}, @@ -66,9 +68,9 @@ uint32_t active_diagnostic_request_t::get_id() const return id_; } -std::shared_ptr active_diagnostic_request_t::get_can_bus_dev() +const std::shared_ptr active_diagnostic_request_t::get_can_bus_dev() const { - return bus_; + return can_bus_t::get_can_device(bus_); } DiagnosticRequestHandle* active_diagnostic_request_t::get_handle() diff --git a/src/diagnostic/active-diagnostic-request.hpp b/src/diagnostic/active-diagnostic-request.hpp index f18282f..b40ae08 100644 --- a/src/diagnostic/active-diagnostic-request.hpp +++ b/src/diagnostic/active-diagnostic-request.hpp @@ -56,7 +56,7 @@ typedef void (*DiagnosticResponseCallback)(const active_diagnostic_request_t* re */ class active_diagnostic_request_t { private: - std::shared_ptr bus_; /*!< bus_ - The CAN bus this request should be made on, or is currently in flight-on*/ + std::string bus_; /*!< bus_ - The CAN bus this request should be made on, or is currently in flight-on*/ uint32_t id_; /*!< id_ - The arbitration ID (aka message ID) for the request.*/ DiagnosticRequestHandle* handle_; /*!< handle_ - A handle for the request to keep track of it between * sending the frames of the request and receiving all frames of the response.*/ @@ -82,15 +82,16 @@ private: public: bool operator==(const active_diagnostic_request_t& b); active_diagnostic_request_t& operator=(const active_diagnostic_request_t& adr); + active_diagnostic_request_t(); active_diagnostic_request_t(active_diagnostic_request_t&&) = default; - active_diagnostic_request_t(std::shared_ptr bus, DiagnosticRequest* request, + active_diagnostic_request_t(const std::string& bus, DiagnosticRequest* request, const std::string& name, bool wait_for_multiple_responses, const DiagnosticResponseDecoder decoder, const DiagnosticResponseCallback callback, float frequencyHz); uint32_t get_id() const; - std::shared_ptr get_can_bus_dev(); + const std::shared_ptr get_can_bus_dev() const; DiagnosticRequestHandle* get_handle(); const std::string get_name() const; static std::string& get_prefix(); diff --git a/src/diagnostic/diagnostic-manager.cpp b/src/diagnostic/diagnostic-manager.cpp index 21a599d..1477b2b 100644 --- a/src/diagnostic/diagnostic-manager.cpp +++ b/src/diagnostic/diagnostic-manager.cpp @@ -33,10 +33,10 @@ diagnostic_manager_t::diagnostic_manager_t() : initialized_{false} {} -bool diagnostic_manager_t::initialize(std::shared_ptr cbd) +bool diagnostic_manager_t::initialize() { // Mandatory to set the bus before intiliaze shims. - bus_ = cbd; + bus_ = configuration_t::instance().get_diagnostic_bus(); init_diagnostic_shims(); reset(); @@ -153,7 +153,7 @@ active_diagnostic_request_t* diagnostic_manager_t::find_recurring_request(const std::shared_ptr diagnostic_manager_t::get_can_bus_dev() { - return bus_; + return can_bus_t::get_can_device(bus_); } bool diagnostic_manager_t::add_request(DiagnosticRequest* request, const std::string name, @@ -178,7 +178,7 @@ bool diagnostic_manager_t::add_request(DiagnosticRequest* request, const std::st find_and_erase(entry, non_recurring_requests_); DEBUG(binder_interface, "Added one-time diagnostic request on bus %s: %s", - bus_->get_device_name(), request_string); + bus_, request_string); non_recurring_requests_.push_back(entry); } @@ -227,7 +227,7 @@ bool diagnostic_manager_t::add_recurring_request(DiagnosticRequest* request, con sizeof(request_string)); DEBUG(binder_interface, "add_recurring_request: Added recurring diagnostic request (freq: %f) on bus %s: %s", - frequencyHz, bus_->get_device_name().c_str(), request_string); + frequencyHz, bus_.c_str(), request_string); uint64_t usec; sd_event_now(afb_daemon_get_event_loop(binder_interface->daemon), CLOCK_MONOTONIC, &usec); @@ -343,7 +343,7 @@ int diagnostic_manager_t::send_request(sd_event_source *s, uint64_t usec, void * // if(adr != nullptr && adr->get_can_bus_dev() == dm.get_can_bus_dev() && adr->should_send() && // dm.clear_to_send(adr)) - if(adr != nullptr && adr->get_can_bus_dev() == dm.bus_) + if(adr != nullptr && adr->get_can_bus_dev() == dm.get_can_bus_dev()) { adr->get_frequency_clock().tick(); start_diagnostic_request(&dm.shims_, adr->get_handle()); @@ -376,7 +376,7 @@ DiagnosticShims& diagnostic_manager_t::get_shims() bool diagnostic_manager_t::shims_send(const uint32_t arbitration_id, const uint8_t* data, const uint8_t size) { - std::shared_ptr can_bus_dev = configuration_t::instance().get_diagnostic_manager().get_can_bus_dev(); + std::shared_ptr can_bus_dev = can_bus_t::get_can_device(configuration_t::instance().get_diagnostic_manager().bus_); return can_bus_dev->shims_send(arbitration_id, data, size); } diff --git a/src/diagnostic/diagnostic-manager.hpp b/src/diagnostic/diagnostic-manager.hpp index 71662ba..ff055d5 100644 --- a/src/diagnostic/diagnostic-manager.hpp +++ b/src/diagnostic/diagnostic-manager.hpp @@ -18,6 +18,7 @@ #pragma once #include +#include #include #include "uds/uds.h" @@ -49,10 +50,10 @@ protected: static void shims_timer(); private: - DiagnosticShims shims_; /*!< shims_ - An array of shim functions for each CAN bus that plug the diagnostics - * library (uds-c) into the VI's CAN peripheral.*/ - std::shared_ptr bus_; /*!< bus_ - A pointer to the CAN bus that should be used for all standard OBD-II requests, if the bus is not - * explicitly spcified in the request. If NULL, all requests require an explicit bus.*/ + DiagnosticShims shims_; /*!< shims_ - A map of shim functions for each CAN bus that plug the diagnostics + * library (uds-c) into the VI's CAN peripheral.*/ + std::string bus_; /*!< bus_ - A pointer to the CAN bus that should be used for all standard OBD-II requests, if the bus is not + * explicitly spcified in the request. Default to the first bus CAN at initialization.*/ std::vector recurring_requests_; /*!< recurringRequests - A list of active recurring diagnostic requests.*/ std::vector non_recurring_requests_; /*!< nonrecurringRequests - A list of active one-time diagnostic requests. When a * response is received for a non-recurring request or it times out, it is removed*/ @@ -63,7 +64,7 @@ private: public: diagnostic_manager_t(); - bool initialize(std::shared_ptr cbd); + bool initialize(); std::shared_ptr get_can_bus_dev(); DiagnosticShims& get_shims(); -- cgit 1.2.3-korg