Commit 5d55d255 authored by baujc's avatar baujc

New tool: monotonicClock

This tool is used to follow the value of a monotonic clock to check if
it does not does big jumps. This jumps may affect the precision of the
timeout in PPSi. They can occur when the nanosecond adjustement is done
in the servo (WR & HA profiles).
parent c2daba1f
#include <inttypes.h>
#include <limits.h>
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#include <float.h>
#include <math.h>
static unsigned long unix_calc_timeout(void)
{
struct timespec now;
uint64_t now_ms;
clock_gettime(CLOCK_MONOTONIC, &now);
now_ms = 1000LL * now.tv_sec + now.tv_nsec / 1000 / 1000;
return now_ms;
}
int main(int argc, char **argv) {
static long lastMs=0;
char text[128]={0};
while (1) {
long ms;
long diff;
ms=unix_calc_timeout();
if ( lastMs==0)
lastMs=ms;
else
lastMs+=1000;
diff=lastMs-ms;
if (abs(diff) > 100 ) {
printf("%s",text);
printf("%ld.%ld %ld\n",ms/1000, ms%1000, lastMs-ms);
}
sprintf(text,"%ld.%ld %ld\n",ms/1000, ms%1000, lastMs-ms);
lastMs=ms;
sleep(1);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment