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.
23 #include "can/can-bus.hpp"
24 #include "can/can-signals.hpp"
25 #include "can/can-message.hpp"
26 #include "obd2/diagnostic-manager.hpp"
28 #include "low-can-binding.hpp"
31 * @brief Class representing a configuration attached to the binding.
33 * @desc It regroups all needed objects instance from other class
34 * that will be used along the binding life. It gets a global vision
35 * on which signals are implemented for that binding.
36 * Here, it is only the definition of the class with predefined accessors
37 * methods used in the binding.
39 * It will be the reference point to needed objects.
44 can_bus_t can_bus_manager_ = can_bus_t(afb_daemon_rootdir_open_locale(binder_interface->daemon, "can_buses.json", O_RDONLY, NULL));
45 diagnostic_manager_t diagnostic_manager_;
46 uint8_t active_message_set_ = 0;
49 const std::vector<obd2_signal_t> obd2_signals_;
50 const std::vector<can_message_set_t> can_message_set_;
51 const std::vector<std::vector<can_signal_t>> can_signals_;
52 const std::vector<std::vector<can_message_definition_t>> can_message_definition_;
54 configuration_t& get_configuration()
59 can_bus_t& get_can_bus_manager()
61 return can_bus_manager_;
64 diagnostic_manager_t& get_diagnostic_manager()
66 return diagnostic_manager_;
69 uint8_t get_active_message_set()
71 return active_message_set_;
74 const std::vector<can_message_set_t>& get_can_message_set()
76 return can_message_set_;
79 const std::vector<can_signal_t>& get_can_signals()
81 return can_signals_[active_message_set_];
84 const std::vector<can_message_definition_t>& get_can_message_definition()
86 return can_message_definition_[active_message_set_];
89 const std::vector<obd2_signal_t>& get_obd2_signals()
94 uint32_t get_signal_id(obd2_signal_t& sig)
99 uint32_t get_signal_id(can_signal_t& sig)
101 return sig.get_message()->id;
104 void set_active_message_set(uint8_t id)
106 active_message_set_ = id;
109 /// TODO: implement this function as method into can_bus class
110 /// @brief Pre initialize actions made before CAN bus initialization
111 /// @param[in] bus A CanBus struct defining the bus's metadata
112 /// @param[in] writable Configure the controller in a writable mode. If false, it will be configured as "listen only" and will not allow writes or even CAN ACKs.
113 /// @param[in] buses An array of all CAN buses.
114 /// @param[in] busCount The length of the buses array.
115 void pre_initialize(can_bus_dev_t* bus, bool writable, can_bus_dev_t* buses, const int busCount);
116 /// TODO: implement this function as method into can_bus class
117 /// @brief Post-initialize actions made after CAN bus initialization
118 /// @param[in] bus A CanBus struct defining the bus's metadata
119 /// @param[in] writable Configure the controller in a writable mode. If false, it will be configured as "listen only" and will not allow writes or even CAN ACKs.
120 /// @param[in] buses An array of all CAN buses.
121 /// @param[in] busCount The length of the buses array.
122 void post_initialize(can_bus_dev_t* bus, bool writable, can_bus_dev_t* buses, const int busCount);
123 /// TODO: implement this function as method into can_bus class
124 /// @brief Check if the device is connected to an active CAN bus, i.e. it's received a message in the recent past.
125 /// @return true if a message was received on the CAN bus within CAN_ACTIVE_TIMEOUT_S seconds.
126 void logBusStatistics(can_bus_dev_t* buses, const int busCount);
127 /// TODO: implement this function as method into can_bus class
128 /// @brief Log transfer statistics about all active CAN buses to the debug log.
129 /// @param[in] buses An array of active CAN buses.
130 /// @param[in] busCount The length of the buses array.
131 bool isBusActive(can_bus_dev_t* bus);