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,
52 generic_name_{ generic_name }
53 , bit_position_{ bit_position }
54 , bit_size_{ bit_size }
57 , min_value_{min_value}
58 , max_value_{max_value}
59 , frequency_{frequency}
60 , send_same_{send_same}
61 , force_send_changed_{force_send_changed}
68 , multiplex_{multiplex}
69 , is_big_endian_{is_big_endian}
70 , is_signed_{is_signed}
75 std::string generic_name,
76 uint32_t bit_position,
82 frequency_clock_t frequency,
84 bool force_send_changed,
85 std::map<uint8_t, std::string> states,
87 signal_decoder decoder,
88 signal_encoder encoder,
90 : generic_name_{ generic_name }
91 , bit_position_{ bit_position }
92 , bit_size_{ bit_size }
95 , min_value_{min_value}
96 , max_value_{max_value}
97 , frequency_{frequency}
98 , send_same_{send_same}
99 , force_send_changed_{force_send_changed}
101 , writable_{writable}
104 , received_{received}
107 std::shared_ptr<message_definition_t> signal_t::get_message() const
112 const std::string signal_t::get_generic_name() const
114 return generic_name_;
117 const std::string signal_t::get_name() const
119 return prefix_ + "." + generic_name_;
122 uint32_t signal_t::get_bit_position() const
124 return bit_position_;
127 uint32_t signal_t::get_bit_size() const
132 float signal_t::get_factor() const
137 float signal_t::get_offset() const
142 frequency_clock_t& signal_t::get_frequency()
147 bool signal_t::get_send_same() const
152 const std::string signal_t::get_states(uint8_t value)
154 if ( states_.count(value) > 0 )
155 return states_[value];
156 return std::string();
159 uint64_t signal_t::get_states(const std::string& value) const
162 for( const auto& state: states_)
164 if(caseInsCompare(state.second, value))
166 ret = (uint64_t)state.first;
173 bool signal_t::get_writable() const
178 signal_decoder& signal_t::get_decoder()
183 signal_encoder& signal_t::get_encoder()
188 bool signal_t::get_received() const
193 float signal_t::get_last_value() const
198 std::pair<float, uint64_t> signal_t::get_last_value_with_timestamp() const
200 return std::make_pair(last_value_, frequency_.get_last_tick());
203 void signal_t::set_parent(std::shared_ptr<message_definition_t> parent)
208 void signal_t::set_received(bool r)
213 void signal_t::set_last_value(float val)
218 void signal_t::set_timestamp(uint64_t timestamp)
220 frequency_.tick(timestamp);
223 std::pair<bool, int> signal_t::get_multiplex() const
228 bool signal_t::get_is_big_endian() const
230 return is_big_endian_;
233 bool signal_t::get_is_signed() const
238 const std::string signal_t::get_unit() const