- SelectableCore: - Split handling of Handle from Input() to InputHandle() method - Allow multiple handles to be connected to single Channel - Update logs to report Handle, not Channel name - TimingCore: - Convert all functions to inline functions in header (remove .cpp file) - Add new function TimeLeft() - WatchdogCore: - Bug fix: No watchdog channel, use InputHandle() method not Input() - Bug fix: ping ignored, use To:"watchdog" in ping command
64 lines
1.6 KiB
C
64 lines
1.6 KiB
C
/*
|
|
* TimingCore.h
|
|
*
|
|
* Created on: 13 May 2016
|
|
* Author: wentzelc
|
|
*/
|
|
|
|
#ifndef REDACORE_TIMINGCORE_H_
|
|
#define REDACORE_TIMINGCORE_H_
|
|
|
|
// Standard C/C++ Libraries
|
|
#include <sys/time.h>
|
|
#include <time.h>
|
|
#include <limits.h>
|
|
|
|
// redA Libraries
|
|
/* none */
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
// Set interval (not for timer)
|
|
inline void SetInterval( timeval * Time, long MilliSeconds ) {
|
|
Time->tv_sec = MilliSeconds / 1000;
|
|
Time->tv_usec = (MilliSeconds % 1000) * 1000;
|
|
};
|
|
|
|
// Mark start time
|
|
inline void SetStartTime( timeval *StartTime ) {
|
|
gettimeofday( StartTime, NULL );
|
|
};
|
|
|
|
// Clear timer
|
|
inline void ClearStartTime( timeval * StartTime ) {
|
|
StartTime->tv_sec = 0;
|
|
StartTime->tv_usec = 0;
|
|
};
|
|
|
|
// Time passed since start time
|
|
inline long TimePassed( timeval StartTime ) {
|
|
timeval CurrTime;
|
|
long Duration;
|
|
|
|
gettimeofday( &CurrTime, NULL );
|
|
Duration = (CurrTime.tv_sec - StartTime.tv_sec) * (time_t)1000 +
|
|
(CurrTime.tv_usec - StartTime.tv_usec) / (time_t)1000;
|
|
if (Duration < 0)
|
|
Duration = LONG_MAX;
|
|
return Duration;
|
|
};
|
|
|
|
// Time remaining from Start time to given time out
|
|
inline long TimeLeft( timeval StartTime, long MilliSeconds ) {
|
|
return (MilliSeconds - TimePassed(StartTime));
|
|
};
|
|
|
|
// Has give time expired after start time
|
|
inline bool Timeout( timeval StartTime, long MilliSeconds ) {
|
|
return ((TimePassed(StartTime) > MilliSeconds)? true : false);
|
|
};
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
#endif /* REDACORE_TIMINGCORE_H_ */
|