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.
20 #include "signals.hpp"
22 #include "../binding/application.hpp"
23 #include "../utils/signals.hpp"
24 #include "can-decoder.hpp"
25 #include "can-bus.hpp"
26 #include "../diagnostic/diagnostic-message.hpp"
27 #include "canutil/write.h"
29 std::string signal_t::prefix_ = "messages";
32 std::string generic_name,
33 uint32_t bit_position,
39 frequency_clock_t frequency,
41 bool force_send_changed,
42 std::map<uint8_t, std::string> states,
44 signal_decoder decoder,
45 signal_encoder encoder,
47 std::pair<bool, int> multiplex,
50 int32_t bit_sign_position,
53 generic_name_{ generic_name }
54 , bit_position_{ bit_position }
55 , bit_size_{ bit_size }
58 , min_value_{min_value}
59 , max_value_{max_value}
60 , frequency_{frequency}
61 , send_same_{send_same}
62 , force_send_changed_{force_send_changed}
69 , multiplex_{multiplex}
70 , is_big_endian_{is_big_endian}
72 , bit_sign_position_{bit_sign_position}
77 std::string generic_name,
78 uint32_t bit_position,
84 frequency_clock_t frequency,
86 bool force_send_changed,
87 std::map<uint8_t, std::string> states,
89 signal_decoder decoder,
90 signal_encoder encoder,
92 : generic_name_{ generic_name }
93 , bit_position_{ bit_position }
94 , bit_size_{ bit_size }
97 , min_value_{min_value}
98 , max_value_{max_value}
99 , frequency_{frequency}
100 , send_same_{send_same}
101 , force_send_changed_{force_send_changed}
103 , writable_{writable}
106 , received_{received}
109 std::shared_ptr<message_definition_t> signal_t::get_message() const
114 const std::string signal_t::get_generic_name() const
116 return generic_name_;
119 const std::string signal_t::get_name() const
121 return prefix_ + "." + generic_name_;
124 uint32_t signal_t::get_bit_position() const
126 return bit_position_;
129 uint32_t signal_t::get_bit_size() const
134 float signal_t::get_factor() const
139 float signal_t::get_offset() const
144 frequency_clock_t& signal_t::get_frequency()
149 bool signal_t::get_send_same() const
154 const std::string signal_t::get_states(uint8_t value)
156 if ( states_.count(value) > 0 )
157 return states_[value];
158 return std::string();
161 uint64_t signal_t::get_states(const std::string& value) const
164 for( const auto& state: states_)
166 if(caseInsCompare(state.second, value))
168 ret = (uint64_t)state.first;
175 bool signal_t::get_writable() const
180 signal_decoder& signal_t::get_decoder()
185 signal_encoder& signal_t::get_encoder()
190 bool signal_t::get_received() const
195 float signal_t::get_last_value() const
200 std::pair<float, uint64_t> signal_t::get_last_value_with_timestamp() const
202 return std::make_pair(last_value_, frequency_.get_last_tick());
205 void signal_t::set_parent(std::shared_ptr<message_definition_t> parent)
210 void signal_t::set_received(bool r)
215 void signal_t::set_last_value(float val)
220 void signal_t::set_timestamp(uint64_t timestamp)
222 frequency_.tick(timestamp);
225 void signal_t::set_bit_position(uint32_t bit_position)
227 bit_position_=bit_position;
230 std::pair<bool,int> signal_t::get_multiplex() const
235 bool signal_t::get_is_big_endian() const
237 return is_big_endian_;
240 sign_t signal_t::get_sign() const
245 int32_t signal_t::get_bit_sign_position() const
247 return bit_sign_position_;
250 const std::string signal_t::get_unit() const