summaryrefslogtreecommitdiffstats
path: root/src/diagnostic/diagnostic-manager.cpp
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-03-22 16:40:15 +0000
committerRomain Forlot <romain.forlot@iot.bzh>2017-03-23 14:42:43 +0100
commit156b8f9c39a81cbbad7c32dbebdf321787611779 (patch)
treef089611edaeaf62b75310d18db7464c06ef14af5 /src/diagnostic/diagnostic-manager.cpp
parentfe8235f257a009c911c63238885a47e0c3633293 (diff)
Send diag request only if not other one with some id running
Fix: elapsed function return that do not compute elapsed_time at first time Fix: reworked should_send() to get it work with our scheduling workflow Reschedule trying to send request if recurring even it is in flight. Change-Id: Idce54cb9bf62616c891a8a25a6c478f931350bc7 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'src/diagnostic/diagnostic-manager.cpp')
-rw-r--r--src/diagnostic/diagnostic-manager.cpp38
1 files changed, 19 insertions, 19 deletions
diff --git a/src/diagnostic/diagnostic-manager.cpp b/src/diagnostic/diagnostic-manager.cpp
index cf84ecc..151c78e 100644
--- a/src/diagnostic/diagnostic-manager.cpp
+++ b/src/diagnostic/diagnostic-manager.cpp
@@ -426,6 +426,17 @@ bool diagnostic_manager_t::clear_to_send(active_diagnostic_request_t* request) c
return true;
}
+int diagnostic_manager_t::reschedule_request(sd_event_source *s, uint64_t usec, active_diagnostic_request_t* adr)
+{
+ usec = usec + (uint64_t)(frequency_clock_t::frequency_to_period(adr->get_frequency_clock().get_frequency())*MICRO);
+ DEBUG(binder_interface, "send_request: Event loop state: %d. usec: %ld", sd_event_get_state(afb_daemon_get_event_loop(binder_interface->daemon)), usec);
+ if(sd_event_source_set_time(s, usec) >= 0)
+ if(sd_event_source_set_enabled(s, SD_EVENT_ON) >= 0)
+ return 0;
+ sd_event_source_unref(s);
+ return -1;
+}
+
/// @brief Systemd timer event callback use to send CAN messages at regular interval. Depending
/// on the diagnostic message frequency.
///
@@ -443,38 +454,27 @@ int diagnostic_manager_t::send_request(sd_event_source *s, uint64_t usec, void *
DiagnosticRequest* request = (DiagnosticRequest*)userdata;
active_diagnostic_request_t* adr = dm.find_recurring_request(request);
-// if(adr != nullptr && adr->get_can_bus_dev() == dm.get_can_bus_dev() && adr->should_send() &&
-// dm.clear_to_send(adr))
- if(adr != nullptr && adr->get_can_bus_dev() == dm.get_can_bus_dev())
+ if(adr != nullptr && adr->get_can_bus_dev() == dm.get_can_bus_dev() && adr->should_send() &&
+ dm.clear_to_send(adr))
{
adr->get_frequency_clock().tick();
start_diagnostic_request(&dm.shims_, adr->get_handle());
- if(adr->get_handle()->completed)
+ if(adr->get_handle()->completed && !adr->get_handle()->success)
{
- if(!adr->get_handle()->success)
- {
ERROR(binder_interface, "send_request: Fatal error sending diagnostic request");
sd_event_source_unref(s);
return -1;
- }
}
- else
- WARNING(binder_interface, "send_request: There was a problem sending your request using bus %s.", adr->get_can_bus_dev()->get_device_name().c_str());
adr->get_timeout_clock().tick();
adr->set_in_flight(true);
+ }
- if(adr->get_recurring())
- {
- usec = usec + (uint64_t)(frequency_clock_t::frequency_to_period(adr->get_frequency_clock().get_frequency())*MICRO);
- DEBUG(binder_interface, "send_request: Event loop state: %d. usec: %ld", sd_event_get_state(afb_daemon_get_event_loop(binder_interface->daemon)), usec);
- if(sd_event_source_set_time(s, usec) >= 0)
- if(sd_event_source_set_enabled(s, SD_EVENT_ON) >= 0)
- return 0;
- sd_event_source_unref(s);
- return -1;
- }
+ if(adr->get_recurring())
+ {
+ return dm.reschedule_request(s, usec, adr);
}
+
sd_event_source_unref(s);
ERROR(binder_interface, "send_request: Something goes wrong when submitting a new request to the CAN bus");
return -2;