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 
57 const FrequencyDiagnostics& FrequencyMonitor::analyse() {
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
ecl::FrequencyDiagnostics::last_incoming
float last_incoming
Definition: frequency.hpp:61
ecl::FrequencyMonitor::last_incoming
ecl::TimeStamp last_incoming
Definition: frequency.hpp:129
ecl::FrequencyMonitor::update
void update()
Let the diagnostics know that new data has arrived.
Definition: lib/frequency.cpp:43
ecl::FrequencyDiagnostics::hz
float hz
Definition: frequency.hpp:57
ecl::FrequencyMonitor::minimum_interval
ecl::TimeStamp minimum_interval
Definition: frequency.hpp:126
ecl::FrequencyDiagnostics::maximum_interval
float maximum_interval
Definition: frequency.hpp:60
ecl::FrequencyDiagnostics::minimum_interval
float minimum_interval
Definition: frequency.hpp:59
frequency.hpp
ecl::FrequencyMonitor::maximum_interval
ecl::TimeStamp maximum_interval
Definition: frequency.hpp:127
ecl::FrequencyMonitor::period
ecl::TimeStamp period
Definition: frequency.hpp:125
ecl::FrequencyMonitor::analyse
const FrequencyDiagnostics & analyse()
Analyse the recent updates to generate monitoring statistics.
Definition: lib/frequency.cpp:61
ecl::FrequencyDiagnostics::has_connection
bool has_connection
Definition: frequency.hpp:56
ecl::FrequencyMonitor::use_realtime_clock
bool use_realtime_clock
Definition: frequency.hpp:128
ecl::FrequencyMonitor::FrequencyMonitor
FrequencyMonitor(const float &window_period=2.0, const bool &use_realtime_clock=false)
Setup the frequency monitor.
Definition: lib/frequency.cpp:24
ecl::FrequencyMonitor::incoming_counter
unsigned int incoming_counter
Definition: frequency.hpp:123
ecl::FrequencyMonitor::last_anyalsed
ecl::TimeStamp last_anyalsed
Definition: frequency.hpp:124
ecl
Embedded control libraries.
ecl::FrequencyMonitor::current_diagnostics
FrequencyDiagnostics current_diagnostics
Definition: frequency.hpp:119


ecl_time
Author(s): Daniel Stonier
autogenerated on Wed Mar 2 2022 00:16:19