Use newly generated cpp file with default encoders
[apps/agl-service-can-low-level.git] / examples / basic / application-generated.cpp
1 #include "application.hpp"
2 #include "../can/can-decoder.hpp"
3 #include "../can/can-encoder.hpp"
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                                         false
150                                 })}
151 ,                               {std::make_shared<diagnostic_message_t>(diagnostic_message_t{
152                                         12,
153                                         "",
154                                         0,
155                                         0,
156                                         UNIT::INVALID,
157                                         1.00000f,
158                                         nullptr,
159                                         nullptr,
160                                         true,
161                                         false
162                                 })}
163 ,                               {std::make_shared<diagnostic_message_t>(diagnostic_message_t{
164                                         6,
165                                         "",
166                                         0,
167                                         0,
168                                         UNIT::INVALID,
169                                         1.00000f,
170                                         handleMyDiagRequest,
171                                         nullptr,
172                                         true,
173                                         false
174                                 })}
175
176                         } // end diagnostic_messages_ vector
177                 })} // end can_message_set entry
178         } // end can_message_set vector
179 {
180         for(auto& cms: can_message_set_)
181         {
182                 std::vector<std::shared_ptr<can_message_definition_t> >& can_messages_definition = cms->get_can_message_definition();
183                 for(auto& cmd : can_messages_definition)
184                 {
185                         cmd->set_parent(cms.get());
186                         std::vector<std::shared_ptr<can_signal_t> >& can_signals = cmd->get_can_signals();
187                         for(auto& sig: can_signals)
188                         {
189                                 sig->set_parent(cmd.get());
190                         }
191                 }
192
193                 std::vector<std::shared_ptr<diagnostic_message_t> >& diagnostic_messages = cms->get_diagnostic_messages();
194                 for(auto& dm : diagnostic_messages)
195                 {
196                         dm->set_parent(cms.get());
197                 }
198         }
199                 }
200
201 const std::string application_t::get_diagnostic_bus() const
202 {
203         return "hs";
204 }
205
206