Beginning of work of get central configuration object
[apps/low-level-can-service.git] / src / 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 #include <vector>
19
20 #include "can/can-bus.hpp"
21 #include "can/can-signals.hpp"
22 #include "obd2/diagnostic-manager.hpp"
23
24 /**
25  * @brief Class representing a configuration attached to the binding.
26  *
27  * @desc It regroups all needed objects instance from other class
28  *  that will be used along the binding life. It gets a global vision 
29  *  on which signals are implemented for that binding. 
30  *  Here, it is only the definition of the class with predefined accessors
31  *  methods used in the binding.
32  *
33  *  It will be the reference point to needed objects.
34  */
35
36 #include "low-can-binding.hpp"
37
38 class configuration_t
39 {
40         private:
41                 can_bus_t can_bus_manager_(afb_daemon_rootdir_open_locale(binder_interface->daemon, "can_buses.json", O_RDONLY, NULL));
42                 diagnostic_manager_t diagnostic_manager_;
43                 uint8_t active_message_set_ = 0;
44
45         public:
46                 const std::vector<obd2_signals_t> obd2_signals_;
47                 const std::vector<can_message_set_t> can_message_set_;
48                 const std::vector<std::vector<can_signal_t>> can_signals_;
49                 const std::vector<std::vector<can_message_definition_t>> can_message_definition_;
50
51                 configuration_t& get_configuration()
52                 { 
53                         return this;
54                 }
55
56                 can_bus_t& get_can_bus_manager()
57                 {
58                         return can_bus_manager_;
59                 }
60                 
61                 diagnostic_manager_t& get_diagnostic_manager()
62                 {
63                         return diagnostic_manager_;
64                 }
65
66                 uint8_t get_active_message_set()
67                 {
68                         return active_message_set_;
69                 }
70
71                 std::vector<can_message_set>& get_can_message_set()
72                 {
73                         return can_message_set_;
74                 }
75
76                 std::vector<can_signal>& get_can_signals()
77                 {
78                         return can_signal_[active_message_set_];
79                 }
80
81                 std::vector<CanSignal>& get_can_signals()
82                 {
83                         return SIGNALS[active_message_set_];
84                 }
85
86                 std::vector<can_message_definition>& get_can_message_definition()
87                 {
88                         return can_message_definition_[active_message_set_];
89                 }
90
91                 std::vector<obd2_signals_t>& get_obd2_signals()
92                 {
93                         return obd2_signals_;
94                 }
95
96                 std::vector<obd2_signals_t>& get_obd2_signals()
97                 {
98                         return OBD2_PIDS;
99                 }
100
101                 uint32_t get_signal_id(obd2_signals_t& sig)
102                 {
103                         return sig.get_pid();
104                 }
105
106                 uint32_t get_signal_id(const CanSignal& sig)
107                 {
108                         return sig.message->id;
109                 }
110
111                 void set_active_message_set(uint8_t id)
112                 {
113                         active_message_set_ = id;
114                 }
115 };