X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=server%2Factuator.c;h=1c105db01a15f0a3b189a2fac47b183bc6c6deef;hb=544b54c409f3731b8e1581af95072a64ff393a28;hp=2be41941eb538741a9b77b6127f38b65dbcd892e;hpb=cf4f872e4a4d739408bd2f0d71887d27ebe598c9;p=matches%2FMCTX3420.git diff --git a/server/actuator.c b/server/actuator.c index 2be4194..1c105db 100644 --- a/server/actuator.c +++ b/server/actuator.c @@ -171,9 +171,12 @@ void * Actuator_Loop(void * arg) Actuator_SetValue(a, a->control.start, true); // Currently does discrete steps after specified time intervals + + struct timespec wait; + DOUBLE_TO_TIMEVAL(a->control.stepsize, &wait); while (!a->control_changed && a->control.steps > 0 && a->activated) { - usleep(1e6*(a->control.stepwait)); + clock_nanosleep(CLOCK_MONOTONIC, 0, &wait, NULL); a->control.start += a->control.stepsize; Actuator_SetValue(a, a->control.start, true); @@ -181,7 +184,7 @@ void * Actuator_Loop(void * arg) } if (a->control_changed) continue; - usleep(1e6*(a->control.stepwait)); + clock_nanosleep(CLOCK_MONOTONIC, 0, &wait, NULL); //TODO: // Note that although this loop has a sleep in it which would seem to make it hard to enforce urgent shutdowns, @@ -231,8 +234,8 @@ void Actuator_SetValue(Actuator * a, double value, bool record) } // Set time stamp - struct timeval t; - gettimeofday(&t, NULL); + struct timespec t; + clock_gettime(CLOCK_MONOTONIC, &t); DataPoint d = {TIMEVAL_DIFF(t, *Control_GetStartTime()), a->last_setting.value}; // Record value change if (record) @@ -296,8 +299,8 @@ void Actuator_EndResponse(FCGIContext * context, Actuator * a, DataFormat format */ void Actuator_Handler(FCGIContext * context, char * params) { - struct timeval now; - gettimeofday(&now, NULL); + struct timespec now; + clock_gettime(CLOCK_MONOTONIC, &now); double current_time = TIMEVAL_DIFF(now, *Control_GetStartTime()); int id = 0; char * name = "";