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