summaryrefslogtreecommitdiffstats
path: root/src/diagnostic
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-03-12 19:38:49 +0100
committerRomain Forlot <romain.forlot@iot.bzh>2017-03-16 17:10:41 +0100
commit24057b7fad6d4d1f1f264995d0f5865acf466004 (patch)
treeced9c92076a3f6c1e87f9aeb0312bfa2440fd3a1 /src/diagnostic
parent62eb024d989037ae7f2ba86de8b68c826cb61ec9 (diff)
Make diagnostic manager initialization processus.
It is initiliazed with by default the first CAN bus device in the CAN bus device list from CAN bus manager. The object is instancied at configuration_t object first invokation and after all CAN buses has been initialized then the diag manager is initialized too. Change-Id: I4894f2c62f575676c34efec3608b97de8c5326e1 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'src/diagnostic')
-rw-r--r--src/diagnostic/active-diagnostic-request.cpp4
-rw-r--r--src/diagnostic/active-diagnostic-request.hpp6
-rw-r--r--src/diagnostic/diagnostic-manager.cpp61
-rw-r--r--src/diagnostic/diagnostic-manager.hpp11
4 files changed, 45 insertions, 37 deletions
diff --git a/src/diagnostic/active-diagnostic-request.cpp b/src/diagnostic/active-diagnostic-request.cpp
index baa11844..505d816e 100644
--- a/src/diagnostic/active-diagnostic-request.cpp
+++ b/src/diagnostic/active-diagnostic-request.cpp
@@ -48,7 +48,7 @@ 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(can_bus_dev_t* bus, DiagnosticRequest* request,
+active_diagnostic_request_t::active_diagnostic_request_t(std::shared_ptr<can_bus_dev_t> bus, DiagnosticRequest* request,
const std::string& name, bool wait_for_multiple_responses,
const DiagnosticResponseDecoder decoder,
const DiagnosticResponseCallback callback, float frequencyHz)
@@ -57,7 +57,7 @@ active_diagnostic_request_t::active_diagnostic_request_t(can_bus_dev_t* bus, Dia
in_flight_{false}, frequency_clock_{frequency_clock_t(frequencyHz)}, timeout_clock_{frequency_clock_t(10)}
{}
-can_bus_dev_t* active_diagnostic_request_t::get_can_bus_dev()
+std::shared_ptr<can_bus_dev_t> active_diagnostic_request_t::get_can_bus_dev()
{
return bus_;
}
diff --git a/src/diagnostic/active-diagnostic-request.hpp b/src/diagnostic/active-diagnostic-request.hpp
index a9abc13d..88d40084 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:
- can_bus_dev_t* bus_; /*!< bus_ - The CAN bus this request should be made on, or is currently in flight-on*/
+ std::shared_ptr<can_bus_dev_t> 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.*/
@@ -83,12 +83,12 @@ public:
active_diagnostic_request_t();
active_diagnostic_request_t(active_diagnostic_request_t&&) = default;
//active_diagnostic_request_t(const active_diagnostic_request_t&) = default;
- active_diagnostic_request_t(can_bus_dev_t* bus, DiagnosticRequest* request,
+ active_diagnostic_request_t(std::shared_ptr<can_bus_dev_t> bus, DiagnosticRequest* request,
const std::string& name, bool wait_for_multiple_responses,
const DiagnosticResponseDecoder decoder,
const DiagnosticResponseCallback callback, float frequencyHz);
- can_bus_dev_t* get_can_bus_dev();
+ std::shared_ptr<can_bus_dev_t> get_can_bus_dev();
DiagnosticRequestHandle* get_handle();
bool get_recurring() const;
bool get_in_flight() const;
diff --git a/src/diagnostic/diagnostic-manager.cpp b/src/diagnostic/diagnostic-manager.cpp
index 92ce33b0..5103bf10 100644
--- a/src/diagnostic/diagnostic-manager.cpp
+++ b/src/diagnostic/diagnostic-manager.cpp
@@ -28,16 +28,45 @@
diagnostic_manager_t::diagnostic_manager_t()
: request_list_entries_(MAX_REQUEST_ENTRIES), initialized_{false}
+{}
+
+bool diagnostic_manager_t::initialize(std::shared_ptr<can_bus_dev_t> cbd)
{
+ // Mandatory to set the bus before intiliaze shims.
+ bus_ = cbd;
+
+ init_diagnostic_shims();
reset();
+
+ initialized_ = true;
+ DEBUG(binder_interface, "initialize: Diagnostic Manager initialized");
+ return initialized_;
}
-diagnostic_manager_t::diagnostic_manager_t(can_bus_dev_t& bus)
- : bus_(&bus), request_list_entries_(MAX_REQUEST_ENTRIES), initialized_{false}
+/**
+ * @brief initialize shims used by UDS lib and set initialized_ to true.
+ * It is needed before used the diagnostic manager fully because shims are
+ * required by most member functions.
+ */
+void diagnostic_manager_t::init_diagnostic_shims()
{
- reset();
+ shims_ = diagnostic_init_shims(shims_logger, shims_send, NULL);
+ DEBUG(binder_interface, "init_diagnostic_shims: Shims initialized");
+}
+
+void diagnostic_manager_t::reset()
+{
+ if(initialized_)
+ {
+ DEBUG(binder_interface, "Clearing existing diagnostic requests");
+ cleanup_active_requests(true);
+ }
+
+ for(int i = 0; i < MAX_SIMULTANEOUS_DIAG_REQUESTS; i++)
+ free_request_entries_.push_back(request_list_entries_[i]);
}
+
void diagnostic_manager_t::find_and_erase(active_diagnostic_request_t* entry, std::vector<active_diagnostic_request_t*>& requests_list)
{
auto i = std::find(requests_list.begin(), requests_list.end(), entry);
@@ -126,19 +155,7 @@ bool diagnostic_manager_t::lookup_recurring_request(const DiagnosticRequest* req
return false;
}
-void diagnostic_manager_t::reset()
-{
- if(initialized_)
- {
- DEBUG(binder_interface, "Clearing existing diagnostic requests");
- cleanup_active_requests(true);
- }
-
- for(int i = 0; i < MAX_SIMULTANEOUS_DIAG_REQUESTS; i++)
- free_request_entries_.push_back(request_list_entries_[i]);
-}
-
-can_bus_dev_t* diagnostic_manager_t::get_can_bus_dev()
+std::shared_ptr<can_bus_dev_t> diagnostic_manager_t::get_can_bus_dev()
{
return bus_;
}
@@ -246,7 +263,7 @@ bool diagnostic_manager_t::add_recurring_request(DiagnosticRequest* request, con
bool diagnostic_manager_t::shims_send(const uint32_t arbitration_id, const uint8_t* data, const uint8_t size)
{
- can_bus_dev_t *can_bus_dev = configuration_t::instance().get_diagnostic_manager().get_can_bus_dev();
+ std::shared_ptr<can_bus_dev_t> can_bus_dev = configuration_t::instance().get_diagnostic_manager().get_can_bus_dev();
return can_bus_dev->shims_send(arbitration_id, data, size);
}
@@ -258,13 +275,3 @@ void diagnostic_manager_t::shims_logger(const char* m, ...)
void diagnostic_manager_t::shims_timer()
{}
-/**
- * @brief initialize shims used by UDS lib and set initialized_ to true.
- * It is needed before used the diagnostic manager fully because shims are
- * required by most member functions.
- */
-void diagnostic_manager_t::init_diagnostic_shims()
-{
- shims_ = diagnostic_init_shims(shims_logger, shims_send, NULL);
- initialized_ = true;
-}
diff --git a/src/diagnostic/diagnostic-manager.hpp b/src/diagnostic/diagnostic-manager.hpp
index 8602db86..39aae321 100644
--- a/src/diagnostic/diagnostic-manager.hpp
+++ b/src/diagnostic/diagnostic-manager.hpp
@@ -49,7 +49,7 @@ protected:
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.*/
- can_bus_dev_t* bus_; /*!< bus_ - A pointer to the CAN bus that should be used for all standard OBD-II requests, if the bus is not
+ std::shared_ptr<can_bus_dev_t> 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.*/
std::vector<active_diagnostic_request_t*> recurring_requests_; /*!< recurringRequests - A queue of active, recurring diagnostic requests. When
* a response is received for a recurring request or it times out, it is
@@ -64,14 +64,16 @@ private:
bool initialized_; /*!< * initialized - True if the DiagnosticsManager has been initialized with shims. It will interface with the uds-c lib*/
+ void init_diagnostic_shims();
+ void reset();
public:
diagnostic_manager_t();
- diagnostic_manager_t(can_bus_dev_t& bus);
- void init_diagnostic_shims();
+ bool initialize(std::shared_ptr<can_bus_dev_t> cbd);
- can_bus_dev_t* get_can_bus_dev();
+ std::shared_ptr<can_bus_dev_t> get_can_bus_dev();
active_diagnostic_request_t* get_free_entry();
+ DiagnosticShims& get_shims();
void find_and_erase(active_diagnostic_request_t* entry, std::vector<active_diagnostic_request_t*>& requests_list);
void cancel_request(active_diagnostic_request_t* entry);
@@ -81,7 +83,6 @@ public:
bool validate_optional_request_attributes(float frequencyHz);
- void reset();
void checkSupportedPids(const active_diagnostic_request_t& request,
const DiagnosticResponse& response, float parsedPayload);