summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-03-09 16:11:43 +0100
committerRomain Forlot <romain.forlot@iot.bzh>2017-03-16 17:10:40 +0100
commit9099177556d598676e4d6322ae49d22bb2f0c59e (patch)
tree83fdb93382341a84e232836c56d908c18c9f9be4 /src
parenta18bc8d9ddaa16e5120c0f21cbaf53d2ce5155f8 (diff)
Added constructor to get vector initialized with default
objects initialized that can be grabed after at runtime. Don't know the impact on performance for now about maximum limit. Change-Id: I220614d479b8254ae0efda66380e96434bcbfbb2 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'src')
-rw-r--r--src/diagnostic/active-diagnostic-request.cpp49
-rw-r--r--src/diagnostic/active-diagnostic-request.hpp51
-rw-r--r--src/diagnostic/diagnostic-manager.cpp4
-rw-r--r--src/diagnostic/diagnostic-manager.hpp24
4 files changed, 92 insertions, 36 deletions
diff --git a/src/diagnostic/active-diagnostic-request.cpp b/src/diagnostic/active-diagnostic-request.cpp
new file mode 100644
index 00000000..96e4b3ab
--- /dev/null
+++ b/src/diagnostic/active-diagnostic-request.cpp
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2015, 2016 "IoT.bzh"
+ * Author "Romain Forlot" <romain.forlot@iot.bzh>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+active_diagnostic_request_t::active_diagnostic_request_t()
+ : can_bus_dev_{nullptr}, uint32_t id_{0}, DiagnosticRequestHandle{nullptr}, name_{""},
+ decoder_{nullptr}, callback_{nullptr}, reccuring_{false}, wait_for_multiple_responses_{false},
+ in_flight_{false}, frequency_clock_{frequency_clock_t()}, timeout_clock_{frequency_clock_t()}
+{}
+
+void updateDiagnosticRequestEntry(CanBus* bus, DiagnosticRequest* request,
+ const char* name, bool waitForMultipleResponses,
+ const DiagnosticResponseDecoder decoder,
+ const DiagnosticResponseCallback callback, float frequencyHz)
+{
+ entry->bus = bus;
+ entry->arbitration_id = request->arbitration_id;
+ entry->handle = generate_diagnostic_request(
+ &manager->shims[bus->address - 1], request, NULL);
+ if(name != NULL) {
+ strncpy(entry->name, name, MAX_GENERIC_NAME_LENGTH);
+ } else {
+ entry->name[0] = '\0';
+ }
+ entry->waitForMultipleResponses = waitForMultipleResponses;
+
+ entry->decoder = decoder;
+ entry->callback = callback;
+ entry->recurring = frequencyHz != 0;
+ entry->frequencyClock = {0};
+ entry->frequencyClock.frequency = entry->recurring ? frequencyHz : 0;
+ // time out after 100ms
+ entry->timeoutClock = {0};
+ entry->timeoutClock.frequency = 10;
+ entry->inFlight = false;
+ } \ No newline at end of file
diff --git a/src/diagnostic/active-diagnostic-request.hpp b/src/diagnostic/active-diagnostic-request.hpp
index 0a64f7c9..28506632 100644
--- a/src/diagnostic/active-diagnostic-request.hpp
+++ b/src/diagnostic/active-diagnostic-request.hpp
@@ -55,27 +55,32 @@ typedef void (*DiagnosticResponseCallback)(const active_diagnostic_request_t* re
* @brief An active diagnostic request, either recurring or one-time.
*/
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*/
- 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.*/
- std::string name_; /*!< name_ - An optional human readable name this response, to be used when publishing received
- * responses. If the name is NULL, the published output will use the raw OBD-II response format.*/
- DiagnosticResponseDecoder decoder_; /*!< decoder_ - An optional DiagnosticResponseDecoder to parse the payload of responses
- * to this request. If the decoder is NULL, the output will include the raw payload
- * instead of a parsed value.*/
- DiagnosticResponseCallback callback_; /*!< callback_ - An optional DiagnosticResponseCallback to be notified whenever a
- * response is received for this request.*/
- bool recurring_; /*!< bool recurring_ - If true, this is a recurring request and it will remain as active until explicitly cancelled.
- * The frequencyClock attribute controls how often a recurrin request is made.*/
- bool waitForMultipleResponses_; /*!< waitForMultipleResponses_ - False by default, when any response is received for a request
- * it will be removed from the active list. If true, the request will remain active until the timeout
- * clock expires, to allow it to receive multiple response (e.g. to a functional broadcast request).*/
- bool inFlight_; /*!< inFlight_ - True if the request has been sent and we are waiting for a response.*/
- FrequencyClock frequency_clock_; /*!< frequency_clock_ - A FrequencyClock object to control the send rate for a
- * recurring request. If the request is not reecurring, this attribute is not used.*/
- FrequencyClock timeout_clock_; /*!< timeout_clock_ - A FrequencyClock object to monitor how long it's been since
- * this request was sent.*/
- public:
+private:
+ 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.*/
+ std::string name_; /*!< name_ - An optional human readable name this response, to be used when publishing received
+ * responses. If the name is NULL, the published output will use the raw OBD-II response format.*/
+ DiagnosticResponseDecoder decoder_; /*!< decoder_ - An optional DiagnosticResponseDecoder to parse the payload of responses
+ * to this request. If the decoder is NULL, the output will include the raw payload
+ * instead of a parsed value.*/
+ DiagnosticResponseCallback callback_; /*!< callback_ - An optional DiagnosticResponseCallback to be notified whenever a
+ * response is received for this request.*/
+ bool recurring_; /*!< bool recurring_ - If true, this is a recurring request and it will remain as active until explicitly cancelled.
+ * The frequencyClock attribute controls how often a recurrin request is made.*/
+ bool wait_for_multiple_responses_; /*!< wait_for_multiple_responses_ - False by default, when any response is received for a request
+ * it will be removed from the active list. If true, the request will remain active until the timeout
+ * clock expires, to allow it to receive multiple response (e.g. to a functional broadcast request).*/
+ bool in_flight_; /*!< in_flight_ - True if the request has been sent and we are waiting for a response.*/
+ frequency_clock_t frequency_clock_; /*!< frequency_clock_ - A frequency_clock_t object to control the send rate for a
+ * recurring request. If the request is not reecurring, this attribute is not used.*/
+ frequency_clock_t timeout_clock_; /*!< timeout_clock_ - A frequency_clock_t object to monitor how long it's been since
+ * this request was sent.*/
+public:
+ active_diagnostic_request_t();
+
+ void updateDiagnosticRequestEntry(DiagnosticsManager* manager, CanBus* bus, DiagnosticRequest* request,
+ const char* name, bool waitForMultipleResponses, const DiagnosticResponseDecoder decoder,
+ const DiagnosticResponseCallback callback, float frequencyHz);
};
diff --git a/src/diagnostic/diagnostic-manager.cpp b/src/diagnostic/diagnostic-manager.cpp
index 1feac97a..2be9a058 100644
--- a/src/diagnostic/diagnostic-manager.cpp
+++ b/src/diagnostic/diagnostic-manager.cpp
@@ -19,12 +19,14 @@
#include "../configuration.hpp"
#include "../low-can-binding.hpp"
+#define MAX_REQUEST_ENTRIES 50
diagnostic_manager_t::diagnostic_manager_t()
+ : request_list_entries_(MAX_REQUEST_ENTRIES, active_diagnostic_request_t())
{}
diagnostic_manager_t::diagnostic_manager_t(can_bus_dev_t& bus)
- : bus_(&bus)
+ : bus_(&bus), request_list_entries_(MAX_REQUEST_ENTRIES, active_diagnostic_request_t())
{}
bool shims_send(const uint32_t arbitration_id, const uint8_t* data, const uint8_t size)
diff --git a/src/diagnostic/diagnostic-manager.hpp b/src/diagnostic/diagnostic-manager.hpp
index faf1eaf4..bb12f6b0 100644
--- a/src/diagnostic/diagnostic-manager.hpp
+++ b/src/diagnostic/diagnostic-manager.hpp
@@ -45,19 +45,19 @@ 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.*/
+ * 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::queue<active_diagnostic_request_t> recurringRequests_; /*!< 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> nonrecurringRequests_; /*!< 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> freeRequestEntries_; /*!< 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> requestListEntries_[50]; /*!< requestListEntries - Static allocation for all active diagnostic requests.*/
+ * explicitly spcified in the request. If NULL, all requests require an explicit bus.*/
+ std::queue<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
+ * 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
+ * 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.*/
bool initialized_; /*!< * initialized - True if the DiagnosticsManager has been initialized with shims. It will interface with the uds-c lib*/