88ee94b9ca965d26718f1ce519b7f9864ebed8d7
[apps/agl-service-can-low-level.git] / examples / basic / application-generated.cpp
1 #include "application.hpp"
2 #include "../can/can-decoder.hpp"
3
4
5 // >>>>> handlers.cpp >>>>>
6 #include "can/canread.h"
7
8 using openxc::can::read::publishNumericalMessage;
9
10 void handleSteeringWheelMessage(CanMessage* message,
11         CanSignal* signals, int signalCount, Pipeline* pipeline) {
12     publishNumericalMessage("latitude", 42.0, pipeline);
13 }
14
15 openxc_DynamicField handleInverted(CanSignal* signal, CanSignal* signals,
16         int signalCount, float value, bool* send) {
17     return openxc::payload::wrapNumber(value * -1);
18 }
19
20 void initializeMyStuff() { }
21
22 void initializeOtherStuff() { }
23
24 void myLooper() {
25     // this function will be called once each time through the main loop, after
26     // all CAN message processing has been completed
27 }
28
29 // <<<<< handlers.cpp <<<<<
30
31 application_t::application_t()
32         : can_bus_manager_{utils::config_parser_t{"/etc/dev-mapping.conf"}}
33         , can_message_set_{
34                 {std::make_shared<can_message_set_t>(can_message_set_t{0,"example",
35                         { // beginning can_message_definition_ vector
36                                 {std::make_shared<can_message_definition_t>(can_message_definition_t{"hs",0x128,can_message_format_t::STANDARD,frequency_clock_t(5.00000f),true,
37                                         { // beginning can_signals vector
38                                                 {std::make_shared<can_signal_t> (can_signal_t{
39                                                         "engine_speed",
40                                                         12,
41                                                         8,
42                                                         1.00000f,
43                                                         0.00000,
44                                                         0,
45                                                         0,
46                                                         frequency_clock_t(15.0000f),
47                                                         true,
48                                                         false,
49                                                         {
50                                                         },
51                                                         false,
52                                                         nullptr,
53                                                         nullptr,
54                                                         false
55                                                 })},
56                                                 {std::make_shared<can_signal_t> (can_signal_t{
57                                                         "GearshiftPosition",
58                                                         41,
59                                                         3,
60                                                         1.00000f,
61                                                         0.00000,
62                                                         0,
63                                                         0,
64                                                         frequency_clock_t(0.00000f),
65                                                         true,
66                                                         false,
67                                                         {
68                                                                 {1,"FIRST"},
69                                                                 {4,"FOURTH"},
70                                                                 {6,"NEUTRAL"},
71                                                                 {5,"REVERSE"},
72                                                                 {2,"SECOND"},
73                                                                 {3,"THIRD"}
74                                                         },
75                                                         false,
76                                                         nullptr,
77                                                         nullptr,
78                                                         false
79                                                 })},
80                                                 {std::make_shared<can_signal_t> (can_signal_t{
81                                                         "SteeringWheelAngle",
82                                                         52,
83                                                         12,
84                                                         0.153920f,
85                                                         0.00000,
86                                                         0,
87                                                         0,
88                                                         frequency_clock_t(0.00000f),
89                                                         true,
90                                                         false,
91                                                         {
92                                                         },
93                                                         false,
94                                                         handleUnsignedSteeringWheelAngle,
95                                                         nullptr,
96                                                         false
97                                                 })},
98                                                 {std::make_shared<can_signal_t> (can_signal_t{
99                                                         "steering_wheel_angle_error",
100                                                         44,
101                                                         12,
102                                                         1.00000f,
103                                                         0.00000,
104                                                         0,
105                                                         0,
106                                                         frequency_clock_t(0.00000f),
107                                                         true,
108                                                         false,
109                                                         {
110                                                         },
111                                                         false,
112                                                         ignoreDecoder,
113                                                         nullptr,
114                                                         false
115                                                 })},
116                                                 {std::make_shared<can_signal_t> (can_signal_t{
117                                                         "steering_angle_sign",
118                                                         52,
119                                                         12,
120                                                         1.00000f,
121                                                         0.00000,
122                                                         0,
123                                                         0,
124                                                         frequency_clock_t(0.00000f),
125                                                         true,
126                                                         false,
127                                                         {
128                                                         },
129                                                         false,
130                                                         ignoreDecoder,
131                                                         nullptr,
132                                                         false
133                                                 })}
134                                         } // end can_signals vector
135                                 })} // end can_message_definition entry
136
137                 }, // end can_message_definition vector
138                         { // beginning diagnostic_messages_ vector
139                                 {std::make_shared<diagnostic_message_t>(diagnostic_message_t{
140                                         12,
141                                         "",
142                                         0,
143                                         0,
144                                         UNIT::INVALID,
145                                         1.00000f,
146                                         handleObd2Pid,
147                                         nullptr,
148                                         true
149                                 })}
150 ,                               {std::make_shared<diagnostic_message_t>(diagnostic_message_t{
151                                         12,
152                                         "",
153                                         0,
154                                         0,
155                                         UNIT::INVALID,
156                                         1.00000f,
157                                         nullptr,
158                                         nullptr,
159                                         true
160                                 })}
161 ,                               {std::make_shared<diagnostic_message_t>(diagnostic_message_t{
162                                         6,
163                                         "",
164                                         0,
165                                         0,
166                                         UNIT::INVALID,
167                                         1.00000f,
168                                         handleMyDiagRequest,
169                                         nullptr,
170                                         true
171                                 })}
172
173                         } // end diagnostic_messages_ vector
174                 })} // end can_message_set entry
175         } // end can_message_set vector
176 {
177         for(auto& cms: can_message_set_)
178         {
179                 std::vector<std::shared_ptr<can_message_definition_t> >& can_messages_definition = cms->get_can_message_definition();
180                 for(auto& cmd : can_messages_definition)
181                 {
182                         cmd->set_parent(cms.get());
183                         std::vector<std::shared_ptr<can_signal_t> >& can_signals = cmd->get_can_signals();
184                         for(auto& sig: can_signals)
185                         {
186                                 sig->set_parent(cmd.get());
187                         }
188                 }
189
190                 std::vector<std::shared_ptr<diagnostic_message_t> >& diagnostic_messages = cms->get_diagnostic_messages();
191                 for(auto& dm : diagnostic_messages)
192                 {
193                         dm->set_parent(cms.get());
194                 }
195         }
196                 }
197
198 const std::string application_t::get_diagnostic_bus() const
199 {
200         return "hs";
201 }
202
203