Implement check of supported diagnostic PID.
[apps/agl-service-can-low-level.git] / src / can / can-signals.cpp
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 #include <fnmatch.h>
19
20 #include "can-signals.hpp"
21
22 #include "../configuration.hpp"
23 #include "../utils/signals.hpp"
24 #include "can-decoder.hpp"
25 #include "../diagnostic/diagnostic-message.hpp"
26 #include "../low-can-binding.hpp"
27
28 std::string can_signal_t::prefix_ = "messages";
29
30 can_signal_t::can_signal_t(can_message_definition_t& message, std::string generic_name, uint8_t bit_position, uint8_t bit_size,
31                          float factor, float offset, float min_value, float max_value, frequency_clock_t frequency, bool send_same, bool force_send_changed,
32                          std::map<uint8_t, std::string> states, bool writable, SignalDecoder decoder, SignalEncoder encoder, bool received)
33         : message_{message}, generic_name_{generic_name}, bit_position_{bit_position}, bit_size_{bit_size}, factor_{factor}, offset_{offset},
34         min_value_{min_value}, max_value_{max_value}, frequency_{frequency}, send_same_{send_same}, force_send_changed_{force_send_changed}, states_{states},
35         writable_{writable}, decoder_{decoder}, encoder_{encoder}, received_{received}, last_value_{(float)NULL}
36 {}
37
38 can_message_definition_t& can_signal_t::get_message()
39 {
40         return message_;
41 }
42
43 const std::string& can_signal_t::get_generic_name() const
44 {
45         return generic_name_;
46 }
47
48 const std::string can_signal_t::get_name() const
49 {
50         return prefix_ + "." + generic_name_;
51 }
52
53 const std::string& can_signal_t::get_prefix() const
54 {
55         return prefix_;
56 }
57
58 uint8_t can_signal_t::get_bit_position() const
59 {
60         return bit_position_;
61 }
62
63 uint8_t can_signal_t::get_bit_size() const
64 {
65         return bit_size_;
66 }
67
68 float can_signal_t::get_factor() const
69 {
70         return factor_;
71 }
72
73 float can_signal_t::get_offset() const
74 {
75         return offset_;
76 }
77
78 float can_signal_t::get_min_value() const
79 {
80         return min_value_;
81 }       
82
83 float can_signal_t::get_max_value() const
84 {
85         return max_value_;
86 }
87
88 frequency_clock_t& can_signal_t::get_frequency()
89 {
90         return frequency_;
91 }
92
93 bool can_signal_t::get_send_same() const
94 {
95         return send_same_;
96 }
97
98 bool can_signal_t::get_force_send_changed() const
99 {
100         return force_send_changed_;
101 }
102
103 const std::map<uint8_t, std::string>& can_signal_t::get_states() const
104 {
105         return states_;
106 }
107
108 const std::string can_signal_t::get_states(uint8_t value)
109 {
110         if (value < states_.size())
111                 return states_[value];
112         return std::string();
113 }
114
115 size_t can_signal_t::get_state_count() const
116 {
117         return states_.size();
118 }
119
120 bool can_signal_t::get_writable() const
121 {
122         return writable_;
123 }
124
125 SignalDecoder& can_signal_t::get_decoder()
126 {
127         return decoder_;
128 }
129
130 SignalEncoder& can_signal_t::get_encoder()
131 {
132         return encoder_;
133 }
134
135 bool can_signal_t::get_received() const
136 {
137         return received_;
138 }
139 float can_signal_t::get_last_value() const
140 {
141         return last_value_;
142 }
143
144 void can_signal_t::set_prefix(std::string val)
145 {
146         prefix_ = val;
147 }
148
149 void can_signal_t::set_received(bool r)
150 {
151         received_ = r;
152 }
153
154 void can_signal_t::set_last_value(float val)
155 {
156         last_value_ = val;
157 }