lib/frequency.cpp
Go to the documentation of this file.
1 
4 /*****************************************************************************
5 ** Includes
6 *****************************************************************************/
7 
8 #include <ecl/time/frequency.hpp>
9 
10 /*****************************************************************************
11 ** Namespaces
12 *****************************************************************************/
13 
14 namespace ecl {
15 
16 /*****************************************************************************
17 ** Implementation
18 *****************************************************************************/
19 
21  const float& window_period,
22  const bool& use_realtime_clock
23 )
24 : current_diagnostics()
25 , incoming_counter(0)
26 , last_anyalsed()
27 , minimum_interval(100000.0) // something ridiculously large so the next interval will fall underneath it
28 , maximum_interval(0.0)
29 , period(window_period)
30 , use_realtime_clock(use_realtime_clock)
31 #if defined(ECL_HAS_RT_TIMERS)
32 , last_incoming((use_realtime_clock) ? ecl::TimeStamp::realtime_now() : ecl::TimeStamp())
33 #else
34 , last_incoming(ecl::TimeStamp())
35 #endif
36 {
37 }
38 
42 #if defined(ECL_HAS_RT_TIMERS)
43  ecl::TimeStamp new_incoming = (use_realtime_clock) ? ecl::TimeStamp::realtime_now() : ecl::TimeStamp();
44 #else
45  ecl::TimeStamp new_incoming = ecl::TimeStamp();
46 #endif
47  ecl::TimeStamp time_since_last = new_incoming - last_incoming;
48  if ( time_since_last < minimum_interval ) {
49  minimum_interval = time_since_last;
50  }
51  if ( time_since_last > maximum_interval ) {
52  maximum_interval = time_since_last;
53  }
54  last_incoming = new_incoming;
55 }
56 
58 #if defined(ECL_HAS_RT_TIMERS)
59  ecl::TimeStamp now = ecl::TimeStamp::realtime_now();
60 #else
61  ecl::TimeStamp now = ecl::TimeStamp();
62 #endif
63  ecl::TimeStamp interval = now - last_anyalsed;
64 
66  if( interval > period )
67  {
68  last_anyalsed = now;
69  if (incoming_counter == 0 ) {
71  current_diagnostics.minimum_interval = ecl::TimeStamp(0.0);
72  current_diagnostics.maximum_interval = ecl::TimeStamp(0.0);
73  current_diagnostics.hz = 0.0;
74  } else {
78  current_diagnostics.hz = static_cast<float>(incoming_counter) / interval;
79 
80  // clear temporary variables
81  incoming_counter = 0;
82  minimum_interval = ecl::TimeStamp(100000.0); // something ridiculously large so the next interval will fall underneath it
83  maximum_interval = ecl::TimeStamp(0.0);
84  }
85  }
86  // always update this one
88  return current_diagnostics;
89 }
90 
91 /*****************************************************************************
92  ** Trailers
93  *****************************************************************************/
94 
95 } // namespace ecl
FrequencyDiagnostics current_diagnostics
Definition: frequency.hpp:113
ecl::TimeStamp last_incoming
Definition: frequency.hpp:123
Embedded control libraries.
Data relevant to frequencies of an incoming stream.
Definition: frequency.hpp:31
void update()
Let the diagnostics know that new data has arrived.
ecl::TimeStamp minimum_interval
Definition: frequency.hpp:120
ecl::TimeStamp maximum_interval
Definition: frequency.hpp:121
const FrequencyDiagnostics & analyse()
Analyse the recent updates to generate monitoring statistics.
ecl::TimeStamp period
Definition: frequency.hpp:119
ecl::TimeStamp last_anyalsed
Definition: frequency.hpp:118
FrequencyMonitor(const float &window_period=2.0, const bool &use_realtime_clock=false)
Setup the frequency monitor.
unsigned int incoming_counter
Definition: frequency.hpp:117


ecl_time
Author(s): Daniel Stonier
autogenerated on Mon Jun 10 2019 13:08:15