diff options
author | Romain Forlot <romain.forlot@iot.bzh> | 2017-03-16 17:20:42 +0100 |
---|---|---|
committer | Romain Forlot <romain.forlot@iot.bzh> | 2017-03-16 17:20:42 +0100 |
commit | 76df856e0df1b67770038e657f526f915c11a140 (patch) | |
tree | 413bb8405bc9a1abe0a0a029eaf483682347dc23 /src/diagnostic/diagnostic-manager.cpp | |
parent | 6cdc94206f3c0cc60dca5ed024619b78dff01a64 (diff) |
Implement regular event launching using systemd event loop
Regular events is made launch a timerfd event from binder event loop and then
in the event handler, reschedule next launch in the future based upon the
signal frequency.
Change-Id: I0b1e84eb2135474f4bcc5ee256ba513eea4035a6
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'src/diagnostic/diagnostic-manager.cpp')
-rw-r--r-- | src/diagnostic/diagnostic-manager.cpp | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/src/diagnostic/diagnostic-manager.cpp b/src/diagnostic/diagnostic-manager.cpp index 482a88f..e7293ca 100644 --- a/src/diagnostic/diagnostic-manager.cpp +++ b/src/diagnostic/diagnostic-manager.cpp @@ -27,6 +27,7 @@ #define MAX_RECURRING_DIAGNOSTIC_FREQUENCY_HZ 10 #define MAX_SIMULTANEOUS_DIAG_REQUESTS 50 #define MAX_REQUEST_ENTRIES 50 +#define TIMERFD_ACCURACY 0 #define MICRO 1000000 diagnostic_manager_t::diagnostic_manager_t() @@ -250,18 +251,11 @@ bool diagnostic_manager_t::add_recurring_request(DiagnosticRequest* request, con DEBUG(binder_interface, "Added recurring diagnostic request (freq: %f) on bus %s: %s", frequencyHz, bus_->get_device_name().c_str(), request_string); + uint64_t usec; + usec = sd_event_now(afb_daemon_get_event_loop(binder_interface->daemon), CLOCK_MONOTONIC, &usec) + (uint64_t)(frequency_clock_t::frequency_to_period(frequencyHz)*MICRO); if(sd_event_add_time(afb_daemon_get_event_loop(binder_interface->daemon), &source, - CLOCK_MONOTONIC, (uint64_t)frequencyHz*MICRO, 0,send_request, request) >= 0) - { - if(sd_event_source_set_enabled(source, SD_EVENT_ON) >= 0) - recurring_requests_.push_back(entry); - else - { - ERROR(binder_interface, "add_reccurring_request: Request has not been enabled, it will occurs only one time"); - free_request_entries_.push_back(entry); - added = false; - } - } + CLOCK_MONOTONIC, usec, TIMERFD_ACCURACY, send_request, request) >= 0) + recurring_requests_.push_back(entry); else { ERROR(binder_interface, "add_recurring_request: Request fails to be schedule through event loop"); @@ -385,7 +379,18 @@ int diagnostic_manager_t::send_request(sd_event_source *s, uint64_t usec, void * adr->get_timeout_clock().tick(); adr->set_in_flight(true); return 1; + + usec = usec + (uint64_t)(frequency_clock_t::frequency_to_period(adr->get_frequency_clock().get_frequency())*MICRO); + DEBUG(binder_interface, "send_request: usec: %d", usec); + if(sd_event_source_set_time(s, usec) >= 0) + if(sd_event_source_set_enabled(s, SD_EVENT_ON) >= 0) + { + dm.recurring_requests_.push_back(adr); + return 1; + } } + dm.recurring_requests_.push_back(adr); + ERROR(binder_interface, "send_request: Something goes wrong when submitting a new request to the CAN bus"); return -1; } |