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"
21 #include "utils/openxc-utils.hpp"
23 /// @brief Return singleton instance of configuration object.
24 configuration_t& configuration_t::instance()
26 static configuration_t config;
30 can_bus_t& configuration_t::get_can_bus_manager()
32 return can_bus_manager_;
35 const std::map<std::string, std::shared_ptr<can_bus_dev_t>>& configuration_t::get_can_bus_devices()
37 return can_bus_manager_.get_can_devices();
40 diagnostic_manager_t& configuration_t::get_diagnostic_manager()
42 return diagnostic_manager_;
45 uint8_t configuration_t::get_active_message_set() const
47 return active_message_set_;
50 const std::vector<can_message_set_t>& configuration_t::get_can_message_set()
52 return can_message_set_;
55 std::vector<can_signal_t>& configuration_t::get_can_signals()
57 return can_signals_[active_message_set_];
60 std::vector<diagnostic_message_t>& configuration_t::get_diagnostic_messages()
62 return diagnostic_messages_[active_message_set_];
65 const std::vector<can_message_definition_t>& configuration_t::get_can_message_definition()
67 return can_message_definition_[active_message_set_];
70 const can_message_definition_t& configuration_t::get_can_message_definition(std::uint8_t message_set_id, std::uint8_t message_id)
72 return can_message_definition_[message_set_id][message_id];
75 uint32_t configuration_t::get_signal_id(diagnostic_message_t& sig) const
80 uint32_t configuration_t::get_signal_id(can_signal_t& sig) const
82 return sig.get_message().get_id();
85 void configuration_t::set_active_message_set(uint8_t id)
87 active_message_set_ = id;
90 /// @brief return diagnostic messages name found searching through diagnostic messages list.
92 /// @param[in] key - can contain numeric or string value in order to search against
93 /// can signals or obd2 signals name.
94 /// @param[out] found_signals - Vector of signals name found.
96 void configuration_t::find_diagnostic_messages(const openxc_DynamicField &key, std::vector<diagnostic_message_t*>& found_signals)
100 case openxc_DynamicField_Type::openxc_DynamicField_Type_STRING:
101 lookup_signals_by_name(key.string_value, diagnostic_messages_[active_message_set_], found_signals);
103 case openxc_DynamicField_Type::openxc_DynamicField_Type_NUM:
104 lookup_signals_by_id(key.numeric_value, diagnostic_messages_[active_message_set_], found_signals);
107 ERROR(binder_interface, "find_diagnostic_messages: wrong openxc_DynamicField specified. Use openxc_DynamicField_Type_NUM or openxc_DynamicField_Type_STRING type only.");
110 DEBUG(binder_interface, "find_diagnostic_messages: Found %d signal(s)", (int)found_signals.size());
113 diagnostic_message_t* configuration_t::get_diagnostic_message(std::string message_name) const
115 std::vector<diagnostic_message_t*> found;
116 configuration_t::instance().find_diagnostic_messages(build_DynamicField(message_name), found);
117 return found.front();
120 DiagnosticRequest* configuration_t::get_request_from_diagnostic_message(diagnostic_message_t* diag_msg) const
122 return new DiagnosticRequest(diag_msg->build_diagnostic_request());
125 DiagnosticRequest* configuration_t::get_request_from_diagnostic_message(std::string message_name) const
127 return new DiagnosticRequest(get_diagnostic_message(message_name)->build_diagnostic_request());
130 /// @brief return signals name found searching through CAN signals list.
132 /// @param[in] key - can contain numeric or string value in order to search against
133 /// can signals or obd2 signals name.
134 /// @param[out] found_signals - provided vector to fill with pointer to matched signals.
136 void configuration_t::find_can_signals(const openxc_DynamicField& key, std::vector<can_signal_t*>& found_signals)
140 case openxc_DynamicField_Type::openxc_DynamicField_Type_STRING:
141 lookup_signals_by_name(std::string(key.string_value), can_signals_[active_message_set_], found_signals);
143 case openxc_DynamicField_Type::openxc_DynamicField_Type_NUM:
144 lookup_signals_by_id(key.numeric_value, can_signals_[active_message_set_], found_signals);
147 ERROR(binder_interface, "find_can_signals: wrong openxc_DynamicField specified. Use openxc_DynamicField_Type_NUM or openxc_DynamicField_Type_STRING type only.");
150 DEBUG(binder_interface, "find_can_signals: Found %d signal(s)", (int)found_signals.size());