Cleaning CMAke
[apps/low-level-can-service.git] / CAN-binder / low-can-binding / 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
27 std::string can_signal_t::prefix_ = "messages";
28
29 can_signal_t::can_signal_t(std::uint8_t message_set_id,
30         std::uint8_t message_id,
31         std::string generic_name,
32         uint8_t bit_position,
33         uint8_t bit_size,
34         float factor,
35         float offset,
36         float min_value,
37         float max_value,
38         frequency_clock_t frequency,
39         bool send_same,
40         bool force_send_changed,
41         std::map<uint8_t, std::string> states,
42         bool writable,
43         SignalDecoder decoder,
44         SignalEncoder encoder,
45         bool received)
46         : message_set_id_{ message_set_id }
47         , message_id_{ message_id }
48         , generic_name_{ generic_name }
49         , bit_position_{ bit_position }
50         , bit_size_{ bit_size }
51         , factor_{ factor }
52         , offset_{ offset }
53         , min_value_{min_value}
54         , max_value_{max_value}
55         , frequency_{frequency}
56         , send_same_{send_same}
57         , force_send_changed_{force_send_changed}
58         , states_{states}
59         , writable_{writable}
60         , decoder_{decoder}
61         , encoder_{encoder}
62         , received_{received}
63         , last_value_{.0f}
64 {}
65
66
67 const can_message_definition_t& can_signal_t::get_message() const
68 {
69         return configuration_t::instance().get_can_message_definition(message_set_id_, message_id_);
70 }
71
72 const std::string& can_signal_t::get_generic_name() const
73 {
74         return generic_name_;
75 }
76
77 const std::string can_signal_t::get_name() const
78 {
79         return prefix_ + "." + generic_name_;
80 }
81
82 const std::string& can_signal_t::get_prefix() const
83 {
84         return prefix_;
85 }
86
87 uint8_t can_signal_t::get_bit_position() const
88 {
89         return bit_position_;
90 }
91
92 uint8_t can_signal_t::get_bit_size() const
93 {
94         return bit_size_;
95 }
96
97 float can_signal_t::get_factor() const
98 {
99         return factor_;
100 }
101
102 float can_signal_t::get_offset() const
103 {
104         return offset_;
105 }
106
107 float can_signal_t::get_min_value() const
108 {
109         return min_value_;
110 }       
111
112 float can_signal_t::get_max_value() const
113 {
114         return max_value_;
115 }
116
117 frequency_clock_t& can_signal_t::get_frequency()
118 {
119         return frequency_;
120 }
121
122 bool can_signal_t::get_send_same() const
123 {
124         return send_same_;
125 }
126
127 bool can_signal_t::get_force_send_changed() const
128 {
129         return force_send_changed_;
130 }
131
132 const std::map<uint8_t, std::string>& can_signal_t::get_states() const
133 {
134         return states_;
135 }
136
137 const std::string can_signal_t::get_states(uint8_t value)
138 {
139         if (value < states_.size())
140                 return states_[value];
141         return std::string();
142 }
143
144 size_t can_signal_t::get_state_count() const
145 {
146         return states_.size();
147 }
148
149 bool can_signal_t::get_writable() const
150 {
151         return writable_;
152 }
153
154 SignalDecoder& can_signal_t::get_decoder()
155 {
156         return decoder_;
157 }
158
159 SignalEncoder& can_signal_t::get_encoder()
160 {
161         return encoder_;
162 }
163
164 bool can_signal_t::get_received() const
165 {
166         return received_;
167 }
168 float can_signal_t::get_last_value() const
169 {
170         return last_value_;
171 }
172
173 void can_signal_t::set_prefix(std::string val)
174 {
175         prefix_ = val;
176 }
177
178 void can_signal_t::set_received(bool r)
179 {
180         received_ = r;
181 }
182
183 void can_signal_t::set_last_value(float val)
184 {
185         last_value_ = val;
186 }