summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/can/can-bus.cpp10
-rw-r--r--src/can/can-bus.hpp6
-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
-rw-r--r--src/low-can-binding.cpp6
7 files changed, 58 insertions, 46 deletions
diff --git a/src/can/can-bus.cpp b/src/can/can-bus.cpp
index 7a18ce8f..8edf5bac 100644
--- a/src/can/can-bus.cpp
+++ b/src/can/can-bus.cpp
@@ -186,13 +186,13 @@ int can_bus_t::init_can_dev()
for(const auto& device : devices_name)
{
- can_devices_m_[device] = std::make_shared<can_bus_dev_t>(device, i);
- if (can_devices_m_[device]->open() == 0)
+ can_devices_.push_back(std::make_shared<can_bus_dev_t>(device, i));
+ if (can_devices_[i]->open() == 0)
{
i++;
DEBUG(binder_interface, "Start reading thread");
NOTICE(binder_interface, "%s device opened and reading", device.c_str());
- can_devices_m_[device]->start_reading(*this);
+ can_devices_[i]->start_reading(*this);
}
else
ERROR(binder_interface, "Can't open device %s", device.c_str());
@@ -349,8 +349,8 @@ void can_bus_t::push_new_vehicle_message(const openxc_VehicleMessage& v_msg)
*
* @return map can_bus_dev_m_ map
*/
-std::map<std::string, std::shared_ptr<can_bus_dev_t>> can_bus_t::get_can_devices()
+const std::vector<std::shared_ptr<can_bus_dev_t>>& can_bus_t::get_can_devices() const
{
- return can_devices_m_;
+ return can_devices_;
}
diff --git a/src/can/can-bus.hpp b/src/can/can-bus.hpp
index 17e60d24..d4d6d74c 100644
--- a/src/can/can-bus.hpp
+++ b/src/can/can-bus.hpp
@@ -65,9 +65,9 @@ private:
std::condition_variable new_decoded_can_message_; /// < condition_variable use to wait until there is a new vehicle message to read from the queue vehicle_message_q_
std::mutex decoded_can_message_mutex_; /// < mutex protecting the vehicle_message_q_ queue.
- std::queue <openxc_VehicleMessage> vehicle_message_q_; /// < queue that'll store openxc_VehicleMessage to pushed
+ std::queue <openxc_VehicleMessage> vehicle_message_q_; /// < queue that'll store openxc_VehicleMessage to pushed
- std::map<std::string, std::shared_ptr<can_bus_dev_t>> can_devices_m_; /// < Can device map containing all can_bus_dev_t objects initialized during init_can_dev function
+ std::vector<std::shared_ptr<can_bus_dev_t>> can_devices_; /// < Can device map containing all can_bus_dev_t objects initialized during init_can_dev function
public:
can_bus_t(int conf_file);
@@ -87,6 +87,6 @@ public:
openxc_VehicleMessage next_vehicle_message();
void push_new_vehicle_message(const openxc_VehicleMessage& v_msg);
- std::map<std::string, std::shared_ptr<can_bus_dev_t>> get_can_devices();
+ const std::vector<std::shared_ptr<can_bus_dev_t>>& get_can_devices() const;
};
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);
diff --git a/src/low-can-binding.cpp b/src/low-can-binding.cpp
index a2b54567..394d906a 100644
--- a/src/low-can-binding.cpp
+++ b/src/low-can-binding.cpp
@@ -223,13 +223,17 @@ extern "C"
{
can_bus_t& can_bus_manager = configuration_t::instance().get_can_bus_manager();
- /* Open CAN socket */
+ /// Initialize CAN socket
if(can_bus_manager.init_can_dev() == 0)
{
can_bus_manager.start_threads();
return 0;
}
+ /// Initialize Diagnostic manager that will handle obd2 requests
+ diagnostic_manager_t& diag_manager = configuration_t::instance().get_diagnostic_manager();
+ diag_manager.initialize(can_bus_manager.get_can_devices().front());
+
ERROR(binder_interface, "There was something wrong with CAN device Initialization. Check your config file maybe");
return 1;
}