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