199054b5340f9f892fb376d017d9a82fdaba83bc
[apps/low-level-can-service.git] / CAN-binder / low-can-binding / diagnostic / diagnostic-manager.cpp
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 #include <systemd/sd-event.h>
19 #include <algorithm>
20 #include <string.h>
21
22 #include "diagnostic-manager.hpp"
23
24 #include "../utils/openxc-utils.hpp"
25 #include "../utils/signals.hpp"
26 #include "../binding/configuration.hpp"
27
28 #define MAX_RECURRING_DIAGNOSTIC_FREQUENCY_HZ 10
29 #define MAX_SIMULTANEOUS_DIAG_REQUESTS 50
30 // There are only 8 slots of in flight diagnostic requests
31 #define MAX_SIMULTANEOUS_IN_FLIGHT_REQUESTS 8
32 #define TIMERFD_ACCURACY 0
33 #define MICRO 1000000
34
35 diagnostic_manager_t::diagnostic_manager_t()
36         : initialized_{false}
37 {}
38
39 /// @brief Diagnostic manager isn't initialized at launch but after
40 ///  CAN bus devices initialization. For the moment, it is only possible
41 ///  to have 1 diagnostic bus which are the first bus declared in the JSON
42 ///  description file. Configuration instance will return it.
43 ///
44 /// this will initialize DiagnosticShims and cancel all active requests 
45 ///  if there are any.
46 bool diagnostic_manager_t::initialize()
47 {
48         // Mandatory to set the bus before intialize shims.
49         bus_ = configuration_t::instance().get_diagnostic_bus();
50
51         init_diagnostic_shims();
52         event_source_ = nullptr;
53         reset();
54
55         initialized_ = true;
56         DEBUG(binder_interface, "%s: Diagnostic Manager initialized", __FUNCTION__);
57         return initialized_;
58 }
59
60 utils::socketcan_bcm_t& diagnostic_manager_t::get_socket()
61 {
62         return socket_;
63 }
64
65 /// @brief initialize shims used by UDS lib and set initialized_ to true.
66 ///  It is needed before used the diagnostic manager fully because shims are
67 ///  required by most member functions.
68 void diagnostic_manager_t::init_diagnostic_shims()
69 {
70         shims_ = diagnostic_init_shims(shims_logger, shims_send, NULL);
71         DEBUG(binder_interface, "%s: Shims initialized", __FUNCTION__);
72 }
73
74 /// @brief Force cleanup all active requests.
75 void diagnostic_manager_t::reset()
76 {
77         DEBUG(binder_interface, "%s: Clearing existing diagnostic requests", __FUNCTION__);
78         cleanup_active_requests(true);
79 }
80
81 /// @brief Adds 8 RX_SETUP jobs to the BCM rx_socket_ then diagnotic manager
82 ///  listens on CAN ID range 7E8 - 7EF affected to the OBD2 communications.
83 ///
84 /// @return -1 or negative value on error, 0 if ok.
85 int diagnostic_manager_t::add_rx_filter(uint32_t can_id)
86 {
87         // Make sure that socket has been opened.
88         if(! socket_)
89                 socket_.open(get_bus_device_name());
90
91         struct utils::simple_bcm_msg bcm_msg;
92         memset(&bcm_msg.msg_head, 0, sizeof(bcm_msg.msg_head));
93
94         const struct timeval freq =  recurring_requests_.back()->get_timeout_clock().get_timeval_from_period();
95
96         bcm_msg.msg_head.opcode  = RX_SETUP;
97         bcm_msg.msg_head.flags = SETTIMER|RX_FILTER_ID;
98         bcm_msg.msg_head.ival2.tv_sec = freq.tv_sec;
99         bcm_msg.msg_head.ival2.tv_usec = freq.tv_usec;
100
101         // If it isn't an OBD2 CAN ID then just add a simple RX_SETUP job
102         if(can_id != OBD2_FUNCTIONAL_BROADCAST_ID) 
103         {
104                 bcm_msg.msg_head.can_id  = can_id;
105
106                 socket_ << bcm_msg;
107                         if(! socket_)
108                                 return -1;
109         }
110         else
111         {
112                 for(uint8_t i = 0; i < 8; i++)
113                 {
114                         can_id  =  OBD2_FUNCTIONAL_RESPONSE_START + i;
115                         bcm_msg.msg_head.can_id  = can_id;
116
117                         socket_ << bcm_msg;
118                         if(! socket_)
119                                 return -1;
120                 }
121         }
122
123         return 0;
124 }
125
126 /// @brief send function use by diagnostic library. Only one bus used for now
127 ///  so diagnostic request is sent using the default diagnostic bus not matter of
128 ///  which is specified in the diagnostic message definition.
129 ///
130 /// @param[in] arbitration_id - CAN arbitration ID to use when send message. OBD2 broadcast ID
131 ///  is 0x7DF by example.
132 /// @param[in] data - The data payload for the message. NULL is valid if size is also 0.
133 /// @param[in] size - The size of the data payload, in bytes.
134 ///
135 /// @return true if the CAN message was sent successfully. 
136 bool diagnostic_manager_t::shims_send(const uint32_t arbitration_id, const uint8_t* data, const uint8_t size)
137 {
138         diagnostic_manager_t& dm = configuration_t::instance().get_diagnostic_manager();
139         active_diagnostic_request_t* current_adr = dm.get_last_recurring_requests();
140         utils::socketcan_bcm_t& tx_socket = current_adr->get_socket();
141
142         // Make sure that socket has been opened.
143         if(! tx_socket)
144                 tx_socket.open(
145                         dm.get_bus_device_name());
146
147         struct utils::simple_bcm_msg bcm_msg;
148         struct can_frame cfd;
149
150         memset(&cfd, 0, sizeof(cfd));
151         memset(&bcm_msg.msg_head, 0, sizeof(bcm_msg.msg_head));
152
153         struct timeval freq = current_adr->get_frequency_clock().get_timeval_from_period();
154
155         bcm_msg.msg_head.opcode  = TX_SETUP;
156         bcm_msg.msg_head.can_id  = arbitration_id;
157         bcm_msg.msg_head.flags = SETTIMER|STARTTIMER|TX_CP_CAN_ID;
158         bcm_msg.msg_head.ival2.tv_sec = freq.tv_sec;
159         bcm_msg.msg_head.ival2.tv_usec = freq.tv_usec;
160         bcm_msg.msg_head.nframes = 1;
161         cfd.can_dlc = size;
162         ::memcpy(cfd.data, data, size);
163
164         bcm_msg.frames = cfd;
165
166         tx_socket << bcm_msg;
167         if(tx_socket)
168                 return true;
169         return false;
170 }
171
172 /// @brief The type signature for an optional logging function, if the user
173 /// wishes to provide one. It should print, store or otherwise display the
174 /// message.
175 ///
176 /// message - A format string to log using the given parameters.
177 /// ... (vargs) - the parameters for the format string.
178 ///
179 void diagnostic_manager_t::shims_logger(const char* format, ...)
180 {
181         va_list args;
182         va_start(args, format);
183
184         char buffer[256];
185         vsnprintf(buffer, 256, format, args);
186
187         DEBUG(binder_interface, "%s: %s", __FUNCTION__, buffer);
188 }
189
190 /// @brief The type signature for a... OpenXC TODO: not used yet.
191 void diagnostic_manager_t::shims_timer()
192 {}
193
194 const std::string diagnostic_manager_t::get_bus_name() const
195 {
196         return bus_;
197 }
198
199 const std::string diagnostic_manager_t::get_bus_device_name() const
200 {
201         return configuration_t::instance().get_can_bus_manager()
202                 .get_can_device_name(bus_);
203 }
204
205 active_diagnostic_request_t* diagnostic_manager_t::get_last_recurring_requests() const
206 {
207         return recurring_requests_.back();
208 }
209
210 /// @brief Return diagnostic manager shims member.
211 DiagnosticShims& diagnostic_manager_t::get_shims()
212 {
213         return shims_;
214 }
215
216 /// @brief Search for a specific active diagnostic request in the provided requests list
217 /// and erase it from the vector. This is useful at unsubscription to clean up the list otherwize
218 /// all received CAN messages will be passed to DiagnosticRequestHandle of all active diagnostic request
219 /// contained in the vector but no event if connected to, so we will decode uneeded request.
220 ///
221 /// @param[in] entry - a pointer of an active_diagnostic_request instance to clean up
222 /// @param[in] requests_list - a vector where to make the search and cleaning.
223 void diagnostic_manager_t::find_and_erase(active_diagnostic_request_t* entry, std::vector<active_diagnostic_request_t*>& requests_list)
224 {
225         auto i = std::find(requests_list.begin(), requests_list.end(), entry);
226         if ( i != requests_list.end())
227                 requests_list.erase(i);
228 }
229
230 // @brief TODO: implement cancel_request if needed... Don't know.
231 void diagnostic_manager_t::cancel_request(active_diagnostic_request_t* entry)
232 {
233         entry->get_socket().close();
234 }
235
236 /// @brief Cleanup a specific request if it isn't running and get complete. As it is almost
237 /// impossible to get that state for a recurring request without waiting for that, you can 
238 /// force the cleaning operation.
239 ///
240 /// @param[in] entry - the request to clean
241 /// @param[in] force - Force the cleaning or not ?
242 void diagnostic_manager_t::cleanup_request(active_diagnostic_request_t* entry, bool force)
243 {
244         if((force || (entry != nullptr && entry->response_received())))
245         {
246                 char request_string[128] = {0};
247                 diagnostic_request_to_string(&entry->get_handle()->request,
248                         request_string, sizeof(request_string));
249                 if(force && entry->get_recurring())
250                 {
251                         find_and_erase(entry, recurring_requests_);
252                         cancel_request(entry);
253                         DEBUG(binder_interface, "%s: Cancelling completed, recurring request: %s", __FUNCTION__, request_string);
254                 }
255                 else
256                 {
257                         DEBUG(binder_interface, "%s: Cancelling completed, non-recurring request: %s", __FUNCTION__, request_string);
258                         find_and_erase(entry, non_recurring_requests_);
259                         cancel_request(entry);
260                 }
261         }
262 }
263
264 /// @brief Clean up all requests lists, recurring and not recurring.
265 ///
266 /// @param[in] force - Force the cleaning or not ? If true, that will do
267 /// the same effect as a call to reset().
268 void diagnostic_manager_t::cleanup_active_requests(bool force)
269 {
270         for(auto& entry : non_recurring_requests_)
271                 if (entry != nullptr)
272                         cleanup_request(entry, force);
273
274         for(auto& entry : recurring_requests_)
275                 if (entry != nullptr)
276                         cleanup_request(entry, force);
277 }
278
279 /// @brief Will return the active_diagnostic_request_t pointer for theDiagnosticRequest or nullptr if
280 /// not found.
281 ///
282 /// @param[in] request - Search key, method will go through recurring list to see if it find that request
283 ///  holded by the DiagnosticHandle member.
284 active_diagnostic_request_t* diagnostic_manager_t::find_recurring_request(const DiagnosticRequest* request)
285 {
286         for (auto& entry : recurring_requests_)
287         {
288                 if(entry != nullptr)
289                 {
290                         if(diagnostic_request_equals(&entry->get_handle()->request, request))
291                         {
292                                 return entry;
293                                 break;
294                         }
295                 }
296         }
297         return nullptr;
298 }
299
300 /// @brief Add and send a new one-time diagnostic request.
301 ///
302 /// A one-time (aka non-recurring) request can existing in parallel with a
303 /// recurring request for the same PID or mode, that's not a problem.
304 ///
305 /// For an example, see the docs for addRecurringRequest. This function is very
306 /// similar but leaves out the frequencyHz parameter.
307 ///
308 /// @param[in] request - The parameters for the request.
309 /// @param[in] name - Human readable name this response, to be used when
310 ///      publishing received responses. TODO: If the name is NULL, the published output
311 ///      will use the raw OBD-II response format.
312 /// @param[in] wait_for_multiple_responses - If false, When any response is received
313 ///      for this request it will be removed from the active list. If true, the
314 ///      request will remain active until the timeout clock expires, to allow it
315 ///      to receive multiple response. Functional broadcast requests will always
316 ///      waint for the timeout, regardless of this parameter.
317 /// @param[in] decoder - An optional DiagnosticResponseDecoder to parse the payload of
318 ///      responses to this request. If the decoder is NULL, the output will
319 ///      include the raw payload instead of a parsed value.
320 /// @param[in] callback - An optional DiagnosticResponseCallback to be notified whenever a
321 ///      response is received for this request.
322 ///
323 /// @return true if the request was added successfully. Returns false if there
324 /// wasn't a free active request entry, if the frequency was too high or if the
325 /// CAN acceptance filters could not be configured,
326 active_diagnostic_request_t* diagnostic_manager_t::add_request(DiagnosticRequest* request, const std::string name,
327         bool wait_for_multiple_responses, const DiagnosticResponseDecoder decoder,
328         const DiagnosticResponseCallback callback)
329 {
330         cleanup_active_requests(false);
331
332         active_diagnostic_request_t* entry = nullptr;
333
334         if (non_recurring_requests_.size() <= MAX_SIMULTANEOUS_DIAG_REQUESTS)
335         {
336                 // TODO: implement Acceptance Filter
337                 //      if(updateRequiredAcceptanceFilters(bus, request)) {
338                         active_diagnostic_request_t* entry = new active_diagnostic_request_t(bus_, request, name,
339                                         wait_for_multiple_responses, decoder, callback, 0);
340                         entry->set_handle(shims_, request);
341
342                         char request_string[128] = {0};
343                         diagnostic_request_to_string(&entry->get_handle()->request, request_string,
344                                         sizeof(request_string));
345
346                         find_and_erase(entry, non_recurring_requests_);
347                         DEBUG(binder_interface, "%s: Added one-time diagnostic request on bus %s: %s", __FUNCTION__,
348                                         bus_.c_str(), request_string);
349
350                         non_recurring_requests_.push_back(entry);
351         }
352         else
353         {
354                 WARNING(binder_interface, "%s: There isn't enough request entry. Vector exhausted %d/%d", __FUNCTION__, (int)non_recurring_requests_.size(), MAX_SIMULTANEOUS_DIAG_REQUESTS);
355                 non_recurring_requests_.resize(MAX_SIMULTANEOUS_DIAG_REQUESTS);
356         }
357         return entry;
358 }
359
360 bool diagnostic_manager_t::validate_optional_request_attributes(float frequencyHz)
361 {
362         if(frequencyHz > MAX_RECURRING_DIAGNOSTIC_FREQUENCY_HZ) {
363                 DEBUG(binder_interface, "%s: Requested recurring diagnostic frequency %lf is higher than maximum of %d", __FUNCTION__,
364                         frequencyHz, MAX_RECURRING_DIAGNOSTIC_FREQUENCY_HZ);
365                 return false;
366         }
367         return true;
368 }
369
370 /// @brief Add and send a new recurring diagnostic request.
371 ///
372 /// At most one recurring request can be active for the same arbitration ID, mode
373 /// and (if set) PID on the same bus at one time. If you try and call
374 /// addRecurringRequest with the same key, it will return an error.
375 ///
376 /// TODO: This also adds any neccessary CAN acceptance filters so we can receive the
377 /// response. If the request is to the functional broadcast ID (0x7df) filters
378 /// are added for all functional addresses (0x7e8 to 0x7f0).
379 ///
380 /// Example:
381 ///
382 ///     // Creating a functional broadcast, mode 1 request for PID 2.
383 ///     DiagnosticRequest request = {
384 ///         arbitration_id: 0x7df,
385 ///         mode: 1,
386 ///         has_pid: true,
387 ///         pid: 2
388 ///     };
389 ///
390 ///     // Add a recurring request, to be sent at 1Hz, and published with the
391 ///     // name "my_pid_request"
392 ///     addRecurringRequest(&getConfiguration()->diagnosticsManager,
393 ///          canBus,
394 ///          &request,
395 ///          "my_pid_request",
396 ///          false,
397 ///          NULL,
398 ///          NULL,
399 ///          1);
400 ///
401 /// @param[in] request - The parameters for the request.
402 /// @param[in] name - An optional human readable name this response, to be used when
403 ///      publishing received responses. If the name is NULL, the published output
404 ///      will use the raw OBD-II response format.
405 /// @param[in] wait_for_multiple_responses - If false, When any response is received
406 ///      for this request it will be removed from the active list. If true, the
407 ///      request will remain active until the timeout clock expires, to allow it
408 ///      to receive multiple response. Functional broadcast requests will always
409 ///      waint for the timeout, regardless of this parameter.
410 /// @param[in] decoder - An optional DiagnosticResponseDecoder to parse the payload of
411 ///      responses to this request. If the decoder is NULL, the output will
412 ///      include the raw payload instead of a parsed value.
413 /// @param[in] callback - An optional DiagnosticResponseCallback to be notified whenever a
414 ///      response is received for this request.
415 /// @param[in] frequencyHz - The frequency (in Hz) to send the request. A frequency above
416 ///      MAX_RECURRING_DIAGNOSTIC_FREQUENCY_HZ is not allowed, and will make this
417 ///      function return false.
418 ///
419 /// @return true if the request was added successfully. Returns false if there
420 /// was too much already running requests, if the frequency was too high TODO:or if the
421 /// CAN acceptance filters could not be configured,
422 active_diagnostic_request_t* diagnostic_manager_t::add_recurring_request(DiagnosticRequest* request, const char* name,
423                 bool wait_for_multiple_responses, const DiagnosticResponseDecoder decoder,
424                 const DiagnosticResponseCallback callback, float frequencyHz)
425 {
426         active_diagnostic_request_t* entry = nullptr;
427
428         if(!validate_optional_request_attributes(frequencyHz))
429                 return entry;
430
431         cleanup_active_requests(false);
432
433         if(find_recurring_request(request) == nullptr)
434         {
435                 if(recurring_requests_.size() <= MAX_SIMULTANEOUS_DIAG_REQUESTS)
436                 {
437                         // TODO: implement Acceptance Filter
438                         //if(updateRequiredAcceptanceFilters(bus, request)) {
439                         entry = new active_diagnostic_request_t(bus_, request, name,
440                                         wait_for_multiple_responses, decoder, callback, frequencyHz);
441                         recurring_requests_.push_back(entry);
442
443                         entry->set_handle(shims_, request);
444                         if(add_rx_filter(OBD2_FUNCTIONAL_BROADCAST_ID) < 0)
445                                 { recurring_requests_.pop_back(); }
446                         else
447                                 {
448                                         start_diagnostic_request(&shims_, entry->get_handle()); 
449                                         if(event_source_ == nullptr && sd_event_add_io(afb_daemon_get_event_loop(binder_interface->daemon), 
450                                                 &event_source_,
451                                                 socket_.socket(),
452                                                 EPOLLIN,
453                                                 read_message,
454                                                 nullptr) < 0)
455                                         {
456                                                 cleanup_request(entry, true);
457                                                 WARNING(binder_interface, "%s: signal: %s isn't supported. Canceling operation.", __FUNCTION__, entry->get_name().c_str());
458                                                 return entry;
459                                         }
460                                 }
461                 }
462                 else
463                 {
464                         WARNING(binder_interface, "%s: There isn't enough request entry. Vector exhausted %d/%d", __FUNCTION__, (int)recurring_requests_.size(), MAX_SIMULTANEOUS_DIAG_REQUESTS);
465                         recurring_requests_.resize(MAX_SIMULTANEOUS_DIAG_REQUESTS);
466                 }
467         }
468         else
469                 { DEBUG(binder_interface, "%s: Can't add request, one already exists with same key", __FUNCTION__);}
470         return entry;
471 }
472
473 /// @brief Will decode the diagnostic response and build the final openxc_VehicleMessage to return.
474 ///
475 /// @param[in] adr - A pointer to an active diagnostic request holding a valid diagnostic handle
476 /// @param[in] response - The response to decode from which the Vehicle message will be built and returned
477 ///
478 /// @return A filled openxc_VehicleMessage or a zeroed struct if there is an error.
479 openxc_VehicleMessage diagnostic_manager_t::relay_diagnostic_response(active_diagnostic_request_t* adr, const DiagnosticResponse& response)
480 {
481         openxc_VehicleMessage message = build_VehicleMessage();
482         float value = (float)diagnostic_payload_to_integer(&response);
483         if(adr->get_decoder() != nullptr)
484         {
485                 value = adr->get_decoder()(&response, value);
486         }
487
488         if((response.success && adr->get_name().size()) > 0)
489         {
490                 // If name, include 'value' instead of payload, and leave of response
491                 // details.
492                 message = build_VehicleMessage(build_SimpleMessage(adr->get_name(), build_DynamicField(value)));
493         }
494         else
495         {
496                 // If no name, send full details of response but still include 'value'
497                 // instead of 'payload' if they provided a decoder. The one case you
498                 // can't get is the full detailed response with 'value'. We could add
499                 // another parameter for that but it's onerous to carry that around.
500                 message = build_VehicleMessage(adr, response, value);
501         }
502
503         // If not success but completed then the pid isn't supported
504         if(!response.success)
505         {
506                 struct utils::signals_found found_signals;
507                 found_signals = utils::signals_manager_t::instance().find_signals(build_DynamicField(adr->get_name()));
508                 found_signals.diagnostic_messages.front()->set_supported(false);
509                 cleanup_request(adr, true);
510                 NOTICE(binder_interface, "%s: PID not supported or ill formed. Please unsubscribe from it. Error code : %d", __FUNCTION__, response.negative_response_code);
511                 message = build_VehicleMessage(build_SimpleMessage(adr->get_name(), build_DynamicField("This PID isn't supported by your vehicle.")));
512         }
513
514         if(adr->get_callback() != nullptr)
515         {
516                 adr->get_callback()(adr, &response, value);
517         }
518
519         // Reset the completed flag handle to make sure that it will be reprocessed the next time.
520         adr->get_handle()->success = false;
521         return message;
522 }
523
524 /// @brief Will take the CAN message and pass it to the receive functions that will process
525 /// diagnostic handle for each active diagnostic request then depending on the result we will 
526 /// return pass the diagnostic response to decode it.
527 ///
528 /// @param[in] entry - A pointer to an active diagnostic request holding a valid diagnostic handle
529 /// @param[in] cm - A raw CAN message.
530 ///
531 /// @return A pointer to a filled openxc_VehicleMessage or a nullptr if nothing has been found.
532 openxc_VehicleMessage diagnostic_manager_t::relay_diagnostic_handle(active_diagnostic_request_t* entry, const can_message_t& cm)
533 {
534         DiagnosticResponse response = diagnostic_receive_can_frame(&shims_, entry->get_handle(), cm.get_id(), cm.get_data(), cm.get_length());
535         if(response.completed && entry->get_handle()->completed)
536         {
537                 if(entry->get_handle()->success)
538                         return relay_diagnostic_response(entry, response);
539         }
540         else if(!response.completed && response.multi_frame)
541         {
542                 // Reset the timeout clock while completing the multi-frame receive
543                 entry->get_timeout_clock().tick(
544                         entry->get_timeout_clock().get_time_function()());
545         }
546
547         return build_VehicleMessage();
548 }
549
550 /// @brief Find the active diagnostic request with the correct DiagnosticRequestHandle
551 /// member that will understand the CAN message using diagnostic_receive_can_frame function
552 /// from UDS-C library. Then decode it with an ad-hoc method.
553 ///
554 /// @param[in] cm - Raw CAN message received
555 ///
556 /// @return VehicleMessage with decoded value.
557 openxc_VehicleMessage diagnostic_manager_t::find_and_decode_adr(const can_message_t& cm)
558 {
559         openxc_VehicleMessage vehicle_message = build_VehicleMessage();
560
561         for ( auto entry : non_recurring_requests_)
562         {
563                 vehicle_message = relay_diagnostic_handle(entry, cm);
564                 if (is_valid(vehicle_message))
565                         return vehicle_message;
566         }
567
568         for ( auto entry : recurring_requests_)
569         {
570                 vehicle_message = relay_diagnostic_handle(entry, cm);
571                 if (is_valid(vehicle_message))
572                         return vehicle_message;
573         }
574
575         return vehicle_message;
576 }
577
578 /// @brief Tell if the CAN message received is a diagnostic response.
579 /// Request broadcast ID use 0x7DF and assigned ID goes from 0x7E0 to Ox7E7. That allows up to 8 ECU to respond 
580 /// at the same time. The response is the assigned ID + 0x8, so response ID can goes from 0x7E8 to 0x7EF.
581 ///
582 /// @param[in] cm - CAN message received from the socket.
583 ///
584 /// @return True if the active diagnostic request match the response.
585 bool diagnostic_manager_t::is_diagnostic_response(const can_message_t& cm)
586 {
587         if (cm.get_id() >= 0x7e8 && cm.get_id() <= 0x7ef)
588                         return true;
589         return false;
590 }