d4ada1de6746db5edb6fb5bc47b673336d47c6b1
[apps/agl-service-can-low-level.git] / src / can-signals.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 <queue>
22 #include <string>
23 #include <vector>
24 #include <fnmatch.h>
25
26 #include "can-utils.hpp"
27
28 extern "C"
29 {
30         #include <afb/afb-event-itf.h>
31 }
32
33 #define MESSAGE_SET_ID 0
34
35 /** 
36  * @brief Can signal event map making access to afb_event
37  * externaly to an openxc existing structure.
38  *
39  * @desc Event map is making relation between CanSignal generic name
40  * and the afb_event struct used by application framework to pushed
41  * to the subscriber.
42  */
43 static std::map<std::string, struct afb_event> subscribed_signals;
44
45 /** Public: Return the currently active CAN configuration. */
46 CanMessageSet* getActiveMessageSet();
47
48 /** Public: Retrive a list of all possible CAN configurations.
49  *
50  * Returns a pointer to an array of all configurations.
51  */
52 CanMessageSet* getMessageSets();
53
54 /** Public: Return the length of the array returned by getMessageSets() */
55 int getMessageSetCount();
56
57 /* Public: Return the number of CAN buses configured in the active
58  * configuration. This is limited to 2, as the hardware controller only has 2
59  * CAN channels.
60  */
61 int getCanBusCount();
62
63 /* Public: Return an array of all CAN messages to be processed in the active
64  * configuration.
65  */
66 CanMessageDefinition* getMessages();
67
68 /* Public: Return signals from an signals array filtered on name.
69  */
70 const std::vector<CanSignal> getSignals();
71
72 /* Public: Return an array of all OpenXC CAN commands enabled in the active
73  * configuration that can write back to CAN with a custom handler.
74  *
75  * * Commands not defined here are handled using a 1-1 mapping from the signals
76  * list.
77  *              */
78 CanCommand* getCommands();
79
80 /* Public: Return the length of the array returned by getCommandCount(). */
81 int getCommandCount();
82
83 /* Public: Return the length of the array returned by getSignals(). */
84 size_t getSignalCount();
85
86 /* Public: Return the length of the array returned by getMessages(). */
87 int getMessageCount();
88
89 /**
90  * @brief Return an array of the metadata for the 2 CAN buses you want to
91  * monitor. The size of this array is fixed at 2.
92  */
93 CanBus* getCanBuses();
94
95 /**
96  * @brief Find one or many signals based on its name or id
97  * passed through openxc_DynamicField.
98  *
99  * @param[in] openxc_DynamicField& - a const reference with the key to search into signal.
100  * Key is either a signal name or its CAN arbitration id.
101  *
102  * @return std::vector<std::string> return found CanSignal generic name vector.
103  */
104 std::vector<CanSignal> find_can_signals(const openxc_DynamicField &key);
105
106 /**
107  * @brief Retrieve can arbitration id of a given CanSignal
108  *
109  * @param[in] CanSignal& - a const reference to a CanSignal
110  *
111  * @return uint32_t - unsigned integer representing the arbitration id.
112  */
113 inline uint32_t get_CanSignal_id(const CanSignal& sig);
114
115 /**
116  * @brief return the subscribed_signals map.
117  * 
118  * return std::map<std::string, struct afb_event> - map of subscribed signals.
119  */
120 const std::map<std::string, struct afb_event> get_subscribed_signals();