Cleanup examples, tests, configuration and plugins
[apps/agl-service-can-low-level.git] / examples / basic / basic-signals.cpp
1 #include <binding/application.hpp>
2 #include <can/can-decoder.hpp>
3 #include <can/can-encoder.hpp>
4
5 extern "C" {
6 CTLP_CAPI_REGISTER("example");
7
8 #include "can/canread.h"
9
10 using openxc::can::read::publishNumericalMessage;
11
12 void handleSteeringWheelMessage(CanMessage* message,
13         CanSignal* signals, int signalCount, Pipeline* pipeline) {
14     publishNumericalMessage("latitude", 42.0, pipeline);
15 }
16
17 openxc_DynamicField handleInverted(CanSignal* signal, CanSignal* signals,
18         int signalCount, float value, bool* send) {
19     return openxc::payload::wrapNumber(value * -1);
20 }
21
22 void initializeMyStuff() { }
23
24 void initializeOtherStuff() { }
25
26 void myLooper() {
27     // this function will be called once, each time through the main loop, after
28     // all CAN message processing has been completed
29 }
30
31 // >>>>> handlers.cpp >>>>>
32 #include "can/canread.h"
33
34 using openxc::can::read::publishNumericalMessage;
35
36 void handleSteeringWheelMessage(CanMessage* message,
37         CanSignal* signals, int signalCount, Pipeline* pipeline) {
38     publishNumericalMessage("latitude", 42.0, pipeline);
39 }
40
41 openxc_DynamicField handleInverted(CanSignal* signal, CanSignal* signals,
42         int signalCount, float value, bool* send) {
43     return openxc::payload::wrapNumber(value * -1);
44 }
45
46 void initializeMyStuff() { }
47
48 void initializeOtherStuff() { }
49
50 void myLooper() {
51     // this function will be called once, each time through the main loop, after
52     // all CAN message processing has been completed
53 }
54
55 // <<<<< handlers.cpp <<<<<
56
57 std::shared_ptr<message_set_t> cms = std::make_shared<message_set_t>(message_set_t{0,"example",
58         { // beginning message_definition_ vector
59                 {std::make_shared<message_definition_t>(message_definition_t{"hs",0x128,"ECM_z_5D2",8,0,frequency_clock_t(5.00000f),true,
60                         { // beginning signals vector
61                                 {std::make_shared<signal_t> (signal_t{
62                                         "engine_speed",// generic_name
63                                         12,// bit_position
64                                         8,// bit_size
65                                         1.00000f,// factor
66                                         0.00000f,// offset
67                                         0,// min_value
68                                         0,// max_value
69                                         frequency_clock_t(15.0000f),// frequency
70                                         true,// send_same
71                                         false,// force_send_changed
72                                         {
73                                         },// states
74                                         false,// writable
75                                         nullptr,// decoder
76                                         nullptr,// encoder
77                                         false,// received
78                                         std::make_pair<bool, int>(false, 0),// multiplex
79                                         static_cast<sign_t>(0),// signed
80                                         -1,// bit_sign_position
81                                         ""// unit
82                                 })},
83                                 {std::make_shared<signal_t> (signal_t{
84                                         "GearshiftPosition",// generic_name
85                                         41,// bit_position
86                                         3,// bit_size
87                                         1.00000f,// factor
88                                         0.00000f,// offset
89                                         0,// min_value
90                                         0,// max_value
91                                         frequency_clock_t(0.00000f),// frequency
92                                         true,// send_same
93                                         false,// force_send_changed
94                                         {
95                                                 {1,"FIRST"},
96                                                 {4,"FOURTH"},
97                                                 {6,"NEUTRAL"},
98                                                 {5,"REVERSE"},
99                                                 {2,"SECOND"},
100                                                 {3,"THIRD"}
101                                         },// states
102                                         false,// writable
103                                         decoder_t::decode_state,// decoder
104                                         nullptr,// encoder
105                                         false,// received
106                                         std::make_pair<bool, int>(false, 0),// multiplex
107                                         static_cast<sign_t>(0),// signed
108                                         -1,// bit_sign_position
109                                         ""// unit
110                                 })},
111                                 {std::make_shared<signal_t> (signal_t{
112                                         "SteeringWheelAngle",// generic_name
113                                         52,// bit_position
114                                         12,// bit_size
115                                         0.153920f,// factor
116                                         0.00000f,// offset
117                                         0,// min_value
118                                         0,// max_value
119                                         frequency_clock_t(0.00000f),// frequency
120                                         true,// send_same
121                                         false,// force_send_changed
122                                         {
123                                         },// states
124                                         false,// writable
125                                         decoder_t::gnedSteeringWheelAngle,// decoder
126                                         nullptr,// encoder
127                                         false,// received
128                                         std::make_pair<bool, int>(false, 0),// multiplex
129                                         static_cast<sign_t>(0),// signed
130                                         -1,// bit_sign_position
131                                         ""// unit
132                                 })},
133                                 {std::make_shared<signal_t> (signal_t{
134                                         "steering_wheel_angle_error",// generic_name
135                                         44,// bit_position
136                                         12,// bit_size
137                                         1.00000f,// factor
138                                         0.00000f,// offset
139                                         0,// min_value
140                                         0,// max_value
141                                         frequency_clock_t(0.00000f),// frequency
142                                         true,// send_same
143                                         false,// force_send_changed
144                                         {
145                                         },// states
146                                         false,// writable
147                                         decoder_t::der,// decoder
148                                         nullptr,// encoder
149                                         false,// received
150                                         std::make_pair<bool, int>(false, 0),// multiplex
151                                         static_cast<sign_t>(0),// signed
152                                         -1,// bit_sign_position
153                                         ""// unit
154                                 })},
155                                 {std::make_shared<signal_t> (signal_t{
156                                         "steering_angle_sign",// generic_name
157                                         52,// bit_position
158                                         12,// bit_size
159                                         1.00000f,// factor
160                                         0.00000f,// offset
161                                         0,// min_value
162                                         0,// max_value
163                                         frequency_clock_t(0.00000f),// frequency
164                                         true,// send_same
165                                         false,// force_send_changed
166                                         {
167                                         },// states
168                                         false,// writable
169                                         decoder_t::der,// decoder
170                                         nullptr,// encoder
171                                         false,// received
172                                         std::make_pair<bool, int>(false, 0),// multiplex
173                                         static_cast<sign_t>(0),// signed
174                                         -1,// bit_sign_position
175                                         ""// unit
176                                 })}
177                         } // end signals vector
178                 })} // end message_definition entry
179         }, // end message_definition vector
180         { // beginning diagnostic_messages_ vector
181                 {std::make_shared<diagnostic_message_t>(diagnostic_message_t{
182                         12,
183                         "",
184                         0,
185                         0,
186                         UNIT::INVALID,
187                         1.00000f,
188                         decoder_t::Pid,
189                         nullptr,
190                         true,
191                         false
192                 })}
193 ,               {std::make_shared<diagnostic_message_t>(diagnostic_message_t{
194                         12,
195                         "",
196                         0,
197                         0,
198                         UNIT::INVALID,
199                         1.00000f,
200                         nullptr,
201                         nullptr,
202                         true,
203                         false
204                 })}
205 ,               {std::make_shared<diagnostic_message_t>(diagnostic_message_t{
206                         6,
207                         "",
208                         0,
209                         0,
210                         UNIT::INVALID,
211                         1.00000f,
212                         decoder_t::agRequest,
213                         nullptr,
214                         true,
215                         false
216                 })}
217
218         } // end diagnostic_messages_ vector
219 }); // end message_set entry
220
221 CTLP_ONLOAD(plugin, handle) {
222         afb_api_t api = (afb_api_t) plugin->api;
223         CtlConfigT* CtlConfig = (CtlConfigT*) afb_api_get_userdata(api);
224         application_t* app = (application_t*) getExternalData(CtlConfig);
225
226         return app->add_message_set(cms);
227 }
228
229
230 }