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 "can-signals.hpp"
22 #include "../configuration.hpp"
23 #include "../utils/signals.hpp"
24 #include "can-decoder.hpp"
25 #include "../diagnostic/diagnostic-message.hpp"
27 std::string can_signal_t::prefix_ = "messages";
29 can_signal_t::can_signal_t(std::uint8_t message_set_id,
30 std::uint8_t message_id,
31 std::string generic_name,
38 frequency_clock_t frequency,
40 bool force_send_changed,
41 std::map<uint8_t, std::string> states,
43 SignalDecoder decoder,
44 SignalEncoder encoder,
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 }
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}
67 const can_message_definition_t& can_signal_t::get_message() const
69 return configuration_t::instance().get_can_message_definition(message_set_id_, message_id_);
72 const std::string& can_signal_t::get_generic_name() const
77 const std::string can_signal_t::get_name() const
79 return prefix_ + "." + generic_name_;
82 const std::string& can_signal_t::get_prefix() const
87 uint8_t can_signal_t::get_bit_position() const
92 uint8_t can_signal_t::get_bit_size() const
97 float can_signal_t::get_factor() const
102 float can_signal_t::get_offset() const
107 float can_signal_t::get_min_value() const
112 float can_signal_t::get_max_value() const
117 frequency_clock_t& can_signal_t::get_frequency()
122 bool can_signal_t::get_send_same() const
127 bool can_signal_t::get_force_send_changed() const
129 return force_send_changed_;
132 const std::map<uint8_t, std::string>& can_signal_t::get_states() const
137 const std::string can_signal_t::get_states(uint8_t value)
139 if (value < states_.size())
140 return states_[value];
141 return std::string();
144 size_t can_signal_t::get_state_count() const
146 return states_.size();
149 bool can_signal_t::get_writable() const
154 SignalDecoder& can_signal_t::get_decoder()
159 SignalEncoder& can_signal_t::get_encoder()
164 bool can_signal_t::get_received() const
168 float can_signal_t::get_last_value() const
173 void can_signal_t::set_prefix(std::string val)
178 void can_signal_t::set_received(bool r)
183 void can_signal_t::set_last_value(float val)