From c59a57338a488cc451482f1180fe672e7d5c9179 Mon Sep 17 00:00:00 2001 From: Romain Forlot Date: Tue, 16 May 2017 00:26:24 +0200 Subject: New function used to set timer in bcm_head msg. As there will be more bcm socket and more need to set its timer values. May be there is a better method to separate integer and decimal parts from a float value. Change-Id: I0cd992dfde5fe8257b17b5b610482f5f5e09aa8c Signed-off-by: Romain Forlot --- CAN-binder/low-can-binding/utils/timer.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'CAN-binder/low-can-binding/utils/timer.cpp') diff --git a/CAN-binder/low-can-binding/utils/timer.cpp b/CAN-binder/low-can-binding/utils/timer.cpp index 3bc96a3a..8c6215b0 100644 --- a/CAN-binder/low-can-binding/utils/timer.cpp +++ b/CAN-binder/low-can-binding/utils/timer.cpp @@ -17,6 +17,7 @@ #include #include +#include #include "timer.hpp" @@ -65,6 +66,16 @@ float frequency_clock_t::frequency_to_period() return frequency_ == 0 ? 0 : 1 / frequency_ * unit_; } +const struct timeval frequency_clock_t::get_timeval_from_period() const +{ + struct timeval freq = {0, 0}; + float f; + freq.tv_usec = (long int)std::modf(frequency_, &f); + freq.tv_sec = (time_t)f; + + return freq; +} + bool frequency_clock_t::started() { return last_tick_ != 0; -- cgit 1.2.3-korg