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.
23 #include "can-bus.hpp"
24 #include "can-message.hpp"
26 #include "low-can-binding.hpp"
43 * @brief A representation of an OBD-II PID.
45 * pid - The 1 byte PID.
46 * name - A human readable name to use for this PID when published.
47 * min - minimum value for this pid
48 * max - maximum value for this pid
50 * frequency - The frequency to request this PID if supported by the vehicle
51 * when automatic, recurring OBD-II requests are enabled.
52 * supported - is it supported by the vehicle. Initialized after scan
54 typedef struct _Obd2Pid {
56 const char* generic_name;
64 std::vector<Obd2Pid>& get_obd2_signals();
65 uint32_t get_signal_id(const Obd2Pid& sig);
66 void find_obd2_signals(const openxc_DynamicField &key, std::vector<Obd2Pid*>& found_signals);
68 bool is_obd2_response(can_message_t can_message);
71 * @brief - Object to handle obd2 session with pre-scan of supported pid
72 * then request them regularly
74 class obd2_handler_t {
84 void find_obd2_pid(const char *name, std::vector<Obd2Pid> *pids);
87 * @brief Check if a request is an OBD-II PID request.
89 * @return true if the request is a mode 1 request and it has a 1 byte PID.
91 bool is_obd2_request(DiagnosticRequest *request);
94 * @brief Check if requested signal name is an obd2 pid
96 * @return true if name began with obd2 else false.
98 bool is_obd2_signal(const char *name);
101 * @brief Decode the payload of an OBD-II PID.
103 * This function matches the type signature for a DiagnosticResponseDecoder, so
104 * it can be used as the decoder for a DiagnosticRequest. It returns the decoded
105 * value of the PID, using the standard formulas (see
106 * http://en.wikipedia.org/wiki/OBD-II_PIDs#Mode_01).
108 * @param[in] DiagnosticResponse response - the received DiagnosticResponse (the data is in response.payload,
109 * a byte array). This is most often used when the byte order is
110 * signiticant, i.e. with many OBD-II PID formulas.
111 * @param[in] float parsed_payload - the entire payload of the response parsed as an int.
113 float handle_obd2_pid(const DiagnosticResponse* response, float parsedPayload);