Make an extern get_signal_id() function plug to get_pid()
[apps/agl-service-can-low-level.git] / src / diagnostic / diagnostic-message.hpp
1 /*
2  * Copyright (C) 2015, 2016 "IoT.bzh"
3  * Author "Romain Forlot" <romain.forlot@iot.bzh>
4  *
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
8  *
9  *       http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  */
17
18 #pragma once
19
20 #include <vector>
21
22 #include "uds/uds.h"
23 #include "can/can-bus.hpp"
24 #include "can/can-message.hpp"
25
26 #include "low-can-binding.hpp"
27
28 enum UNIT {
29         POURCENT,
30         DEGREES_CELSIUS,
31         KPA,
32         RPM,
33         GRAMS_SEC,
34         SECONDS,
35         KM,
36         KM_H,
37         PA,
38         NM,
39         INVALID
40 };
41
42 /**
43  *      @brief A representation of an OBD-II PID.
44  *
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
49  * unit - unit used
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
53  */
54 typedef struct _Obd2Pid {
55         uint8_t pid;
56         const char* generic_name;
57         const int min;
58         const int max;
59         enum UNIT unit;
60         int frequency;
61         bool supported;
62 } Obd2Pid;
63
64 /**
65  * @brief - Object to handle obd2 session with pre-scan of supported pid
66  * then request them regularly
67  */
68 class obd2_signals_t {
69         private:
70                 uint8_t pid_;
71                 const char* generic_name_;
72                 const int min_;
73                 const int max_;
74                 enum UNIT unit_;
75                 int frequency_;
76                 bool supported_;
77
78         public:
79                 const char* generic_name = generic_name_;
80                 obd2_signals_t(uint8_t pid, const char* generic_name, const int min_, const int max_, enum UNIT unit, int frequency, bool supported);
81
82                 uint32_t get_pid();
83
84                 void add_request(int pid);
85
86                 void find_obd2_signals(const openxc_DynamicField &key, std::vector<obd2_signals_t*>& found_signals);
87
88                 bool is_obd2_response(can_message_t can_message);
89                 bool is_obd2_request(DiagnosticRequest *request);
90                 bool is_obd2_signal(const char *name);
91
92                 float decode_obd2_response(const DiagnosticResponse* response, float parsedPayload);
93 };
94
95 uint32_t get_signal_id(obd2_signals_t& sig);
96 std::vector<obd2_signals_t>& get_obd2_signals();