Follow the moving binding and configuration files.
[apps/low-level-can-service.git] / CAN-binder / low-can-binding / binding / configuration.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 <fcntl.h>
24
25 #include "../can/can-bus.hpp"
26 #include "../can/can-signals.hpp"
27 #include "../can/can-message.hpp"
28 #include "../diagnostic/diagnostic-manager.hpp"
29
30 #include "low-can-binding.hpp"
31
32 ///
33 /// @brief Class representing a configuration attached to the binding.
34 ///
35 /// It regroups all needed objects instance from other class
36 ///  that will be used along the binding life. It gets a global vision 
37 ///  on which signals are implemented for that binding. 
38 ///  Here, it is only the definition of the class with predefined accessors
39 ///  methods used in the binding.
40 ///
41 ///  It will be the reference point to needed objects.
42 ///
43 class configuration_t
44 {
45         private:
46                 can_bus_t can_bus_manager_; ///< instanciate the CAN bus manager. It's the one in charge of initialize the CAN bus devices.
47                 diagnostic_manager_t diagnostic_manager_; ///< Diagnostic manager use to manage diagnostic message communication.
48                 uint8_t active_message_set_ = 0; ///< Which is the active message set ? Default to 0.
49
50                 std::vector<can_message_set_t> can_message_set_; ///< Vector holding all message set from JSON signals description file
51                 std::vector<std::vector<can_message_definition_t>> can_message_definition_; ///< Vector of vector holding all can message definition from JSON signals description file. This describe a CAN message. First vector map to message set
52                 std::vector<std::vector<can_signal_t>> can_signals_; ///< Vector of vector holding all can signasl from JSON signals description file. A CAN signal is a part of a CAN message.  First vector map to message set
53                 std::vector<std::vector<diagnostic_message_t>> diagnostic_messages_; ///< Vector of vector holding all diagnostics messages from JSON signals description file. First vector map to message set
54
55                 configuration_t(); ///< Private constructor with implementation generated by the AGL generator.
56
57         public:
58                 static configuration_t& instance();
59
60                 can_bus_t& get_can_bus_manager();
61
62                 const std::map<std::string, std::shared_ptr<can_bus_dev_t>>& get_can_bus_devices();
63
64                 const std::string get_diagnostic_bus() const;
65
66                 diagnostic_manager_t& get_diagnostic_manager() ;
67
68                 uint8_t get_active_message_set() const;
69
70                 const std::vector<can_message_set_t>& get_can_message_set();
71
72                 std::vector<can_signal_t>& get_can_signals();
73
74                 std::vector<diagnostic_message_t>& get_diagnostic_messages();
75
76                 const std::vector<std::string>& get_signals_prefix() const;
77
78                 const std::vector<can_message_definition_t>& get_can_message_definition();
79                 const can_message_definition_t& get_can_message_definition(std::uint8_t message_set_id, std::uint8_t message_id);
80
81                 uint32_t get_signal_id(diagnostic_message_t& sig) const;
82
83                 uint32_t get_signal_id(can_signal_t& sig) const;
84
85                 void set_active_message_set(uint8_t id);
86
87                 diagnostic_message_t* get_diagnostic_message(std::string message_name) const;
88                 DiagnosticRequest* get_request_from_diagnostic_message(std::string message_name) const;
89 /*
90                 /// TODO: implement this function as method into can_bus class
91                 /// @brief Pre initialize actions made before 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 pre_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 Post-initialize actions made after CAN bus initialization
98                 /// @param[in] bus A CanBus struct defining the bus's metadata
99                 /// @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.
100                 /// @param[in] buses An array of all CAN buses.
101                 void post_initialize(can_bus_dev_t* bus, bool writable, can_bus_dev_t* buses, const int busCount);
102                 /// TODO: implement this function as method into can_bus class
103                 /// @brief Check if the device is connected to an active CAN bus, i.e. it's received a message in the recent past.
104                 /// @return true if a message was received on the CAN bus within CAN_ACTIVE_TIMEOUT_S seconds.
105                 void logBusStatistics(can_bus_dev_t* buses, const int busCount);
106                 /// TODO: implement this function as method into can_bus class
107                 /// @brief Log transfer statistics about all active CAN buses to the debug log.
108                 /// @param[in] buses An array of active CAN buses.
109                 bool isBusActive(can_bus_dev_t* bus);
110                 */
111 };
112