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 "signals.hpp"
21 /// @brief Can signal event map making access to afb_event
22 /// externaly to an openxc existing structure.
24 /// Event map is making relation between can_signal_t generic name
25 /// and the afb_event struct used by application framework to pushed
26 /// to the subscriber.
28 std::map<std::string, struct afb_event> subscribed_signals;
31 /// @brief Mutex allowing safe manipulation on subscribed_signals map.
32 /// To ensure that the map object isn't modified when we read it, you
33 /// have to set this mutex before use subscribed_signals map object.
35 std::mutex subscribed_signals_mutex;
37 std::mutex& get_subscribed_signals_mutex()
39 return subscribed_signals_mutex;
42 std::map<std::string, struct afb_event>& get_subscribed_signals()
44 return subscribed_signals;
48 /// @fn std::vector<std::string> find_signals(const openxc_DynamicField &key)
49 /// @brief return signals name found searching through CAN_signals and OBD2 pid
51 /// @param[in] key : can contain numeric or string value in order to search against
52 /// can signals or obd2 signals name.
54 /// @return Vector of signals name found.
56 std::vector<std::string> find_signals(const openxc_DynamicField &key)
58 std::vector<std::string> found_signals_name;
62 case openxc_DynamicField_Type::openxc_DynamicField_Type_STRING:
63 lookup_signals_by_name(key.string_value, configuration_t::instance().get_can_signals(), found_signals_name);
64 lookup_signals_by_name(key.string_value, configuration_t::instance().get_diagnostic_messages(), found_signals_name);
66 case openxc_DynamicField_Type::openxc_DynamicField_Type_NUM:
67 lookup_signals_by_id(key.numeric_value, configuration_t::instance().get_can_signals(), found_signals_name);
68 lookup_signals_by_id(key.numeric_value, configuration_t::instance().get_diagnostic_messages(), found_signals_name);
71 ERROR(binder_interface, "find_signals: wrong openxc_DynamicField specified. Use openxc_DynamicField_Type_NUM or openxc_DynamicField_Type_STRING type only.");
74 DEBUG(binder_interface, "find_signals: Found %d signal(s)", (int)found_signals_name.size());
75 return found_signals_name;