2 * Copyright (C) 2015, 2016 "IoT.bzh"
3 * Author "Romain Forlot" <romain.forlot@iot.bzh>
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
22 #include "active-diagnostic-request.hpp"
24 #include "../binding/application.hpp"
26 #define AFB_ERROR_PID 0xFF
28 std::string active_diagnostic_request_t::prefix_ = "diagnostic_messages";
30 active_diagnostic_request_t::active_diagnostic_request_t(const std::string& bus, uint32_t id,
31 const std::string& name,
32 bool wait_for_multiple_responses,
33 const DiagnosticResponseDecoder decoder,
34 const DiagnosticResponseCallback callback,
43 recurring_{frequencyHz ? true : false},
44 permanent_{permanent},
45 wait_for_multiple_responses_{wait_for_multiple_responses},
46 frequency_clock_{frequency_clock_t(frequencyHz)},
47 timeout_clock_{frequency_clock_t(10)},
51 active_diagnostic_request_t::~active_diagnostic_request_t()
58 uint32_t active_diagnostic_request_t::get_id() const
63 uint16_t active_diagnostic_request_t::get_pid() const
65 if (handle_->request.has_pid)
66 return handle_->request.pid;
70 DiagnosticRequestHandle* active_diagnostic_request_t::get_handle()
75 const std::string active_diagnostic_request_t::get_name() const
80 std::string& active_diagnostic_request_t::get_prefix()
82 return active_diagnostic_request_t::prefix_;
85 DiagnosticResponseDecoder& active_diagnostic_request_t::get_decoder()
90 DiagnosticResponseCallback& active_diagnostic_request_t::get_callback()
95 bool active_diagnostic_request_t::get_recurring() const
100 bool active_diagnostic_request_t::get_permanent() const
105 frequency_clock_t& active_diagnostic_request_t::get_frequency_clock()
107 return frequency_clock_;
110 frequency_clock_t& active_diagnostic_request_t::get_timeout_clock()
112 return timeout_clock_;
115 utils::socketcan_bcm_t& active_diagnostic_request_t::get_socket()
120 void active_diagnostic_request_t::set_handle(DiagnosticShims& shims, DiagnosticRequest* request)
122 handle_ = new DiagnosticRequestHandle(generate_diagnostic_request(&shims, request, nullptr));
125 /// @brief Returns true if a sufficient response has been received for a
126 /// diagnostic request.
128 /// This is true when at least one response has been received and the request is
129 /// configured to not wait for multiple responses. Functional broadcast requests
130 /// may often wish to wait the full 100ms for modules to respond.
131 bool active_diagnostic_request_t::response_received() const
133 return !wait_for_multiple_responses_ &&
134 handle_->completed && handle_->success;