2024-12-01 19:35:24 +00:00
|
|
|
//| Copyright: (C) 2020-2024 Kevin Larke <contact AT larke DOT org>
|
|
|
|
//| License: GNU GPL version 3.0 or above. See the accompanying LICENSE file.
|
2019-12-24 15:05:24 +00:00
|
|
|
#include "cwCommon.h"
|
|
|
|
#include "cwLog.h"
|
|
|
|
#include "cwCommonImpl.h"
|
2024-05-29 16:37:53 +00:00
|
|
|
#include "cwTest.h"
|
2019-12-24 15:05:24 +00:00
|
|
|
#include "cwTime.h"
|
|
|
|
|
2020-03-24 12:51:51 +00:00
|
|
|
#ifdef OS_OSX
|
2019-12-24 15:05:24 +00:00
|
|
|
|
|
|
|
#include <mach/mach.h>
|
|
|
|
#include <mach/mach_time.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
void cw::time::get( spec_t& t )
|
|
|
|
{
|
|
|
|
static uint64_t t0 = 0;
|
|
|
|
static mach_timebase_info_data_t tbi;
|
|
|
|
static struct timespec ts;
|
|
|
|
|
|
|
|
if( t0 == 0 )
|
|
|
|
{
|
|
|
|
mach_timebase_info(&tbi);
|
|
|
|
t0 = mach_absolute_time();
|
|
|
|
ts.tv_sec = time(NULL);
|
|
|
|
ts.tv_nsec = 0; // accept 1/2 second error vs. wall-time.
|
|
|
|
}
|
|
|
|
|
|
|
|
// get the current time
|
|
|
|
uint64_t t1 = mach_absolute_time();
|
|
|
|
|
|
|
|
// calc the elapsed time since the last call in nanosecs
|
|
|
|
uint64_t dt = (t1-t0) * tbi.numer / tbi.denom;
|
|
|
|
|
|
|
|
// calc the elapsed time since the first call in secs
|
|
|
|
uint32_t s = (uint32_t)(dt / 2^9);
|
|
|
|
|
|
|
|
// calc the current time in secs, and nanosecs
|
|
|
|
t.tv_sec = ts.tv_sec + s;
|
|
|
|
t.tv_nsec = dt - (s * 2^9);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2020-03-24 12:51:51 +00:00
|
|
|
#ifdef OS_LINUX
|
2023-05-20 01:21:03 +00:00
|
|
|
#include <sys/time.h> // gettimeofday()
|
2019-12-24 15:05:24 +00:00
|
|
|
void cw::time::get( spec_t& t )
|
2022-12-12 17:11:30 +00:00
|
|
|
{
|
2024-02-10 16:49:47 +00:00
|
|
|
clock_gettime(CLOCK_MONOTONIC,&t);
|
|
|
|
}
|
|
|
|
|
|
|
|
cw::time::spec_t cw::time::current_time()
|
|
|
|
{
|
|
|
|
spec_t t;
|
2024-02-24 18:55:44 +00:00
|
|
|
get(t);
|
2024-02-10 16:49:47 +00:00
|
|
|
return t;
|
2022-12-12 17:11:30 +00:00
|
|
|
}
|
2024-02-10 16:49:47 +00:00
|
|
|
|
2019-12-24 15:05:24 +00:00
|
|
|
#endif
|
|
|
|
|
2024-02-24 18:55:44 +00:00
|
|
|
unsigned long long cw::time::elapsedMicros( const spec_t& t0, const spec_t& t1 )
|
2024-03-25 14:50:11 +00:00
|
|
|
{
|
2024-02-24 18:55:44 +00:00
|
|
|
const unsigned long long ns_per_sec = 1000000000;
|
|
|
|
const unsigned long long us_per_sec = 1000000;
|
|
|
|
const unsigned long long ns_per_us = 1000;
|
|
|
|
|
|
|
|
// we assume that the time is normalized
|
2024-03-25 14:50:11 +00:00
|
|
|
assert( t0.tv_nsec < (long long)ns_per_sec );
|
|
|
|
assert( t1.tv_nsec < (long long)ns_per_sec );
|
2024-02-24 18:55:44 +00:00
|
|
|
|
|
|
|
if( t0.tv_sec > t1.tv_sec )
|
|
|
|
{
|
|
|
|
cwLogWarning("Negative elapsed time detected.");
|
|
|
|
spec_t tt0 = t1;
|
|
|
|
spec_t tt1 = t0;
|
|
|
|
return elapsedMicros(tt0,tt1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// t1 does not cross a 'seconds' boundary with t0
|
|
|
|
if( t0.tv_sec == t1.tv_sec )
|
|
|
|
{
|
|
|
|
// then t0 nsecs must be <= t1 nsecs
|
|
|
|
assert( t0.tv_nsec <= t1.tv_nsec );
|
|
|
|
return (t1.tv_nsec - t0.tv_nsec)/ns_per_us;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// t1 occurs in a different second than t0
|
|
|
|
unsigned long long d_sec = (t1.tv_sec - t0.tv_sec) - 1; // difference in seconds
|
|
|
|
unsigned long long d_nsec0 = ns_per_sec - t0.tv_nsec; // time from t0 to next seconds boundary
|
|
|
|
unsigned long long d_nsec1 = t1.tv_nsec; // time from t1 to prev. seconds boundary
|
|
|
|
|
|
|
|
return (d_sec*us_per_sec) + ((d_nsec0 + d_nsec1)/ns_per_us);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
unsigned long long cw::time::elapsedMicros0( const spec_t& t0, const spec_t& t1 )
|
|
|
|
{
|
|
|
|
const unsigned long long us_per_sec = 1000000;
|
|
|
|
const unsigned long long ns_per_us = 1000;
|
|
|
|
|
2019-12-24 15:05:24 +00:00
|
|
|
// convert seconds to usecs
|
2024-02-24 18:55:44 +00:00
|
|
|
unsigned long long u0 = t0.tv_sec * us_per_sec;
|
|
|
|
unsigned long long u1 = t1.tv_sec * us_per_sec;
|
|
|
|
|
2019-12-24 15:05:24 +00:00
|
|
|
|
|
|
|
// convert nanoseconds to usec
|
2024-02-24 18:55:44 +00:00
|
|
|
u0 += t0.tv_nsec / ns_per_us;
|
|
|
|
u1 += t1.tv_nsec / ns_per_us;
|
2019-12-24 15:05:24 +00:00
|
|
|
|
|
|
|
// take diff between t1 and t0
|
|
|
|
return u1 - u0;
|
|
|
|
}
|
2024-02-24 18:55:44 +00:00
|
|
|
*/
|
2019-12-24 15:05:24 +00:00
|
|
|
|
2024-02-24 18:55:44 +00:00
|
|
|
unsigned long long cw::time::elapsedMicros( const spec_t& t0 )
|
2020-09-22 15:37:19 +00:00
|
|
|
{
|
|
|
|
spec_t t1;
|
|
|
|
get(t1);
|
|
|
|
return elapsedMicros(t0,t1);
|
|
|
|
}
|
|
|
|
|
2020-04-17 15:16:21 +00:00
|
|
|
unsigned cw::time::elapsedMs( const spec_t& t0, const spec_t& t1 )
|
2024-02-24 18:55:44 +00:00
|
|
|
{ return (unsigned)(elapsedMicros(t0,t1)/1000); }
|
2020-02-01 15:13:21 +00:00
|
|
|
|
2020-09-22 15:37:19 +00:00
|
|
|
unsigned cw::time::elapsedMs( const spec_t& t0 )
|
|
|
|
{
|
|
|
|
spec_t t1;
|
|
|
|
get(t1);
|
|
|
|
return elapsedMs(t0,t1);
|
|
|
|
}
|
2020-02-01 15:13:21 +00:00
|
|
|
|
2022-03-20 14:18:54 +00:00
|
|
|
double cw::time::elapsedSecs( const spec_t& t0, const spec_t& t1 )
|
|
|
|
{
|
|
|
|
return elapsedMicros(t0,t1) / 1000000.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
double cw::time::elapsedSecs( const spec_t& t0 )
|
|
|
|
{
|
|
|
|
spec_t t1;
|
|
|
|
get(t1);
|
|
|
|
return elapsedSecs(t0,t1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-17 15:16:21 +00:00
|
|
|
unsigned cw::time::absElapsedMicros( const spec_t& t0, const spec_t& t1 )
|
2019-12-24 15:05:24 +00:00
|
|
|
{
|
|
|
|
if( isLTE(t0,t1) )
|
|
|
|
return elapsedMicros(t0,t1);
|
|
|
|
|
|
|
|
return elapsedMicros(t1,t0);
|
|
|
|
}
|
|
|
|
|
2020-04-17 15:16:21 +00:00
|
|
|
int cw::time::diffMicros( const spec_t& t0, const spec_t& t1 )
|
2019-12-24 15:05:24 +00:00
|
|
|
{
|
|
|
|
if( isLTE(t0,t1) )
|
|
|
|
return elapsedMicros(t0,t1);
|
|
|
|
|
|
|
|
return -((int)elapsedMicros(t1,t0));
|
|
|
|
}
|
|
|
|
|
2020-04-17 15:16:21 +00:00
|
|
|
bool cw::time::isLTE( const spec_t& t0, const spec_t& t1 )
|
2019-12-24 15:05:24 +00:00
|
|
|
{
|
2020-04-17 15:16:21 +00:00
|
|
|
if( t0.tv_sec < t1.tv_sec )
|
2019-12-24 15:05:24 +00:00
|
|
|
return true;
|
|
|
|
|
2020-04-17 15:16:21 +00:00
|
|
|
if( t0.tv_sec == t1.tv_sec )
|
|
|
|
return t0.tv_nsec <= t1.tv_nsec;
|
2019-12-24 15:05:24 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-12-12 21:41:03 +00:00
|
|
|
bool cw::time::isLT( const spec_t& t0, const spec_t& t1 )
|
|
|
|
{
|
|
|
|
if( t0.tv_sec < t1.tv_sec )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if( t0.tv_sec == t1.tv_sec )
|
|
|
|
return t0.tv_nsec < t1.tv_nsec;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-04-17 15:16:21 +00:00
|
|
|
bool cw::time::isGTE( const spec_t& t0, const spec_t& t1 )
|
2019-12-24 15:05:24 +00:00
|
|
|
{
|
2020-04-17 15:16:21 +00:00
|
|
|
if( t0.tv_sec > t1.tv_sec )
|
2019-12-24 15:05:24 +00:00
|
|
|
return true;
|
|
|
|
|
2020-04-17 15:16:21 +00:00
|
|
|
if( t0.tv_sec == t1.tv_sec )
|
|
|
|
return t0.tv_nsec >= t1.tv_nsec;
|
2019-12-24 15:05:24 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-12-12 21:41:03 +00:00
|
|
|
bool cw::time::isGT( const spec_t& t0, const spec_t& t1 )
|
|
|
|
{
|
|
|
|
if( t0.tv_sec > t1.tv_sec )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if( t0.tv_sec == t1.tv_sec )
|
|
|
|
return t0.tv_nsec > t1.tv_nsec;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-04-17 15:16:21 +00:00
|
|
|
bool cw::time::isEqual( const spec_t& t0, const spec_t& t1 )
|
|
|
|
{ return t0.tv_sec==t1.tv_sec && t0.tv_nsec==t1.tv_nsec; }
|
2019-12-24 15:05:24 +00:00
|
|
|
|
2020-04-17 15:16:21 +00:00
|
|
|
bool cw::time::isZero( const spec_t& t0 )
|
|
|
|
{ return t0.tv_sec==0 && t0.tv_nsec==0; }
|
2019-12-24 15:05:24 +00:00
|
|
|
|
2020-04-17 15:16:21 +00:00
|
|
|
void cw::time::setZero( spec_t& t0 )
|
2019-12-24 15:05:24 +00:00
|
|
|
{
|
2020-04-17 15:16:21 +00:00
|
|
|
t0.tv_sec = 0;
|
|
|
|
t0.tv_nsec = 0;
|
2019-12-24 15:05:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-04 19:06:27 +00:00
|
|
|
cw::rc_t cw::time::now( spec_t& ts )
|
|
|
|
{
|
|
|
|
rc_t rc = kOkRC;
|
|
|
|
int errRC;
|
|
|
|
|
|
|
|
memset(&ts,0,sizeof(ts));
|
|
|
|
|
2024-02-10 16:49:47 +00:00
|
|
|
if((errRC = clock_gettime(CLOCK_MONOTONIC, &ts)) != 0 )
|
|
|
|
rc = cwLogSysError(kInvalidOpRC,errRC,"Unable to obtain system time.");
|
2020-03-04 19:06:27 +00:00
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2021-10-11 16:22:27 +00:00
|
|
|
void cw::time::subtractMicros( spec_t& ts, unsigned micros )
|
|
|
|
{
|
|
|
|
|
|
|
|
unsigned rem_us = micros % 1000000; // fractional seconds in microseconds
|
|
|
|
unsigned rem_ns = rem_us * 1000; // fractional seconds in nanoseconds
|
|
|
|
|
|
|
|
// if the fractional micros is greater than the fractional nano's
|
|
|
|
if( rem_ns > ts.tv_nsec )
|
|
|
|
{
|
|
|
|
// subtract the fractional nano's from the fractional micros
|
|
|
|
// (this sets the fractional nano's to 0)
|
|
|
|
rem_ns -= ts.tv_nsec;
|
|
|
|
|
|
|
|
// convert the remaining fractional micros to the fractional nano's
|
|
|
|
ts.tv_nsec = 1000000000 - rem_ns;
|
|
|
|
|
|
|
|
// subtract the carry
|
|
|
|
ts.tv_sec -= 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ts.tv_nsec -= rem_ns;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert( ts.tv_sec > micros / 1000000 );
|
|
|
|
|
|
|
|
ts.tv_sec -= micros / 1000000;
|
|
|
|
|
|
|
|
}
|
2020-03-04 19:06:27 +00:00
|
|
|
|
2024-02-14 16:39:23 +00:00
|
|
|
|
2023-01-14 22:15:55 +00:00
|
|
|
void cw::time::advanceMicros( spec_t& ts, unsigned us )
|
|
|
|
{
|
2024-02-14 16:39:23 +00:00
|
|
|
const unsigned ns_per_sec = 1000000000;
|
2023-01-14 22:15:55 +00:00
|
|
|
|
2024-09-13 19:09:56 +00:00
|
|
|
ts.tv_nsec += us * 1000; // convert us to nano's
|
2023-01-14 22:15:55 +00:00
|
|
|
|
2024-09-13 19:09:56 +00:00
|
|
|
// check if nano's now have more than ns_pser_sec
|
|
|
|
time_t sec = ts.tv_nsec / ns_per_sec;
|
2023-01-14 22:15:55 +00:00
|
|
|
|
2024-02-14 16:39:23 +00:00
|
|
|
ts.tv_sec += sec;
|
|
|
|
ts.tv_nsec -= sec * ns_per_sec;
|
2023-01-14 22:15:55 +00:00
|
|
|
}
|
|
|
|
|
2024-02-14 16:39:23 +00:00
|
|
|
|
|
|
|
|
2020-03-04 19:06:27 +00:00
|
|
|
void cw::time::advanceMs( spec_t& ts, unsigned ms )
|
|
|
|
{
|
|
|
|
|
2024-02-14 16:39:23 +00:00
|
|
|
const unsigned ns_per_sec = 1000000000;
|
2024-09-13 19:09:56 +00:00
|
|
|
|
|
|
|
ts.tv_nsec += ms * 1000000;
|
|
|
|
time_t sec = ts.tv_nsec / ns_per_sec;
|
2024-02-14 16:39:23 +00:00
|
|
|
|
|
|
|
ts.tv_sec += sec;
|
|
|
|
ts.tv_nsec -= sec * ns_per_sec;
|
2024-09-13 19:09:56 +00:00
|
|
|
|
2020-03-04 19:06:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cw::rc_t cw::time::futureMs( spec_t& ts, unsigned ms )
|
|
|
|
{
|
|
|
|
rc_t rc;
|
|
|
|
if((rc = now(ts)) == kOkRC )
|
|
|
|
advanceMs(ts,ms);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
2020-04-17 17:28:09 +00:00
|
|
|
|
2024-11-08 16:09:43 +00:00
|
|
|
void cw::time::fracSecondsToSpec( spec_t& ts, double sec )
|
|
|
|
{
|
|
|
|
const unsigned long long ns_per_sec = 1000000000;
|
|
|
|
ts.tv_sec = (unsigned long long)sec;
|
|
|
|
ts.tv_nsec = (sec - ts.tv_sec) * ns_per_sec;
|
|
|
|
}
|
|
|
|
|
2021-10-11 16:22:27 +00:00
|
|
|
void cw::time::secondsToSpec( spec_t& ts, unsigned sec )
|
|
|
|
{
|
|
|
|
ts.tv_sec = sec;
|
|
|
|
ts.tv_nsec = 0;
|
|
|
|
}
|
|
|
|
|
2023-05-01 01:16:14 +00:00
|
|
|
double cw::time::specToSeconds( const spec_t& t )
|
|
|
|
{
|
2024-11-08 16:09:43 +00:00
|
|
|
const long long ns_per_sec = 1000000000;
|
2024-02-14 16:39:23 +00:00
|
|
|
spec_t ts = t;
|
2023-05-01 01:16:14 +00:00
|
|
|
double sec = ts.tv_sec;
|
2024-11-08 16:09:43 +00:00
|
|
|
while( ts.tv_nsec >= ns_per_sec )
|
2023-05-01 01:16:14 +00:00
|
|
|
{
|
|
|
|
sec += 1.0;
|
2024-11-08 16:09:43 +00:00
|
|
|
ts.tv_nsec -= ns_per_sec;
|
2023-05-01 01:16:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return sec + ((double)ts.tv_nsec)/1e9;
|
|
|
|
}
|
|
|
|
|
2024-02-14 16:39:23 +00:00
|
|
|
unsigned long long cw::time::specToMicroseconds( const spec_t& ts )
|
|
|
|
{
|
|
|
|
const unsigned long long us_per_sec = 1000000;
|
|
|
|
const unsigned long long ns_per_sec = 1000000000;
|
|
|
|
|
|
|
|
unsigned long long us = ts.tv_sec * us_per_sec;
|
|
|
|
unsigned long long sec = ts.tv_nsec / ns_per_sec;
|
|
|
|
us += sec * us_per_sec;
|
|
|
|
us += (ts.tv_nsec - (sec * ns_per_sec))/1000;
|
|
|
|
|
|
|
|
return us;
|
|
|
|
}
|
|
|
|
|
2023-05-01 01:16:14 +00:00
|
|
|
|
2021-10-11 16:22:27 +00:00
|
|
|
void cw::time::millisecondsToSpec( spec_t& ts, unsigned ms )
|
|
|
|
{
|
|
|
|
unsigned sec = ms/1000;
|
|
|
|
unsigned ns = (ms - (sec*1000)) * 1000000;
|
|
|
|
|
|
|
|
ts.tv_sec = sec;
|
|
|
|
ts.tv_nsec = ns;
|
|
|
|
}
|
|
|
|
|
2024-02-14 16:39:23 +00:00
|
|
|
void cw::time::microsecondsToSpec( spec_t& ts, unsigned long long us )
|
2021-10-11 16:22:27 +00:00
|
|
|
{
|
2024-02-14 16:39:23 +00:00
|
|
|
const unsigned long long usPerSec = 1000000;
|
|
|
|
unsigned long long sec = us/usPerSec;
|
|
|
|
unsigned long long ns = (us - (sec*usPerSec)) * 1000;
|
2021-10-11 16:22:27 +00:00
|
|
|
|
|
|
|
ts.tv_sec = sec;
|
|
|
|
ts.tv_nsec = ns;
|
|
|
|
}
|
2020-04-17 17:28:09 +00:00
|
|
|
|
2024-02-14 16:39:23 +00:00
|
|
|
cw::time::spec_t cw::time::microsecondsToSpec( unsigned long long us )
|
|
|
|
{
|
|
|
|
spec_t ts;
|
|
|
|
microsecondsToSpec(ts,us);
|
|
|
|
return ts;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-05-20 01:21:03 +00:00
|
|
|
|
|
|
|
unsigned cw::time::formatDateTime( char* buffer, unsigned bufN, bool includeDateFl )
|
|
|
|
{
|
|
|
|
// from here: https://stackoverflow.com/questions/3673226/how-to-print-time-in-format-2009-08-10-181754-811
|
|
|
|
int millisec;
|
|
|
|
struct tm* tm_info;
|
|
|
|
struct timeval tv;
|
|
|
|
int n = 0;
|
|
|
|
|
|
|
|
gettimeofday(&tv, NULL);
|
|
|
|
|
|
|
|
millisec = lrint(tv.tv_usec/1000.0); // Round to nearest millisec
|
|
|
|
|
|
|
|
// Allow for rounding up to nearest second
|
|
|
|
if (millisec>=1000)
|
|
|
|
{
|
|
|
|
millisec -=1000;
|
|
|
|
tv.tv_sec++;
|
|
|
|
}
|
|
|
|
|
|
|
|
tm_info = localtime(&tv.tv_sec);
|
|
|
|
|
|
|
|
const char* fmt = "%H:%M:%S";
|
|
|
|
|
|
|
|
if( includeDateFl )
|
|
|
|
fmt = "%Y:%m:%d %H:%M:%S";
|
|
|
|
|
|
|
|
|
|
|
|
n = strftime(buffer, bufN, fmt, tm_info);
|
|
|
|
|
|
|
|
if( n < (int)bufN && bufN-n >= 5 )
|
|
|
|
n = snprintf(buffer + n, bufN-n,".%03d", millisec);
|
|
|
|
|
|
|
|
return (unsigned)n;
|
|
|
|
}
|
|
|
|
|
2024-05-29 16:37:53 +00:00
|
|
|
cw::rc_t cw::time::test(const test::test_args_t& test )
|
2020-04-17 17:28:09 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
spec_t t0,t1;
|
|
|
|
|
|
|
|
get(t0);
|
|
|
|
|
|
|
|
futureMs(t1,1000);
|
|
|
|
|
|
|
|
unsigned dMs = elapsedMs(t0,t1);
|
|
|
|
|
2024-05-29 16:37:53 +00:00
|
|
|
cwLogPrint("dMs:%i : GTE:%i LTE:%i\n",dMs, isGTE(t0,t1), isLTE(t0,t1) );
|
2020-04-17 17:28:09 +00:00
|
|
|
|
2021-10-11 16:22:27 +00:00
|
|
|
|
|
|
|
microsecondsToSpec( t0, 2500000 ); // 2.5 seconds
|
2024-05-29 16:37:53 +00:00
|
|
|
cwLogPrint("%li %li\n",t0.tv_sec,t0.tv_nsec);
|
2021-10-11 16:22:27 +00:00
|
|
|
subtractMicros( t0, 750000 ); // subtract .75 seconds
|
2024-05-29 16:37:53 +00:00
|
|
|
cwLogPrint("%li %li\n",t0.tv_sec,t0.tv_nsec);
|
2021-10-11 16:22:27 +00:00
|
|
|
subtractMicros( t0, 500000 ); // subtract .5 seconds
|
2024-05-29 16:37:53 +00:00
|
|
|
cwLogPrint("%li %li\n",t0.tv_sec,t0.tv_nsec);
|
2021-10-11 16:22:27 +00:00
|
|
|
|
2023-06-27 21:27:15 +00:00
|
|
|
|
|
|
|
time::get(t0);
|
|
|
|
//time::get(t1);
|
|
|
|
t1 = t0;
|
|
|
|
|
|
|
|
advanceMicros(t1,5000);
|
2021-10-11 16:22:27 +00:00
|
|
|
|
2023-06-27 21:27:15 +00:00
|
|
|
int usec = time::elapsedMicros(t0,t1);
|
|
|
|
|
2024-05-29 16:37:53 +00:00
|
|
|
cwLogPrint("usec:%i\n",usec);
|
2023-06-27 21:27:15 +00:00
|
|
|
|
2024-02-24 18:55:44 +00:00
|
|
|
t0 = current_time();
|
|
|
|
sleepMs(1000);
|
2024-05-29 16:37:53 +00:00
|
|
|
cwLogPrint("sleep %i ms\n",elapsedMs(t0));
|
2023-06-27 21:27:15 +00:00
|
|
|
|
2021-10-11 16:22:27 +00:00
|
|
|
|
2024-11-08 16:16:31 +00:00
|
|
|
|
|
|
|
cw::time::fracSecondsToSpec( t0, 12.34567 );
|
|
|
|
double sec = specToSeconds( t0 );
|
|
|
|
cwLogPrint("fsecs: %f\n",sec);
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-04-17 17:28:09 +00:00
|
|
|
return kOkRC;
|
|
|
|
|
|
|
|
}
|
2021-10-11 16:22:27 +00:00
|
|
|
|
|
|
|
|