aboutsummaryrefslogtreecommitdiffstats
path: root/src/diagnostic
diff options
context:
space:
mode:
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 baa1184..505d816 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 a9abc13..88d4008 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 92ce33b..5103bf1 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 8602db8..39aae32 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);