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 "../binding/application.hpp"
23 #include "../utils/signals.hpp"
24 #include "can-decoder.hpp"
25 #include "message/can-message.hpp"
26 #include "can-bus.hpp"
27 #include "../diagnostic/diagnostic-message.hpp"
28 #include "canutil/write.h"
30 std::string can_signal_t::prefix_ = "messages";
32 can_signal_t::can_signal_t(
33 std::string generic_name,
40 frequency_clock_t frequency,
42 bool force_send_changed,
43 std::map<uint8_t, std::string> states,
45 signal_decoder decoder,
46 signal_encoder encoder,
49 generic_name_{ generic_name }
50 , bit_position_{ bit_position }
51 , bit_size_{ bit_size }
54 , min_value_{min_value}
55 , max_value_{max_value}
56 , frequency_{frequency}
57 , send_same_{send_same}
58 , force_send_changed_{force_send_changed}
67 can_message_definition_t* can_signal_t::get_message() const
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 uint8_t can_signal_t::get_bit_position() const
87 uint8_t can_signal_t::get_bit_size() const
92 float can_signal_t::get_factor() const
97 float can_signal_t::get_offset() const
102 frequency_clock_t& can_signal_t::get_frequency()
107 bool can_signal_t::get_send_same() const
112 const std::string can_signal_t::get_states(uint8_t value)
114 if ( states_.count(value) > 0 )
115 return states_[value];
116 return std::string();
119 uint64_t can_signal_t::get_states(const std::string& value) const
122 for( const auto& state: states_)
124 if(state.second == value)
126 ret = (uint64_t)state.first;
133 bool can_signal_t::get_writable() const
138 signal_decoder& can_signal_t::get_decoder()
143 signal_encoder& can_signal_t::get_encoder()
148 bool can_signal_t::get_received() const
153 float can_signal_t::get_last_value() const
158 std::pair<float, uint64_t> can_signal_t::get_last_value_with_timestamp() const
160 return std::make_pair(last_value_, frequency_.get_last_tick());
163 void can_signal_t::set_parent(can_message_definition_t* parent)
168 void can_signal_t::set_received(bool r)
173 void can_signal_t::set_last_value(float val)
178 void can_signal_t::set_timestamp(uint64_t timestamp)
180 frequency_.tick(timestamp);