X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=low-can-binding%2Fdiagnostic%2Factive-diagnostic-request.cpp;h=80d2e696b790bfcbc290bb148190aaa63a121591;hb=d1530f94446bf69599664b0341be35317e18b8b5;hp=7ddf1d5184348e5e7cbb7b49efc4c9de5de5cd04;hpb=9e444ade872bc436cf12bc12d03c3a5d51ac0b9e;p=apps%2Fagl-service-can-low-level.git diff --git a/low-can-binding/diagnostic/active-diagnostic-request.cpp b/low-can-binding/diagnostic/active-diagnostic-request.cpp index 7ddf1d51..80d2e696 100644 --- a/low-can-binding/diagnostic/active-diagnostic-request.cpp +++ b/low-can-binding/diagnostic/active-diagnostic-request.cpp @@ -15,71 +15,56 @@ * limitations under the License. */ -#include + #include +#include #include "active-diagnostic-request.hpp" -#include "../configuration.hpp" +#include "../binding/application.hpp" -#define ERROR_PID 0xFF +#define AFB_ERROR_PID 0xFF std::string active_diagnostic_request_t::prefix_ = "diagnostic_messages"; -bool active_diagnostic_request_t::operator==(const active_diagnostic_request_t& b) -{ - return (bus_ == b.bus_ && id_ == b.id_ && handle_ == b.handle_); -} +active_diagnostic_request_t::active_diagnostic_request_t(const std::string& bus, uint32_t id, + const std::string& name, + bool wait_for_multiple_responses, + const DiagnosticResponseDecoder decoder, + const DiagnosticResponseCallback callback, + float frequencyHz, + bool permanent) + : bus_{bus}, + id_{id}, + handle_{nullptr}, + name_{name}, + decoder_{decoder}, + callback_{callback}, + recurring_{frequencyHz ? true : false}, + permanent_{permanent}, + wait_for_multiple_responses_{wait_for_multiple_responses}, + frequency_clock_{frequency_clock_t(frequencyHz)}, + timeout_clock_{frequency_clock_t(10)}, + socket_{} +{} -active_diagnostic_request_t& active_diagnostic_request_t::operator=(const active_diagnostic_request_t& adr) +active_diagnostic_request_t::~active_diagnostic_request_t() { - 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; + socket_.close(); + delete handle_; + handle_ = nullptr; } -active_diagnostic_request_t::active_diagnostic_request_t() - : bus_{nullptr}, id_{0}, handle_{nullptr}, name_{""}, - decoder_{nullptr}, callback_{nullptr}, recurring_{false}, wait_for_multiple_responses_{false}, - in_flight_{false}, frequency_clock_{frequency_clock_t()}, timeout_clock_{frequency_clock_t()} -{} - -active_diagnostic_request_t::active_diagnostic_request_t(const std::string& bus, DiagnosticRequest* request, - const std::string& name, bool wait_for_multiple_responses, const DiagnosticResponseDecoder decoder, - const DiagnosticResponseCallback callback, float frequencyHz) - : bus_{bus}, id_{request->arbitration_id}, handle_{nullptr}, name_{name}, - decoder_{decoder}, callback_{callback}, recurring_{frequencyHz ? true : false}, wait_for_multiple_responses_{wait_for_multiple_responses}, - in_flight_{false}, frequency_clock_{frequency_clock_t(frequencyHz)}, timeout_clock_{frequency_clock_t(10)} -{} - uint32_t active_diagnostic_request_t::get_id() const { return id_; } -const std::shared_ptr active_diagnostic_request_t::get_can_bus_dev() const -{ - return can_bus_t::get_can_device(bus_); -} - uint16_t active_diagnostic_request_t::get_pid() const { if (handle_->request.has_pid) return handle_->request.pid; - return ERROR_PID; + return AFB_ERROR_PID; } DiagnosticRequestHandle* active_diagnostic_request_t::get_handle() @@ -112,9 +97,9 @@ bool active_diagnostic_request_t::get_recurring() const return recurring_; } -bool active_diagnostic_request_t::get_in_flight() const +bool active_diagnostic_request_t::get_permanent() const { - return in_flight_; + return permanent_; } frequency_clock_t& active_diagnostic_request_t::get_frequency_clock() @@ -127,50 +112,14 @@ frequency_clock_t& active_diagnostic_request_t::get_timeout_clock() return timeout_clock_; } -void active_diagnostic_request_t::set_handle(DiagnosticShims& shims, DiagnosticRequest* request) -{ - handle_ = new DiagnosticRequestHandle(generate_diagnostic_request(&shims, request, nullptr)); -} - -void active_diagnostic_request_t::set_in_flight(bool val) +utils::socketcan_bcm_t& active_diagnostic_request_t::get_socket() { - in_flight_ = val; + return socket_; } -/// -/// @brief Check if requested signal name is a diagnostic message. If the name -/// begin with the diagnostic message prefix then true else false. -/// -/// @param[in] name - A signal name. -/// -/// @return true if name began with the diagnostic message prefix else false. -/// -bool active_diagnostic_request_t::is_diagnostic_signal(const std::string& name) -{ - const std::string p = active_diagnostic_request_t::prefix_ + "*"; - if(::fnmatch(p.c_str(), name.c_str(), FNM_CASEFOLD) == 0) - return true; - return false; -} - -/// @brief Check is the request should be sent or not -/// -/// @return true if the request is not running or recurring nor completed, -/// or it's recurring, its clock elapsed -/// so it's time to send another one. -bool active_diagnostic_request_t::should_send() -{ - return !in_flight_ && ( (!recurring_ && !request_completed()) || - (recurring_ && frequency_clock_.elapsed(true)) ); -} - -/// @brief check if the timeout clock has elapsed -/// -/// @return true if elapsed, so it is a timeout, else false. -bool active_diagnostic_request_t::timed_out() +void active_diagnostic_request_t::set_handle(DiagnosticShims& shims, DiagnosticRequest* request) { - // don't use staggered start with the timeout clock - return timeout_clock_.elapsed(false); + handle_ = new DiagnosticRequestHandle(generate_diagnostic_request(&shims, request, nullptr)); } /// @brief Returns true if a sufficient response has been received for a @@ -182,13 +131,5 @@ bool active_diagnostic_request_t::timed_out() bool active_diagnostic_request_t::response_received() const { return !wait_for_multiple_responses_ && - handle_->completed; -} - -/// @brief Returns true if the request has timed out waiting for a response, -/// or a sufficient number of responses has been received. -bool active_diagnostic_request_t::request_completed() -{ - return response_received() || - (timed_out() && diagnostic_request_sent(handle_)); + handle_->completed && handle_->success; }