Change the way to check signal type making prefix_
[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 class obd2_signal_t {
46         private:
47                 uint8_t pid_; /*!< pid - The 1 byte PID.*/
48                 std::string generic_name_; /*!< generic_name_ - A human readable name to use for this PID when published.*/
49                 static std::string prefix_; /*!< prefix_ - generic_name_ will be prefixed with it. It has to reflect the used protocol.
50                                                   * which make easier to sort message when the come in.*/
51                 int min_; /*!< min_ - Minimum value that can take this pid */
52                 int max_; /*!< max_ - Maximum value that can take this pid */
53                 enum UNIT unit_; /*!< unit_ : Which unit system is used by that pid. See enum UNIT above.*/
54                 int frequency_; /*!< frequency - The frequency to request this PID if supported by the vehicle when automatic, recurring OBD-II requests are enabled.*/
55                 bool supported_; /*!< supported_ - boolean indicating whether this pid is supported by the vehicle or not.*/
56
57         public:
58                 const char* generic_name = generic_name_.c_str();
59                 obd2_signal_t(uint8_t pid, const char* generic_name, const int min_, const int max_, enum UNIT unit, int frequency, bool supported);
60
61                 uint32_t get_pid();
62                 const std::string& get_generic_name() const;
63                 const std::string get_name() const;
64                 static const std::string& get_prefix();
65                 int get_frequency() const;
66
67                 static void set_prefix(const std::string& val);
68
69                 const DiagnosticRequest build_diagnostic_request();
70
71                 bool is_obd2_response(can_message_t can_message);
72                 bool is_obd2_request(DiagnosticRequest *request);
73                 static bool is_obd2_signal(const std::string& name);
74
75                 static float decode_obd2_response(const DiagnosticResponse* response, float parsedPayload);
76 };