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.
18 #include "configuration.hpp"
20 #include "utils/signals.hpp"
22 /// @brief Return singleton instance of configuration object.
23 configuration_t& configuration_t::instance()
25 static configuration_t config;
29 can_bus_t& configuration_t::get_can_bus_manager()
31 return can_bus_manager_;
34 const std::map<std::string, std::shared_ptr<can_bus_dev_t>>& configuration_t::get_can_bus_devices()
36 return can_bus_manager_.get_can_devices();
39 diagnostic_manager_t& configuration_t::get_diagnostic_manager()
41 return diagnostic_manager_;
44 uint8_t configuration_t::get_active_message_set() const
46 return active_message_set_;
49 const std::vector<can_message_set_t>& configuration_t::get_can_message_set()
51 return can_message_set_;
54 std::vector<can_signal_t>& configuration_t::get_can_signals()
56 return can_signals_[active_message_set_];
59 std::vector<diagnostic_message_t>& configuration_t::get_diagnostic_messages()
61 return diagnostic_messages_[active_message_set_];
64 const std::vector<can_message_definition_t>& configuration_t::get_can_message_definition()
66 return can_message_definition_[active_message_set_];
69 const can_message_definition_t& configuration_t::get_can_message_definition(std::uint8_t message_set_id, std::uint8_t message_id)
71 return can_message_definition_[message_set_id][message_id];
74 uint32_t configuration_t::get_signal_id(diagnostic_message_t& sig) const
79 uint32_t configuration_t::get_signal_id(can_signal_t& sig) const
81 return sig.get_message().get_id();
84 void configuration_t::set_active_message_set(uint8_t id)
86 active_message_set_ = id;
89 /// @brief return diagnostic messages name found searching through diagnostic messages list.
91 /// @param[in] key - can contain numeric or string value in order to search against
92 /// can signals or obd2 signals name.
93 /// @param[out] found_signals - Vector of signals name found.
95 void configuration_t::find_diagnostic_messages(const openxc_DynamicField &key, std::vector<diagnostic_message_t*>& found_signals)
99 case openxc_DynamicField_Type::openxc_DynamicField_Type_STRING:
100 lookup_signals_by_name(key.string_value, diagnostic_messages_[active_message_set_], found_signals);
102 case openxc_DynamicField_Type::openxc_DynamicField_Type_NUM:
103 lookup_signals_by_id(key.numeric_value, diagnostic_messages_[active_message_set_], found_signals);
106 ERROR(binder_interface, "find_diagnostic_messages: wrong openxc_DynamicField specified. Use openxc_DynamicField_Type_NUM or openxc_DynamicField_Type_STRING type only.");
109 DEBUG(binder_interface, "find_diagnostic_messages: Found %d signal(s)", (int)found_signals.size());
112 /// @brief return signals name found searching through CAN signals list.
114 /// @param[in] key - can contain numeric or string value in order to search against
115 /// can signals or obd2 signals name.
116 /// @param[out] found_signals - provided vector to fill with pointer to matched signals.
118 void configuration_t::find_can_signals(const openxc_DynamicField& key, std::vector<can_signal_t*>& found_signals)
122 case openxc_DynamicField_Type::openxc_DynamicField_Type_STRING:
123 lookup_signals_by_name(std::string(key.string_value), can_signals_[active_message_set_], found_signals);
125 case openxc_DynamicField_Type::openxc_DynamicField_Type_NUM:
126 lookup_signals_by_id(key.numeric_value, can_signals_[active_message_set_], found_signals);
129 ERROR(binder_interface, "find_can_signals: wrong openxc_DynamicField specified. Use openxc_DynamicField_Type_NUM or openxc_DynamicField_Type_STRING type only.");
132 DEBUG(binder_interface, "find_can_signals: Found %d signal(s)", (int)found_signals.size());