c75a178c842f6b3ecbc9f8e2ae3cd5f34ac1418f
[apps/low-level-can-service.git] / low-can-binding / binding / application.hpp
1 /*
2  * Copyright (C) 2015, 2016 "IoT.bzh"
3  * Author "Romain Forlot" <romain.forlot@iot.bzh>
4  *
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
8  *
9  *       http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  */
17
18 #pragma once
19
20 #include <map>
21 #include <vector>
22 #include <string>
23 #include <memory>
24
25 #include "../can/can-bus.hpp"
26 #include "../can/can-message-set.hpp"
27 #include "../can/can-signals.hpp"
28 #include "../diagnostic/diagnostic-manager.hpp"
29
30 ///
31 /// @brief Class representing a configuration attached to the binding.
32 ///
33 /// 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.
38 ///
39 ///  It will be the reference point to needed objects.
40 ///
41 class application_t
42 {
43         private:
44                 can_bus_t can_bus_manager_; ///< instanciate the CAN bus manager. It's the one in charge of initialize the CAN bus devices.
45                 diagnostic_manager_t diagnostic_manager_; ///< Diagnostic manager use to manage diagnostic message communication.
46                 uint8_t active_message_set_ = 0; ///< Which is the active message set ? Default to 0.
47
48                 std::vector<std::shared_ptr<can_message_set_t> > can_message_set_; ///< Vector holding all message set from JSON signals description file
49
50                 std::map<std::string, std::shared_ptr<low_can_socket_t> > can_devices_; ///< Map containing all independant opened CAN sockets, key is the socket int value.
51
52                 application_t(); ///< Private constructor with implementation generated by the AGL generator.
53
54         public:
55                 static application_t& instance();
56
57                 can_bus_t& get_can_bus_manager();
58
59                 std::map<std::string, std::shared_ptr<low_can_socket_t> >& get_can_devices();
60
61                 const std::string get_diagnostic_bus() const;
62
63                 diagnostic_manager_t& get_diagnostic_manager() ;
64
65                 uint8_t get_active_message_set() const;
66
67                 std::vector<std::shared_ptr<can_message_set_t> > get_can_message_set();
68
69                 std::vector<std::shared_ptr<can_signal_t> > get_all_can_signals();
70
71                 std::vector<std::shared_ptr<diagnostic_message_t> >& get_diagnostic_messages();
72
73                 const std::vector<std::string>& get_signals_prefix() const;
74
75                 std::vector<std::shared_ptr<can_message_definition_t> >& get_can_message_definition();
76
77                 uint32_t get_signal_id(diagnostic_message_t& sig) const;
78
79                 uint32_t get_signal_id(can_signal_t& sig) const;
80
81                 void set_active_message_set(uint8_t id);
82
83 /*
84                 /// TODO: implement this function as method into can_bus class
85                 /// @brief Pre initialize actions made before CAN bus initialization
86                 /// @param[in] bus A CanBus struct defining the bus's metadata
87                 /// @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.
88                 /// @param[in] buses An array of all CAN buses.
89                 void pre_initialize(can_bus_dev_t* bus, bool writable, can_bus_dev_t* buses, const int busCount);
90                 /// TODO: implement this function as method into can_bus class
91                 /// @brief Post-initialize actions made after CAN bus initialization
92                 /// @param[in] bus A CanBus struct defining the bus's metadata
93                 /// @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.
94                 /// @param[in] buses An array of all CAN buses.
95                 void post_initialize(can_bus_dev_t* bus, bool writable, can_bus_dev_t* buses, const int busCount);
96                 /// TODO: implement this function as method into can_bus class
97                 /// @brief Check if the device is connected to an active CAN bus, i.e. it's received a message in the recent past.
98                 /// @return true if a message was received on the CAN bus within CAN_ACTIVE_TIMEOUT_S seconds.
99                 void logBusStatistics(can_bus_dev_t* buses, const int busCount);
100                 /// TODO: implement this function as method into can_bus class
101                 /// @brief Log transfer statistics about all active CAN buses to the debug log.
102                 /// @param[in] buses An array of active CAN buses.
103                 bool isBusActive(can_bus_dev_t* bus);
104                 */
105 };
106