frequency.cpp
Go to the documentation of this file.
00001 
00004 /*****************************************************************************
00005 ** Includes
00006 *****************************************************************************/
00007 
00008 #include <ecl/time/frequency.hpp>
00009 
00010 /*****************************************************************************
00011 ** Namespaces
00012 *****************************************************************************/
00013 
00014 namespace ecl {
00015 
00016 /*****************************************************************************
00017 ** Implementation
00018 *****************************************************************************/
00019 
00020 FrequencyMonitor::FrequencyMonitor(
00021     const float& window_period,
00022     const bool& use_realtime_clock
00023 )
00024 : current_diagnostics()
00025 , incoming_counter(0)
00026 , last_anyalsed()
00027 , minimum_interval(100000.0) // something ridiculously large so the next interval will fall underneath it
00028 , maximum_interval(0.0)
00029 , period(window_period)
00030 , use_realtime_clock(use_realtime_clock)
00031 #if defined(ECL_HAS_RT_TIMERS)
00032 , last_incoming((use_realtime_clock) ? ecl::TimeStamp::realtime_now() : ecl::TimeStamp())
00033 #else
00034 , last_incoming(ecl::TimeStamp())
00035 #endif
00036 {
00037 }
00038 
00039 void FrequencyMonitor::update() {
00040   current_diagnostics.has_connection = true;
00041   incoming_counter++;
00042 #if defined(ECL_HAS_RT_TIMERS)
00043   ecl::TimeStamp new_incoming = (use_realtime_clock) ? ecl::TimeStamp::realtime_now() : ecl::TimeStamp();
00044 #else
00045   ecl::TimeStamp new_incoming = ecl::TimeStamp();
00046 #endif
00047   ecl::TimeStamp time_since_last = new_incoming - last_incoming;
00048   if ( time_since_last < minimum_interval ) {
00049     minimum_interval = time_since_last;
00050   }
00051   if ( time_since_last > maximum_interval ) {
00052     maximum_interval = time_since_last;
00053   }
00054   last_incoming = new_incoming;
00055 }
00056 
00057 const FrequencyDiagnostics& FrequencyMonitor::analyse() {
00058 #if defined(ECL_HAS_RT_TIMERS)
00059   ecl::TimeStamp now = ecl::TimeStamp::realtime_now();
00060 #else
00061   ecl::TimeStamp now = ecl::TimeStamp();
00062 #endif 
00063   ecl::TimeStamp interval = now - last_anyalsed;
00064 
00066   if( interval > period )
00067   {
00068     last_anyalsed = now;
00069     if (incoming_counter == 0 ) {
00070       current_diagnostics.has_connection = false;
00071       current_diagnostics.minimum_interval = ecl::TimeStamp(0.0);
00072       current_diagnostics.maximum_interval = ecl::TimeStamp(0.0);
00073       current_diagnostics.hz = 0.0;
00074     } else {
00075       current_diagnostics.has_connection = true;
00076       current_diagnostics.minimum_interval = minimum_interval;
00077       current_diagnostics.maximum_interval = maximum_interval;
00078       current_diagnostics.hz = static_cast<float>(incoming_counter) / interval;
00079 
00080       // clear temporary variables
00081       incoming_counter = 0;
00082       minimum_interval = ecl::TimeStamp(100000.0); // something ridiculously large so the next interval will fall underneath it
00083       maximum_interval = ecl::TimeStamp(0.0);
00084     }
00085   }
00086   // always update this one
00087   current_diagnostics.last_incoming = last_incoming;
00088   return current_diagnostics;
00089 }
00090 
00091 /*****************************************************************************
00092  ** Trailers
00093  *****************************************************************************/
00094 
00095 } // namespace ecl


ecl_time
Author(s): Daniel Stonier
autogenerated on Mon Jul 3 2017 02:21:18