change system time function to UNIX time

This commit is contained in:
2025-11-01 14:59:37 +03:00
parent a7fbae47f0
commit 683da9739d
15 changed files with 98 additions and 52 deletions

View File

@@ -51,17 +51,18 @@ static mcc_errcodes_t shortcmd(short_command_t *cmd);
* @return time in seconds
*/
double nanotime(){
static struct timespec *start = NULL;
//static struct timespec *start = NULL;
struct timespec now;
if(!start){
/*if(!start){
start = malloc(sizeof(struct timespec));
if(!start) return -1.;
if(clock_gettime(CLOCK_MONOTONIC, start)) return -1.;
}
}*/
if(clock_gettime(CLOCK_MONOTONIC, &now)) return -1.;
double nd = ((double)now.tv_nsec - (double)start->tv_nsec) * 1e-9;
/*double nd = ((double)now.tv_nsec - (double)start->tv_nsec) * 1e-9;
double sd = (double)now.tv_sec - (double)start->tv_sec;
return sd + nd;
return sd + nd;*/
return (double)now.tv_sec + (double)now.tv_nsec * 1e-9;
}
/**
@@ -75,7 +76,7 @@ static void quit(){
DBG("Exit");
}
void getModData(coordval_pair_t *c){
void getModData(coordval_pair_t *c, movestate_t *xst, movestate_t *yst){
if(!c || !Xmodel || !Ymodel) return;
double tnow = nanotime();
moveparam_t Xp, Yp;
@@ -87,6 +88,8 @@ void getModData(coordval_pair_t *c){
c->X.t = c->Y.t = tnow;
c->X.val = Xp.coord;
c->Y.val = Yp.coord;
if(xst) *xst = Xst;
if(yst) *yst = Yst;
}
/**