Important Update:
- 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
This commit is contained in:
47
TimingCore.h
47
TimingCore.h
@@ -10,20 +10,53 @@
|
||||
|
||||
// Standard C/C++ Libraries
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
#include <limits.h>
|
||||
|
||||
// redA Libraries
|
||||
/* none */
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
// Manage as Interval
|
||||
void SetInterval( timeval *Time, long MilliSeconds );
|
||||
// Set interval (not for timer)
|
||||
inline void SetInterval( timeval * Time, long MilliSeconds ) {
|
||||
Time->tv_sec = MilliSeconds / 1000;
|
||||
Time->tv_usec = (MilliSeconds % 1000) * 1000;
|
||||
};
|
||||
|
||||
// Manage as Timer
|
||||
void SetStartTime( timeval *StartTime );
|
||||
void ClearStartTime( timeval * StartTime );
|
||||
long TimePassed( timeval StartTime );
|
||||
bool Timeout( timeval StartTime, long MilliSeconds );
|
||||
// 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);
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
|
||||
Reference in New Issue
Block a user