summaryrefslogtreecommitdiffstats
path: root/src/diagnostic
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-03-10 13:09:19 +0100
committerRomain Forlot <romain.forlot@iot.bzh>2017-03-16 17:10:40 +0100
commit94506d3985429d79f8521fca46ed7b9dc1eb4109 (patch)
tree176162d27e5b359ede621a5ed7ef1b71f51f881b /src/diagnostic
parentc67a16cdc749b79dab650b99cc2990448e9a7ac6 (diff)
Keep raw pointer for now as we have to move them around vector.
Change-Id: I8a518540b54552d60c6fd1054a0fc41dda5400b4 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'src/diagnostic')
-rw-r--r--src/diagnostic/active-diagnostic-request.cpp27
-rw-r--r--src/diagnostic/active-diagnostic-request.hpp2
-rw-r--r--src/diagnostic/diagnostic-manager.cpp100
-rw-r--r--src/diagnostic/diagnostic-manager.hpp16
4 files changed, 81 insertions, 64 deletions
diff --git a/src/diagnostic/active-diagnostic-request.cpp b/src/diagnostic/active-diagnostic-request.cpp
index 3e6ab14..baa1184 100644
--- a/src/diagnostic/active-diagnostic-request.cpp
+++ b/src/diagnostic/active-diagnostic-request.cpp
@@ -24,18 +24,21 @@ bool active_diagnostic_request_t::operator==(const active_diagnostic_request_t&
active_diagnostic_request_t& active_diagnostic_request_t::operator=(const active_diagnostic_request_t& adr)
{
- bus_ = adr.bus_;
- id_ = adr.id_;
- handle_ = adr.handle_;
- name_ = adr.name_;
- decoder_ = adr.decoder_;
- callback_ = adr.callback_;
- recurring_ = adr.recurring_;
- wait_for_multiple_responses_ = adr.wait_for_multiple_responses_;
- in_flight_ = adr.in_flight_;
- frequency_clock_ = adr.frequency_clock_;
- timeout_clock_ = adr.timeout_clock_;
-
+ if (this != &adr)
+ {
+ bus_ = adr.bus_;
+ id_ = adr.id_;
+ handle_ = adr.handle_;
+ name_ = adr.name_;
+ decoder_ = adr.decoder_;
+ callback_ = adr.callback_;
+ recurring_ = adr.recurring_;
+ wait_for_multiple_responses_ = adr.wait_for_multiple_responses_;
+ in_flight_ = adr.in_flight_;
+ frequency_clock_ = adr.frequency_clock_;
+ timeout_clock_ = adr.timeout_clock_;
+ }
+
return *this;
}
diff --git a/src/diagnostic/active-diagnostic-request.hpp b/src/diagnostic/active-diagnostic-request.hpp
index 52f4d48..a9abc13 100644
--- a/src/diagnostic/active-diagnostic-request.hpp
+++ b/src/diagnostic/active-diagnostic-request.hpp
@@ -82,7 +82,7 @@ public:
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(const 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,
const std::string& name, bool wait_for_multiple_responses,
const DiagnosticResponseDecoder decoder,
diff --git a/src/diagnostic/diagnostic-manager.cpp b/src/diagnostic/diagnostic-manager.cpp
index b4de554..5678dc4 100644
--- a/src/diagnostic/diagnostic-manager.cpp
+++ b/src/diagnostic/diagnostic-manager.cpp
@@ -38,7 +38,7 @@ diagnostic_manager_t::diagnostic_manager_t(can_bus_dev_t& bus)
reset();
}
-void diagnostic_manager_t::find_and_erase(active_diagnostic_request_t& entry, std::vector<active_diagnostic_request_t>& requests_list)
+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);
if ( i != requests_list.end())
@@ -47,7 +47,7 @@ void diagnostic_manager_t::find_and_erase(active_diagnostic_request_t& entry, st
/// Move the entry to the free list and decrement the lock count for any
/// CAN filters it used.
-void diagnostic_manager_t::cancel_request(active_diagnostic_request_t& entry)
+void diagnostic_manager_t::cancel_request(active_diagnostic_request_t* entry)
{
free_request_entries_.push_back(entry);
/* TODO: implement acceptance filters.
@@ -68,16 +68,16 @@ void diagnostic_manager_t::cancel_request(active_diagnostic_request_t& entry)
}*/
}
-void diagnostic_manager_t::cleanup_request(active_diagnostic_request_t& entry, bool force)
+void diagnostic_manager_t::cleanup_request(active_diagnostic_request_t* entry, bool force)
{
- if(force || (entry.get_in_flight() && entry.request_completed()))
+ if(force || (entry->get_in_flight() && entry->request_completed()))
{
- entry.set_in_flight(false);
+ entry->set_in_flight(false);
char request_string[128] = {0};
- diagnostic_request_to_string(&entry.get_handle()->request,
+ diagnostic_request_to_string(&entry->get_handle()->request,
request_string, sizeof(request_string));
- if(entry.get_recurring())
+ if(entry->get_recurring())
{
find_and_erase(entry, recurring_requests_);
if(force)
@@ -114,12 +114,11 @@ bool diagnostic_manager_t::lookup_recurring_request(const DiagnosticRequest* req
active_diagnostic_request_t existingEntry;
for (auto& entry : recurring_requests_)
{
- active_diagnostic_request_t& candidate = entry;
- if(candidate.get_can_bus_dev()->get_device_name() == bus_->get_device_name() &&
- diagnostic_request_equals(&candidate.get_handle()->request, request))
+ active_diagnostic_request_t* candidate = entry;
+ if(candidate->get_can_bus_dev()->get_device_name() == bus_->get_device_name() &&
+ diagnostic_request_equals(&candidate->get_handle()->request, request))
{
find_and_erase(entry, recurring_requests_);
- //existingEntry = entry;
return true;
break;
}
@@ -144,13 +143,12 @@ can_bus_dev_t* diagnostic_manager_t::get_can_bus_dev()
return bus_;
}
-active_diagnostic_request_t& diagnostic_manager_t::get_free_entry()
+active_diagnostic_request_t* diagnostic_manager_t::get_free_entry()
{
- //FIXME: Test against empty vector
- //if (request_list_entries_.empty())
- // return;
+ if (request_list_entries_.empty())
+ return nullptr;
- active_diagnostic_request_t& adr = request_list_entries_.back();
+ active_diagnostic_request_t* adr = request_list_entries_.back();
request_list_entries_.pop_back();
return adr;
}
@@ -162,24 +160,31 @@ bool diagnostic_manager_t::add_request(DiagnosticRequest* request, const std::st
cleanup_active_requests(false);
bool added = true;
- active_diagnostic_request_t& entry = get_free_entry();
+ active_diagnostic_request_t* entry = get_free_entry();
- // TODO: implement Acceptance Filter
- // if(updateRequiredAcceptanceFilters(bus, request)) {
- entry = active_diagnostic_request_t(bus_, request, name,
- wait_for_multiple_responses, decoder, callback, 0);
- entry.set_handle(shims_, request);
-
- char request_string[128] = {0};
- diagnostic_request_to_string(&entry.get_handle()->request, request_string,
- sizeof(request_string));
+ if (entry != nullptr)
+ {
+ // TODO: implement Acceptance Filter
+ // if(updateRequiredAcceptanceFilters(bus, request)) {
+ entry = new active_diagnostic_request_t(bus_, request, name,
+ wait_for_multiple_responses, decoder, callback, 0);
+ entry->set_handle(shims_, request);
- 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);
+ char request_string[128] = {0};
+ diagnostic_request_to_string(&entry->get_handle()->request, request_string,
+ sizeof(request_string));
- non_recurring_requests_.push_back(entry);
+ 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);
+ non_recurring_requests_.push_back(entry);
+ }
+ else
+ {
+ WARNING(binder_interface, "There isn't enough request entry. Vector exhausted %d/%d", (int)request_list_entries_.size(), (int)request_list_entries_.max_size());
+ added = false;
+ }
return added;
}
@@ -205,22 +210,31 @@ bool diagnostic_manager_t::add_recurring_request(DiagnosticRequest* request, con
bool added = true;
if(lookup_recurring_request(request))
{
- active_diagnostic_request_t& entry = get_free_entry();
- // TODO: implement Acceptance Filter
- //if(updateRequiredAcceptanceFilters(bus, request)) {
- entry = active_diagnostic_request_t(bus_, request, name,
- wait_for_multiple_responses, decoder, callback, frequencyHz);
- entry.set_handle(shims_, request);
+ active_diagnostic_request_t* entry = get_free_entry();
- char request_string[128] = {0};
- diagnostic_request_to_string(&entry.get_handle()->request, request_string,
- sizeof(request_string));
+ if(entry != nullptr)
+ {
+ // TODO: implement Acceptance Filter
+ //if(updateRequiredAcceptanceFilters(bus, request)) {
+ entry = new active_diagnostic_request_t(bus_, request, name,
+ wait_for_multiple_responses, decoder, callback, frequencyHz);
+ entry->set_handle(shims_, request);
- find_and_erase(entry, recurring_requests_);
- DEBUG(binder_interface, "Added recurring diagnostic request (freq: %f) on bus %d: %s",
- frequencyHz, bus_->get_device_name(), request_string);
+ char request_string[128] = {0};
+ diagnostic_request_to_string(&entry->get_handle()->request, request_string,
+ sizeof(request_string));
+
+ find_and_erase(entry, recurring_requests_);
+ DEBUG(binder_interface, "Added recurring diagnostic request (freq: %f) on bus %d: %s",
+ frequencyHz, bus_->get_device_name(), request_string);
- recurring_requests_.push_back(entry);
+ recurring_requests_.push_back(entry);
+ }
+ else
+ {
+ WARNING(binder_interface, "There isn't enough request entry. Vector exhausted %d/%d", (int)request_list_entries_.size(), (int)request_list_entries_.max_size());
+ added = false;
+ }
}
else
{
diff --git a/src/diagnostic/diagnostic-manager.hpp b/src/diagnostic/diagnostic-manager.hpp
index 05752f6..8602db8 100644
--- a/src/diagnostic/diagnostic-manager.hpp
+++ b/src/diagnostic/diagnostic-manager.hpp
@@ -51,16 +51,16 @@ private:
* 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
* 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
+ 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
* popped from the queue and pushed onto the back. */
- std::vector<active_diagnostic_request_t> non_recurring_requests_; /*!< nonrecurringRequests - A list of active one-time diagnostic requests. When a
+ std::vector<active_diagnostic_request_t*> 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 from this list and placed back in the free list.*/
- std::vector<active_diagnostic_request_t> free_request_entries_; /*!< freeRequestEntries - A list of all available slots for active diagnostic
+ std::vector<active_diagnostic_request_t*> free_request_entries_; /*!< freeRequestEntries - A list of all available slots for active diagnostic
* requests. This free list is backed by statically allocated entries in
* the requestListEntries attribute.*/
- std::vector<active_diagnostic_request_t> request_list_entries_; /*!< requestListEntries - Static allocation for all active diagnostic requests.*/
+ std::vector<active_diagnostic_request_t*> request_list_entries_; /*!< requestListEntries - Static allocation for all active diagnostic requests.*/
bool initialized_; /*!< * initialized - True if the DiagnosticsManager has been initialized with shims. It will interface with the uds-c lib*/
@@ -71,11 +71,11 @@ public:
void init_diagnostic_shims();
can_bus_dev_t* get_can_bus_dev();
- active_diagnostic_request_t& get_free_entry();
+ active_diagnostic_request_t* get_free_entry();
- 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);
- void cleanup_request(active_diagnostic_request_t& entry, bool force);
+ 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);
+ void cleanup_request(active_diagnostic_request_t* entry, bool force);
void cleanup_active_requests(bool force);
bool lookup_recurring_request(const DiagnosticRequest* request);