New function used to set timer in bcm_head msg.
authorRomain Forlot <romain.forlot@iot.bzh>
Mon, 15 May 2017 22:26:24 +0000 (00:26 +0200)
committerRomain Forlot <romain.forlot@iot.bzh>
Fri, 19 May 2017 09:36:42 +0000 (11:36 +0200)
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 <romain.forlot@iot.bzh>
CAN-binder/low-can-binding/utils/timer.cpp
CAN-binder/low-can-binding/utils/timer.hpp

index 3bc96a3..8c6215b 100644 (file)
@@ -17,6 +17,7 @@
 
 #include <time.h>
 #include <stdlib.h> 
+#include <cmath>
 
 #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;
index f565904..d3fedbd 100644 (file)
@@ -17,6 +17,8 @@
 
 #pragma once
 
+#include <sys/time.h>
+
 /// @brief return epoch in milliseconds
 ///
 /// @return long long int epoch in milliseconds
@@ -43,6 +45,7 @@ public:
        frequency_clock_t(float frequency, unsigned long last_tick, time_function_t time_function);
 
        float get_frequency() const;
+       const struct timeval get_timeval_from_period() const;
 
        float frequency_to_period();
        bool started();