30e21833760743e61bd86964abf1b82a757d8d5a
[apps/agl-service-can-low-level.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/message-set.hpp"
27 #include "../can/signals.hpp"
28 #include "../diagnostic/diagnostic-manager.hpp"
29 #ifdef USE_FEATURE_J1939
30         #include "../utils/socketcan-j1939/socketcan-j1939-data.hpp"
31         #include "../utils/socketcan-j1939/socketcan-j1939-addressclaiming.hpp"
32 #endif
33
34 ///
35 /// @brief Class represents a configuration attached to the binding.
36 ///
37 /// It regroups all object instances from other classes
38 ///  that will be used through the binding life. It receives a global vision
39 ///  on which signals are implemented for that binding.
40 ///  Here, only the definition of the class is given with predefined accessors
41 ///  methods used in the binding.
42 ///
43 ///  It will be the reference point to needed objects.
44 ///
45 class application_t
46 {
47         private:
48                 can_bus_t can_bus_manager_; ///< instanciate the CAN bus manager. It's responsible of initializing the CAN bus devices.
49                 diagnostic_manager_t diagnostic_manager_; ///< Diagnostic manager use to manage diagnostic message communication.
50                 uint8_t active_message_set_ = 0; ///< Which is the active message set ? Default to 0.
51
52                 std::vector<std::shared_ptr<message_set_t> > message_set_; ///< Vector holding all message set from JSON signals description file
53
54                 std::map<std::string, std::shared_ptr<low_can_subscription_t> > can_devices_; ///< Map containing all independant opened CAN sockets, key is the socket int value.
55 #ifdef USE_FEATURE_J1939
56                 std::shared_ptr<low_can_subscription_t> subscription_address_claiming_; ///< Subscription holding the socketcan J1939 which is in charge of handling the address claiming protocol
57                 //std::shared_ptr<utils::socketcan_j1939_addressclaiming_t> socket_address_claiming_;
58 #endif
59                 application_t(); ///< Private constructor with implementation generated by the AGL generator.
60
61         public:
62                 static application_t& instance();
63
64                 can_bus_t& get_can_bus_manager();
65
66                 std::map<std::string, std::shared_ptr<low_can_subscription_t> >& get_can_devices();
67
68                 const std::string get_diagnostic_bus() const;
69
70                 diagnostic_manager_t& get_diagnostic_manager() ;
71
72                 uint8_t get_active_message_set() const;
73
74                 int add_message_set(std::shared_ptr<message_set_t> new_message_set);
75
76                 std::vector<std::shared_ptr<message_set_t> > get_message_set();
77
78                 vect_ptr_signal_t get_all_signals();
79
80                 vect_ptr_diag_msg_t get_diagnostic_messages();
81
82                 const std::vector<std::string>& get_signals_prefix() const;
83
84                 vect_ptr_msg_def_t get_messages_definition();
85
86                 std::shared_ptr<message_definition_t> get_message_definition(uint32_t id);
87
88                 uint32_t get_signal_id(diagnostic_message_t& sig) const;
89
90                 uint32_t get_signal_id(signal_t& sig) const;
91
92                 bool isEngineOn();
93
94                 void set_active_message_set(uint8_t id);
95
96 #ifdef USE_FEATURE_J1939
97                 std::shared_ptr<utils::socketcan_t> get_socket_address_claiming();
98
99                 std::shared_ptr<low_can_subscription_t> get_subscription_address_claiming();
100
101                 void set_subscription_address_claiming(std::shared_ptr<low_can_subscription_t> new_subscription);
102 #endif
103 /*
104                 /// TODO: implement this function as method into can_bus class
105                 /// @brief Pre initialize actions made before CAN bus initialization
106                 /// @param[in] bus A CanBus struct defining the bus's metadata
107                 /// @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.
108                 /// @param[in] buses An array of all CAN buses.
109                 void pre_initialize(can_bus_dev_t* bus, bool writable, can_bus_dev_t* buses, const int busCount);
110                 /// TODO: implement this function as method into can_bus class
111                 /// @brief Post-initialize actions made after CAN bus initialization
112                 /// @param[in] bus A CanBus struct defining the bus's metadata
113                 /// @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.
114                 /// @param[in] buses An array of all CAN buses.
115                 void post_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 Check if the device is connected to an active CAN bus, i.e. it's received a message in the recent past.
118                 /// @return true if a message was received on the CAN bus within CAN_ACTIVE_TIMEOUT_S seconds.
119                 bool isBusActive(can_bus_dev_t* bus);
120                 */
121 };