summaryrefslogtreecommitdiffstats
path: root/src/diagnostic/active-diagnostic-request.hpp
blob: f18282f60e255d55e8fcc890e32bff07353730cf (plain)
1
2

@media only all and (prefers-color-scheme: dark) {
.highlight .hll { background-color: #49483e }
.highlight .c { color: #75715e } /* Comment */
.highlight .err { color: #960050; background-color: #1e0010 } /* Error */
.highlight .k { color: #66d9ef } /* Keyword */
.highlight .l { color: #ae81ff } /* Literal */
.highlight .n { color: #f8f8f2 } /* Name */
.highlight .o { color: #f92672 } /* Operator */
.highlight .p { color: #f8f8f2 } /* Punctuation */
.highlight .ch { color: #75715e } /* Comment.Hashbang */
.highlight .cm { color: #75715e } /* Comment.Multiline */
.highlight .cp { color: #75715e } /* Comment.Preproc */
.highlight .cpf { color: #75715e } /* Comment.PreprocFile */
.highlight .c1 { color: #75715e } /* Comment.Single */
.highlight .cs { color: #75715e } /* Comment.Special */
.highlight .gd { color: #f92672 } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gi { color: #a6e22e } /* Generic.Inserted */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #75715e } /* Generic.Subheading */
.highlight .kc { color: #66d9ef } /* Keyword.Constant */
.highlight .kd { color: #66d9ef } /* Keyword.Declaration */
.highlight .kn { color: #f92672 } /* Keyword.Namespace */
.highlight .kp { color: #66d9ef } /* Keyword.Pseudo */
.highlight .kr { color: #66d9ef } /* Keyword.Reserved */
.highlight .kt { color: #66d9ef } /* Keyword.Type */
.highlight .ld { color: #e6db74 } /* Literal.Date */
.highlight .m { color: #ae81ff } /* Literal.Number */
.highlight .s { color: #e6db74 } /* Literal.String */
.highlight .na { color: #a6e22e } /* Name.Attribute */
.highlight .nb { color: #f8f8f2 } /* Name.Builtin */
.highlight .nc { color: #a6e22e } /* Name.Class */
.highlight .no { color: #66d9ef } /* Name.Constant */
.highlight .nd { color: #a6e22e } /* Name.Decorator */
.highlight .ni { color: #f8f8f2 } /* Name.Entity */
.highlight .ne { color: #a6e22e } /* Name.Exception */
.highlight .nf { color: #a6e22e } /* Name.Function */
.highlight .nl { color: #f8f8f2 } /* Name.Label */
.highlight .nn { color: #f8f8f2 } /* Name.Namespace */
.highlight .nx { color: #a6e22e } /* Name.Other */
.highlight .py { color: #f8f8f2 } /* Name.Property */
.highlight .nt { color: #f92672 } /* Name.Tag */
.highlight .nv { color: #f8f8f2 } /* Name.Variable */
.highlight .ow { color: #f92672 } /* Operator.Word */
.highlight .w { color: #f8f8f2 } /* Text.Whitespace */
.highlight .mb { color: #ae81ff } /* Literal.Number.Bin */
.highlight .mf { color: #ae81ff } /* Literal.Number.Float */
.highlight .mh { color: #ae81ff } /* Literal.Number.Hex */
.highlight .mi { color: #ae81ff } /* Literal.Number.Integer */
.highlight .mo { color: #ae81ff } /* Literal.Number.Oct */
.highlight .sa { color: #e6db74 } /* Literal.String.Affix */
.highlight .sb { color: #e6db74 } /* Literal.String.Backtick */
.highlight .sc { color: #e6db74 } /* Literal.String.Char */
.highlight .dl { color: #e6db74 } /* Literal.String.Delimiter */
.highlight .sd { color: #e6db74 } /* Literal.String.Doc */
.highlight .s2 { color: #e6db74 } /* Literal.String.Double */
.highlight .se { color: #ae81ff } /* Literal.String.Escape */
.highlight .sh { color: #e6db74 } /* Literal.String.Heredoc */
.highlight .si { color: #e6db74 } /* Literal.String.Interpol */
.highlight .sx { color: #e6db74 } /* Literal.String.Other */
.highlight .sr { color: #e6db74 } /* Literal.String.Regex */
.highlight .s1 { color: #e6db74 } /* Literal.String.Single */
.highlight .ss { color: #e6db74 }
/*
 * 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.
 */

#pragma once

#include <vector>

#include "uds/uds.h"
#include "uds/uds_types.h"
#include "../can/can-bus-dev.hpp"
#include "../can/can-message.hpp"

#include "../low-can-binding.hpp"

class active_diagnostic_request_t;
class diagnostic_manager_t;

/* Public: The signature for an optional function that can apply the neccessary
 * formula to translate the binary payload into meaningful data.
 *
 * response - the received DiagnosticResponse (the data is in response.payload,
 *      a byte array). This is most often used when the byte order is
 *      signiticant, i.e. with many OBD-II PID formulas.
 * parsed_payload - the entire payload of the response parsed as an int.
 */
typedef float (*DiagnosticResponseDecoder)(const DiagnosticResponse* response,
		float parsed_payload);

/* Public: The signature for an optional function to handle a new diagnostic
 * response.
 *
 * manager - The DiagnosticsManager providing this response.
 * request - The original diagnostic request.
 * response - The response object that was just received.
 * parsed_payload - The payload of the response, parsed as a float.
 */
typedef void (*DiagnosticResponseCallback)(const active_diagnostic_request_t* request,
		const DiagnosticResponse* response, float parsed_payload);

/**
 * @brief An active diagnostic request, either recurring or one-time.
 */
class active_diagnostic_request_t {
private:
	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.*/
	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.*/
	static std::string prefix_; /*!< prefix_ - generic_name_ will be prefixed with it. It has to reflect the used protocol.
								 * which make easier to sort message when the come in.*/
	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:
	bool operator==(const active_diagnostic_request_t& b);
	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(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);
	
	uint32_t get_id() const;
	std::shared_ptr<can_bus_dev_t> get_can_bus_dev();
	DiagnosticRequestHandle* get_handle();
	const std::string get_name() const;
	static std::string& get_prefix();
	DiagnosticResponseDecoder& get_decoder();
	DiagnosticResponseCallback& get_callback();
	bool get_recurring() const;
	bool get_in_flight() const;
	frequency_clock_t& get_frequency_clock();
	frequency_clock_t& get_timeout_clock();
	
	void set_handle(DiagnosticShims& shims, DiagnosticRequest* request);
	void set_in_flight(bool val);

	static bool is_diagnostic_signal(const std::string& name);

	bool should_send();

	bool timed_out();
	bool response_received() const;
	bool request_completed();
};